From 75dd558bdaff030688d483e1a2bd51d38c55ab49 Mon Sep 17 00:00:00 2001 From: "Li, Xun" Date: Thu, 10 May 2018 11:05:38 +0800 Subject: [PATCH] Linux 2.1.3 Open Source Gold Release Security updates to Linux SDK and PSW Support for Intel SGX Protected Code Loader Signed-off-by: Li, Xun --- .../com.intel.sgx.feature/feature.xml | 18 +- .../Images/Enclave_Configuration_Settings.png | Bin 37159 -> 50249 bytes .../com.intel.sgx.userguide/html/content.html | 2 +- Linux_SGXEclipsePlugin/clean.sh | 2 +- Linux_SGXEclipsePlugin/readme.txt | 4 +- SampleCode/SampleEnclavePCL/App/App.cpp | 367 + SampleCode/SampleEnclavePCL/App/App.h | 77 + .../App/Edger8rSyntax/Arrays.cpp | 92 + .../App/Edger8rSyntax/Functions.cpp | 72 + .../App/Edger8rSyntax/Pointers.cpp | 141 + .../App/Edger8rSyntax/Types.cpp | 77 + .../App/TrustedLibrary/Libc.cpp | 51 + .../App/TrustedLibrary/Libcxx.cpp | 51 + .../App/TrustedLibrary/Thread.cpp | 98 + .../Enclave/Edger8rSyntax/Arrays.cpp | 102 + .../Enclave/Edger8rSyntax/Arrays.edl | 98 + .../Enclave/Edger8rSyntax/Functions.cpp | 84 + .../Enclave/Edger8rSyntax/Functions.edl | 88 + .../Enclave/Edger8rSyntax/Pointers.cpp | 197 + .../Enclave/Edger8rSyntax/Pointers.edl | 180 + .../Enclave/Edger8rSyntax/Types.cpp | 155 + .../Enclave/Edger8rSyntax/Types.edl | 87 + .../Enclave/Enclave.config.xml | 12 + .../SampleEnclavePCL/Enclave/Enclave.cpp | 51 + .../SampleEnclavePCL/Enclave/Enclave.edl | 62 + SampleCode/SampleEnclavePCL/Enclave/Enclave.h | 49 + .../SampleEnclavePCL/Enclave/Enclave.lds | 10 + .../Enclave/Enclave_private.pem | 39 + .../Enclave/TrustedLibrary/Libc.cpp | 59 + .../Enclave/TrustedLibrary/Libc.edl | 55 + .../Enclave/TrustedLibrary/Libcxx.cpp | 89 + .../Enclave/TrustedLibrary/Libcxx.edl | 52 + .../Enclave/TrustedLibrary/Thread.cpp | 104 + .../Enclave/TrustedLibrary/Thread.edl | 51 + .../SampleEnclavePCL/Include/user_types.h | 40 + SampleCode/SampleEnclavePCL/Makefile | 330 + SampleCode/SampleEnclavePCL/README.md | 38 + .../SampleEnclavePCL/Seal/Seal.config.xml | 12 + SampleCode/SampleEnclavePCL/Seal/Seal.cpp | 126 + SampleCode/SampleEnclavePCL/Seal/Seal.edl | 51 + SampleCode/SampleEnclavePCL/Seal/Seal.lds | 10 + .../SampleEnclavePCL/Seal/Seal_private.pem | 39 + .../SampleEnclavePCL/debug_mock_key.bin | 1 + buildenv.mk | 5 +- common/inc/internal/ae_ipp.h | 1 - common/inc/internal/ipp_wrapper.h | 17 - common/inc/internal/metadata.h | 5 +- common/inc/internal/pcl_common.h | 101 + common/inc/internal/rts.h | 7 +- common/inc/internal/se_version.h | 2 +- common/inc/sgx_error.h | 9 +- common/inc/sgx_key_exchange.h | 1 - common/inc/sgx_pcl_guid.h | 60 + common/inc/sgx_tcrypto.h | 46 +- common/inc/sgx_tkey_exchange.h | 3 +- common/inc/sgx_trts.h | 2 +- common/inc/sgx_urts.h | 9 + common/src/ipp_rsa_key.cpp | 351 - common/src/linux/xsave_gnu.S | 2 +- download_prebuilt.sh | 10 +- external/epid-sdk-3.0.0/CHANGELOG.md | 87 - external/epid-sdk-3.0.0/Makefile.in | 129 - external/epid-sdk-3.0.0/SConstruct | 237 - external/epid-sdk-3.0.0/configure.ac | 20 - .../common-testhelper/common-testhelper.parts | 91 - external/epid-sdk-3.0.0/epid/member/Makefile | 76 - external/epid-sdk-3.0.0/epid/member/api.h | 491 - .../epid-sdk-3.0.0/epid/member/member.parts | 84 - .../epid-sdk-3.0.0/epid/member/src/context.c | 423 - .../epid-sdk-3.0.0/epid/member/src/context.h | 85 - .../epid-sdk-3.0.0/epid/member/src/nr_prove.c | 277 - .../epid-sdk-3.0.0/epid/member/src/presig.c | 229 - .../epid-sdk-3.0.0/epid/member/src/privkey.c | 84 - .../epid-sdk-3.0.0/epid/member/src/privkey.h | 67 - .../epid/member/src/request_join.c | 418 - .../epid/member/src/signbasic.c | 272 - .../member/unittests/compute_presig-test.cc | 93 - .../epid/member/unittests/context-test.cc | 264 - .../member/unittests/member-testhelper.cc | 522 - .../epid/member/unittests/nr_prove-test.cc | 290 - .../epid/member/unittests/presig-test.cc | 246 - .../member/unittests/request_join-test.cc | 320 - .../groupb/member0/mprivkey.dat | Bin 80 -> 0 bytes .../groupb/privrevokedmember0/mprivkey.dat | Bin 80 -> 0 bytes .../compressed_data/groupb/privrl_empty.bin | Bin 92 -> 0 bytes .../example/compressed_data/groupb/pubkey.bin | Bin 340 -> 0 bytes .../groupb/sigrevokedmember0/mprivkey.dat | Bin 80 -> 0 bytes .../example/compressed_data/groupb/sigrl.bin | Bin 476 -> 0 bytes .../compressed_data/groupb/sigrl_empty.bin | Bin 92 -> 0 bytes .../epid-sdk-3.0.0/example/data/README.md | 179 - .../epid-sdk-3.0.0/example/data/cacert.bin | Bin 324 -> 0 bytes .../epid-sdk-3.0.0/example/data/data.parts | 72 - .../example/data/groupa/member0/mprivkey.dat | Bin 144 -> 0 bytes .../example/data/groupa/member1/mprivkey.dat | Bin 144 -> 0 bytes .../groupa/privrevokedmember0/mprivkey.dat | Bin 144 -> 0 bytes .../groupa/privrevokedmember1/mprivkey.dat | Bin 144 -> 0 bytes .../groupa/privrevokedmember2/mprivkey.dat | Bin 144 -> 0 bytes .../example/data/groupa/privrl.bin | Bin 188 -> 0 bytes .../example/data/groupa/privrl_empty.bin | Bin 92 -> 0 bytes .../example/data/groupa/pubkey.bin | Bin 340 -> 0 bytes .../groupa/sigrevokedmember0/mprivkey.dat | Bin 144 -> 0 bytes .../groupa/sigrevokedmember1/mprivkey.dat | Bin 144 -> 0 bytes .../groupa/sigrevokedmember2/mprivkey.dat | Bin 144 -> 0 bytes .../example/data/groupa/sigrl.bin | Bin 476 -> 0 bytes .../example/data/groupa/sigrl_empty.bin | Bin 92 -> 0 bytes .../example/data/groupb/member0/mprivkey.dat | Bin 144 -> 0 bytes .../groupb/privrevokedmember0/mprivkey.dat | Bin 144 -> 0 bytes .../example/data/groupb/privrl.bin | Bin 188 -> 0 bytes .../example/data/groupb/privrl_empty.bin | Bin 92 -> 0 bytes .../example/data/groupb/pubkey.bin | Bin 340 -> 0 bytes .../groupb/sigrevokedmember0/mprivkey.dat | Bin 144 -> 0 bytes .../example/data/groupb/sigrl.bin | Bin 476 -> 0 bytes .../example/data/groupb/sigrl_empty.bin | Bin 92 -> 0 bytes .../epid-sdk-3.0.0/example/data/grprl.bin | Bin 876 -> 0 bytes .../example/data/grprl_empty.bin | Bin 76 -> 0 bytes .../epid-sdk-3.0.0/example/data/mprivkey.dat | Bin 144 -> 0 bytes .../epid-sdk-3.0.0/example/data/privrl.bin | Bin 92 -> 0 bytes .../epid-sdk-3.0.0/example/data/pubkey.bin | Bin 340 -> 0 bytes .../epid-sdk-3.0.0/example/data/sigrl.bin | Bin 92 -> 0 bytes .../example/signmsg/signmsg.parts | 52 - .../epid-sdk-3.0.0/example/signmsg/src/main.c | 410 - .../epid-sdk-3.0.0/example/signmsg/src/prng.c | 98 - .../example/signmsg/src/signmsg.c | 176 - .../example/signmsg/src/signmsg.h | 42 - external/epid-sdk-3.0.0/example/util/Makefile | 32 - .../epid-sdk-3.0.0/example/util/buffutil.h | 159 - .../epid-sdk-3.0.0/example/util/convutil.h | 77 - .../epid-sdk-3.0.0/example/util/envutil.h | 54 - .../epid-sdk-3.0.0/example/util/src/bufutil.c | 364 - .../example/util/src/convutil.c | 95 - .../epid-sdk-3.0.0/example/util/src/envutil.c | 91 - .../epid-sdk-3.0.0/example/util/src/strutil.c | 53 - .../epid-sdk-3.0.0/example/util/util.parts | 61 - .../example/verifysig/src/main.c | 501 - .../example/verifysig/src/verifysig.c | 211 - .../example/verifysig/src/verifysig.h | 42 - .../example/verifysig/src/verifysig11.c | 187 - .../example/verifysig/src/verifysig11.h | 38 - .../example/verifysig/verifysig.parts | 53 - external/epid-sdk-3.0.0/ext/dropt/LICENSE | 22 - external/epid-sdk-3.0.0/ext/dropt/Makefile | 23 - .../epid-sdk-3.0.0/ext/dropt/include/dropt.h | 249 - .../ext/dropt/include/dropt_string.h | 94 - external/epid-sdk-3.0.0/ext/dropt/src/dropt.c | 1562 -- .../ext/dropt/src/dropt_handlers.c | 438 - .../ext/dropt/src/dropt_string.c | 686 - .../ext/ipp/include/ippcpdefs.h | 371 - .../ext/ipp/include/ippcpepid.h | 218 - .../epid-sdk-3.0.0/ext/ipp/ippcommon.parts | 56 - external/epid-sdk-3.0.0/ext/ipp/ippcp.parts | 115 - .../epid-sdk-3.0.0/ext/ipp/ippcpepid.parts | 105 - .../ext/ipp/sources/include/owndefs.h | 934 -- .../ext/ipp/sources/ippcp/Makefile | 31 - .../ext/ipp/sources/ippcp/src/owncp.h | 171 - .../ext/ipp/sources/ippcp/src/pcpbn.h | 203 - .../ext/ipp/sources/ippcp/src/pcpbnca.c | 1286 -- .../ipp/sources/ippcp/src/pcpbnresourceca.c | 87 - .../ext/ipp/sources/ippcp/src/pcpbnsetca.c | 117 - .../ext/ipp/sources/ippcp/src/pcpbnu32arith.c | 366 - .../ext/ipp/sources/ippcp/src/pcpbnu32arith.h | 50 - .../ext/ipp/sources/ippcp/src/pcpbnu32misc.c | 229 - .../ext/ipp/sources/ippcp/src/pcpbnu32misc.h | 71 - .../ext/ipp/sources/ippcp/src/pcpbnuarith.c | 537 - .../ext/ipp/sources/ippcp/src/pcpbnuarith.h | 169 - .../ext/ipp/sources/ippcp/src/pcpbnuimpl.h | 136 - .../ext/ipp/sources/ippcp/src/pcpbnumisc.c | 294 - .../ext/ipp/sources/ippcp/src/pcpbnumisc.h | 160 - .../ext/ipp/sources/ippcp/src/pcpeccp.h | 260 - .../ext/ipp/sources/ippcp/src/pcpeccpdpca.c | 801 - .../ipp/sources/ippcp/src/pcpeccpgenkeyca.c | 105 - .../ext/ipp/sources/ippcp/src/pcpeccpinitca.c | 454 - .../ext/ipp/sources/ippcp/src/pcpeccpmethod.h | 98 - .../ipp/sources/ippcp/src/pcpeccpmethod128.h | 118 - .../sources/ippcp/src/pcpeccpmethod128ca.c | 879 -- .../ipp/sources/ippcp/src/pcpeccpmethod192.h | 117 - .../sources/ippcp/src/pcpeccpmethod192ca.c | 880 -- .../ipp/sources/ippcp/src/pcpeccpmethod224.h | 118 - .../sources/ippcp/src/pcpeccpmethod224ca.c | 877 -- .../ipp/sources/ippcp/src/pcpeccpmethod256.h | 118 - .../sources/ippcp/src/pcpeccpmethod256ca.c | 879 -- .../ipp/sources/ippcp/src/pcpeccpmethod384.h | 118 - .../sources/ippcp/src/pcpeccpmethod384ca.c | 879 -- .../ipp/sources/ippcp/src/pcpeccpmethod521.h | 118 - .../sources/ippcp/src/pcpeccpmethod521ca.c | 879 -- .../ipp/sources/ippcp/src/pcpeccpmethodcom.h | 133 - .../sources/ippcp/src/pcpeccpmethodcomca.c | 1025 -- .../ipp/sources/ippcp/src/pcpeccpmethodsm2.h | 120 - .../sources/ippcp/src/pcpeccpmethodsm2ca.c | 879 -- .../ext/ipp/sources/ippcp/src/pcpeccppoint.h | 54 - .../ipp/sources/ippcp/src/pcpeccppointca.c | 126 - .../ipp/sources/ippcp/src/pcpeccppointopca.c | 482 - .../sources/ippcp/src/pcpeccppublickeyca.c | 87 - .../ipp/sources/ippcp/src/pcpeccpsetkeyca.c | 102 - .../ipp/sources/ippcp/src/pcpeccpsigndsaca.c | 146 - .../ext/ipp/sources/ippcp/src/pcpeccpsscm.c | 160 - .../ext/ipp/sources/ippcp/src/pcpeccpsscm.h | 45 - .../ext/ipp/sources/ippcp/src/pcpeccpstdca.c | 465 - .../sources/ippcp/src/pcpeccpverifydsaca.c | 173 - .../ext/ipp/sources/ippcp/src/pcphash.h | 239 - .../ext/ipp/sources/ippcp/src/pcphashcnt.c | 434 - .../ext/ipp/sources/ippcp/src/pcphashmd5px.c | 211 - .../ext/ipp/sources/ippcp/src/pcphashsha1px.c | 189 - .../ipp/sources/ippcp/src/pcphashsha256px.c | 214 - .../ipp/sources/ippcp/src/pcphashsha512px.c | 221 - .../ext/ipp/sources/ippcp/src/pcpmd5ca.c | 485 - .../ipp/sources/ippcp/src/pcpmontexpbinca.c | 562 - .../ext/ipp/sources/ippcp/src/pcpmontgomery.h | 282 - .../ipp/sources/ippcp/src/pcpmontgomeryca.c | 479 - .../ext/ipp/sources/ippcp/src/pcpmontred.c | 75 - .../ext/ipp/sources/ippcp/src/pcpmulbnukara.h | 84 - .../ext/ipp/sources/ippcp/src/pcppma.h | 106 - .../ext/ipp/sources/ippcp/src/pcppma128.c | 169 - .../ext/ipp/sources/ippcp/src/pcppma128.h | 79 - .../ext/ipp/sources/ippcp/src/pcppma192.c | 153 - .../ext/ipp/sources/ippcp/src/pcppma192.h | 84 - .../ext/ipp/sources/ippcp/src/pcppma224.c | 169 - .../ext/ipp/sources/ippcp/src/pcppma224.h | 81 - .../ext/ipp/sources/ippcp/src/pcppma256.c | 181 - .../ext/ipp/sources/ippcp/src/pcppma256.h | 82 - .../ext/ipp/sources/ippcp/src/pcppma384.c | 191 - .../ext/ipp/sources/ippcp/src/pcppma384.h | 82 - .../ext/ipp/sources/ippcp/src/pcppma521.c | 124 - .../ext/ipp/sources/ippcp/src/pcppma521.h | 80 - .../ext/ipp/sources/ippcp/src/pcppmasm2.c | 311 - .../ext/ipp/sources/ippcp/src/pcppmasm2.h | 121 - .../ext/ipp/sources/ippcp/src/pcpprimeg.h | 72 - .../ipp/sources/ippcp/src/pcpprimeginitca.c | 158 - .../ext/ipp/sources/ippcp/src/pcpprng.h | 59 - .../ext/ipp/sources/ippcp/src/pcpprngenca.c | 251 - .../ext/ipp/sources/ippcp/src/pcpprnginitca.c | 111 - .../ext/ipp/sources/ippcp/src/pcpprngsetca.c | 239 - .../ext/ipp/sources/ippcp/src/pcpsha1ca.c | 551 - .../ext/ipp/sources/ippcp/src/pcpsha256ca.c | 728 - .../ext/ipp/sources/ippcp/src/pcpsha512ca.c | 674 - .../ext/ipp/sources/ippcp/src/pcptool.h | 631 - .../ext/ipp/sources/ippcp/src/pcpvariant.h | 326 - .../ext/ipp/sources/ippcpepid/Makefile | 37 - .../ipp/sources/ippcpepid/src/ippcpepid_y8.h | 44 - .../ext/ipp/sources/ippcpepid/src/owncpepid.h | 58 - .../ext/ipp/sources/ippcpepid/src/pcpgfp.c | 846 -- .../ext/ipp/sources/ippcpepid/src/pcpgfpec.c | 322 - .../ipp/sources/ippcpepid/src/pcpgfpecpoint.c | 426 - .../ippcpepid/src/pcpgfpecpointstuff.c | 1227 -- .../ipp/sources/ippcpepid/src/pcpgfpecstuff.h | 320 - .../sources/ippcpepid/src/pcpgfphashstuff.h | 117 - .../ipp/sources/ippcpepid/src/pcpgfpstuff.c | 486 - .../ipp/sources/ippcpepid/src/pcpgfpstuff.h | 212 - .../ext/ipp/sources/ippcpepid/src/pcpgfpx.c | 202 - .../ipp/sources/ippcpepid/src/pcpgfpxstuff.c | 1307 -- .../ipp/sources/ippcpepid/src/pcpgfpxstuff.h | 174 - .../parts-site/configurations/debug/g++.py | 47 - .../parts-site/configurations/debug/gcc.py | 52 - .../configurations/debug/intelc_posix-any.py | 48 - .../debug/intelc_win32-any_win32-x86.py | 49 - .../debug/intelc_win32-any_win32-x86_64.py | 48 - .../debug/msvc_win32-any_win32-x86.py | 54 - .../debug/msvc_win32-any_win32-x86_64.py | 53 - .../configurations/release/__init__.py | 20 - .../parts-site/configurations/release/g++.py | 47 - .../parts-site/configurations/release/gcc.py | 54 - .../release/intelc_posix-any.py | 49 - .../release/intelc_win32-any_win32-x86.py | 53 - .../release/intelc_win32-any_win32-x86_64.py | 52 - .../release/msvc_win32-any_win32-x86.py | 58 - .../release/msvc_win32-any_win32-x86_64.py | 57 - external/epid-sdk-3.0.0/tools/Makefile | 107 - .../tools/extractgrps/extractgrps.parts | 47 - .../tools/extractgrps/src/main.c | 227 - .../tools/extractkeys/extractkeys.parts | 47 - .../tools/extractkeys/src/main.c | 252 - .../tools/revokegrp/revokegrp.parts | 46 - .../epid-sdk-3.0.0/tools/revokegrp/src/main.c | 382 - .../tools/revokekey/revokekey.parts | 47 - .../epid-sdk-3.0.0/tools/revokekey/src/main.c | 356 - .../tools/revokesig/revokesig.parts | 46 - .../epid-sdk-3.0.0/tools/revokesig/src/main.c | 455 - external/epid-sdk/CHANGELOG.md | 241 + .../{epid-sdk-3.0.0 => epid-sdk}/LICENSE.txt | 16 +- external/epid-sdk/Makefile | 184 + external/epid-sdk/Makefile.in | 184 + .../{epid-sdk-3.0.0 => epid-sdk}/NOTICE.txt | 20 +- .../{epid-sdk-3.0.0 => epid-sdk}/README.md | 14 +- external/epid-sdk/SConstruct | 566 + .../{epid-sdk-3.0.0 => epid-sdk}/configure | 169 + .../1.1/epid_params-testhelper.cc | 142 +- .../1.1/epid_params-testhelper.h | 12 +- .../member0/sig_bsn0_msg_0_255_sha256.inc | 89 + .../1.1/testdata/grp_x/corrupted_privrl.inc | 35 + .../1.1/testdata/grp_x/epid_grpcrt.inc | 0 .../grp_x/member0/sig_sha256_bsn0_msg0.inc | 0 .../sig_sha256_bsn0_msg0_single_entry.inc | 0 .../sig_sha256_bsn0_msg0_three_entry.inc | 0 .../grp_x/member0/sig_sha256_bsn0_msg1.inc | 0 .../grp_x/member0/sig_sha256_bsn1_msg0.inc | 0 .../grp_x/member0/sig_sha256_rndbase_msg0.inc | 0 .../grp_x/member0/sig_sha256_rndbase_msg1.inc | 0 .../grp_x/member1/sig_sha256_bsn0_msg0.inc | 0 .../sig_sha256_bsn0_msg0_revkey000.inc | 0 .../sig_sha256_bsn0_msg0_revkey001.inc | 0 .../sig_sha256_bsn0_msg0_revkey002.inc | 0 .../1.1/testdata/grp_x/privrl.inc | 0 .../testdata/grp_x/privrl_single_entry.inc | 0 .../testdata/grp_x/sig_sha256_bsnrnd_msg0.inc | 0 ...ber0_sig_bsn0_msg0_revoked_first_entry.inc | 0 ...mber0_sig_bsn0_msg0_revoked_last_entry.inc | 0 ...er0_sig_bsn0_msg0_revoked_middle_entry.inc | 0 ...er0_sig_bsn0_msg0_revoked_single_entry.inc | 0 .../grprl_revoked_grp_x_first_entry.inc | 0 .../grprl_revoked_grp_x_last_entry.inc | 0 .../grprl_revoked_grp_x_middle_entry.inc | 0 .../grprl_revoked_grp_x_single_entry.inc | 0 .../1.1/verifier_wrapper-testhelper.cc | 4 +- .../1.1/verifier_wrapper-testhelper.h | 0 .../epid/common-testhelper/Makefile | 27 +- .../bignum_wrapper-testhelper.cc | 4 +- .../bignum_wrapper-testhelper.h | 0 .../common-testhelper/common-testhelper.parts | 86 + .../ecgroup_wrapper-testhelper.cc | 46 +- .../ecgroup_wrapper-testhelper.h | 0 .../ecpoint_wrapper-testhelper.cc | 4 +- .../ecpoint_wrapper-testhelper.h | 4 +- .../epid2params_wrapper-testhelper.cc | 49 + .../epid2params_wrapper-testhelper.h | 55 + .../epid_gtest-testhelper.cc | 69 + .../common-testhelper/epid_gtest-testhelper.h | 30 + .../epid_params-testhelper.cc | 153 +- .../epid_params-testhelper.h | 15 +- .../common-testhelper/errors-testhelper.h | 15 +- .../ffelement_wrapper-testhelper.cc | 4 +- .../ffelement_wrapper-testhelper.h | 4 +- .../finite_field_wrapper-testhelper.cc | 6 +- .../finite_field_wrapper-testhelper.h | 0 .../mem_params-testhelper.cc} | 28 +- .../common-testhelper/mem_params-testhelper.h | 48 + .../member_wrapper-testhelper.cc | 290 + .../member_wrapper-testhelper.h | 84 + .../common-testhelper/octstr-testhelper.cc | 7 +- .../common-testhelper/octstr-testhelper.h | 0 .../epid/common-testhelper/prng-testhelper.h | 62 +- .../common-testhelper/testapp-testhelper.cc | 74 + .../common-testhelper/testapp-testhelper.h | 33 + .../testdata/grp01/gpubkey.inc | 0 .../member0/sig_bsn0_msg_0_255_sha512.inc | 72 + .../grp01/member0/sig_test0_sha256_sigrl.inc | 0 .../grp01/member0/sig_test0_sha384_sigrl.inc | 0 .../grp01/member0/sig_test0_sha512_sigrl.inc | 0 .../testdata/grp01/member0/sig_test1.inc | 0 .../member0/sig_test1_basename1_sha256.inc | 0 .../grp01/member0/sig_test1_sha256.inc | 0 .../grp01/member0/sig_test1_sha384.inc | 0 .../grp01/member0/sig_test1_sha512.inc | 0 .../testdata/grp01/privrl.inc | 0 .../testdata/grp01/sigrl.inc | 0 .../testdata/grp01/verrl.inc | 0 .../testdata/grp_x/cmember9/cmpprivkey.inc | 0 .../testdata/grp_x/cmember9/mprivkey.inc | 0 .../testdata/grp_x/corrupted_privrl.inc | 36 + .../testdata/grp_x/iprivkey.inc | 0 .../testdata/grp_x/member0/mprivkey.inc | 0 .../grp_x/member0/sig_sha256_bsn0_msg0.inc | 0 .../sig_sha256_bsn0_msg0_rl_singleentry.inc | 0 .../grp_x/member0/sig_sha256_bsn0_msg1.inc | 0 .../grp_x/member0/sig_sha256_bsn1_msg0.inc | 0 .../grp_x/member0/sig_sha256_rndbase_msg0.inc | 0 .../grp_x/member0/sig_sha256_rndbase_msg1.inc | 0 .../grp_x/member0/sig_sha384_bsn0_msg0.inc | 0 .../grp_x/member0/sig_sha384_rndbase_msg0.inc | 0 .../member0/sig_sha512_256_bsn0_msg0.inc | 100 + .../member0/sig_sha512_256_rndbase_msg0.inc | 100 + .../sig_sha512_256_rndbase_msg0_no_sigrl.inc | 88 + .../grp_x/member0/sig_sha512_bsn0_msg0.inc | 0 .../member0/sig_sha512_huge_bsn_msg0.inc | 99 + .../grp_x/member0/sig_sha512_rndbase_msg0.inc | 0 .../testdata/grp_x/member1/mprivkey.inc | 0 .../grp_x/member1/sig_sha256_bsn0_msg0.inc | 0 .../grp_x/privrevoked/mprivatekey000.inc | 0 .../grp_x/privrevoked/mprivatekey001.inc | 0 .../grp_x/privrevoked/mprivatekey002.inc | 0 .../sig_sha256_bsn0_msg0_revkey000.inc | 0 .../sig_sha256_bsn0_msg0_revkey001.inc | 0 .../sig_sha256_bsn0_msg0_revkey002.inc | 0 .../testdata/grp_x/privrl.inc | 0 .../privrl_single_entry_revoked_key000.inc | 0 .../testdata/grp_x/pubkey.inc | 0 .../grp_x/sigrevoked/mprivatekey000.inc | 0 .../grp_x/sigrevoked/mprivatekey001.inc | 0 .../grp_x/sigrevoked/mprivatekey002.inc | 0 .../testdata/grp_x/sigrl.inc | 0 ...g_sha256_bsn0_msg0_revoked_first_entry.inc | 0 ...ig_sha256_bsn0_msg0_revoked_last_entry.inc | 0 ..._sha256_bsn0_msg0_revoked_middle_entry.inc | 0 ...a512_rndbase_msg0_revoked_middle_entry.inc | 77 + .../testdata/grp_x/sigrl_single_entry.inc | 0 .../testdata/grp_x/sigrl_ver_2.inc | 0 .../grp_x/verrevoked/bsn0/mprivkey000.inc | 0 .../grp_x/verrevoked/bsn0/mprivkey001.inc | 0 .../grp_x/verrevoked/bsn0/mprivkey002.inc | 0 .../bsn0/sig_revoked0sha256bsn0msg0.inc | 0 .../bsn0/sig_revoked0sha384bsn0msg0.inc | 0 .../bsn0/sig_revoked0sha512_256bsn0msg0.inc | 100 + .../bsn0/sig_revoked0sha512bsn0msg0.inc | 0 .../bsn0/sig_revoked1sha256bsn0msg0.inc | 0 .../bsn0/sig_revoked1sha384bsn0msg0.inc | 0 .../bsn0/sig_revoked1sha512_256bsn0msg0.inc | 100 + .../bsn0/sig_revoked1sha512bsn0msg0.inc | 0 .../bsn0/sig_revoked2sha256bsn0msg0.inc | 0 .../bsn0/sig_revoked2sha384bsn0msg0.inc | 0 .../bsn0/sig_revoked2sha512_256bsn0msg0.inc | 100 + .../bsn0/sig_revoked2sha512bsn0msg0.inc | 0 .../testdata/grp_x/verrevoked/bsn0/verrl.inc | 0 .../grp_x/verrevoked/bsn0/verrl_1entry.inc | 0 .../grp_x/verrevoked/bsn0/verrl_sha384.inc | 0 .../grp_x/verrevoked/bsn0/verrl_sha512.inc | 0 .../verrevoked/bsn0/verrl_sha512_256.inc | 68 + .../grp_x/verrevoked/bsn1/mprivkey003.inc | 0 .../grp_x/verrevoked/bsn1/mprivkey004.inc | 0 .../grp_x/verrevoked/bsn1/mprivkey005.inc | 0 .../bsn1/sig_revoked3sha256bsn1msg0.inc | 0 .../testdata/grp_x/verrevoked/bsn1/verrl.inc | 0 .../verrevoked/bsn1/verrl_012revoked.inc | 0 .../testdata/grp_y/cmember9/cmpprivkey.dat | Bin .../testdata/grp_y/cmember9/cmpprivkey.inc | 0 .../testdata/grp_y/iprivkey.inc | 0 .../testdata/grp_y/pubkey.inc | 0 .../epid/common-testhelper/testdata/grprl.inc | 0 .../grprl_revoked_grp_x_first_entry.inc | 0 .../grprl_revoked_grp_x_last_entry.inc | 0 .../grprl_revoked_grp_x_middle_entry.inc | 0 .../grprl_single_entry_revoked_grp_x.inc | 0 .../testdata/ikgf/groupa/member0/mprecomp.inc | 4 +- .../testdata/ikgf/groupa/member0/mprivkey.inc | 4 +- .../testdata/ikgf/groupa/privrl.inc | 0 .../testdata/ikgf/groupa/privrl_empty.inc | 0 .../testdata/ikgf/groupa/pubkey.inc | 0 .../ikgf/groupa/sig_msg0_sha256_sigrl.inc | 0 .../ikgf/groupa/sig_sha256_bsn0_msg0.inc | 0 .../sig_sha256_bsn0_msg0_empty_sigrl.inc | 0 .../groupa/sig_sha256_bsn0_msg0_nosigrl.inc | 0 .../groupa/sig_sha256_bsn0_msg0_revkey.inc | 0 .../ikgf/groupa/sig_sha256_rndbase_msg0.inc | 0 .../sig_sigrevoked_sha256_bsn0_msg0.inc | 0 .../groupa/sig_test1_basename1_sha256.inc | 0 .../groupa/sigrevokedmember0/mprivkey.inc | 4 +- .../testdata/ikgf/groupa/sigrl.inc | 0 .../testdata/ikgf/groupa/sigrl_empty.inc | 0 .../testdata/ikgf/groupb/member0/mprivkey.inc | 4 +- .../sig_grouprevoked_sha256_bsn0_msg0.inc | 0 .../common-testhelper/testdata/ikgf/grprl.inc | 0 .../unittests/bignum_wrapper-test.cc | 5 +- .../unittests/ecgroup_wrapper-test.cc | 45 +- .../unittests/ecpoint_wrapper-test.cc | 31 +- .../unittests/ffelement_wrapper-test.cc | 3 +- .../unittests/finite_field_wrapper-test.cc | 5 +- .../common-testhelper}/unittests/main-test.cc | 3 +- .../verifier_wrapper-testhelper.cc | 4 +- .../verifier_wrapper-testhelper.h | 0 .../epid/common/1.1/file_parser.h | 25 +- .../epid/common/1.1/src/commitment.c | 8 +- .../epid/common/1.1/src/commitment.h | 4 +- .../epid/common/1.1/src/epid11params.c | 4 +- .../epid/common/1.1/src/epid11params.h | 0 .../epid/common/1.1/src/epid11params_tate.inc | 0 .../epid/common/1.1/src/file_parser.c | 6 +- .../epid/common/1.1/src/grouppubkey.c | 0 .../epid/common/1.1/src/grouppubkey.h | 4 +- .../epid/common/1.1/types.h | 8 +- .../common/1.1/unittests/file_parser-test.cc | 61 +- .../epid/common/Makefile | 23 +- .../epid/common/bitsupplier.h | 28 +- .../epid/common/common.parts | 5 +- external/epid-sdk/epid/common/epiddefs.h | 39 + .../epid/common/errors.h | 3 +- .../epid/common/file_parser.h | 30 +- .../epid/common/math/bignum.h | 8 +- .../epid/common/math/ecdsa.h | 8 +- .../epid/common/math/ecgroup.h | 24 +- .../epid/common/math/finitefield.h | 19 +- .../epid/common/math/hash.h | 4 +- .../epid/common/math/pairing.h | 17 +- .../epid/common/math/printutils.h | 6 +- .../epid/common/math/src/bignum-internal.h | 35 +- .../epid/common/math/src/bignum.c | 69 +- .../epid/common/math/src/ecdsa_sign.c | 8 +- .../epid/common/math/src/ecdsa_verify.c | 23 +- .../epid/common/math/src/ecgroup-internal.h | 15 +- .../epid/common/math/src/ecgroup.c | 410 +- .../common/math/src/finitefield-internal.h | 36 +- .../epid/common/math/src/finitefield.c | 586 +- .../epid/common/math/src/pairing-internal.h | 8 +- .../epid/common/math/src/pairing.c | 803 +- .../epid/common/math/src/printutils.c | 82 +- .../epid/common/math/src/sha256.c | 5 +- .../common/math/src/tatepairing-internal.h | 6 +- .../epid/common/math/src/tatepairing.c | 423 +- .../epid/common/math/tatepairing.h | 22 +- .../epid/common/math/unittests/bignum-test.cc | 5 +- .../common/math/unittests/ecdsa_sign-test.cc | 3 +- .../math/unittests/ecdsa_verify-test.cc | 3 +- .../common/math/unittests/ecgroup-test.cc | 869 +- .../common/math/unittests/ffelement-test.cc | 500 +- .../common/math/unittests/finitefield-test.cc | 95 +- .../epid/common/math/unittests/hash-test.cc | 3 +- .../epid/common/math}/unittests/main-test.cc | 3 +- .../math/unittests/octstrconvert-test.cc | 3 +- .../common/math/unittests/pairing-test.cc | 107 +- .../common/math/unittests/printutils-test.cc | 177 +- .../common/math/unittests/tatepairing-test.cc | 5 +- .../epid/common/src/commitment.c | 6 +- .../epid/common/src/commitment.h | 33 +- .../epid/common/src/endian_convert.h | 0 .../epid/common/src/epid2params.c | 19 +- .../epid/common/src/epid2params.h | 3 +- .../epid/common/src/epid2params_ate.inc | 0 .../epid/common/src/errors.c | 4 +- .../epid/common/src/file_parser-internal.h | 6 +- .../epid/common/src/file_parser.c | 6 +- .../epid/common/src/grouppubkey.c | 0 .../epid/common/src/grouppubkey.h | 0 external/epid-sdk/epid/common/src/hashsize.c | 44 + external/epid-sdk/epid/common/src/hashsize.h | 46 + .../epid/common/src/memory.c | 4 +- .../epid/common/src/memory.h | 0 .../epid/common/src/sigrlvalid.c | 0 .../epid/common/src/sigrlvalid.h | 0 .../epid/common/src/stack.c | 6 +- .../epid/common/src/stack.h | 13 +- .../epid/common/stdtypes.h | 0 .../epid-sdk/epid/common/tinycommon.parts | 46 + .../epid/common/types.h | 22 +- .../epid/common/unittests/file_parser-test.cc | 11 +- external/epid-sdk/epid/member/Makefile | 186 + external/epid-sdk/epid/member/api.h | 443 + external/epid-sdk/epid/member/member.parts | 93 + .../epid-sdk/epid/member/software_member.h | 48 + .../epid/member/src/allowed_basenames.c | 117 + .../epid/member/src/allowed_basenames.h | 45 + external/epid-sdk/epid/member/src/context.c | 289 + external/epid-sdk/epid/member/src/context.h | 99 + .../epid/member/src/decompress_privkey.c | 59 +- .../epid/member/src/get_sigsize.c | 4 +- .../epid-sdk/epid/member/src/hash_basename.c | 54 + .../epid-sdk/epid/member/src/hash_basename.h | 59 + external/epid-sdk/epid/member/src/join.c | 152 + .../epid/member/src/join_commitment.c | 89 + .../epid/member/src/join_commitment.h | 64 + external/epid-sdk/epid/member/src/nrprove.c | 293 + external/epid-sdk/epid/member/src/nrprove.h | 71 + .../epid/member/src/nrprove_commitment.c | 113 + .../epid/member/src/nrprove_commitment.h | 82 + external/epid-sdk/epid/member/src/precomp.c | 91 + external/epid-sdk/epid/member/src/precomp.h | 59 + .../epid/member/src/presig-internal.h | 53 + external/epid-sdk/epid/member/src/presig.c | 295 + .../epid-sdk/epid/member/src/privateexp.c | 141 + .../epid/member/src/privateexp.h} | 38 +- .../epid-sdk/epid/member/src/provision_bulk.c | 88 + .../epid/member/src/provision_compressed.c | 41 + .../epid-sdk/epid/member/src/provision_join.c | 85 + external/epid-sdk/epid/member/src/resize.c | 40 + external/epid-sdk/epid/member/src/resize.h | 45 + .../epid/member/src/sign.c | 67 +- .../epid/member/src/sign_commitment.c | 71 + .../epid/member/src/sign_commitment.h | 73 + external/epid-sdk/epid/member/src/signbasic.c | 340 + external/epid-sdk/epid/member/src/signbasic.h | 70 + external/epid-sdk/epid/member/src/startup.c | 127 + external/epid-sdk/epid/member/src/storage.c | 71 + external/epid-sdk/epid/member/src/storage.h | 72 + .../epid-sdk/epid/member/src/validatekey.c | 130 + .../epid-sdk/epid/member/src/validatekey.h | 64 + .../epid-sdk/epid/member/src/write_precomp.c | 36 + .../epid-sdk/epid/member/src/write_precomp.h | 46 + external/epid-sdk/epid/member/tiny/math/efq.h | 254 + .../epid-sdk/epid/member/tiny/math/efq2.h | 103 + external/epid-sdk/epid/member/tiny/math/fp.h | 135 + external/epid-sdk/epid/member/tiny/math/fq.h | 168 + .../epid-sdk/epid/member/tiny/math/fq12.h | 165 + external/epid-sdk/epid/member/tiny/math/fq2.h | 155 + external/epid-sdk/epid/member/tiny/math/fq6.h | 137 + .../epid-sdk/epid/member/tiny/math/hashwrap.h | 109 + .../epid-sdk/epid/member/tiny/math/math.parts | 51 + .../epid/member/tiny/math/mathdefs.h} | 15 +- .../epid/member/tiny/math/mathtypes.h | 101 + .../epid-sdk/epid/member/tiny/math/pairing.h | 48 + .../epid/member/tiny/math/serialize.h | 183 + .../epid-sdk/epid/member/tiny/math/sha256.h | 133 + .../epid-sdk/epid/member/tiny/math/sha512.h | 89 + .../epid-sdk/epid/member/tiny/math/src/efq.c | 412 + .../epid-sdk/epid/member/tiny/math/src/efq2.c | 253 + .../epid-sdk/epid/member/tiny/math/src/fp.c | 120 + .../epid-sdk/epid/member/tiny/math/src/fq.c | 126 + .../epid-sdk/epid/member/tiny/math/src/fq12.c | 282 + .../epid-sdk/epid/member/tiny/math/src/fq2.c | 150 + .../epid-sdk/epid/member/tiny/math/src/fq6.c | 192 + .../epid/member/tiny/math/src/hashwrap.c | 86 + .../epid/member/tiny/math/src/pairing.c | 300 + .../epid/member/tiny/math/src/serialize.c | 232 + .../epid/member/tiny/math/src/sha256.c | 225 + .../epid/member/tiny/math/src/sha512.c | 169 + .../epid-sdk/epid/member/tiny/math/src/vli.c | 316 + .../tiny/math/unittests/cmp-testhelper.cc | 71 + .../tiny/math/unittests/cmp-testhelper.h | 65 + .../member/tiny/math/unittests/efq-test.cc | 714 + .../member/tiny/math/unittests/efq2-test.cc | 406 + .../member/tiny/math/unittests/fp-test.cc | 263 + .../member/tiny/math/unittests/fq-test.cc | 329 + .../member/tiny/math/unittests/fq12-test.cc | 1058 ++ .../member/tiny/math/unittests/fq2-test.cc | 352 + .../member/tiny/math/unittests/fq6-test.cc | 452 + .../unittests/internal/onetimepad-test.cc | 130 + .../tiny/math/unittests/main-testhelper.cc} | 12 +- .../member/tiny/math/unittests/onetimepad.h | 122 + .../tiny/math/unittests/pairing-test.cc | 79 + .../tiny/math/unittests/serialize-test.cc | 423 + .../member/tiny/math/unittests/sha256-test.cc | 350 + .../member/tiny/math/unittests/sha512-test.cc | 108 + .../member/tiny/math/unittests/utest.parts | 47 + .../member/tiny/math/unittests/vli-test.cc | 379 + external/epid-sdk/epid/member/tiny/math/vli.h | 196 + .../epid/member/tiny/src/allowed_basenames.c | 76 + .../epid/member/tiny/src/allowed_basenames.h | 46 + .../epid-sdk/epid/member/tiny/src/context.h | 75 + .../epid/member/tiny/src/createjoinrequest.c | 121 + .../epid/member/tiny/src/decompresskey.c | 29 + external/epid-sdk/epid/member/tiny/src/init.c | 94 + .../epid/member/tiny/src/native_types.h | 64 + .../epid-sdk/epid/member/tiny/src/nrprove.c | 136 + .../epid-sdk/epid/member/tiny/src/nrprove.h | 66 + .../epid-sdk/epid/member/tiny/src/presig.c | 31 + .../epid/member/tiny/src/presig_compute.c | 100 + .../epid/member/tiny/src/presig_compute.h | 51 + .../member/tiny/src/provisioncompressed.c | 31 + .../member/tiny/src/provisioncredential.c | 81 + .../epid/member/tiny/src/provisionkey.c | 90 + .../epid/member/tiny/src/registerbasename.c | 47 + .../epid-sdk/epid/member/tiny/src/serialize.c | 141 + .../epid-sdk/epid/member/tiny/src/serialize.h | 98 + .../epid/member/tiny/src/sethashalg.c | 33 + .../epid-sdk/epid/member/tiny/src/setsigrl.c | 79 + external/epid-sdk/epid/member/tiny/src/sign.c | 117 + .../epid-sdk/epid/member/tiny/src/signbasic.c | 159 + .../epid-sdk/epid/member/tiny/src/signbasic.h | 37 + .../epid-sdk/epid/member/tiny/src/startup.c | 27 + .../epid-sdk/epid/member/tiny/src/validate.c | 101 + .../epid-sdk/epid/member/tiny/src/validate.h | 86 + .../epid-sdk/epid/member/tiny/stdlib/endian.h | 38 + .../member/tiny/stdlib/src/tiny_stdlib.c} | 56 +- .../epid/member/tiny/stdlib/tiny_stdlib.h | 64 + .../member/tiny/stdlib/tiny_stdlib.parts} | 25 +- .../tiny/unittests/allowed_basenames-test.cc | 117 + .../member/tiny/unittests/context-test.cc | 484 + .../tiny/unittests/decompress_privkey-test.cc | 99 + .../member/tiny/unittests/get_sigsize-test.cc | 94 + .../tiny/unittests/internal/nr_prove-test.cc | 181 + .../unittests/internal/presig_compute-test.cc | 44 + .../tiny/unittests/internal/serialize-test.cc | 409 + .../tiny/unittests/internal/signbasic-test.cc | 109 + .../tiny/unittests/internal/validate-test.cc | 317 + .../tiny/unittests/join_request-test.cc | 369 + .../member/tiny/unittests/main-testhelper.cc | 24 + .../tiny/unittests/member-testhelper.cc | 468 + .../member/tiny/unittests/member-testhelper.h | 119 + .../epid/member/tiny/unittests/presig-test.cc | 117 + .../unittests/provision_compressed-test.cc | 176 + .../unittests/provision_credential-test.cc | 317 + .../tiny/unittests/provision_key-test.cc | 243 + .../epid/member/tiny}/unittests/sign-test.cc | 529 +- .../epid/member/tiny/unittests/utest.parts | 64 + .../epid-sdk/epid/member/tinymember.parts | 98 + external/epid-sdk/epid/member/tpm2/commit.h | 72 + external/epid-sdk/epid/member/tpm2/context.h | 123 + .../epid/member/tpm2/createprimary.h} | 36 +- .../epid-sdk/epid/member/tpm2/getrandom.h | 57 + .../epid/member/tpm2/ibm_tss/commit.c | 147 + .../epid/member/tpm2/ibm_tss/context.c | 150 + .../epid/member/tpm2/ibm_tss/conversion.c | 134 + .../epid/member/tpm2/ibm_tss/conversion.h | 117 + .../epid/member/tpm2/ibm_tss/createprimary.c | 100 + .../epid/member/tpm2/ibm_tss/getrandom.c | 78 + .../epid/member/tpm2/ibm_tss/load_external.c | 137 + .../epid-sdk/epid/member/tpm2/ibm_tss/nv.c | 166 + .../epid/member/tpm2/ibm_tss/printtss.c | 37 + .../epid/member/tpm2/ibm_tss/printtss.h | 36 + .../epid-sdk/epid/member/tpm2/ibm_tss/sign.c | 155 + .../epid-sdk/epid/member/tpm2/ibm_tss/state.h | 39 + .../epid-sdk/epid/member/tpm2/load_external.h | 54 + external/epid-sdk/epid/member/tpm2/nv.h | 110 + external/epid-sdk/epid/member/tpm2/sign.h | 85 + .../epid-sdk/epid/member/tpm2/src/commit.c | 188 + .../epid-sdk/epid/member/tpm2/src/context.c | 119 + .../epid/member/tpm2/src/createprimary.c | 58 + .../epid-sdk/epid/member/tpm2/src/getrandom.c | 43 + .../epid/member/tpm2/src/load_external.c | 54 + external/epid-sdk/epid/member/tpm2/src/nv.c | 134 + external/epid-sdk/epid/member/tpm2/src/sign.c | 127 + .../epid-sdk/epid/member/tpm2/src/state.h | 63 + external/epid-sdk/epid/member/tpm2/tpm2.parts | 123 + .../tpm2/unittests/commit-simulator-test.cc | 292 + .../epid/member/tpm2/unittests/commit-test.cc | 321 + .../member/tpm2/unittests/context-test.cc | 105 + .../tpm2/unittests/conversion-tss-test.cc | 160 + .../tpm2/unittests/createprimary-test.cc | 48 + .../unittests/getrandom-simulator-test.cc | 53 + .../member/tpm2/unittests/getrandom-test.cc | 67 + .../tpm2/unittests/getrandom-tss-test.cc | 44 + .../unittests/load_external-simulator-test.cc | 58 + .../tpm2/unittests/load_external-test.cc | 60 + .../member/tpm2/unittests/main-testhelper.cc | 64 + .../epid/member/tpm2/unittests/nv-test.cc | 326 + .../tpm2/unittests/sign-simulator-test.cc | 75 + .../epid/member/tpm2/unittests/sign-test.cc | 320 + .../member/tpm2/unittests/tpm2-testhelper.cc | 157 + .../member/tpm2/unittests/tpm2-testhelper.h | 78 + .../tpm2/unittests/tpm2_wrapper-testhelper.cc | 61 + .../tpm2/unittests/tpm2_wrapper-testhelper.h | 58 + .../epid/member/tpm_member.h} | 51 +- .../epid/member/unittests/context-test.cc | 620 + .../unittests/decompress_privkey-test.cc | 3 +- .../epid/member/unittests/get_sigsize-test.cc | 3 +- .../epid/member/unittests/iskeyvalid-test.cc | 198 + .../member/unittests/join_request-test.cc | 380 + .../epid/member/unittests/main-test.cc | 66 + .../member/unittests/member-testhelper.cc | 436 + .../epid/member/unittests/member-testhelper.h | 61 +- .../epid/member/unittests/nr_prove-test.cc | 413 + .../epid/member/unittests/presig-test.cc | 116 + .../epid/member/unittests/privateexp-test.cc | 155 + .../unittests/provision_compressed-test.cc | 178 + .../unittests/provision_credential-test.cc | 318 + .../member/unittests/provision_key-test.cc | 244 + .../epid/member/unittests/resize-test.cc | 63 + .../epid/member/unittests/sign-test.cc | 1160 ++ .../epid/member/unittests/signbasic-test.cc | 428 +- .../epid/member/unittests/storage-test.cc | 126 + .../epid/verifier/1.1/api.h | 38 +- .../verifier/1.1/src/check_privrl_entry.c | 0 .../epid/verifier/1.1/src/context.c | 8 +- .../epid/verifier/1.1/src/context.h | 6 +- .../epid/verifier/1.1/src/nrverify.c | 8 +- .../epid/verifier/1.1/src/sigs_linked.c | 0 .../epid/verifier/1.1/src/verify.c | 14 +- .../epid/verifier/1.1/src/verifybasic.c | 6 +- .../1.1/unittests/check_privrl_entry-test.cc | 5 +- .../verifier/1.1/unittests/context-test.cc | 18 +- .../verifier/1.1/unittests/nrverify-test.cc | 21 +- .../1.1/unittests/sigs_linked-test.cc | 3 +- .../unittests/testdata/verifier_precmp.inc | 0 .../1.1/unittests/verifier-testhelper.cc | 154 +- .../1.1/unittests/verifier-testhelper.h | 13 +- .../verifier/1.1/unittests/verify-test.cc | 80 +- .../1.1/unittests/verifybasic-test.cc | 17 +- .../epid/verifier/Makefile | 27 +- .../epid/verifier/api.h | 53 +- .../epid/verifier/src/check_privrl_entry.c | 15 +- .../epid/verifier/src/context.c | 35 +- .../epid/verifier/src/context.h | 6 +- .../epid/verifier/src/nrverify.c | 0 .../epid/verifier/src/sigs_linked.c | 0 .../epid/verifier/src/verify.c | 6 +- .../epid/verifier/src/verifybasic.c | 6 +- .../unittests/check_privrl_entry-test.cc | 7 +- .../epid/verifier/unittests/context-test.cc | 53 +- .../epid/verifier}/unittests/main-test.cc | 3 +- .../epid/verifier/unittests/nrverify-test.cc | 59 +- .../verifier/unittests/sigs_linked-test.cc | 5 +- .../testdata/sigrl/pub_key_sigrl_verify.inc | 4 +- .../testdata/sigrl/signature_sigrl_first.inc | 0 .../testdata/sigrl/signature_sigrl_last.inc | 0 .../testdata/sigrl/signature_sigrl_middle.inc | 0 .../testdata/sigrl/sigrl_five_entries.inc | 162 +- .../testdata/sigrl/sigrl_single_entry.inc | 0 .../verifier/unittests/verifier-testhelper.cc | 162 +- .../verifier/unittests/verifier-testhelper.h | 19 +- .../epid/verifier/unittests/verify-test.cc | 219 +- .../verifier/unittests/verifybasic-test.cc | 33 +- .../epid/verifier/verifier.parts | 5 +- .../example/Makefile | 34 +- .../example/compressed_data/README.md | 26 +- .../example/compressed_data/cacert.bin | Bin .../compressed_data/compressed_data.parts | 0 .../groupa/member0/mprivkey.dat | Bin .../groupa/member1/mprivkey.dat | Bin .../groupa/privrevokedmember0/mprivkey.dat | Bin .../groupa/privrevokedmember1/mprivkey.dat | Bin .../groupa/privrevokedmember2/mprivkey.dat | Bin .../example/compressed_data/groupa/privrl.bin | Bin .../compressed_data/groupa/privrl_empty.bin | Bin .../example/compressed_data/groupa/pubkey.bin | Bin .../groupa/sigrevokedmember0/mprivkey.dat | Bin .../groupa/sigrevokedmember1/mprivkey.dat | Bin .../groupa/sigrevokedmember2/mprivkey.dat | Bin .../example/compressed_data/groupa/sigrl.bin | Bin .../compressed_data/groupa/sigrl_empty.bin | Bin .../example/compressed_data/groupb/privrl.bin | Bin .../example/compressed_data/grprl.bin | Bin .../example/compressed_data/grprl_empty.bin | Bin .../example/compressed_data/mprivkey.dat | Bin .../example/compressed_data/privrl.bin | Bin .../example/compressed_data/pubkey.bin | Bin .../example/compressed_data/sigrl.bin | Bin external/epid-sdk/ext/argtable3/LICENSE | 26 + external/epid-sdk/ext/argtable3/Makefile | 22 + external/epid-sdk/ext/argtable3/argtable3.c | 5062 +++++++ external/epid-sdk/ext/argtable3/argtable3.h | 305 + .../ext/argtable3/argtable3.parts} | 36 +- .../ext/ipp/include/ippbase.h | 37 +- .../ext/ipp/include/ippcp.h | 475 +- external/epid-sdk/ext/ipp/include/ippcpdefs.h | 785 + .../ext/ipp/include/ippdefs.h | 44 +- .../ext/ipp/include/ipptypes.h | 39 +- external/epid-sdk/ext/ipp/include/sgx_ippcp.h | 534 + external/sgxssl/prepare_sgxssl.sh | 11 +- external/sqlite/src/sqlite3.c | 12299 +++++++++++----- external/sqlite/src/sqlite3.h | 658 +- linux/installer/common/sdk/BOMs/sdk_base.txt | 43 + linux/installer/common/sdk/BOMs/sdk_x64.txt | 3 + psw/ae/aesm_service/Makefile | 4 +- .../source/aesm/application/aesm_logic.cpp | 5 +- .../aesm/extension/endpoint_select_info.cpp | 2 - psw/ae/aesm_service/source/le/LEClass.cpp | 2 +- psw/ae/common/pve_qe_common.cpp | 67 +- psw/ae/data/prebuilt/le_prod_css.bin | Bin 1808 -> 1808 bytes .../prebuilt/white_list_cert_to_be_verify.bin | Bin 440 -> 1464 bytes psw/ae/inc/internal/pve_qe_common.h | 5 +- psw/ae/pce/Makefile | 2 +- psw/ae/pce/config.xml | 2 +- psw/ae/pce/pce.cpp | 6 +- psw/ae/pse/pse_op/config.xml | 2 +- psw/ae/pse/pse_pr/Makefile | 5 +- psw/ae/pse/pse_pr/config.xml | 2 +- psw/ae/pse/pse_pr/sigma_crypto_layer.cpp | 6 + psw/ae/pse/pse_pr/t_long_term_pairing.cpp | 8 +- psw/ae/pve/Makefile | 3 +- psw/ae/pve/config.xml | 8 +- psw/ae/pve/provision_msg2.cpp | 24 +- psw/ae/pve/provision_msg3.cpp | 36 +- psw/ae/pve/provision_msg4.cpp | 42 +- psw/ae/qe/Makefile | 7 +- psw/ae/qe/config.xml | 6 +- psw/ae/qe/quoting_enclave.cpp | 326 +- psw/ae/ref_le/ref_le.md | 3 +- psw/ae/ref_le/ref_wl_gen/parse_key_file.h | 31 +- psw/uae_service/linux/Makefile | 2 +- psw/urts/enclave.cpp | 11 + psw/urts/enclave.h | 3 + psw/urts/enclave_creator_hw.h | 2 - psw/urts/enclave_creator_hw_com.cpp | 3 +- psw/urts/linux/Makefile | 3 +- psw/urts/linux/edmm_utility.cpp | 206 + psw/urts/linux/edmm_utility.h | 90 + psw/urts/linux/enclave_creator_hw.cpp | 86 +- psw/urts/linux/urts.cpp | 56 + psw/urts/linux/urts.lds | 1 + psw/urts/linux/urts_internal.cpp | 2 +- psw/urts/parser/binparser.h | 1 + psw/urts/parser/elfparser.cpp | 16 + psw/urts/parser/elfparser.h | 3 + psw/urts/urts_com.h | 28 +- sdk/Makefile.opt_lib | 13 +- sdk/Makefile.source | 13 +- sdk/edger8r/linux/CodeGen.ml | 16 +- sdk/edger8r/linux/Preprocessor.ml | 23 +- sdk/edger8r/linux/Util.ml | 10 +- sdk/encrypt_enclave/Makefile | 71 + sdk/encrypt_enclave/encryptip.cpp | 897 ++ sdk/encrypt_enclave/encryptip.h | 148 + sdk/protected_code_loader/Makefile | 184 + sdk/protected_code_loader/crypto/pcl_cmac.c | 115 + .../crypto/pcl_crypto.cpp | 210 + .../crypto/pcl_crypto_internal.h | 109 + sdk/protected_code_loader/crypto/pcl_gcm128.c | 2477 ++++ .../crypto/pcl_ghash-x86_64.s | 691 + .../crypto/pcl_md32_common.h | 216 + .../crypto/pcl_modes_lcl.h | 96 + sdk/protected_code_loader/crypto/pcl_sha256.c | 215 + .../crypto/pcl_vpaes-x86_64.s | 770 + sdk/protected_code_loader/pcl_entry.cpp | 179 + sdk/protected_code_loader/pcl_internal.h | 98 + sdk/protected_code_loader/pcl_mem.cpp | 190 + .../unseal/pcl_sgx_get_key.cpp | 189 + .../unseal/pcl_tSeal.cpp | 135 + .../unseal/pcl_tSeal_internal.cpp | 116 + .../unseal/pcl_tSeal_util.cpp | 94 + .../unseal/pcl_unseal_internal.h | 81 + .../unseal/sim/pcl_deriv.cpp | 82 + .../unseal/sim/pcl_t_instructions.cpp | 196 + sdk/sample_libcrypto/Makefile | 14 +- sdk/sample_libcrypto/sample_libcrypto.cpp | 2 +- sdk/sign_tool/SignTool/manage_metadata.cpp | 117 +- sdk/sign_tool/SignTool/sign_tool.cpp | 215 +- sdk/sign_tool/SignTool/util_st.h | 52 +- sdk/simulation/assembly/linux/lowlib.S | 2 +- sdk/simulation/tinst/t_instructions.cpp | 3 + sdk/simulation/tinst/t_instructions.h | 2 +- sdk/simulation/uae_service_sim/linux/Makefile | 2 +- sdk/simulation/uinst/td_mngr.h | 2 +- .../urtssim/enclave_creator_sim.cpp | 1 + sdk/simulation/urtssim/urts_deploy.c | 6 + sdk/tlibcrypto/Makefile | 18 +- sdk/tlibcrypto/ipp/init_tcrypto_lib.cpp | 5 +- .../ipp/ipp_disp/ippcpsgx_disp00000.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00001.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00002.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00003.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00004.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00005.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00006.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00007.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00008.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00009.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00010.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00011.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00012.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00013.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00014.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00015.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00016.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00017.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00018.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00019.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00020.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00021.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00022.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00023.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00024.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00025.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00026.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00027.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00028.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00029.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00030.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00031.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00032.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00033.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00034.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00035.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00036.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00037.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00038.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00039.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00040.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00041.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00042.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00043.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00044.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00045.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00046.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00047.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00048.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00049.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00050.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00051.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00052.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00053.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00054.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00055.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00056.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00057.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00058.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00059.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00060.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00061.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00062.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00063.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00064.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00065.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00066.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00067.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00068.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00069.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00070.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00071.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00072.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00073.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00074.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00075.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00076.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00077.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00078.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00079.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00080.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00081.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00082.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00083.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00084.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00085.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00086.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00087.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00088.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00089.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00090.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00091.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00092.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00093.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00094.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00095.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00096.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00097.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00098.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00099.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00100.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00101.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00102.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00103.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00104.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00105.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00106.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00107.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00108.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00109.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00110.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00111.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00112.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00113.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00114.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00115.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00116.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00117.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00118.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00119.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00120.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00121.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00122.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00123.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00124.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00125.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00126.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00127.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00128.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00129.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00130.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00131.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00132.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00133.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00134.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00135.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00136.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00137.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00138.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00139.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00140.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00141.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00142.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00143.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00144.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00145.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00146.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00147.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00148.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00149.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00150.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00151.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00152.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00153.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00154.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00155.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00156.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00157.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00158.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00159.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00160.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00161.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00162.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00163.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00164.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00165.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00166.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00167.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00168.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00169.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00170.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00171.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00172.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00173.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00174.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00175.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00176.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00177.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00178.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00179.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00180.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00181.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00182.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00183.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00184.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00185.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00186.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00187.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00188.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00189.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00190.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00191.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00192.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00193.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00194.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00195.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00196.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00197.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00198.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00199.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00200.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00201.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00202.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00203.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00204.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00205.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00206.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00207.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00208.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00209.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00210.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00211.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00212.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00213.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00214.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00215.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00216.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00217.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00218.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00219.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00220.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00221.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00222.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00223.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00224.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00225.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00226.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00227.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00228.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00229.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00230.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00231.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00232.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00233.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00234.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00235.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00236.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00237.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00238.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00239.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00240.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00241.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00242.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00243.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00244.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00245.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00246.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00247.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00248.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00249.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00250.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00251.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00252.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00253.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00254.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00255.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00256.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00257.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00258.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00259.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00260.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00261.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00262.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00263.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00264.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00265.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00266.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00267.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00268.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00269.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00270.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00271.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00272.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00273.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00274.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00275.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00276.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00277.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00278.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00279.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00280.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00281.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00282.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00283.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00284.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00285.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00286.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00287.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00288.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00289.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00290.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00291.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00292.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00293.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00294.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00295.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00296.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00297.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00298.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00299.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00300.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00301.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00302.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00303.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00304.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00305.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00306.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00307.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00308.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00309.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00310.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00311.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00312.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00313.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00314.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00315.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00316.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00317.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00318.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00319.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00320.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00321.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00322.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00323.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00324.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00325.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00326.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00327.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00328.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00329.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00330.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00331.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00332.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00333.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00334.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00335.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00336.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00337.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00338.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00339.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00340.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00341.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00342.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00343.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00344.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00345.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00346.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00347.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00348.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00349.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00350.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00351.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00352.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00353.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00354.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00355.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00356.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00357.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00358.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00359.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00360.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00361.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00362.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00363.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00364.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00365.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00366.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00367.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00368.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00369.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00370.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00371.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00372.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00373.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00374.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00375.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00376.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00377.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00378.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00379.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00380.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00381.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00382.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00383.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00384.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00385.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00386.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00387.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00388.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00389.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00390.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00391.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00392.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00393.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00394.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00395.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00396.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00397.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00398.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00399.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00400.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00401.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00402.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00403.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00404.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00405.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00406.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00407.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00408.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00409.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00410.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00411.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00412.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00413.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00414.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00415.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00416.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00417.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00418.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00419.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00420.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00421.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00422.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00423.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00424.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00425.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00426.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00427.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00428.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00429.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00430.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00431.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00432.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00433.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00434.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00435.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00436.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00437.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00438.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00439.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00440.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00441.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00442.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00443.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00444.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00445.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00446.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00447.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00448.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00449.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00450.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00451.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00452.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00453.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00454.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00455.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00456.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00457.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00458.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00459.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00460.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00461.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00462.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00463.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00464.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00465.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00466.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00467.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00468.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00469.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00470.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00471.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00472.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00473.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00474.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00475.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00476.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00477.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00478.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00479.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00480.c | 54 + .../ipp/ipp_disp/ippcpsgx_disp00481.c | 54 + sdk/tlibcrypto/ipp/sgx_ecc256.cpp | 4 +- sdk/tlibcrypto/ipp/sgx_ecc256_ecdsa.cpp | 6 +- sdk/tlibcrypto/ipp/sgx_ecc256_internal.cpp | 6 +- sdk/tlibcrypto/ipp/sgx_rsa3072.cpp | 2 +- sdk/tlibcrypto/ipp/sgx_rsa_encryption.cpp | 185 +- sdk/tlibcrypto/ipp/sgx_rsa_internal.cpp | 123 +- sdk/tlibcrypto/ipp/sgx_sha256.cpp | 15 +- sdk/tlibcrypto/ipp/sgx_sha256_msg.cpp | 2 +- ...c256_common.cpp => sgx_tcrypto_common.cpp} | 31 +- ...x_ecc256_common.h => sgx_tcrypto_common.h} | 11 +- sdk/tlibcrypto/sgxssl/sgx_rsa_encryption.cpp | 86 +- sdk/tlibcxx/README.sgx | 8 +- sdk/trts/init_enclave.cpp | 30 +- sdk/trts/linux/trts_pic.S | 51 +- sdk/trts/trts_add_trim.cpp | 54 +- sdk/trts/trts_ecall.cpp | 86 +- sdk/trts/trts_internal.h | 6 +- sdk/trts/trts_nsp.cpp | 6 +- sdk/trts/trts_shared_constants.h | 1 + sdk/trts/trts_xsave.cpp | 8 +- sdk/tsetjmp/_setjmp.S | 20 +- sdk/ukey_exchange/Makefile | 2 +- 1404 files changed, 92858 insertions(+), 55199 deletions(-) create mode 100644 SampleCode/SampleEnclavePCL/App/App.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/App.h create mode 100644 SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp create mode 100644 SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave.h create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave.lds create mode 100644 SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp create mode 100644 SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl create mode 100644 SampleCode/SampleEnclavePCL/Include/user_types.h create mode 100644 SampleCode/SampleEnclavePCL/Makefile create mode 100644 SampleCode/SampleEnclavePCL/README.md create mode 100644 SampleCode/SampleEnclavePCL/Seal/Seal.config.xml create mode 100644 SampleCode/SampleEnclavePCL/Seal/Seal.cpp create mode 100644 SampleCode/SampleEnclavePCL/Seal/Seal.edl create mode 100644 SampleCode/SampleEnclavePCL/Seal/Seal.lds create mode 100644 SampleCode/SampleEnclavePCL/Seal/Seal_private.pem create mode 100644 SampleCode/SampleEnclavePCL/debug_mock_key.bin create mode 100644 common/inc/internal/pcl_common.h create mode 100644 common/inc/sgx_pcl_guid.h delete mode 100644 common/src/ipp_rsa_key.cpp delete mode 100644 external/epid-sdk-3.0.0/CHANGELOG.md delete mode 100644 external/epid-sdk-3.0.0/Makefile.in delete mode 100644 external/epid-sdk-3.0.0/SConstruct delete mode 100644 external/epid-sdk-3.0.0/configure.ac delete mode 100644 external/epid-sdk-3.0.0/epid/common-testhelper/common-testhelper.parts delete mode 100644 external/epid-sdk-3.0.0/epid/member/Makefile delete mode 100644 external/epid-sdk-3.0.0/epid/member/api.h delete mode 100644 external/epid-sdk-3.0.0/epid/member/member.parts delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/context.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/context.h delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/nr_prove.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/presig.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/privkey.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/privkey.h delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/request_join.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/src/signbasic.c delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/compute_presig-test.cc delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/context-test.cc delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.cc delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/nr_prove-test.cc delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/presig-test.cc delete mode 100644 external/epid-sdk-3.0.0/epid/member/unittests/request_join-test.cc delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/member0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/privrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/privrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/pubkey.bin delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/README.md delete mode 100644 external/epid-sdk-3.0.0/example/data/cacert.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/data.parts delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/member0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/member1/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember1/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember2/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/privrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/privrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/pubkey.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember1/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember2/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/sigrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupa/sigrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/member0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/privrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/privrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/privrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/pubkey.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/sigrevokedmember0/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/sigrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/groupb/sigrl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/grprl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/grprl_empty.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/mprivkey.dat delete mode 100644 external/epid-sdk-3.0.0/example/data/privrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/pubkey.bin delete mode 100644 external/epid-sdk-3.0.0/example/data/sigrl.bin delete mode 100644 external/epid-sdk-3.0.0/example/signmsg/signmsg.parts delete mode 100644 external/epid-sdk-3.0.0/example/signmsg/src/main.c delete mode 100644 external/epid-sdk-3.0.0/example/signmsg/src/prng.c delete mode 100644 external/epid-sdk-3.0.0/example/signmsg/src/signmsg.c delete mode 100644 external/epid-sdk-3.0.0/example/signmsg/src/signmsg.h delete mode 100644 external/epid-sdk-3.0.0/example/util/Makefile delete mode 100644 external/epid-sdk-3.0.0/example/util/buffutil.h delete mode 100644 external/epid-sdk-3.0.0/example/util/convutil.h delete mode 100644 external/epid-sdk-3.0.0/example/util/envutil.h delete mode 100644 external/epid-sdk-3.0.0/example/util/src/bufutil.c delete mode 100644 external/epid-sdk-3.0.0/example/util/src/convutil.c delete mode 100644 external/epid-sdk-3.0.0/example/util/src/envutil.c delete mode 100644 external/epid-sdk-3.0.0/example/util/src/strutil.c delete mode 100644 external/epid-sdk-3.0.0/example/util/util.parts delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/src/main.c delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/src/verifysig.c delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/src/verifysig.h delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.c delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.h delete mode 100644 external/epid-sdk-3.0.0/example/verifysig/verifysig.parts delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/LICENSE delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/Makefile delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/include/dropt.h delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/include/dropt_string.h delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/src/dropt.c delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/src/dropt_handlers.c delete mode 100644 external/epid-sdk-3.0.0/ext/dropt/src/dropt_string.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/include/ippcpdefs.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/include/ippcpepid.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/ippcommon.parts delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/ippcp.parts delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/ippcpepid.parts delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/include/owndefs.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/Makefile delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/owncp.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbn.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresourceca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnsetca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuimpl.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccp.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpdpca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpgenkeyca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpinitca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod128.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod128ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcom.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcomca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppoint.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointopca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppublickeyca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsetkeyca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsigndsaca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsscm.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsscm.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpstdca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpverifydsaca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphash.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashcnt.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashmd5px.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha1px.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha256px.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha512px.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmd5ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontexpbinca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontgomery.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontgomeryca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontred.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmulbnukara.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppmasm2.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppmasm2.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprimeg.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprimeginitca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprng.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngenca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprnginitca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngsetca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha1ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha256ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha512ca.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcptool.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpvariant.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/Makefile delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/ippcpepid_y8.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/owncpepid.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfp.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpec.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpoint.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpointstuff.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecstuff.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfphashstuff.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpstuff.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpstuff.h delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpx.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.c delete mode 100644 external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.h delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/g++.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/gcc.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/intelc_posix-any.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/intelc_win32-any_win32-x86.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/intelc_win32-any_win32-x86_64.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/msvc_win32-any_win32-x86.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/debug/msvc_win32-any_win32-x86_64.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/__init__.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/g++.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/gcc.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/intelc_posix-any.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/intelc_win32-any_win32-x86.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/intelc_win32-any_win32-x86_64.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/msvc_win32-any_win32-x86.py delete mode 100644 external/epid-sdk-3.0.0/parts-site/configurations/release/msvc_win32-any_win32-x86_64.py delete mode 100644 external/epid-sdk-3.0.0/tools/Makefile delete mode 100644 external/epid-sdk-3.0.0/tools/extractgrps/extractgrps.parts delete mode 100644 external/epid-sdk-3.0.0/tools/extractgrps/src/main.c delete mode 100644 external/epid-sdk-3.0.0/tools/extractkeys/extractkeys.parts delete mode 100644 external/epid-sdk-3.0.0/tools/extractkeys/src/main.c delete mode 100644 external/epid-sdk-3.0.0/tools/revokegrp/revokegrp.parts delete mode 100644 external/epid-sdk-3.0.0/tools/revokegrp/src/main.c delete mode 100644 external/epid-sdk-3.0.0/tools/revokekey/revokekey.parts delete mode 100644 external/epid-sdk-3.0.0/tools/revokekey/src/main.c delete mode 100644 external/epid-sdk-3.0.0/tools/revokesig/revokesig.parts delete mode 100644 external/epid-sdk-3.0.0/tools/revokesig/src/main.c create mode 100644 external/epid-sdk/CHANGELOG.md rename external/{epid-sdk-3.0.0 => epid-sdk}/LICENSE.txt (97%) create mode 100644 external/epid-sdk/Makefile create mode 100644 external/epid-sdk/Makefile.in rename external/{epid-sdk-3.0.0 => epid-sdk}/NOTICE.txt (51%) rename external/{epid-sdk-3.0.0 => epid-sdk}/README.md (61%) create mode 100644 external/epid-sdk/SConstruct rename external/{epid-sdk-3.0.0 => epid-sdk}/configure (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/epid_params-testhelper.cc (67%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/epid_params-testhelper.h (98%) create mode 100644 external/epid-sdk/epid/common-testhelper/1.1/testdata/grp01/member0/sig_bsn0_msg_0_255_sha256.inc create mode 100644 external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/corrupted_privrl.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/epid_grpcrt.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_three_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/privrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/sig_sha256_bsnrnd_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_first_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_last_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_middle_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_first_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_last_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_middle_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/1.1/verifier_wrapper-testhelper.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/Makefile (74%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/bignum_wrapper-testhelper.cc (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/bignum_wrapper-testhelper.h (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/common-testhelper.parts rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ecgroup_wrapper-testhelper.cc (85%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ecgroup_wrapper-testhelper.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ecpoint_wrapper-testhelper.cc (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ecpoint_wrapper-testhelper.h (98%) create mode 100644 external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.cc create mode 100644 external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.h create mode 100644 external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.cc create mode 100644 external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/epid_params-testhelper.cc (64%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/epid_params-testhelper.h (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/errors-testhelper.h (78%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ffelement_wrapper-testhelper.cc (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/ffelement_wrapper-testhelper.h (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/finite_field_wrapper-testhelper.cc (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/finite_field_wrapper-testhelper.h (100%) rename external/{epid-sdk-3.0.0/example/util/strutil.h => epid-sdk/epid/common-testhelper/mem_params-testhelper.cc} (61%) create mode 100644 external/epid-sdk/epid/common-testhelper/mem_params-testhelper.h create mode 100644 external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.cc create mode 100644 external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/octstr-testhelper.cc (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/octstr-testhelper.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/prng-testhelper.h (63%) create mode 100644 external/epid-sdk/epid/common-testhelper/testapp-testhelper.cc create mode 100644 external/epid-sdk/epid/common-testhelper/testapp-testhelper.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/gpubkey.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_bsn0_msg_0_255_sha512.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha384_sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test1.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test1_basename1_sha256.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/privrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp01/verrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/corrupted_privrl.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/iprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0_rl_singleentry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_rndbase_msg0.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_bsn0_msg0.inc create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0.inc create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0_no_sigrl.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_huge_bsn_msg0.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member1/mprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey001.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey002.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/privrl_single_entry_revoked_key000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/pubkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey001.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey002.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_first_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_last_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/sigrl_ver_2.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey000.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey001.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey002.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha256bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha384bsn0msg0.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512_256bsn0msg0.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha256bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha384bsn0msg0.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512_256bsn0msg0.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha256bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha384bsn0msg0.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512_256bsn0msg0.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512bsn0msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha384.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc (100%) create mode 100644 external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey003.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey004.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey005.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/sig_revoked3sha256bsn1msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl_012revoked.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_y/iprivkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grp_y/pubkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grprl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grprl_revoked_grp_x_first_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grprl_revoked_grp_x_last_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grprl_revoked_grp_x_middle_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/grprl_single_entry_revoked_grp_x.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/privrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_empty_sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_nosigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_revkey.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_rndbase_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_sigrevoked_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sig_test1_basename1_sha256.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/groupb/sig_grouprevoked_sha256_bsn0_msg0.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/testdata/ikgf/grprl.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/unittests/bignum_wrapper-test.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc (85%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc (83%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/unittests/ffelement_wrapper-test.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/unittests/finite_field_wrapper-test.cc (97%) rename external/{epid-sdk-3.0.0/epid/verifier => epid-sdk/epid/common-testhelper}/unittests/main-test.cc (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/verifier_wrapper-testhelper.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common-testhelper/verifier_wrapper-testhelper.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/file_parser.h (94%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/commitment.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/commitment.h (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/epid11params.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/epid11params.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/epid11params_tate.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/file_parser.c (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/grouppubkey.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/src/grouppubkey.h (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/types.h (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/1.1/unittests/file_parser-test.cc (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/Makefile (79%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/bitsupplier.h (57%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/common.parts (97%) create mode 100644 external/epid-sdk/epid/common/epiddefs.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/errors.h (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/file_parser.h (92%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/bignum.h (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/ecdsa.h (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/ecgroup.h (93%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/finitefield.h (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/hash.h (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/pairing.h (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/printutils.h (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/bignum-internal.h (74%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/bignum.c (84%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/ecdsa_sign.c (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/ecdsa_verify.c (94%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/ecgroup-internal.h (79%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/ecgroup.c (75%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/finitefield-internal.h (56%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/finitefield.c (75%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/pairing-internal.h (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/pairing.c (81%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/printutils.c (85%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/sha256.c (88%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/tatepairing-internal.h (92%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/src/tatepairing.c (65%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/tatepairing.h (85%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/bignum-test.cc (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/ecdsa_sign-test.cc (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/ecdsa_verify-test.cc (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/ecgroup-test.cc (77%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/ffelement-test.cc (91%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/finitefield-test.cc (82%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/hash-test.cc (96%) rename external/{epid-sdk-3.0.0/epid/member => epid-sdk/epid/common/math}/unittests/main-test.cc (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/octstrconvert-test.cc (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/pairing-test.cc (68%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/printutils-test.cc (80%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/math/unittests/tatepairing-test.cc (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/commitment.c (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/commitment.h (80%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/endian_convert.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/epid2params.c (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/epid2params.h (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/epid2params_ate.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/errors.c (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/file_parser-internal.h (92%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/file_parser.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/grouppubkey.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/grouppubkey.h (100%) create mode 100644 external/epid-sdk/epid/common/src/hashsize.c create mode 100644 external/epid-sdk/epid/common/src/hashsize.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/memory.c (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/memory.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/sigrlvalid.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/sigrlvalid.h (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/stack.c (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/src/stack.h (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/stdtypes.h (100%) create mode 100644 external/epid-sdk/epid/common/tinycommon.parts rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/types.h (94%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/common/unittests/file_parser-test.cc (99%) create mode 100644 external/epid-sdk/epid/member/Makefile create mode 100644 external/epid-sdk/epid/member/api.h create mode 100644 external/epid-sdk/epid/member/member.parts create mode 100644 external/epid-sdk/epid/member/software_member.h create mode 100644 external/epid-sdk/epid/member/src/allowed_basenames.c create mode 100644 external/epid-sdk/epid/member/src/allowed_basenames.h create mode 100644 external/epid-sdk/epid/member/src/context.c create mode 100644 external/epid-sdk/epid/member/src/context.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/src/decompress_privkey.c (88%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/src/get_sigsize.c (96%) create mode 100644 external/epid-sdk/epid/member/src/hash_basename.c create mode 100644 external/epid-sdk/epid/member/src/hash_basename.h create mode 100644 external/epid-sdk/epid/member/src/join.c create mode 100644 external/epid-sdk/epid/member/src/join_commitment.c create mode 100644 external/epid-sdk/epid/member/src/join_commitment.h create mode 100644 external/epid-sdk/epid/member/src/nrprove.c create mode 100644 external/epid-sdk/epid/member/src/nrprove.h create mode 100644 external/epid-sdk/epid/member/src/nrprove_commitment.c create mode 100644 external/epid-sdk/epid/member/src/nrprove_commitment.h create mode 100644 external/epid-sdk/epid/member/src/precomp.c create mode 100644 external/epid-sdk/epid/member/src/precomp.h create mode 100644 external/epid-sdk/epid/member/src/presig-internal.h create mode 100644 external/epid-sdk/epid/member/src/presig.c create mode 100644 external/epid-sdk/epid/member/src/privateexp.c rename external/{epid-sdk-3.0.0/example/signmsg/src/prng.h => epid-sdk/epid/member/src/privateexp.h} (57%) create mode 100644 external/epid-sdk/epid/member/src/provision_bulk.c create mode 100644 external/epid-sdk/epid/member/src/provision_compressed.c create mode 100644 external/epid-sdk/epid/member/src/provision_join.c create mode 100644 external/epid-sdk/epid/member/src/resize.c create mode 100644 external/epid-sdk/epid/member/src/resize.h rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/src/sign.c (68%) create mode 100644 external/epid-sdk/epid/member/src/sign_commitment.c create mode 100644 external/epid-sdk/epid/member/src/sign_commitment.h create mode 100644 external/epid-sdk/epid/member/src/signbasic.c create mode 100644 external/epid-sdk/epid/member/src/signbasic.h create mode 100644 external/epid-sdk/epid/member/src/startup.c create mode 100644 external/epid-sdk/epid/member/src/storage.c create mode 100644 external/epid-sdk/epid/member/src/storage.h create mode 100644 external/epid-sdk/epid/member/src/validatekey.c create mode 100644 external/epid-sdk/epid/member/src/validatekey.h create mode 100644 external/epid-sdk/epid/member/src/write_precomp.c create mode 100644 external/epid-sdk/epid/member/src/write_precomp.h create mode 100644 external/epid-sdk/epid/member/tiny/math/efq.h create mode 100644 external/epid-sdk/epid/member/tiny/math/efq2.h create mode 100644 external/epid-sdk/epid/member/tiny/math/fp.h create mode 100644 external/epid-sdk/epid/member/tiny/math/fq.h create mode 100644 external/epid-sdk/epid/member/tiny/math/fq12.h create mode 100644 external/epid-sdk/epid/member/tiny/math/fq2.h create mode 100644 external/epid-sdk/epid/member/tiny/math/fq6.h create mode 100644 external/epid-sdk/epid/member/tiny/math/hashwrap.h create mode 100644 external/epid-sdk/epid/member/tiny/math/math.parts rename external/{epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/precomp.h => epid-sdk/epid/member/tiny/math/mathdefs.h} (66%) create mode 100644 external/epid-sdk/epid/member/tiny/math/mathtypes.h create mode 100644 external/epid-sdk/epid/member/tiny/math/pairing.h create mode 100644 external/epid-sdk/epid/member/tiny/math/serialize.h create mode 100644 external/epid-sdk/epid/member/tiny/math/sha256.h create mode 100644 external/epid-sdk/epid/member/tiny/math/sha512.h create mode 100644 external/epid-sdk/epid/member/tiny/math/src/efq.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/efq2.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/fp.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/fq.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/fq12.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/fq2.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/fq6.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/hashwrap.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/pairing.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/serialize.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/sha256.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/sha512.c create mode 100644 external/epid-sdk/epid/member/tiny/math/src/vli.c create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.h create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/efq-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/efq2-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/fp-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/fq-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/fq12-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/fq2-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/fq6-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/internal/onetimepad-test.cc rename external/{epid-sdk-3.0.0/epid/common-testhelper/unittests/main-test.cc => epid-sdk/epid/member/tiny/math/unittests/main-testhelper.cc} (83%) create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/onetimepad.h create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/pairing-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/serialize-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/sha256-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/sha512-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/utest.parts create mode 100644 external/epid-sdk/epid/member/tiny/math/unittests/vli-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/math/vli.h create mode 100644 external/epid-sdk/epid/member/tiny/src/allowed_basenames.c create mode 100644 external/epid-sdk/epid/member/tiny/src/allowed_basenames.h create mode 100644 external/epid-sdk/epid/member/tiny/src/context.h create mode 100644 external/epid-sdk/epid/member/tiny/src/createjoinrequest.c create mode 100644 external/epid-sdk/epid/member/tiny/src/decompresskey.c create mode 100644 external/epid-sdk/epid/member/tiny/src/init.c create mode 100644 external/epid-sdk/epid/member/tiny/src/native_types.h create mode 100644 external/epid-sdk/epid/member/tiny/src/nrprove.c create mode 100644 external/epid-sdk/epid/member/tiny/src/nrprove.h create mode 100644 external/epid-sdk/epid/member/tiny/src/presig.c create mode 100644 external/epid-sdk/epid/member/tiny/src/presig_compute.c create mode 100644 external/epid-sdk/epid/member/tiny/src/presig_compute.h create mode 100644 external/epid-sdk/epid/member/tiny/src/provisioncompressed.c create mode 100644 external/epid-sdk/epid/member/tiny/src/provisioncredential.c create mode 100644 external/epid-sdk/epid/member/tiny/src/provisionkey.c create mode 100644 external/epid-sdk/epid/member/tiny/src/registerbasename.c create mode 100644 external/epid-sdk/epid/member/tiny/src/serialize.c create mode 100644 external/epid-sdk/epid/member/tiny/src/serialize.h create mode 100644 external/epid-sdk/epid/member/tiny/src/sethashalg.c create mode 100644 external/epid-sdk/epid/member/tiny/src/setsigrl.c create mode 100644 external/epid-sdk/epid/member/tiny/src/sign.c create mode 100644 external/epid-sdk/epid/member/tiny/src/signbasic.c create mode 100644 external/epid-sdk/epid/member/tiny/src/signbasic.h create mode 100644 external/epid-sdk/epid/member/tiny/src/startup.c create mode 100644 external/epid-sdk/epid/member/tiny/src/validate.c create mode 100644 external/epid-sdk/epid/member/tiny/src/validate.h create mode 100644 external/epid-sdk/epid/member/tiny/stdlib/endian.h rename external/{epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresource.h => epid-sdk/epid/member/tiny/stdlib/src/tiny_stdlib.c} (51%) create mode 100644 external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.h rename external/{epid-sdk-3.0.0/parts-site/configurations/debug/__init__.py => epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.parts} (51%) create mode 100644 external/epid-sdk/epid/member/tiny/unittests/allowed_basenames-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/context-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/decompress_privkey-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/get_sigsize-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/internal/nr_prove-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/internal/presig_compute-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/internal/serialize-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/internal/signbasic-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/internal/validate-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/join_request-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/main-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/member-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/member-testhelper.h create mode 100644 external/epid-sdk/epid/member/tiny/unittests/presig-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/provision_compressed-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/provision_credential-test.cc create mode 100644 external/epid-sdk/epid/member/tiny/unittests/provision_key-test.cc rename external/{epid-sdk-3.0.0/epid/member => epid-sdk/epid/member/tiny}/unittests/sign-test.cc (77%) create mode 100644 external/epid-sdk/epid/member/tiny/unittests/utest.parts create mode 100644 external/epid-sdk/epid/member/tinymember.parts create mode 100644 external/epid-sdk/epid/member/tpm2/commit.h create mode 100644 external/epid-sdk/epid/member/tpm2/context.h rename external/{epid-sdk-3.0.0/parts-site/configurations/__init__.py => epid-sdk/epid/member/tpm2/createprimary.h} (50%) create mode 100644 external/epid-sdk/epid/member/tpm2/getrandom.h create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/commit.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/context.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.h create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/createprimary.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/getrandom.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/load_external.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/nv.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.h create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/sign.c create mode 100644 external/epid-sdk/epid/member/tpm2/ibm_tss/state.h create mode 100644 external/epid-sdk/epid/member/tpm2/load_external.h create mode 100644 external/epid-sdk/epid/member/tpm2/nv.h create mode 100644 external/epid-sdk/epid/member/tpm2/sign.h create mode 100644 external/epid-sdk/epid/member/tpm2/src/commit.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/context.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/createprimary.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/getrandom.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/load_external.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/nv.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/sign.c create mode 100644 external/epid-sdk/epid/member/tpm2/src/state.h create mode 100644 external/epid-sdk/epid/member/tpm2/tpm2.parts create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/commit-simulator-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/commit-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/context-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/conversion-tss-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/createprimary-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/getrandom-simulator-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/getrandom-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/getrandom-tss-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/load_external-simulator-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/load_external-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/main-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/nv-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/sign-simulator-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/sign-test.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.h create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.cc create mode 100644 external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h rename external/{epid-sdk-3.0.0/example/util/stdtypes.h => epid-sdk/epid/member/tpm_member.h} (55%) create mode 100644 external/epid-sdk/epid/member/unittests/context-test.cc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/unittests/decompress_privkey-test.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/unittests/get_sigsize-test.cc (97%) create mode 100644 external/epid-sdk/epid/member/unittests/iskeyvalid-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/join_request-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/main-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/member-testhelper.cc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/unittests/member-testhelper.h (68%) create mode 100644 external/epid-sdk/epid/member/unittests/nr_prove-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/presig-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/privateexp-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/provision_compressed-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/provision_credential-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/provision_key-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/resize-test.cc create mode 100644 external/epid-sdk/epid/member/unittests/sign-test.cc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/member/unittests/signbasic-test.cc (50%) create mode 100644 external/epid-sdk/epid/member/unittests/storage-test.cc rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/api.h (93%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/check_privrl_entry.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/context.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/context.h (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/nrverify.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/sigs_linked.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/verify.c (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/src/verifybasic.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/check_privrl_entry-test.cc (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/context-test.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/nrverify-test.cc (93%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/sigs_linked-test.cc (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/testdata/verifier_precmp.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/verifier-testhelper.cc (56%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/verifier-testhelper.h (88%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/verify-test.cc (91%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/1.1/unittests/verifybasic-test.cc (86%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/Makefile (82%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/api.h (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/check_privrl_entry.c (84%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/context.c (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/context.h (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/nrverify.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/sigs_linked.c (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/verify.c (99%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/src/verifybasic.c (98%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/check_privrl_entry-test.cc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/context-test.cc (96%) rename external/{epid-sdk-3.0.0/epid/common/math => epid-sdk/epid/verifier}/unittests/main-test.cc (90%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/nrverify-test.cc (85%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/sigs_linked-test.cc (96%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc (95%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/signature_sigrl_first.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/signature_sigrl_last.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/signature_sigrl_middle.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/testdata/sigrl/sigrl_single_entry.inc (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/verifier-testhelper.cc (87%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/verifier-testhelper.h (93%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/verify-test.cc (87%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/unittests/verifybasic-test.cc (83%) rename external/{epid-sdk-3.0.0 => epid-sdk}/epid/verifier/verifier.parts (97%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/Makefile (77%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/README.md (82%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/cacert.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/compressed_data.parts (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/member0/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/member1/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/privrevokedmember0/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/privrevokedmember1/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/privrevokedmember2/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/privrl.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/privrl_empty.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/pubkey.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/sigrevokedmember0/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/sigrevokedmember1/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/sigrevokedmember2/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/sigrl.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupa/sigrl_empty.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/groupb/privrl.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/grprl.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/grprl_empty.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/mprivkey.dat (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/privrl.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/pubkey.bin (100%) rename external/{epid-sdk-3.0.0 => epid-sdk}/example/compressed_data/sigrl.bin (100%) create mode 100644 external/epid-sdk/ext/argtable3/LICENSE create mode 100644 external/epid-sdk/ext/argtable3/Makefile create mode 100644 external/epid-sdk/ext/argtable3/argtable3.c create mode 100644 external/epid-sdk/ext/argtable3/argtable3.h rename external/{epid-sdk-3.0.0/ext/dropt/dropt.parts => epid-sdk/ext/argtable3/argtable3.parts} (50%) rename external/{epid-sdk-3.0.0 => epid-sdk}/ext/ipp/include/ippbase.h (80%) rename external/{epid-sdk-3.0.0 => epid-sdk}/ext/ipp/include/ippcp.h (62%) create mode 100644 external/epid-sdk/ext/ipp/include/ippcpdefs.h rename external/{epid-sdk-3.0.0 => epid-sdk}/ext/ipp/include/ippdefs.h (77%) rename external/{epid-sdk-3.0.0 => epid-sdk}/ext/ipp/include/ipptypes.h (97%) create mode 100644 external/epid-sdk/ext/ipp/include/sgx_ippcp.h create mode 100644 psw/urts/linux/edmm_utility.cpp create mode 100644 psw/urts/linux/edmm_utility.h create mode 100644 sdk/encrypt_enclave/Makefile create mode 100644 sdk/encrypt_enclave/encryptip.cpp create mode 100644 sdk/encrypt_enclave/encryptip.h create mode 100644 sdk/protected_code_loader/Makefile create mode 100644 sdk/protected_code_loader/crypto/pcl_cmac.c create mode 100644 sdk/protected_code_loader/crypto/pcl_crypto.cpp create mode 100644 sdk/protected_code_loader/crypto/pcl_crypto_internal.h create mode 100644 sdk/protected_code_loader/crypto/pcl_gcm128.c create mode 100644 sdk/protected_code_loader/crypto/pcl_ghash-x86_64.s create mode 100644 sdk/protected_code_loader/crypto/pcl_md32_common.h create mode 100644 sdk/protected_code_loader/crypto/pcl_modes_lcl.h create mode 100644 sdk/protected_code_loader/crypto/pcl_sha256.c create mode 100644 sdk/protected_code_loader/crypto/pcl_vpaes-x86_64.s create mode 100644 sdk/protected_code_loader/pcl_entry.cpp create mode 100644 sdk/protected_code_loader/pcl_internal.h create mode 100644 sdk/protected_code_loader/pcl_mem.cpp create mode 100644 sdk/protected_code_loader/unseal/pcl_sgx_get_key.cpp create mode 100644 sdk/protected_code_loader/unseal/pcl_tSeal.cpp create mode 100644 sdk/protected_code_loader/unseal/pcl_tSeal_internal.cpp create mode 100644 sdk/protected_code_loader/unseal/pcl_tSeal_util.cpp create mode 100644 sdk/protected_code_loader/unseal/pcl_unseal_internal.h create mode 100644 sdk/protected_code_loader/unseal/sim/pcl_deriv.cpp create mode 100644 sdk/protected_code_loader/unseal/sim/pcl_t_instructions.cpp create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c create mode 100644 sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c rename sdk/tlibcrypto/ipp/{sgx_ecc256_common.cpp => sgx_tcrypto_common.cpp} (84%) rename sdk/tlibcrypto/ipp/{sgx_ecc256_common.h => sgx_tcrypto_common.h} (90%) diff --git a/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml b/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml index b03cd79b..8cdc2628 100644 --- a/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml +++ b/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml @@ -114,15 +114,15 @@ This Agreement is governed by the laws of the State of New York and the intellec - - - - - - - - - + + + + + + + + + Z58XAiigbg32t#*EBV9vx$IzYctz%cRnPKL>`r3PczWchvloVz0uqm*SkdW}+y?y-=2?==$2?<5+5eo31 zzAR8P@Ph30QC146c#vuv_<&|6sUV4jR2GACYlsef#4b#z*!j;BdBK#{4GF1z z;oWOVRX4r8v`}rL>6`Nl-)qEA^NxiNbU_PfZ=BJ8g_~$LXejFt5-Pn`CC=4g&I(@e zJP`YKD#g6Af8m{xghe0hS6_tezQ5aC`<2IRFg0oJWVyfh`IU*6myUv!wY7YK>I-7* zIvtMK-sg|QG}uV6gL86n+S}Vv{0$5YGFw_&YHDio^Ya@T8VU;wD=I30Z=0H$U@%ym znw*>*4~$VOs*=K4RXj)7dm>p44?9@OyMY%iNseN_|E+ZHwFh3lIrk-4smlQGvda%2 ziaCdRjg0Ca)GD3%w3P4>Rw|kn3Xgwk>xWF{Qer5!4thO`k$)wwqkj_-5m9WVk72k$ z()-+(nWb-^kLKFz>(g3e@msX&V>H)KnLxs(r3ZY54lA|vKVARSdHaN!7~4dP;$vcb z2p`YrXLA|cJl_7~Wj<71U0$oKA~|D&XQ0P|1%2SmAIK5@m0fIk5~57OcwKG7!gRD# zLv&MqEx2A)Qxhl&)1OQq___Ax1&3^(o*$x1MTINDU09{vr*0 z$(}~e!J`Ccco}F!_uPKeud{0vY((R8!QRS>J*v*Pp%*2+t@1^~NzZ-@}^Uh`EE)%k2sNj~9d2urvZS~VB z_L*d6#P?`XS%r3Wv0>D|WW!jn)WoI3xI2y`#+VY1h!)-P9iAS+j*`h4(Ym>DZ*e<{ z{NDShE(l!j1mKL+_o#>rupNF*Mi%|f-uEOA|7u39>7E=23X?kw1 z$mA&Xq|>SVG69_hm;IXd2;y3G_;>l`~?_t7V0hli!e*5)qYg;2#o#K}Jzi zUF|~@;miHT5E1$MbnKC(90$K5zM45NMO6COezA@jCZxZD>Fn&Ro{c{-Co#6OrC)k^ za8QxV=!WLi(vCI4d?LIi`u&1YIco;N3Hi*MRY-?^_S~YEA z*I-7|9^$$`RXO5_sIMwygWqENE*}-ArR>$>6hVQi#gmW|85kH^!DOVU;!%qYsG}%$ zABS|dJPMWyX$uStyt}&-6BFx?L@QdHn$pnL?pxnO8&5vo*G-v(=_2-l2DH_E z_N<`|o)2vy<-A2^D5@&F*qZ?>J%lD%8CBWb#1EvfQBSAfkz@f~^)*H^H8eD|u&^*O zVK^jW{#{B|i|vfwgE&Fp|Lp#;07Ov0=v!QgGbNFl} z0~}5z7cud0F>4t*A3xJZYquIbpjrFcBSOy~!(d~5{mGLjadC0T;{MsKAL(A$$0cPV zjao7>C#FRBceb=TnF{vHzvpUS&dbZYzV;x~YDY>jstW9zHrdk^;YT&ITg153tD|uq znNsq(IiG-O^CM>JrVZwW2Ff<9HSQ=oX~ga}Dy^C%2heRyZ2G|N9RdQU5VfWwV<9h3 zoJC_R)_Q6AC2IU+5zEHAqS2s<{Jy zctun_5puSh=*w^4&&CGVKxo)msVYo%QKwWKwrsIe+{FPyv9`9hxoO43jJr^aI{GpY zj4&<+B=XWvdJ)Q;tT~_?3yFoS#Ps8!bHj4rvg^H>nvg2Vw5Hs{N|Jc+^*HKd11Aj zaV#gi{i-HD_jyRh*+LcEziA@#SlulqcO5brdey)0%J;2C?e+ew^+jpwD~jp-iz3}! zgQmk@x3&j{PMRrRA4LqD(3kP8mVL>H_or;y!TN034XSP?L+Jw~Iyp~TdPOemHMHkT zUNglBjNVM>X(eB;!Ltyl)NCs3L(^rnW7@peyLherz++&5osA962jxu?7PhGpZlnoD zXFU-y7xR5^oeByaOhlxJ8Xt8W*2CZW!@tI+%Gr4d#f(!=5JzuF%f{MNdAKSf`ka5Z z#+J+c*HpYyKyBbd&li&hr!f!s%tSIF6W_*Mqalpi^QOPPLBM7joJFp4SD$Y3t89hL zk8DT7wp1sV-2S27V}N3pnvIebTnFJ3)o&PVi?_8|trj~y<{R8&S5x!kx0&h3b@J7% z^4Mimpw>OW$h1Cp`&P1OW-phz7+*E$$*-x2SSWR`Kp#8N_nnn;NfAz0vn~|6fDTlH z%Tk{fW`4Pj9Gl&~FPIJzNvAnDXA!%F|?`jT+LHRHsv$2$MGz*X~3Ec z;INFl$*i=C-_5Rg!m>z; zw03(I>U{cW5-MtF7DcwJP0~<3PipoP&Y}K>w38*S*z6-hI^POoy#yR;ep%HR4L&1i zFrDL05mUoChsWkd}LW=EP zH8C@z#0_^b3r})I_%+QWfw4PgmhEL_Wv#4Oc|>sOIDyBD7vO_w>_~yqb&m)mS#OS1 z@jJ667A}Je_yB8t$YWE&aiN_9)H6ISu4*=o%%^YKNnXfvAc#GjNRgnwhF(^i$~RH$KgKxQ>}1@`O--m#Sw8Vz2} z6m9LMr%Y;Di=F$w*miTZ@2=;gtl6L5y9k+ieHZJ!J6WV%GqC#67-GV%x>c;`?bPlh zV1;L`oIg~$jR@8IHey54+yLnbv!1TCXc*AT5dScvZCAYnD)+hLzrcy%`CV8bV>z}s zFJxZj1EZccv5XPyu-wpx!Vf;!PA{E&@t6Z`R|ZziP$Zk!Tr}Pa<`jh&D=ljMl8ZWA zwJj}8%pIMthG{=$ZndH?q39o4vZ7sayA8~ye>xnFs*3~Fv zcaCNv)qAj;E4KAPb5rO|PzOeb7rS;|Nfi}nx2`j(hfXf;TqCGTU z7VOc`HQJ?`FvS@CeZGq?Mc`m=*;|ahr84wIi7m66dt8N2PIuZ|UI@MqbP`^LZyXDW z88(L@Cl(YG^k~OJeg3Z{9@}^My)@kj=34tS~&!ZoWi}a`_>2qt<5LqG^!v$2UFI$NOe2SY0bt z{C1_KvlU5AW|&l!LNT||XCzvnT^H-Dg<>tUY&lAK+FqB!N!ybT!8vFHY9>#Ji7WXT z(xy!feK`|~bq;$BVe`>0{rj0C^%w>|*QZz*okBuF{Rkpp?tqA30zVwjl*wnL$(77+ zpix0xR~L_tlY=8<hT#Ph@P z9+i|Na*E$W%+`+`{>GyeF1WYQ;p{fXUzqeow^wD-1v1NCd4sZmp9tsun0AdhyE3_0 zP2;2U;nT+AW^qzh;1LaM#J{Ir-}lDlY-hr1(t13=jkOPq7~~OB6`7z_+}F6<{W;M6 zwZLT)=}3kew9AL{uViAT#(2Q4&_~;-EV)Aa!mU{QPWJ{qM|Y#=vzQ1R zw&*~|tIP8mQN-~;202^WAJ|nx%)B$jPd@shpIhOY99`y0IA0J}=TV4Wrkp^h&KR@y z)1|uR#g8{h0<|P9_lqUtygku~_y&UcDDSK51;hQ23H}DYhCrEJ3csu6_Rz{oUQ-AP zGd7#atHrFFIy1x`8V}(1k`fFgtPlCABMS|kn>;s7%RLMI4TC&y6A!{xo4aGK{E!>^ zQDIdK&eZy3l9ZJO*3=;N8h$mdVvqGIqqGGiv(;<7*&(m*KjY@B^=~NqckBcx~rvQU$+mtY^>u?^egBVEVJfG4?|$q@Mf}lyQAj#!dem6V(m?`PYPAB z-j;><)Tie?k}-*FvoNckeQLG{1uc-BRzq^tgZqtqMT!7|7aiPpCQPSiHMO^|E22Oh zyXZ_&Hs4Hg{^kLgh6}M96T=28{4>0WpOM*xb=fPZsc*-iK z$o3iiNsFP}s6yl~NGoX~0tchoCi5hHQIz~a-<7Hv){rV6^Oqw-znWL6Mrop?_m zN4%iLY+?&GrOejh*FxF@7qktoe3z|xz)m_s_}$I235p23q+Y0>w?qsgdAyxaf^>I1 z#xS21*k8a}*XFm=sS2)@Y2Su z=Bk#X=~BzpF6w$Zy{2V*;R)Iu+I9>$h8Sp9puuO1Mx}eLMnV2ra7-F}#XBK5vBAN{&_s(yvk)8Bq&9`xZ1*FqvG!w{OJ6#6aA<_kF2+x-~_h?0j!} z*>x>*$dHrEU~;Pe>5mGt3&;<<;eawciJ~|L+z;~U3x)8#R|#@yOjV6?)oeQ$e)^h} z0;M&GQiHmdyboEa;*cWErVyR%FRJ#z71xvc?1I0>wa)Jg|C^XBT`AL|L-yAZa)rZK7#?rxW%-Q(3>uy%95-Vo^soA?>U#|4p z^V}+GU=Xk0VYbfb=30TO#0WFZb%a*yYGCw=aXxnNo49MSmd#2}tj#Q(!qs~ATnPKj z(+ayIdRI*|QS_@-wRP2WojV>MnMTD;4Dk-bKJ;R)wq4}%Dx%gi)P~KsVxjI`3fdo# zH?S*&_^Tf^od zT=j2N>T>FHsEdUI3!JRk>%I+CDxGbg4xa7D{3z%e41u@BG>-FLbE8x5Dgc0PQ`OKt zS^3!^zKH~*S{q(o?JmwTObmf54M6ybbrzcXjs-4b@)0K?HbExd`zk~#3X?*==BlhF zZ6UsbW5@j|S}?miSM8$F&g@?_Fu101ll$2qwf1CjI{HzyOCh{?cKIfNqH#B=t2?<$ zTP!10>SjvDp6);=S6*r-i@tJ?kp=#gu-I8zEzQ{ zh9&-tT6uI|f9sCOO~Am+#Gzxq`7fc4fXTv&bb)dN=b?cJ~?vu^Dbxm9FTLFU!+#c9pdxm+kb zwB`CLz;-hw6*J|gV{kE&*_g3|%eaTq?G67WJ{mHHF8#ZU=tO~98k44eo=x_ZW%sW}9G?AFchIYNXDju3WRHw5qGr&dlLyc%IlgN^g5yOc={yPKb?IqJ#CiAP6A zPKrcBPDHbu^+X;0A}+vRa&mI*nj*}uq3x)6EB}f?MMyeLu|Z4|M`Tj|pyGL{b2|o3 zVAaNv7DD$z7_51_SZ&krBjxPj;Gu~B4r79i-#WCrrC6(T;r*G-Y&AOxTi>VT4=-*P zcP3i6*LMZ%^qayhM=YNeRrP}JFl^EuZq6RmVAlhdCzhrSlr`ovi_#P0&ZfI?cB{z} zeX)w)b}e_+E_Wp&rtv!-t0aOM?53~Ck9=G1&sonl);6k2A5oMUNIvTi&}W~7%}8I^ zL~M(_)OhWAk~}ev`C&Gyt0W~$Tl-G$qrgj7U(s@Jgq>%#rtNg~6B&=0 zyW6vxMR>`LO~MF?MT#gRCD6(WnG-DXDTiHl5{yFMZl4kDakusj8f=*Ns$5udarOuXhC#FY zNk|eShR=>75v5m$qHA&@3U_3zAu^97?x!SzaUi^wAQGjq>)SY+{lR&WG@HU-4%aH0 zsW!>M3#}ELt*aAm)5j0Bo=3^a`$Q>F%=07WesZC_3w%?+OI9#Z1&`+)Q{Qh&%jIko zC>6LhRV5dTIeME-x`@;d3?@xZS%}SZl@2b-VW*p50o5|(nw=D_xxbIUi9dTXD^)8#uW9|*Xx#N z86RJ7yzGnF)41@R<)>7W88Q<6y7kb8)URHm*W`Jz-yTZP`e6gd&+kWnx3FIs#=#^q z6dmOkC$QQ|TbFXEfYaJQzk1{ zJaXB&5j6$K$}Y)3qR6ukjrU7(a{aGS6tWmVJl#UaYefUTOGOH&m=i?)KGEa=Ch0&R z5cL{#=+F^j?U-S53^xfj?e!tp~`+8bLjr^fo zriBF`zKq!y;gx>Wdpxj6I8S9ODkHG*%WrU+8u*2 zEAdyd_Br1p_tUsZ!vEtuujE5XI{K-tL+DIjsdf7$Uh&F8Ap8MjK*=o=NZ<_~YFwy) zZhgi!(kO*jo)M5y1nuOfw^54W`|bM z7T*M4X{3>K%nS*%{|40NE;}v~k-*%?gmfdBAPLdU{8Sgoey`d=P=~^G z%fK(MW_LwUyWdXL={&=)U;6Dk1 zMW+BkettC^@ZTTq`pl!DuH4`Ih=J5UecBEX3Y1KQp72+vJ*9_K$aM{ zBqVuzd*!4HLRH3-==YirqK8)L%M_tI$jEfXAeBi?eM(Bv=Tsv5mNL?%`?b2mgXkvn zaar|iD+h(zny6jAW(mVe^LOrqF(;z3tC%+_dIhu=?^a{IJA`V%EHqD7zpj5>&b2gp zE+Zqe1B{n8Fm#l@L>p|-B+h4WbO&HpsQYVhfA&fJ?0s>JX6& zjC6&3_1diUT&}yK-MhYqi01rfFJxMtc4TKq z=zvdT-^aYdTW`M-NP8rd#QkHORbTa?Z?$MQ7j?zXBbS7i$jI9P<%HzXVX7Vwy1shd z#jyC*u(E6ullw#=v7Rpdgf;9;LPt~60%_&@_ve8&iD=yP@Oy5&r*(Pu!G4#NYzLkP zAE+45bvZ&HBW{mJeQ zL>AeU+TwNN{>4A6cX3&x;}C-~NlepRQ1>R{b8C@OD7 z!t>y>tzqu6Wx|U7%tBweKes(vHEiC$wP%ioSrz{{a1N$ZY>dx^;7O=KmYcr*nCSzDgRhd9{>7TN(8ULjhMDpL@ZBr2RIO)qX0VaS(xANVA^AxTg=Q$f19-v!$7}lIE;* zIC^!a4#~(niMV|4ziAg0R(8-plcY$$ihgb93_S%lAU8QjqcskvJ4|D&$NU$A_R5p_ z=XvQI!$WrOs*dPiIt=rY-#4pU`ma5#@dMe27-w_IqC4Bm5)=pIJCS#bxGOodT79&% z#TWj~f#4oBCA@>#CXH4pZ$9HDo?l{7+Z*+$C{k(}a!GC)^UL2B19 zRH!9gzMT8;yO3?OrLI1qG^V5K9W$t*tOcuMbi>@P?Fi=sdm*gg#gd6C?r{Fa9KuRH zBS-GExs*Ws?e9U(Ub(RQcC115ffvH`{AEJ0;B^7&-h-j?XN_TF17K4nwqo}+Nu5BR z$1!DQ(Q#q>Bb4Q@uD_`(X>>eXt`)Ug({ADW;z7@1Dz-^Y;7XgWQmI34o*&_yTov?A zBeJieLq2j?Zk$|pK8ee%JDL<*Hi6pY*>io^G$a}c#c~im5frMa{qdP}-A=RjCwsjM!@}WxIHxDG zA8ov#@>INd(3ageE#@onx=l3hlV<>k!|%RCm!LZg_8&a=#(|2Tvvwd36dk5RvwzCQ zowELJeIxYEDP2yq?dO)x#|M|OLHnNO9+@!0*FV14Z3t0T`+^ff9zApCQXP(5iWK97 zc0Q>|gZ3e${P*W}+Ypp4?>GzI2WMa0DNEgcwHV!IOLlS+rrF3aj9q29yGtUqhTSbf zTBij+6Pou4rBAUlH?}f#zdB=;cO5Dv=&kVP+A6gG?NV>L>wTLR_G%K2+!UgySHnG2 z1f8=ifFjEkT+^q6W}9Bp^N^9o>A4Q4E=1hCXP=`WG7_WqnSJ96`z>`RAo@BlkI^|g ztUN<_A^D2gL19X71=8{uV*Ja;NBd_K!N@HpqCu}9`0GRLELj*KAt45xsn7S-P=AfA zuV=>`B43;68SVxS!(YeUK;I81{oR^LJB_JlPEKF5>`Wp5=P+0=F!_la+!(kcagw8R3w1={wX>flz!HBPOf ze`P0Zg8fdqmdSwtmb<~w3@&M5nCJ>MzYjduEg47YeVD#m3`p!=^(KHWi|5llL{mCo zh2w~1Vy@85JH0Y|1!^ElsW`CG(oU}0-y$8l8&ZS6sdD~CAvZ|;`{vbU`c2MvqQSmjSt#A%C`3h#xNZwyw%CR4aoNc3v<&)*?Fgy2s2H%QsLtD%q{Lc`+f^~ zhPvjWs{UcBhs6d;+2D(>$(W^KlqOF9T?MN`n^02oKSSU*wZ^UdJJgY5>T7$6hzv#B z#m9k>lTMrqqT90qz*C&iRvvid{>VRh{$O?y0L(x8_KoE2_E`P_68CfK$~{g3sU?OH zd4)&iC^pdU9Et%e&I5(eGQUlu7w#)FvYrJ!mPT1rYiaACn$M0SY}%V;rBub?wZ6yK zW{30#3ONgR^}6(FA1FYnB1Q*UAK&zdH-Aj&`cf!Kz+o`+_c$Av6qzxOQ!DTT_X zTW63}78^wfCqQHRVjGRJOXoD&&qeW|(>s^M7SSLfdO@Epx#!$KwF5xUp>yS0HILAt z;8k==+=tYSyV>9yq1}?VfGtjb$n>6M&9w+U)&UlTm^jqMSA3ipdUJhEg5&@OXaC}F zM(I#`sY8R!3~$zCDvA(&3%%(~Jk19CjOyR(fN#vO@0ve@xkNzeX+H7FO8p+ol(+FPH44*v%Ziwu zttf8Ys1Y`)%0$V)hSp93eO*@0MOvo$~C2dCHo)Q>5Ij(?%xk6Edb`Pp_( zwBmg3@KI6O!9nr8u&H$?{)_uiyAbC@)ZaK)2By8yWY6uk^Nb8sm(0K{Nod8|PL&h@(`h6`B zt7`fE*D2QKL9X|VIzuW1ulOtuzI}Dc4Zdtp!kJR^F+9~q9&KKkDwLf|YB1gtMNMzx zyP0!UP>Lr|Z)u<`U5qZaIdFOLyudWbR!4{0-I6nb!&HO@H*$0VgIE1V7>~l`9auO` z_!nQDP*;vS7n$%Sc+i!4J)n{(h)T||>&yvam(CO9F*ArGwq7t@3%mI>788!QD3r7+ znBt>s%8p?7AFTa&VM-Xy>S8wPwYg(%bc`@MjnYwd!K``adQw3D(3qwko~*K;aqJjm zt5J7-`D@#otJ>s9pXKlt#?8$?-dmIvjNg1j|M7Q7IBkaGs-Vtq(qv)A)B5A$8VS=- zx=Yd`mMqHDl8nV<%hgHm=D#*8RrjTL+r2dqGOX&43t*I;o9+5o=d!-eO^j&iJpKe1J^ zQFR|(^yll{vKKR$d*yCab3djP_i3bqCS|~Q&>Wk>!iFPky>jI*MI>+=`LI@!lPS=+0SxhtZF$lmF@r9lqpa*t_lHAEE(H9^$Rhr} ze{=4Ovhwxo*DFaK70tZQ%ea4zIV?n>HAq#v6EriSnS|H zVPXDP@4Fa0O4@u4(73PjPhv338V{PpT}B(`Sg5}Y#YgNuZThjYs9)7v8LV%l3)+oy zZ9bu|PKbDov7UFU@8_n^TvA!oD8KqMp8oDZOn>v?amVjpMG@6OZh9Wc{eA0Zd5vMU zr129>JVpGwCCEpslqdN#Y#z z1nV$$=h#FKVLS28^_o;DB5p<5rnhKQXXKJONzgV~-OxYniE2}wyLAa(({NYk&A9%w z_xQt$;8K>Wb7g^@Tqd0wq7Rm5%n#Hh5nh?hPlrP_{ikTce&$f5K0JAyin@16>FXWt7OFU67!6_#1|M1LImDxbD%uj<4=OJ)q9lgv9d!c1n z=-B!iW7gmVmI)Cn1uX+nx5C9IuDXi<7ct>+KH7_xnxR4{2>L7+m{jq7LT`)=M{Z&b zJ8;w8`cxDxs>sUB!rn7zN2SJbiJd(nJ}get(SFNg?I@btB7PD8t9qElU+R&N$zQJ}Rnh=YVkpTFUMzhs&03QyjPNvRj8`bEv!&p+&C-*fxP9veJ* zkB59h|T}wyu!&YHBhCrbvprRYYE%2D=D0L)YJC^DAVd(u@>^s^vOcb3gSW)X+Cuwkko>njQf>O^apYEa7s5CI-so%QN!DpxI zLuoqpwR-ypclK+>>}@aN=aQWX|$jZzRDny6>#TrR&%ATQ5wVC*c${o?n{?b~`DaqXY7v zAxVcv<+TThb-leV0bwvV#<+iH-~apGas&z)QTNlxM>+kKHkInFKQ=R3D3v!MpbrDRY)HGUYlZ2WzlcO9^4|CS6WOInE3dO1VB`>ph)-cKQqX18UZ z9nH~L$AxtJ!K3TWJhj^dI{5rFKt2@$l@B;BlDKM*L?Vc2?w5NRJ5C^w7Oy;qL)S(Q zj6$!IFOoT=-F}jOS=daMyE=asD8m{5kMMga>qmyMR`KCYt^n0iWr3NZxaJ3$j45x<_+7yl_QqcD#gi@KkKS~{F-7vk0_MHE%J4M z+90gur~<=7U4A2{1y1{yei<8ji5-5$LVH|~$3)_y=oSb5{&YMR)a_Rqv=^}Qb#6RJ zKy$vHmdsFM?@HanP}$)qvTp~yb=^G$hCTZMIyT+?PN-Do4|rtgz~kJ|lIy#zKv0St zgCqZ?pn%`W*E3%QGxJC~##ITN!$5-t#O&21JNe(2uc|UbImM0FNJ%!#7=tn(Pdm=^ zrlJ4Y@y%&Zh!>pcjTg_<$vaKZx4B7|eP5!2HC@kVJ0e$pCfA402_&RpU3|FzJm?v= zcvMeT1g_6>{7k!MyY9%~Bw>48mWR%J?FkEgJtI!l0Wd+N$R8$nv-S@YZ08RNYx=(1 zd!lc))5TQ0S%8_5Y-*<;i}Q2EF70sX;~c%(xu-Wr$Ea}zCNhs2zG-^s*__nR*BR5e^Bqi{55T@KsxKRm>gPCnp`3bI@R>_SJRA`|HHLaf_IpLXsg&h`e zpBL5V)%S~a43sZ?ynaWm+Oz2YAhVHg_Ks|>i_+R(f~?uT^5&M*TsR}?*#n_H^zbq` z2cDd&a9F?f0Buzy)WIUAYH#$Qzbz;Gdy_Rr4w-*-!bQ7n7ScZb2TDG{bi8koIxvm2 z>Bv@gdQ?1 z-DCH<+_+Dlf>}oVIf6VlR1W$*vCL10cAwya9lW2PNs3fgEW$1Zq^KZCi`bIywzvs4 zR02BSCmpa$>@+)ksT^Ou5`#bS^yw(q-~igT2LB`d`!{FoqG-N7QZ ztiu808siUpkhIbOU_6DN{G*l+Y4@&aq*c-z5Mx(9lPrBbMoLR>B}h0 z&PU+W82<0}hnkWm^wO3#14=v)1{NKM+qa! zQE6;fsG3t2az@#tvwW~6_vml!vB^@2D;I*EXzw~-pJk!t3cMdr@yi2^n>_1c{sXQiOhR^Xb>i;H%s5 zwLJ)-$|3?HqpR|4Pd8s8d;5i(4@i15^pdnL$n%wJ5Hk1uTuC%J$d?2w?+l#|VyJn& z4i)Da`s7jr(`YDGElA8~9zQ1S@DchaZ2l6CCU#a=!h!rjcmEqcYn0EG&VQ76UWVi5 zN*=0m&T?gx@zt~{#+w{d^Fk3mLyC@8g(eJg%JIoFDLS=Y;YDi3jvMzv)qIeGCk==Q zo?fVRsCX*sYEtIq_&j-&dAxk`C30D@PE4qmbv7eaqy$?5-n`siNdmT+TEcnb3B#J( zj2{(A9Z~462~R{beuoU+s0`>q0LVy9I!jOi^2MEw79-s`_NuztBp7O)EK+bF{t$`?lP@7#SzTa_5;7ae|@Td^YNbwqBbd0TJab71UC4ZLZ z8S36iDhT7=V8O1sMK9CGr{gD6f61So3^GQa0maDjQM~@`IW{x{8tTRaTaM83cifd= z6P_#phYNFIoCJisW7~oKPl2Pck_(#nM~^ZrK9|*=kLayX=^PEv<@t~-$laLE?`fIO zocLV|8zLGtp60(39U)xrnc3yZ?_J529@Cm`bFL~)3etdr}uv|Zj z3yoWeC(~G?x;$0U1Jb=RXrd#Hn)ze}|Mlr_Iy;3}3K+Z{I}IRoyk6IuGLqcl>(Y7` zUaksm3m;h7Ua%~kJkD5nwg39jr0>Q#U!zr9>xp0OO>P21-;TVz+B>~AmxMF6{WQy9 zQ?E#=JGARwVEE?$5dy7I`cFj9mWaes`q{qz>vTtX2L5rna4VUr6^Pyz%Lh}eS@_-3 zwrnTLK<1|z?Z=*HP*#^4isjmLH>m-Gp88R#TiqWvrD?Zqzk_BJw){07P^kwo6?L#4 zl%`8^`4{*MmyV9ODLMjLfK_{cQ}N^Uo!<$+TkRL8OO6sdoeJFGYZkOJ+D9Td`F_9N zl^IJ!>T#!&sT0WPCek1tZu&?W(;}HcIZEPX2CqeDINdzR|0ffRFV=FTIec|-YQ~rm z3F`Qfp);02f8JiQPX`^@5cqDt=F+38-zPqn@i0Q@r*ZNKsEhB894vmkPyff1OJfK3 z62|JDJ$R*$qY(#dVO@)2m67^{0}|7~fkTy+)|Xti)jOD)B}%vy3`uf{{(R-uSP&go z5gQO5WVOZeKH`MRuIzgg;@zXNr6*r*_5pWh-L3ojKHRnV-d`;~v@(x7PKv80(vSN3 z`n##ntFzJre&mfS&%Nqnk9Tg4U>&WbXYxL5oR?e+AMf2ujkJcv#6|_!sV=o&-qy%N zWjO8RLg@QdzoXCpb)UM4WQ^?Z1OMy(XjE93m>9bla*jux-$5Fm^T~X>)gYsNd40`6 z(X@BBk$#BqR+eJ^tbTf5wk7@jTSlgNFM zTj_@h>m#lXvNqf=AqLWo^lKm&B-TjLLsaUm+?6bPNn_*ZuVvXt`qq!RwJfVVQsHRW zRsEgM$)64w|A`nvTc!7AXSDDXF@X^0E(h;fKwDeD+?-C>>+CSV?W3UihfbN9no`TqMAS@54_SfeFILP;qiEQ~#pD)nz9VZeGOW_`_s{yX1@yPY}&wh93L0|t>+OqxoB`8b3>sOLsmmTRCsr(t&;z8%7tx))JH|8`yvYmFWk~tDsfIq;EP(Dy2OG$p$ z3OF~5(>KZ~dz<85{IkKPbH*k2eW&P~toRnX^FEA@7r8%p*r!6}pjDgOOPfh&f#pe- zqj~vyLEg7w(s~Xm<34R-8PB+o_FZAc$Vc5i!L@huEF3pVs%JkQ=QG~pq#%|3JjXCZ z)cr(1cs=B#PSVFDo9!Mg#qP<@2~zprGzsUrBA#Cvpp07l0x5=Kk0r%a+l2miy>@!u zBpphy1lQ>=dw49{b}}H&W(EJ+4Pn2_WPGR*Az&Eg`UpCB;!nS))-a_yHTqmD@Ym7Z zh$iesSc76n7VV$k&;C=hpGn;dwOb?*C)zEzkBc=P099y)gREohA2`oVQx1}LjKkbo2lRE!P70pqaP3gs_*1o|do}9^Di*@z%&@AIxQDUW{6I1F1zA|PY zlS4+-a$0VznHJXjqF1hVzdXIONd-0>8Ke9oL!$3dhohnNXrM$!Q#CJpSX9G7@Q)%$ zSbPjIQIbe7tpL;v$LzMLkTQ_WGWuIk?XDl$L9zyJOiZDElLv5v`#nG0OnEyNY14*{ z#Om4Rp|0LyZ64KM9~OGp&SGHyk&PUbqaMlBH37n^(;0kC6s#rm-_RWNkA>-up=EfC zrBlGY4WLE9|3C|AY{j|GVt3dz7DJ-v$sXS|#QjSRr2khjvM^a~(Is4yB0 zm|$5zkh&ExhvcGp9~Bkld)CXN&(B9kKSJM|nli?8%YFFpK|w*`-8+AORO~8wbmR~+ zX~6w~tf2xyRN44|t)+Yj;voZ?pR$Z%1J=PC3Hs7rls~+c(I#9F@>zO3%ItaN|6Piw zLX%4{@yoA3w??<4r!QXY05>TSDE(M386F-kEiFAfJcL3YJ%TtpJA=Vscg^X~2E$9l z!xTUZ0=rdz&*|J(Y;BE?t3HzV^z<|{GgDVr2f6^b@TH|pz=2fIlOJb5ZxiB$raN^eusyrWEDJpK@4v-eGPT^+d$b}aLFI3Y0F8L8g@wo6&u z;hxx?ENQ5(Uusi`RU)=T|FbqQX;vl;vIp$m(svZLwD_jp@5m8b2LD|(%8vrvgtQm> z2*gOqK0V`R*0%*(2R1SS{4ag7%D;sZSm!o}Dm;AGu%#oJ4Dy_<)mz0OmWgn_i<|H% z{TDU;+cIxi*=@qk7|$gcz=6l;O&!q~K_CgXxc7WVf4TS^bk896l;nx-+T#@Qj~=H& z477tS+pl|iBPAI`<0=~)wmgNi!OlK;UM5u!zyCLH21Ww^=P;l2Ot7RixWV)lg^U`@ z>dK1o%Ou8>`s9B|G_VtF^Dl~i8_IuYa*>addX~B*oSWC-EV8HtSj?Yv=OCXy!C81N zD%gF|(>I)!!}Y!FTE+TG{aenTmlx_bFKw1bs~x#^v)Sp>6Ve$^9IujC?4Irio1FFD zJAqQ>ij@_3QZRt&e6VJAaZSCzAQ8HH&Mtm4@G1X{ZFcF!)i={+o#b!TCNilGrD%TT zMS;7YlEEqnFDoJJs-A!;P6tp#O7=NnbOY<`PLCD4lZp5L!`@p)MZKu~--49n&`5Vn zNOw0#N=XRP5(3gKHHd&BEg{|AtuRP;w~`Wqbi@BQDBFE@oOAB`InRrGt@F;c#=RFa z&M?>Yjn9>9UJL1bt1v^Rp?*FT_@;q%^-|7G>k&7+Rm-dkKXbWySAj)cf`5Ny9K@VQ zd9yq{g#_JwoII`8PPFsK0*fUic-4hx#>~>ZENNYg6S0n`mc^4gni^YpKl6u+RA=4^8b zn#7bAj^kPh)k9+!a<==`hz79BtIHk!b4J(#Rf>d37<-GcWjf zI^ZDzeGuAIP0k``X8!z|j5so%cZ7xl@Y1xaICv(_O)Fv@e%WC-O{*|FT2*XMbYvRH zMrsmgs7G#dmfwNeO-f_b=jWX~e92GCYFgZ|5Gq3Xnuo_MwBE=t*KV zv!$dYB+jxV%raOie{$kk@T4hxH#d0~csKM7s=Rd9%`N2N9$l6`DGO;093i!k)W+VD z;uSu6yUW;pVpp_9vq|-gngPfHUQvOVa9&z^g}Deh{%JYSl0I2=Des7e-8p6pG&;(` z!&Nsu-NSk4R=^(6TGlkpCLJ4ZC370K%rPyRil+oRqd{LVy1dKHmpn9|;`VWD>dGcq zk%6oOsbZN}c@q!E;B(}Ylv7+skmjCtuF5_w84ZNh4KK;@;ad#zl*QMrJ0xmW=`ZJ^ zo|HULWA!zo0I|-%mQ$Lln(LNe#Dbpo4}a|E*g)jE?dh*XpnYQrAqP5ueXg^5ar(n? zYoDT@8vx(_TbuQGJDZeYO4eFeqU>Cc7Q^kqtNue21n59EqJOgF0=s^xXXp)3QS0&5 zf8?WT0}IKUA_}Nn&BOD>7V6j6VNN0L+~1F)-yR|z+gcn)x10aGQxOKURj@B+otKnq z#~l1EO(is+2E*7*xs2=!+{zszHiEx#jQBB(a2Zwa>cwwIq#bMzpUy*rL>;ok^}=`;28u${o#Bq5{w0dt9| zfY)xe&RTUnUftSBKnFcB_d}vbpXoF%-E2ufW4DGg#{P!t^@Q&QLFHH7UGf-ikt164 zafL5STKk!aiw+ldN%keeSo1LWeZQsEgw;`x(?a=%N2#4KgurM1gb3*^L*yPn!c|HVvc@si!OT&h!k7nZjJ7H zSkhyYMc!A@EiX&FAS*bp*0`eAdMAJRNE0|4SA~`!rsys}O8FX|nvFy~+_P8eZuasq zDyece)7C_pHjy^-*;ysB5`5u^5(PJN->fv(MURF+nH_U>Rp|BaUIik^0->+p^aUfK zT1(#978`weeGggIR!w9Dj4ZKjRLBa|W;1+g#lbR#F*Jx)+x~P=v_R!ht=fOnXNVqm zTzE<$jI)xQv=jaD+t%&6uR7?gJ5+fnlav)OAJ{&1Y!abVQhj<=$@wx#W^|jRItgOWMCS!{$h9`&l3u& z<`Om$4vO;%Y>J|zE@_RIA2&r=N`)?%)8EIX>{1jznjol5dHpLLcIyElgt1NbApx^J z{~0esc1{g19ZhA1@=?(p%SY#yEcWPKLtaF^OU_Q3QJm7P-rqc4OEeqF)_RG;U12hc z3*E6tMN;Tsp=aq-QgVGedhfz+J0b2ige}Hv&9t+OAN%dY$k=DIrb3|}*}CjP_n4ZE zdKVB{TUk?rhacEHnVicc?eDq;p`AK8bilECQ@JE2n1I;&(Vun2(_fZFRzR$yG|Kx# zFyLaGJP2>fEj3%Pb{~h~r!us!u{mBXs`Jw+8IQ3I{^^v&4)`nm@M@f@38y<*3l!j%SJSqO8a6(+Uq z&y|LhEyH-`5kd1$UrZ794)(c3r>lfA0^9es;BMUMOVDU6$X*mA+p+9Gn?OI(g$W^T z!GJ1MK>q5=LIPRD`<(ub>}UBfIXb{PfNBU5$AFr#N2J!VxFZc6v##E&FiHO!)+qu# zg?(IIfk{tS^~anJ)f9w^G-G39xi~pLL?_Uu(vKj6u4n9E^$(vjL_z636{An`{QNF~ z(hlGa+=sa!Lq1Rs?c}@uOYMeVMOp7CKX|33_0ZJBWMpIn2@W<|zU|z42>A0pr_(z^ zY&{$+K4e%__8>Ni42l~I2D(<<7$`p!q$LL(84nLjO9n|A4i12ok_j--fJj$H#)l6u zfx20Ln1P`iM3_&@-B-Y9+WX9p8+e^8S~`rz)GhXvjgmB=PRl0_EZzT6UaMk~nSi*b zwSP|W5*MhK_bdKhOKR&! zH~wAorsI_+Qaz*N-Ud9f|88*w0JnNKffx-&>%!k3;w1!$-zwE$9EAYODLZsIjok-p zYdn9WV0|gOHrW2wllLkMn}Uu5A=-V}(EPWUSg$|niG`P%><4cT@y@Bv4M<@C9{a7* zg=CbSR~E;86yI9Nxl8pq$inXCN7>uk-;Y;(tE8{=Dn>fVdGe!iDYrfPywbL+Wf%TH zKndGKNZXWslVTAA+hCtD@adbU`R&uU=Bqt-G?&s6)SWbhd175#!!i`gczN;go#LY! z#RB4k&ai{6)}Xi`l-gSV3rtjY_|xJ{4B|8qo33RVY%*p zZ^uzfp>FOPdErbQ3pMq!^^(R%)!$0tK(S0YSnA)HHGxif(!ZGAhbJPRH#UDYZO@wM zxvsF}Bjwy9>S$UJ)w5k0OgD35-F_i-Ht-gK;P(1`g}GSAtBmUWdyV()zt`fuJ>Fai z@p9fTZx!1n%*lF1&ll-2_L5jGt$odKvgOrpF|S$iu6^1H{{6Ct+(+Jn(aZk0#df4l zs~@nc8jlV}Y-_h3guGk4U9)*Rl}4ic9e1sM5^kF*4@pi~@4B{?h|_+CmlS&}x_}yu zGa@XNqsQk;mEUSW9S20`!apQ4m^eIni?Q6FwiZ?Eq|c_wn{N0tIr=1Gd6WsGwbL3o zxltG;B((?Ila7qJ=h3UE;8j~0-dgSD5e}SnkBWUUX6EKKS#O^hk}pb$ws;)=#`e8b z7z>1nZ(LvX0v)Z4yiTcJPtxX^v@%Yf%Q`w0=BoI#ss@qO1nl=UqU37|0(N!>XXOZ( zqc2#>zqXIHrCVDPZeOg0xsezM+O14_77W7g= zg(G7`@75jCJtrYw#H}zmDGTl#Q4*(|$+<-@pYv!PVI97y;l2ZJ%yYQ#;_oFuF0L+- z=66y>IN=J6~OP8v;DMxCfUz;C4$Ey!yW)AlH`65|=%n~84Q?R=xCtQ@k- z^3CX*u=ls`hiIhA)1NrGK6xyl+q#_RYwozYJK#aGrta!yIDExGKJbFh!$;I-m=7K& zgFg9Uo`rbGE~_~9h*c>(%T=K$Ky{`?d@`M>qCS#D;xstkIv7-9L!85t9`2n8Q=#{v zSzh0EJM=v*O`Mt13vG&AbbA_)R;#-&!(#MSu(r($OG1j_OV@xY*}MSfXw0MmiEqPF zY68(V+gV`+ZfE9<=Ej|@EL6>^7egYFZsb9R%bIIVd{Q4o9uxXB4IML|sx%>a;2lSl zOWy zI?R*ruDS;H?J;drAB-pGiysc)3S;>2-ZJ5iax_txp83|HSaDUjtl^`QvyBDuw)EH5 zyN&v+-cYJs4w?n~WPF_kGoi8hfDue&O4;_KWil?+k3bKtnQ#D|M*KM-Ef^HTot<1w zMS9d7r?aws>(`F(8P;F*zp-f(7s4^CLRm2inT8UX(HAne3loKyt7F|t-#oNBx zH=T#UBlFZq^+*YMV_uyEEktD9>M)s;8R29UeJ{Z?#FhMduqVPqOmWD=4Uc>lP#z0M!DU?UocYFV0R2t{KJKKw{;Hop;yX66QsZYNkuPb> zHxqxd59_Rs7(8J1f}p7)f)_^xVK~^Lo;M1aNqI-uVEW*Lja=uTeUZ-0 z>W@`UBCe;Z>_WI_HsmoVM3JO$r<;|T(-hoWP55bLQ#AXJ)yJao7PiG_3qLvUqA+21 ztwzpH9+O9YSyQ_Oi^9&+uw1 z;d3FX>*?e8Y}puxu(L4B#V%areXt%apLsg1og$T~44YV8s$CG4*y`fuwdivtG>7*E zGUe1H%C9sYN9gJ?5V=e`%q1t1G-wWkw$R1itG?)rR|(hyEWe^N2#~M1iy`)0lHx3} z9D{&{8h#^OUc1UfYR5Z^G9i+%T2_kusyWfn@shM90;&SP7AKA1f%=H&h|sz1TE~Yj z5oiocdnW+I7|D3#CD!$7AoIh(t^;Zqsi`nUBfsoQB#}f|gdfHu;Af(t?)#kXTRJ#I z-uZe3gqU;{`=ACjlE|ev;>(O_ILe+#SyS=qVMBXOV8RJv6` zkHPE#cPY_62K^~uW%fNzo{x{6BDR}A;k(Ar?pE6N8u;bl zN$GC%=p_{s!cYYE!da0F_ak~s*G;*a*ie~DnoyfREfuA;7;TCF5f1>F;x9Y^tZF{d zzg{EwNwmfP#R9<_OPgsEk7-WK4D+6OhAG}*@#MHgsz?zfRq zK7jd>YspjKBr514(9&slFFQF^B{Vk^!`SFVNoMz~d=trT;dy!7U7XOTq;8<` ) ztbwQkMbuZU7;kH@eTL%qCE%-_P95J@c6#pubO&puO1~B?L>haa+gN#i!y$-IRM&oe zahiZgftbv#b_@_O3@2ZVp#oh8OZ*UO<1m^0RzWi{=0A<~n02cTsvIfptVKD@y{C40otArSOlpCg;MLa%K(wRB5wPSTEPU!d z)Z3Bw_<%*zZcFM${YUUXi*ceMHODT_?!`(vmB021P!kGoc8LnJ5*Gd6Z3*ACoXqV1 z17d%4S`hdGB9!5f!?!{{O;e+h1JXngcMULU~{!st$8wuLzYU5H329Lhc?oCeEdX?4NR?Pq!*Fz*X z7=|(4WCp>s`3dMS$LMR9Qv`*HTBkv+4B(3wPahDFhgMeSAYa@W60cr1MLFsfT@`Ym zkI5_ue4f&g>@D8%(q`Z!jq zK)P}Yu#9hEKnv%@IGVFA!S?a9rk897F;N+4+6&Lp6*iok zUWOjT`spXCNf>K~V|{#~wNzpTq@^A-V=0ks43-@vJKrlsjtxTXNrhSevMafC4Hx}i z!~C7PtdPF*;2-gkf#=up5y)@xk-gad$Vl>ygQ_D&es$QYa_eo4`&<=6h^3v*O_ho6 zLE`tafaMI@<+zo8(BrEy_7>BgZr>{(Y{0l7_nl^JbysHpjfroz&mH5;8XAO8>3x36 zB2enPspN;ZS4dEOUMh!OQSyRy1WWXmTb-s0$RbT}GgBjYg;7xma-MRtl2%zbor<8MC9q3~_ z`VxF9V{K&C(KI(Mli$TEsxL6N-_~Ht$~Il*DbSgD?0USs_iQTHhIzVvWKrj?FR+Nt z8vt&28SqSH_8yUfVcqbeiWVKTY{Tx=jm2av8~_E z3vz^?O^WJN9<$ZE-=h*-RbO$_&I_;frJ~$v|M;zA)^k0Lo7X#v_ZzH>j+&OVH~0W}5@|pHer1l$xj+WOR@t z{RqY8nGcaMF8E%`G8(U7Gax@k#@5XVO_$uNfe(%^T#E`7fVLsl)-tqBZ2ah^zpYZ{ zyvuLTlqz-ZPk~s8%mr0^7OBU$j6{P?f5OV zn_vvu&w8~(Uf?!DX+<&p%8-#vo>2X5zc;l)_w!~TnoIv;KsEpaahU-n3n%7EL%GrT zbdD}D@7MLw-O)WTwch>;y;-6K1vgz0=YKA$-%+MLUBJN1_WeFmK{Uoso?K7zC8M?r z$j9Jhn!+0=NdB(i43Bs6sZuV-N}AlcK1p?a1nJQ>j_iI6<8qpraD<_rs!jrt&n&hq z$+TjsBPoc?dzb}F4ni2A8SK{cLi^7NmFKaF)`64oSM&x3Vn%(zUlm9Lc=c8edLNiG z;g*HFiijsdgR+*+PYcWO`i)x5fC%>sR`JPq~q^SyeVC3!zr&$yNn4~@{5x%V&JUgimo5wsZT%-ay8 zcPmy>ajBmu8mi`4f-mmh-a%EyeL1(39&k)^q=Lf%TRJxqaQU+Q7oABCi1rW<`D*jU zx%CBoOPQcCUyoSQFUxHIJcak6?h*UfkOHP1-gmA-HZfmEv|jQLzwmlIVExUF|Jcp! z;(b;n-=X*jq01`?L9!_HkI#Hu0O}@CZZ_>GpsK^fe#9P- zTd{Yr9gx@q`ikN0m-mNg3VG$1ItP2D5ej1`YR&TOEP-@O$J}Wg@YAB(9Yt%t%+7cw zz6&3cfRH;&!6c|vnw)#E?{z$2O4Ap{aDbis&PJg*69G7j#v7#3%n_5QwR%*#4?BdG~tV@Jj&iM(9vJdTl>oia8w z<4m;^DMRd8_WjI8lLR+m&3?V9h>wewZfzuw@SffdHT7xMOwD~CUB>_kYO9^j$w~o& zOlDaQc~|r}_rMqZh)}u_Lq^}7g*ThGxcSbD6y#Y6fr;$b=EI2R2fH4v%>F~RyGzv#y83%@mG!pyo2M(O-ptuy6hb@56ATuRT) zCMV#)&977?x{~k}mN+|U`O}DXh%Q`P`VEB@6wAtfGI%ul0Q%rGi_SA)!oHpjTC~RI$DR=zp&H57i%j#$?V2TTF?-0Tz z@M-4d!iyHD{S}MI%AM&s(8i4~skU^3pA1QDuL*Emu&LkTEc&~u?Ut}SVY(5daa#=i zB8YnV5C-$RPhTH%aXszIE%sNYhVD9L1$_{c=p`CG7oGlvxm-;}mlyk z$O?(!R};3QLiwQq66CR^p*^6MZgD^Na88C%-Y{}~YQ=;KJ|f*adcXC!+=0*GLJ7Xn z>91$Kt@MlwnrGU|9PLKoeax}-w4d5X0i>&1u7(fM#?RUhUTEcy-p~1VbNe)9qIP{B zzHIgyq55q*4BfJsCv~)I*%hDOZQllObBWo6tyr`dEJNQ$zj7JJbmbqfuqwj;E?<2W zh6%|+V>mzFNtdMbW8$Jsq92j}5vq^@UC~p4mHwO1_-{hvKbX(}a`>a`r4ti?eyj>! z!9lJxhGsWzKg!)U8Wv&jb_Rt$ZE3X8E8c-ePM2cpRaj9GMS_6_ z8LJLTv6P-rWy+*#vHX^w&NMg~*SQf0i(1BTN`+~ut=FjY&?zWX%e?8%?J^yh2@5`s2 zzsaX7j54X5{~~~)kb@;ReimxrZ2hvAxcZ5UNX1LvsWQJ!CUnTM8L5y}%+W5(L^+0# zrLWQZo3u;rZd2kJU8BCuT6D-CBi5o^@L!8-R>cLW2*36+X#9kjx+h*n-?O;jBELcV za2Z_(ql4#;_*~vjaa|f_H|W=D@Rd58UU-_A)l2#WF#QN-6Zjjfs{9%jQ}~}dI!W_& zU^rAe)JF1=kK28(w?T$-}#*3BK zth_bn$tu}aAIm0P8kNo)*E^rRsb1_Ac zDq*~&hk9x~5zR_y6-lsEZyk|Q$_x$n$d^70OEXle4wGMY;Z>N4dLAp)%Ti-L71SkJ zVMj6kGqeYwqAG6D4#WJKGfR|$yBmaOJBgw3?B^TM^u|^5i@sE7u=*Y0yAOXJGVw_u z$brVXhKu_BdfGAGd<*?Ojt^&Tn8u2j9_Hn$UY^V{J7kIq3M(2-2<1t&X~bU&NgwPV-A z2jbT(O=NrfcPh2r+J-YqSwI_H{t!yk2U(l>_SSiB2 zEz4a!9CIOd1f@U+34&7np+FXQh&)+>5Ky;n!qAEr&@lAUK=)WY3ak=Ud429UOrSgf z=15d(Naj{}zRq+V(_pixIus;17cBQy8BX|E_q=zk<_Yn_$@}L>L9K?P@lt?Soo{6a zf|jnIDczK=hlkbE8WcRV>mv*W8od15hq)1I$^nHd*Ey(11N}lKl>jiMyFDT=km%Ty zb8!9^5Gt;u>f$^iWr!g|)KX>telCLl)E;5L0p^O)sjZRqMMBi$1g<;Aff@Xe=uNbI z++i*m1s2DUqjJp&$UhZaIpds`iS;PBE8hjNMPJLSROpzn>W(TZ%0wV`vFMv?qHPdnsOltg?H-x)0h!wrajDi zF234Rr@Nq1;UwXX?-$K*KVsE0;$2cbRc6)>JiyhNud5dyX-L16Yu%F8JXGUJhvu?J z^|jb_;R#lfF9v$8UlduUafI4olV9GKMq_X>V16@9{q8H+!Ng{N@s5bk2{Xf;G6Or0 z;xrDL#{%7l4`|dSn7lymtlRaV$+4G1k%*-^`$4yX!m9bF)SGDa8qZ8rSu&iVu@{Sv z-a2~`JN`#8h z>`D4Spfb$VBi3Dz={D${MZ4!ReUvm{3;-CMO(+JZI_L(26Wgj%#C~$f?t;$Y-+3L1 z_R*%W1@ns%7q0-R1R8z22%R_cPaZ+$fnsBF^`5x0+kKvpQkz+fWN!`T_uE^#)*$~( zueMUHh??mEqH-wz2BUSl*2NJ4;t_G;p_24-aQ7N~U#U0odY^p2y!c*u-gWbl`4q2u zvQJ^ksHd2O8ni}4C#jMV(RNCm-6qaXWjxRQ%5+ZYRLk5R(hFJu(na61RzSOS?F)9I# z!vZ)U$p52rj0R$oY^sKpei3`GE#ipSj~!vj_CA7nZK?NTMa%QlX@gB$SS0?vb@WoJ|{VY(!Kt6ja$K=fZ!Y1FnQ!tWK4(|51MhU z-sPn1Z^EqJ4`H_8ZzNpF)R+h$2|)lU$Kw$>piC4&0YV-vQ*6o~z8OmScTHMF{Vwn< z#6j+i^1YgBtNO&>p-u%K@{>9$)-poYDfCn-oce(NbLmZM(jD~yv1d^mwQ#+gaSF-B z=Cc6-w8^!xj=3k7qoxPm z2dU#wRwK#vhEnFc_C?w5EqU_SP!Y*Q*cSC+TkQ?sUy+B+hd(0^0dM!kajfoIP6FyG z){-c%xf|@gSu^Gh@DUYc4VY@5nN>UmENB^#iWm{$j;cGZ)AEg(htcF&`8s5weT*y& zEA8`#uonD(XfIBULBEuaM`q3o0?sb=TKGP3`Ei}A?oxVv>#CL>J@n0G(UKpU!(gYh+ zb)jnN_yO^ZSNmc&!QqbrH^E_x27?89X+VoA_)Z&^~btiNZ*hS6kBaDXDU<1 zlabMUGA&l{S|hk7veBs0xNdncvRiNAqTrzwoN;Ca( z6y=u%KMpYRw=k>-Kqw0Sn*f{@MRXnsk_7zR=171l{(GK1hlB%Msao#2vHW@#hzM`h zHa)?cdyqszSxGi)E!*(ZZ-63CxKhJpa!pkH`RBmRlDF%a{yZC~1)E;m${m+<`y=n|3`r@+vWF4lk*`Q0WkpNanve~-x01gBrLfg1l_qJEAWwg6LSv?L`Dq9?$vadZ#RQTQ(}_d^{+PiV7d#G znY_RJ0}Bwrpni^tXt2lv&KP-PIn{UJ?)A78jAZ}&z8fOA@FK+oCnjnsQ?R)%1r)5% zV2}s@S1$Q#T<U_hR{gTZN_H)0XoBx0ntHzjqs&CTW1oBGye8taL>5)#b_GO*H>UdSd&W4|LwgR01sUCrBKUgfGx` zekKz=keWZP-GWkrKC?$VI2Z$YRi}#T*q9h`jr$xNZh{8x?(SArR`T-5sKh{Hit!JO z9w1COcTAV~5eOPiqT*X%FIs_VUlE%L1xjDxjLC5UGzeQks#LCjfgSuu;`h7W7au>q zLM4SP0(ZLrW)=|S^aSc%K7m0&L4kpR!ND?;lAFLZN_M;g=_E;00~iWmt!9KG$=Ijg@B01Wq$_>}-8ubzAre*g(?v1p z7a@gX=h}ln5F>rtw_5gb0A*mV9!MN3k?lV}_KI;S{XmWa=Iq;A-i<`*l<*MhUYpD} zp2JL9Q-nRZ<`pf?AB!Nco3OF4JfMARS!S8@d(wl6m6dS?=XymqI^ZLOI3C-&N64!K zSrDdQ;c7(4Zqv~vj)&e>RCtGZcbn521C5>S;wh7<7E`0Zoa(BKni`;5dv)Q2-*OnS z+`5>yF!b^ev(}-4ajKv2ko)u8-cdur=6*)3k(gGBW+*~A%M{jv+nVKl*4UKzUD^c$ zZOs(LY8`--XK@vWFxca#3p7UnM>~v@!KV8a@8aV-A53)+$MZSc*0*@K(U=`}<#fFd z-{n8p(5d?PaF?MM7$Z)QjGG~1e}7}?UaCB`{x+-oB)h-twbH4^7KvtJXiv_m$idk|rP)5$OIT?mUpn6_#`{a^%l zN956)>}WQS9S!=6$tHlEP`lq-E53?FNe6BsW^92A_KXbfss~pfbIgw5si}+w(qQFHqRqP#VHj6w3 zsowkgA`S?Z{^Cbi{E;6qGOfPnyUFy3tpXDqNF#hIrGsiotOZCpD&FLky#D{IG-f9M> zd{@1rjR9WNMM^CN#!gH2x?*ycV$R-+C9ptj6qt$tk#kBrC0n?4{#P25`zA%2h3BX7 z4_rsge^bl6ZOwq-N{4iYV+Ur@Lf^IH#m;uDR-V#16Sf<93`PiG0h<@q{6&RKG%QfG z3R)p6=Y}h7c$*+3OfY?a+$0oAw?dRo8%xgiPca|EARHU?J$}+GK6AN+6YE8v=dK~= zvdJXY@a*a!?_-+q93RmFCb|~EucT?Y#ZA)GtfcGwpAUn8IO4Y4&x32S}J+ zq2)4ud-)?^si#I%haXnBVAXCYKj63cXXii0KdEoc z-&`mXp8^t`6lZpyRv(V>jN%I(jlz@~*X#@H89Zv;E$PDSoylh*M`hDE8t|_X$uVN1 zW=1QcGZ?(*D+oPnw1BBu&(@&`bijC@rssydIaknYx!~|{UU0Hia98V_#_r=YxZ2bx zV*$fVzBm`Kh0xHmZ2ICsuIjFWGyq{XRWy;}z3ArevjIJ*olctZ<3C_u>S{cJ6D7PZ zM5FuVAzK9QR^s=SL@w@Y_A4sAVpj$rtyJKPA%xNzga`K3XAe1r10EjD8s(U}#4D%E z4{(~-AoE3eoOHz0KS(hwlA#cKyxB+mY(p;ecbllL~N4w}kxydKNMlD?i>za`l z%FnZs55!Ofgmn+`&##~}@zvQSk;=odXwR0Hu0ocP^gkM50Q_Od+UpZSe$TcY925W{ z+i(ql*!c|r5pMt%zejab-GX-#;s}3xU?Mql$7^1``Ab&R0rfG~hT{pJ8OagZz|&hQKQcs$Q10&Q zUEP~&MrtI{xvz3{t~<~gOLl)31!a!|yG8kSvHo^+n1vQ6EPLR=u8QamD)`FlYRziw zQu#izg8Z&pvSFaa*0Ydth06B?xkv}p5O#8Aiu(68)I3~Ylr)cs%kPdvU7WipdEN#a zDV`5?N18g((&kgMeyQtr$2)pZDb67*4P64RL!r-~8c%85Kpkr3*{9+>&*B7vlM|_l zuTSj+<1Pf{+=lE}CHvM6iw+$e#^Ig_RY?^ff{WX8YLf8XyWZBhplDlecz@qdH-_PQ zesPMoFNg^K_%b!`2;*wszTAlW$?6v$KE~=s?lrOZ{RS)CY{rXQ9u$oE`e_2^oCxeH zb{W(VeUt^CSsypnD*%avuhgE1o)pnx{qCE8MKSN;I;M+RZj$+jVR!#&IDkULZ9fh< zt~nje*J6xbw^JvyYr-IJ8s{u>yF8lzV==2-0T@TAe-|3~zYlZx?~wj~en`LSD{Gno z=kplw$f0%(&Kp;{GjnqTSUQ|EzQCWL(GQyI9uxb@$bfR8J#=hBW{+M3B8p0HZu=9j zVI8bJhPf@V5;>fNOrfFja@z4pQObmQe-<(yOYj54=EA!VJAS4Dh94FtH9VM+x4_)s z%m*zQIH%$N!h)xbXdY`)f$`fIP4)B=6={b})bsBcwdFr;3KtkF2bzx7{UT}I(sZ1m zKs!(z+6;u&2it~#`>!L99;xZ+Y3LtHfn#ok+(^^z`Ih5bYu}w|B3p#7sh)*p~<2fOqApPPr zLS6iWC5{VH{&`oG$xM^8QWg>NE9iOBqx-eEf&sK4XMk6eWV)v{9Jd10Td^&EuLjbX z|55{0Y)fRH05~xCyXFPpr?Q!n3|6l0NYax&!b+X29qumuu@alC83!G?R$2H!WIrs7 z{E~E-T$3JWIEyorFwdQ&WO``FyKtdA3#b|20konR@)#Gj@^;{|fQkDkK`1ooSQDV_ zk&N!0tRrHf4M38VJ+rkbaqqaVI~wXcAhyggkZ7VVC$3^elrZ*E`!}$DLk$L4pHcKt zS@>T@APcSrpl+1gRb})x{5Z3|1W*ol6S=p9-?7w&9(mRu>+`o+Di!X6Ho6X6JKAYW z#VLOF=+(C2hGK3o-=4`*NDFN{4dlsccczFK_vS_TjoPM4t}LhHpnS|b6?$R?gq_V0 zni-Mu;IJ&({a+-ja`jGBF!bu=s1sUm(nb1y&u!D7DzUl>rGeW!iJ>4!=o3PSeCBR< zgW9N`dAYMek(wn`J~RZKE#EP2d$yxQCk~7Y2A``q01&B<_@Rhplod+Y3b;}e`R3fB z498OAnz;>lbrE65Gn4=%Fv|ku!I*qV!0lFcx}{a{G51u^0(GTztH?DOalCY@53yS2 zd?*Bk?+Ngv^m|-U?mL@wieBtJ6~i#}?&x4;?&()V5FXiv|H-(bYr)F0UnZ_!#ns=TmZ0YrZeOGbdnF_$ zn!uil;H+oky>f!@X;3mWgGe_n!U% z{R0(hK;AzZx7SA~mLLIoEE^VftoQB(=9rk7?YcGq=xKnU6cvR-zzYC9HU3<3ZroAk z^@kq7xXUs?3y@xw2>5#bclhjg!}5VM6UeoSEE4Il`4k@z-k4c~y!D~fSN0_}YGNDU z8Xf~fXHQR0N5{aNBq~5QHNE$(5ONJvZ73{6gSA6$hYDP%_64~`z)^(l&CRGz6ZN-m zhk+~d@yVC-B3I|lR~Hyz23tYY{s4(}vtM1^p|&AEpGkxj!&rna^qOjfWNc{2ii+Lj zdD7yEMV4{$j2`)5SPpv!_%BOPOSiYTIn3CvY1Iq?iTei!?CcjrfU0E-My(0BM$}e| zvoJ9-sxd}$1~k7PWP*TPqvheh{Nh+q1fICLSyd*qu>DNPt*);AK-;p>(V1I0M7Dh2 z=Okw>akx>p{jCXUc%q7!gg!oAsw$!RHjtj~F(6=9; zE+|^w*wXhu_T3scTt^;r!$8FmYjBN`hperw;eaXLsjIsusS^9i@W&=wuo}7FKbgYUrFUca} z!k35Tv=EwqQ@Wb;+h0`q!fIgY=4R=A7;G*UTmX)~>c-o#CV2v&pD)N<5g>;2s6^he zRcss76o{028|xc+-N>%2b{FWZ7jJ5c*jp2>0^83lK(QUbAoI124L}Yw2Z#wiwck@` zZ8<4_rtyff0BtYBLYLEmEfP0&-hr}8>!pkn3edTmIMVM&O~P&LY)9HbDo$VVS-!n& zFXmnJEE)SzF$czQLR(LX7CvMsM%&JqOe4*&%(G3#^7sD#Xcg1AE67wD1cN zuv~(ga)=x1{zsS_*deowbuSud5DZ{rL;E=tx{xEuj_tv%nXkmSm?Ot8mgNtHY#!eK zW+5ubiyrYXsTdt=W3m6l6nD9;Ax?zY2uw0B#ly>z+t7@E$z|vk|4_{!64&L-h3S@k zX_O^gSn_!B;sWQ_QPs`8RfJJa1UzLWU>KtTFDH#`?tGlUi#Oo?|gk$gI%6+82Vvq_!5fS`-79|&JP9wyH6?s+=4NQDDFF!4B53QaWNXX&a(Vil82cR)54V&`Iy zJU|Qv!c2L@DX+)pvc(D>PYwFIilRkWf&^v?qLkI>S|QJn0~Wr@SPdRqjPX5Pz#T41 zBT6(`0r%r8#7Pf)4J6L)Us&x=A<`H~kl!4khIq%nI7WkCz%K+?n`LSao=v> z`o5j%Dei#un6ImQ!V235{MWos4xX*t5l3&+sHk+Qs^)yS>gD;oD_NV&Yc!8Qi;3{F z2npyRzq%pcYgBwGy8A)xv?g3Q;FJncE~_^+Dz}YYfzx<;6i@Kv@?Ru{XmJh@5u!TM zg;(d95o#PztB|uqvMB?nWS{BHFa@#nr?e9=4;?H)c%dI>=HCr#_%(K7za5M-&yKtc z@(A2v%HJSN5IB>`jYph9edzyO3^n_+IFvrhpU)P9v1(971vtPV9wNl$WzD*rY4tcl z!N9+jvQLnOxM=(6lX6m`u3Nz8la2Qi#KqI$1u50G&k!ZqTMqJ~TMzCZ;9hjf+=4Vv zjMh{f`Y{2e;MW|XlJK11v-Z!WY5uS~VGa!Cvbqxev^)|@tq9SxoM0519(B&s4Pxv) zRBIKB$3bnsW3@BAJfgj~YsG*o_U54@_g-7&8!`IAaZH&o*6M*>l@A z444aNzMJFo2Uxz}IFvbB!PIx#I9g2`-|aQ%D3pCos_i_Z`Mef#*pGAC%dewFnRt?X z{c2WyhrbYjDbxZN$}ZVada-qO1r5ULMj( zU^~84P}sw=s}VazmQ+;Ybl>SIIo{iaXV+%eIJo?hB5cdOuYo$<*LvlkVe4V@gX#bL zZmIoIBPe>5WiaVu90ugp%#U+7BT7owcdu0)+xICaRdyEDZHa>wPQ>+r@LVGeG(4wP zU5t563F`R@t(+w*fFH?5gWX=bDD{}j8d+Jbk1S=lTcg6}Rco+oxIQ5xRtU3B#7IPS zPnbj~HD!Fo5X@wtKipt-_CQ3@F4hviv#y*hX{?|JAQu70!8<`txHL9iV*c8DlrNd? zf;ft2lX+ zSCE?(l=)-|Hy5Ejx6`6mcd#{5x^j(~06r*!NbltDSb8la>U26XYE+!{1`(z~QDG&&1eGz~`1>$ zVI(;FW@2JQKs=>5{M2d$tUNZ{ z!_|r^w-MQ1kpiat_SPO<>vjAl$4}HFA#zE zh7qO)n>KvdWoHAdXaPurPFk|TE`D*9!^Eo=Q_HTw_SDXY&^#Hvz*+&41{7B^GBRGi zd&g2X5a%tf9_$b=Vr zZk@izSJf`G-b#Ak@Q*Nv8Eq{J&&Jv+H6ImLR!-@Lo`sXYWFimkAgmJgEn$5@j@;1{ zym^Pb>D#u8S@IYDyRu04-~(1Y`=)u~XC}jYT#{#I;_dhG&g;b7eA5da61k8GI|^i$ z4bu|7YItyLx_#urh=`92;jm2=;Q(isPcO^M%ZvAJIMjZEMMfJy4Py_rrLaC6`n~{D zx(ivh8Ar`DHKl={?B7liIj^NI6ef7c&h}{c|26j2VNrEm-*gK@Hw+~W(kd!Lr!)u> zQX(;w(jWsffP-{NcQ*q_jg*vvfOI#gz<_|#^&Y+N=lQ>!)#5YFgu_VR4J?<_wOCHtP6k}{Nlt#9gm*GEY)S8xgFQf#)8f~ z+@EIN3unrC!@kgHdxt1fPg3jplyG_}q($QtUai9k!oGq6DV)5@To}FD z+ZM#0iTNST@=hU!;au0($=>kMwj|3l9+$R7s{?FQJ@5C^@;F>|7jGwN;A-^m&2@Xm zlI%tm#z0leQ3G&!6*a#z0d^Y|eH|+;olDNX5j(DMJB4VeG*aZR=3= zh-lhgqVA|aZ917oCLQ{4InnR#qd$~BJ9f3`&>%6TZ6sg*Mp5kj7#}r0M;9B$CjEN` zXlh=DZdcyI`8rT?;ae>H8y$+pyu#kYCF%xEp1L-^Us&z16*9BqceoKTWN%=~tm_co zm#W+Zk`8e6)k82Ct&WU)J?7he^K>XeCTM|BsW(zVm#- zfGc>jl=e3(?;5tAj3T3ceW#3PGQ>@urjO_rC0zcQs^(F$XknF1S?oN0&--a0<^ zs3|Dc|KY*G0T}ZJ9QyyQwHT7Mt!Uau`^I)rl|n|2Ac&&SbB5qBCS2_qZ^P)Ta>BRT zq1qHSX7j(gbJS&jO2?F1P&0oN+>fvCcNa38^K7v(sj4aY&xEa#Wnh~prVk|}8=dnd zcHNN;TuyZ+mT$q@+S-ltyDONRe|F^Gg;pk5b9o{jsi_ee6<+vb-%UnsY#Z0cJ(b`^ zqmSQ6Lfz2hdr?8swICpGd6kG7aeYnuUNOPjLQSZ=ysAdRe)&{)naQ8 z?l5GkJ(8o$GB(lIPk2q}Ho?Bb($@Q3T4U_EUZ-woQ`uCk0}2@Esn_QPw^iDf8X6?a zk;Ki{O0;53wseaMGnk^)UR;~yL7qp;UZ=lz>5VMdNg=n8!cy_7jh_^|xcTj_vZ?hX zHNJ?QZu_0)4do4Z@=HR;+aquLC8f4?`);BanH@nUpTb3TmOlGQ%vM2nBve^uX_&kR zB)Mzy$1nH4v=2?Z+-)ovJ$m=~{or7ZBk8JR3djMMMP$&d`-p3PqRq74Z{(!u%XVzs z@M`gIK~?W+iul5j_EUQ~$cOK%&a^!_*QLa|lMa%{Cnvb?VfZvmxr|H_$XU(FNP-?r zu=lauO|AHbyGqG&2xm@unZM8K-fctnw+*AN_gOfB#rt3gJ6CH)ey>6sJit zGI~N^vMh_zdwQk#l<+866kl*!Q1;j1;XWY(K5bt=`hK`mMCpmNE$5@ZI;g!Tt<7)< zY+3mZM*N^5S%fBO3MzZ~BJg?5Sk(tl%u#cHp9&g{9vm3Zx@`~?6a;|7g>!!BG}G!) z9hmefcz{f83mpR6ixy%(shP(85)&N*Z(Kjz9Db`u6&pQ3oy?5NOLJ9`4&YCd|6*T1 zO9~|r%NVj3t!3WkDK~`82rEA35K&KGou>#KWE z5wy{aHLHh-@ZcoZ9ADz$l07i?3C5Kt|qtT{Pa(sKYtz`9v&C~ zvaV`6I{lHGLfpYD`#5P}#tnomqbYuv?HiZcjwTdp)IqWxKxG2DJ*xWK*sK9=3KbRA zzP}&IMGRgXt|b>Ww}Gzi*NGWqr5)#v`0t-E;M{Gw0D)M*0fSaqRT;l{+Wv`C{cK-< z-|eN2n>%6$C(mG4%gZp)S6p}uj^MuGFutY8IPtx zC}1@ymW3~Ry5<=oT8&>qf;s|!WDN^UVEY2g!@`0Uk=o`yk~+aXfG}%P<@EEV91x>G-$lJxk-fW_|Dfw^CjQuX-k zEu>NQu-8&kQyJySjsZc4T!au`llS-c*^%jJ)gr{|KBhQreCyzBEG{XT zo|?#Y>Z5mG#9+$Uj{M_ksT5rgYo&o%q(N8!5JWEI{M;NI$K&P8I#*Wc@#Tzb{aUO$ z4k2z#c*Kcjzb)e1kNVY!Dz?SnEqCfZI+C_uow?w^JT8-Ai(W1VPd&~dz9Hb+yLw zm#c`6)-0K?oG&Wo=Xo42q6a9?26-nRojS$dFu(FCx@mQ0HTs;<(Uv)C&z}6^;5eh2 zeeqZC(@k8*p%`1rK9MGqT%TqUj?4L>yi-1I=tv9n4&IktQJCj>#?i|QFSL#d{fYmb zQK0Hn?B@bwMr;op2lcry!>1iu)A8OY!CQ55HeQxTPRz9;dWK)!%(cB?&_#t;9&8Aeqlf1lFKP&z~z+-8<9ydS1~l?5gGS{?RN~)#Y&r>O&}U-BKjl&i38oAJ3o<75%MdAQhYtE2J5y8|(9I&S3m2a{HqJvGSTGr52goux^- zlVtAQ#|}OLs%^O9$f7%e9W#Mda{@OP7t-0PT$6AZ-WpKC#EL}42vKr2nbB_72wSeAJ`Z7Zd8> z>IOXt=cBNZqO6njEX&w})hRm0QRCg0NfG`o9}JyeNeY6ijZ!3hRD@$I<4nGSv)2s~ zC=#1Msjsg$ppiTv^n-%z>&)(i-@Tv51D+mP;tCiyp8U6acgcdeG037sf1>EzE-}z75#H=E>xBf z%6736K!Tjy{E`*Hq$Xqn8u2Udnt2-Jot1f+>vouZeVJHM==EYyb$@CxML0IycWE6X zWwFSm?i}0SQKx;DlFrUm1jDt_H6*l&n-WDbGc$XEhd+O|2K4z?0pxNAuchxobxVVD z>4QLAr?nsVb7#I6aIBwjj4f?w8@Aphe>23ZSfsf1P$Z@Q`WQvF_EPXYOPL;I!QmBp z;i{!yvB-r|bTXD^yyx+gia;WGEc7wfK{%-qS9;$o8zJ_;y2KoL+{*JMQrK%+MssZM z6H~75%Y5fr0h<(Vmv&2My`|#;@KVacmU}?kyVi?~CmPN%ylu)8iKJ5%9Y_@IpY7?4b8vC84%E^Q-fQwcqRUJne7t*l<{fAsWUVKE9H~0p zT`=I!T;KzzrcZcVzO()8T`!xGa^}*mXRC`F4JakV{g6tfTokuQucp#>mnF!LS;FNm z-NAx`h!nGgxP~n2@amiypt7z;Gt|#|i;BY1A`bj^rAy|Qu33zZj|aoUA7M(o6R(RR zn0_MgJgiq?@lLvI)$M2*rG&;SPYDr;Wrr_OXfGSVYo7LY1N`C7w=y4+AQSIn4$Wd; zlpapG0*bY3Vx5LGO_Zw$jZ;jO+g>}e#=JT zI-<6My$v# z%MNgLY3Wz^T^=6gCUWV3AZU}R-mG66TN1Z#B=JoMt83GXi5*tvWZ{#L=Bz`B0rOLp z2lptC@0OwZ1uX^L4&u$A40M}xk%#5uuW!fro0~L0Sls-0C>5E`%*A6DHi_RpjVG|i znaD3AqbhT8`BeLx?I+8o{-P`1cWCau4~ZV5G!#$$7qrEmXG5E2`8Gz z$by^z7j_$RxwnXRgqRx`6ySRRSfzkn(Mg7+5{nFZ-Kk^Z9^7jXSZdYk*{98 z0)kh3N!^5;95)mhx{K~CWQYqB+{nq3*`T5#v;xHf0jNaubac5+Y)qJ(I#A>A6p&90 zp0N{9vgtycjuxom^jMYA^?<9$dlnZL1&|r(=?&mMIqpA3xKAv&qdO!dsO3|=nTKI6 zyxvq8vn6DJ%a7foh(Pcy173$?6BC&!z6w{&UVA&6wp8w>VL&UoPF&(~SlDSchny8m zqtJkrmGu@#F5p-zm;v_r>0jS6mCcM70>l;g$Y&pX^UMe{9?B7DZ0~GRrnokZZ$Xr` zgr-;pptEWOXJDS#`N^5n^18Y)cBF;3nUPUZpyvy_q~vrnvn6jIuir=B6u(dMA#5nJ zop&D=q5vm<402nocyl*Hzy6+}poE+p1^2B(J$0;u_5N6FKo18qm`}nPCXTQ@oSiG^ zdQN$1z(8PO1L(B@h*&%AZEo(FWVZ$FlEu~9ydQ}bwk;6*!F#&kzqADUKx}}b8#Nu~ z;yYFkzfJ>HKZ(Rtz!Db~{Y9{9SJTw&g>B&%3+Xs2cEXbR9Z%T-*UEiN!N2tZ(2Jen z2DHM5Su>2DMROb~&4^@;F}3lu8Uu4LQ#$(?Dw3Ljsklarr69xJrloIpoIW1G~< z!H*Q9L|#?~aSsnH*HF~}3Ycc)eL&qOdy8Bk+k3fuCIBgYPV!nK>WA1Kii!vl{r4e_n;tcvC%jH?H#RnAW=cBytIV2QMFKcNkw_#EiQU0@^Ke^gr2ybg z37RzGOz@4-x&iuqQw8pG_CJ_fewzcyuf7jop)g^fVc>KK&<nWYW0%QlslgjcC07H^3m`9xHw% zNi_)|csM=(^wJkcZh2GV{R#ZOKq$64IXCiN85nm1!8#PyN1s$SGDi4B{t32??lfVK ziwn@f&r{RJUyabdSk`)bstXu~!7A>5h1CPFQUgrq6Gjgv2q?iuHS>stq`G$Yf&Yv! zHNEg9*QF8S0U@f#m!eL&kO0JcuW*DI;+O#1>QxKG(6Yf>Q_fhZ=21MP1`r|2KixMD zZbqZc@Wm|5Rhu#(1|GPL0Bro<^ufr0=WB^Y|64RgI~iBNH+XM%*WzGrQMR=?=8uL^ z1Q$Es2a4pp0JhCSy|HuxUP}NmJr%OcthI8OutySpi+#M;Yfa!qYq26AX+X|_u(r9~ zG(hT2b9)+uZ2RrtwjHRcsfiltML!*p*YjTzoydbt$T;bqywYl`tS%`5&d>mGW195S zlarI9Qmm5h@V|+R`j=2>Wpg?rTNKL9v1;5unsQmLCFM^&i&PA!OaB)ie!IA_H;&MX0rSzRblf9FWO?9JS`XH4E%&F z%+Jp+FN-2lgK7#Wp=&4ineN7?q?7T2ur0of!MwaY?*%%n&z2v9&UWj2|C{j&1Z*Q9ssx<{kM-0`9G!Z z-!J20dfg9T%3T*FD8y^T6{s2&^Knj;F5L4bqrr(J(#WM|z}Kg&>l6WzvEUAMO2*v^ z#NF(?529GWz4~!{xx!IOBn^*S;dW4G1%$<9T3!oGm+}&;2LS|ry37VY@w})bmm&rR zG`6#H2k+}T;{GBgCPtx9v1|{iga8=n0;O!NFU19`X25Kcyd9drVlFkFSj;q_q z!0icsPH}nD{^uM@1XcR>m@+k zd~HPjDS$x!lx{uKeP>EIlcn~xArp0s$8qP>%|SoAlAUl8ehTr>{rib=lo6c2c%_~I z#eJ8B`kk?caILX-N~Iha5FGg-E?5-LDZ~QIVAK_AwSOxKcc-VI94|~>S&!WLf(J6% zi94-JUI8v%BG#jkajfQqDGMDPlTgo?OX`?DPo7Y;L ze^)}nz*865`X{0TwEg%h!wa(Q%HUcGLoP*n5p%Ezb$Z0`fWd{K9^C-(Rso+7Rqr3^ z8Q0(m<4gu8a(*bS)KmKM4?C1=ao%@|z!@9}inl;y05|gK=(4C*xRblVC3`RKGl|M? z);2!-XoISRxM&F#=U__tfIkh&9_@!4+?8BXQnWj`7pOhp#UB7eFBfH$#ASFkQYbA2=&%JUMnk$y8|SFi`_L+ED-WZCw7L zGNtt!P~o8(hp5*hP#sbG${(^Q;qv$Vq0-HS=OH0r4qqYxcr=*%A+!1uazv>i`S^&Z zlJ#~9hsYcU6ujmz6o?1F9cR4DD)R|O1=S#+6Dl6Ql0+2EEhD-)J_`_s6*$+mk&aSU6@Sc|^;is$PIdnNt>4Qz2i^4Zl2g)LQ zZG=_JX!g1O%P}I(l>{O*s8o3$zrW!Uf3uW?;G`5pKwPE@=hMof@}wm6(r^fPSR`8qU{}qhP%L9l0NB&0mo$Xs#4l7xA7+Ry7&#I?boVH*YE(Gu75S1q4~Z;G46W~GY;P<3o~|Q+kqQ_TFnfg(evAaf)m4NN@FfL-Bwuc3db)=BZOL^^ z$ZJsWZR-;-hL`w4NQs|FPg003QcCdOg%I$e8CDQTz8ylUH>3&rqjBM)e1ub!FnPH< zAa1;WmZET8<3~^~sg`xgcneMqPA!8F{q#fIEx@!IGTA0u!SwVfH9R=Qhl%kvF&OBY zxHf&LeSSTbWW+J(;}VJW_b@*4ED$vy24{&HB+tsU^a|@#;s?O^@40bAlvZ%MI>k6e zKdJ2F?;tyJ*%^qa;BO3x5OMI2Yfj&=XnxwV6vPeYzun+TmpM)cmgbxSe^=TpBx z*Y((#zCavG>Mk!RNiUyNgjA9`i}))yhAlo_30+0on@4Q}C<`H&zWSFVL$M z2eY%iU8_+Z103bWi}$bx^ZoZ>bBaU(f=U-P)XM8RPC@?~3qZ^ck_VWS1rRh72}A~= yLLWtxHo`h(%3%?}42}L_?prac`uy7d^)ncD{=4qSt3t$Bz(-wKTd7*X3jROQuxqOT literal 37159 zcmc$lWl$Yox8@u7KyZS)A1t^NBtR0}-Q6v?2Y2`2?(PH+?(XjHI_H0@Zryul-gm0z z(|kD9b-KE{dUyBQYyY10tPt5B5-5nD5CH%{k^Cwu4*(EL;9n&?BzTX5nSUsF1LYth zsR$1bzq~240sf0%`&G>W06z5o^MgpB|9}qwB!Hx-u;S13lT{ZF1*Lbmi}PlBGv#}0 zT1LkFcu2-vk`K{`P<~L+aJIiMHXyM+!hEDAE20t9Y(k4^#}sWqhA~7i!pauP7IKLz zFiTx=^7796K22pdjs82~+Us&FVP$8{{j8ZYD>FUaovB8>9M=G-dOs(9P9xl}e?Nct zJ!jyez~>r50^hBHCX(5?!`1h;aQA!eJrb2qFDvPiFU&~IIjPTSz;3l!^Zus4Jpz1W zLFCBoj+Ij$a}%O|xLr9MJZWgok#_y*DDuzfzDVJdK8`CVaW-MJ-rEZbzfGQ{zPn~a zwF=&NtB?`h@tOxJYWr2DkI=%JsN=1)ZL<=>a`6nqPSo~B#|zvV?XiPrnLK1xhJGa0 ztfzB}Jr0^+NplQn zy?s3yJ3<@hc^+q+0g(R!M_>-kvw{ZMGSLE#br_R74cpnLzDP#>W~uF^!N`!s-D#sB~LL{oiW2M9275yv%-Q4kWeoQVBQaL_ zoy2oeNP=OD8{1Dn!Gu{HEm1jhkf*O$k*|Yy9QID@cI6$x>Zkhqveu6Hi$(^EyVE>W z=+MHS75&|)yF3y7P1G!alDiT6_=%2v=zXU5Eqvqcm(K|aIGFlxC)EbnrmuH@g#uLYi>gr~i)4F3QB%flp zh`nD5nyP&C@KVJAl!wz;68J3+e@eMM7#1!r$6jyZ``hb6v(y}#)B-D10&b3?812eR z-mr4zW1OsUMs`dEOv;d03Mk-^m;~O>7EbQ7K3;0$m9H?VL8e>cHrJAGtElmcQFVEg zNNgUI_bDTYP8YY|9LxGv{GW&7sfsR)P8n%{gm{HYyp*+eI`)Za{-m|ag_6z5u==}r z|Hn`fKAD`k{Qn@eE+_7Yn49ajg#5MsdniEtNwU{+9juT}i_khHEN5NjGw?UY*@05{{tc zBjV6A9~nb}X#PnO(<+T@Q0mK{1p62%c%{|uPOC8(2kz>S_(T#*X4nC)0vf4UilQO? zfl^i7aJ`v|&P>SPC@gOrsR9*C)%xn)Vz&6}o1( zVMe_`fqSWDMGGU#w69JuO7ABhhBq0EPooPZ3RwEBg1lNyv01hsS5T<*8)j68(nkGg z41m<^dO8l-LM(iHBU)Yr2RA53!prW9R&_Xfp}|%5>(S9w>Jhvo{UuiSyD^Wryf)tu z%NP%-u-msyUvmpz1bWKQJtHHvX5)vEO4uizhr?A@>T=sxJd+sQxa?key%=Ud1Q7;j zb9hKo%eyuM$$45z8f_lIpsKH$F^q70-C;!EvNa%@KM?#{hv%vp4E!f&3dh@(OO+BS zlLFDiVhRp<&kkA)20)3orH#aDIsvfWPp>_H>Zx=dP7b-71)BWsKF92;&;MzP>HLxk zLmY?D^1=QR?yz$sW>fF`f)%$uf>uU$O#YR`OubO776{Q&r+X8y zh84Htw_rh%V*5bw*~{{LWQ?j{>f2&O z{`@-T3Yo^n!A^CZ90)={xrhT2;t_Vmp+;>PzpyLoq8J%Vr%3iDgXd1da(Oe0*Trfn zx;QjG>$~fF=*2=(CsU6oYwEc-`*b-yyaV~%MR{vpfK? z+dkAGUQecTK6PP>8OVZ9b#jpjRQmbNn*45KNUxA3RMjm9A81LX zRnpX#DuV6{`hYzR5LnJ8s%&HnRGmU~rkbifDrQ!=gBP^i+0Q z$5VU+%9OeJ$oM#!#w8BTcqv_WkD1Ebsg^QHs6aEE^E=BnFKnK%WIY~O@Io}rO*XGv zO70Gr>N+2}+SkxM@BMS(@~L6yg_vJzA4~7&d1hdKqm%!@IM$k_Iv z&E9!gL!nPRA5ngUOH7V`?U%7zBap&?{d#x|1y~*-T`PA0vK{vkI1P>`acdyl{Vddo`W84q_?jTj`}eLI|-nCe@Zsn=tx=EHwb zv);GTyTqIbIjn^W0~U1IVRV~o4EFGk)%jTun^Uo_WKxRFw?&8_57H!njjI}jX&1zA zX>bzvG6vx@lbwy&NPWAC{v1--xAoLDDR99@ll%a1leX?{v1vzcDuSW$d};Jm(LQ$M z@YVyr(A;E30EF~QY0@d_F36$;V*7o+<}2SGa(=ACchFjtXOV(FJ;bi>lk zD_2A)!ZuDe*0V7df(OiGuq8i!^|9;^}|fuT5-cOdYYE_y`6P!~%7+;wYr zvl_98W2^tRK=|Na$I-Y!;PUsT+gR^C)P+@m{pdhKVPMLH7W`E8kB@yh-JA>!7SANUm6O|% ze=g-+NkUW4Jb4-rl@&--#bo7Sb7>@hVC9t2)Q(fd<4N88Y9nJSnLLej82$Ez6H#sG zq%|2boIV^209pb*gnayzx+h&>Y!sFrn`Gu$oS#r?o-`^ZYw~9$9$Qpx`>cuu7dnYu zP45riv|D%By%W5`P(Dm^pC6Bq9>*8mLJ%X?MqKpT7;3a>`MoX`yhLP(I=vQQT3bCY zz2;j@ke22vI$F1%Y=(P7LlyZmW}sg!BP<_=fXCj|W0CY8-maAZE zUJyTw!5M7LWSm95U8W($f_6iM^?>fbV&|S!>;rySn><~E>)B;B%7sl2r^Dpf6XrVQ zJimvf&rxi!lG9IQY=$1L`Fb0!&L=1xjT%_8C8UAD_iNee9hdoBPbi2AkoRo{ds1Gs zK;`}oyd+~BFoPP>v`1Ei>4aKMudA9g)UGPO^ zNHvSO%zC?Gsk+4Z&x>PraAjegk~xmqB&V9akjXrI2+J-G);EZ*zH^hd&U_(}aI%s4 zM#t+R6kmS7$`h`lB%#u)7x4Q#xk*cJPwQR-HRusc&l!=m5~%s2v8FM?D`jcxTafeC zd>4jKNYbDgy1fWb4Qvp^WWZjY5^Yz54YfBtm6IxX84+{~zE*)NF_O$7=dBY3=E9v? zE5u;Uhd$El!PuM1O9|me6ul0rWD%iNmS>I>b0gZzSdRNCUka~I`!(#`n??W?ug#UR z`f*G301!;T;{FHznZPT?3%Oh3-6 z#y}clH3@jsG|7d^c)#_X*BZ9r@GFq+EP^>8c_XV!)vWvM9|PbZTnmQRgJ9_ z^m(d+4%)ZxE#CTYK#^I1OgwUUj|{&}t_HcNr5W^O)*L6j=IN$W_~vIj>pKBA8DiU>>jg&44lT~9b{iatKQZIGfw8?&qH*IZ>4k5I*9u)R`hZ;`EYondz z-&v_s`RYs%^*UM|nPpTG7 zDsp02`X3T32F<5@GfvInw~^hc@Hoz|pQnHZ2IqseX7o0gBR@dI{zL$PNqD_*Q$&C{ zkv{0*uYN=}+=8xB6)m|oF50+ck_*Fnj9J7dz5*L0XyErwnMA`Y`2h8=_0`%&QeViX zo9Ar#&|*z0OyUI(n$D8RsPFqfVMW8O7P}{8`HL8Mi?QMtPwaO-JzwD4i*4)qRUsrDu{&Ajrr+Kwi3 zI6qDKGMSzWdq{LtjpO9;xsIFe#fHGCx-;SDYKwgxZEq6|Jy&ksfMQsWVRCrD)^xAs zdls~=bi6f@*AoU zbe(EdUF1D~SCar>izwsaAmcKgB5h=WnuMcXt4N(Dp(3*l85nYgYJI>y3hQyZiG%}K z_7$^tD(rS=C>7nqGgWOt#6UdleLmb@R%jTS5|bV2TWkQ{GOY-sylq>=9E2h1cTgc> zxTXn$5E9Z1U@h#Gx2&S8G9bp>!taoa^xiTWiC0rBUv5O$67}6Tn#|(_t2ycFA<;Vp zOXX#->4uM=TfZi$(Tq0fEFTv}TxO+;y zxRCx^4<7g&?0tp?RKF@22p5-FSf8V@4=U|g>3+16$Nt~{Ai@N(oOwyO?E81j=nBCr zDJsU}O4WZ#(9|jIeycH9XA$ZPc~5&fV+m^H<}d37TCPrdVgyxTV zv7NPtsRd3@#-2WOkA&0~dZjo`LT{!n3i$aH5At*bWbI5H zeo5{*vVypq^w)jkrecj}0thl=YOGTtw535A;{1(Hx`^8O?$ zY%u0+zd0nU9aK6=5pZ=CK&&4BfrrYepSx31dol_c=70XMem%RrV)+dZ4iWHu^BFeR ziPZ`f8!FZv4y90ZF|$zAioj;x$m!Iaqv)?e`+2|O;$9pfCT2`UfehsNmChACzwzd! z2?{MFbQ%*dG+un>ZVkAIKRM#$PA#wy1NAT5iLE=4ZMRsFrR9zPeP#qEp+_= zL$k{kW;~|u@Ogj&3P%1gzg>F2t^Emo8$;Cq>ga)dSCQ#WYTEbR{W*8`nRQHy$9u1L zk^llQl+qN)QT+H}T((UG{Gi z#pr4|d=DiOXcdDAua=;0Y=dx+W)q2uR@?Vjib-Fvuteg)wa>rLo4us!s+~weM<r|H_m&Ool$|7lR^oW~^I60vl3I&9f zHGH}f6O!w26jLgdsL(7Bi)R5y5Ce;7V{Rd++j`X)sbat@nH(C*pcfBSA{Ja+g+Qe` z#X(%Oz|T^7@=w7&6td0B1Vr2&d5{1e{jhYHD_)RUbjYnye7d5lDwTe(*ax@ki~$X~ zzO=QJmMyaKsf%Q`wC`l&%N08klV3}t)$+vymWH8!uPOyADXR{n_>n*Wqq2HD6$Flv zwcuDG;AJgiHDSl6T*li4f^!rJOg-ZvbB-#U_x;p-id*Zbs0P2sd^Y~QI-3`WwD(;s zHk<{>iB|Vjlp@Z}!wl~WF8JcXO&={hAPO~D!{@x>Krm3vVDX$~q}K2I3L-t|4n%5@ zh6%|rl?DgINeEbJ4014T2{QoDU?zu0u!Uc9 za@p&;<5cQNe|UYE%qF(@VLW?_dPHST!Y;YOH}-hU8V2EG=OHgawjNpz{`^eu_`sqO zFFk5HI-a>WTZjQzs_VB)>5F7qBxa60Z|L0M3hZSOMib4QJue z%(4LDk#!+kFPj33q%XX#v3(29qlo*(LVjQ+wA=k?RKKW=BB{s0<(vu}8=nT^7+?po zt~5J(xMNuQ17RNf<=aVSI`IDyfltGY@G>gBZNJipu!DdzNo@aZ$*Hl*W=ldG>>Z8r zx#R`tM9O(sGI+ltDtLYEvxIKHm*@%ReU;-eecLzM$}<-zA+usq1~Naxe+J0NFdQHz z`bqkBjA=HlufluC!RzQNCUoNE%~KzEM2%R9dKtX-{D1Xr?-eqy6~Ov>&LsGDZNs;D z)b<5f<54qhlA5LDTX34naz%rWHmfkE4!3@1DENc zFVyx4|HD|;ldJL)J#n~Ip|f^}bko*W19691D^n{n6wb_HwHeb5q8^|L>YO99z$_*Q ze7we~F`N&EMe{<=Jl^AEP|VAPMaG6y3eJAG@5c>nak(6qP^2La`yfs2S!ui0o$ojb zLIb+|@5dzy--@IraFV0}h9>$n#WtJG{n9AIeLPnn2vU^|EdT7~{~;c05ln|byY^1w zINVR1-WN>Evu$P6nsGWudVb@n)|-qSl>ntN=Y|n8n;i`%TGK)Fu8caY>)5p=!)^G* zJ`3F4T+|7{c4?(R2(hLwH2qvG__8RDXR0KtnC3np^ONM)?UL7}C5}H8UG;bTi0v7k zp%YC~7WSiICCX$rfedEe*7q{hpn)oY1jj0i#V+JL?=g;-KJ=JQyC-V-)9ln*bBdddRBy9Z*IF3o+w!uY9(Q+FdFYw;I+PkaOLGTfD_G;4lG*2*Y$=&+0%ANN6c`ziZ z-bcDMi813k^Y%1_e4Ac@yy!hI$qi=O$HUJ9NMrMMyN?s}hZDSY+xMvnuU}`#Y-c`+ z+vfoiDI^o|WjRRq=Uu}-!0~^+9Gw9cqgAkv27o3FFY}0Tqfs&l0KoCwFA|n~Yq}V0 z=^GZ%oY|T-;kCUjFHJQBvE&{|^!L8-c<yybKjud`R8iQ5aiFh>LRuF+Y=-JupCuqcbKcxpWhsR;nb!-ke>Y$ zzAPm>-C^}C@U*o7u!DH2H(O_~JEfEFrEmyiSL4Zj@It1eKKj zMB%koo1fj{%YURT-3L2@JPH^bqO`aDH-e5YWfHftxo#0>_hL$_n>7Zd9Q$I(8LunR zgGbYwt4bpHfhA(*^Vk4z$+AT6-PW)z>N_E3@~p6{xp(&wue5OoX8nDwH%P-Cu$P?V zSvX#Oof25d75gK2{m$v;HETaz=*f~zcv>-1K^NeniEXcjur$ZNRa|+W!FqRk7&Wqg zpBbkfDK(Wy_}n(O#eUNC-LV9_^f=Uh=h3Tpzl(}*TTie`<$Z?K=*1sHBGb!r(?mm~ zlRz(v0W>(Od&#K0jgX9~>BcB;@{Ow{2|Q`zy9%E+J=p`!v* zcH6I0n?~n9c-C{zeIPuiwjIMc6UUz#FW?+Pn)_v>K=Vr98*mxA0w1b`U679(o_g4y z5%vAO7b|S|uR3rky+shPzXT$av@&XpLO%38^vtQlT*zuY`_*<*vq{{XT6)XyCy?wA ztG;fxc$(PXVoUX1bv0mTpni5w3G^Ew5KcYZ7#2z-VC50|2>{T_QB;7L z7sg8Ql;dKw`2?RAc{fUVop;xgn@nD;{dYdb{)lfVww+1zVe?(vcP%rIA}zN6=>=%j zIpVHDsI=E;j5rb9BYPI)eLAoR6MVO7YO$m2#`Tv;GATfbswc+%x>@P;nj(rh>|?q~ z2#c>*8UmMUfCi4>_v0+5v4z{^U$zhYq6IM_=7b}VB;tL3eTo@{ma-yT zC4(J)e&nZQek&-GdLA0$GhjQiMl4?(wT1A!B!3hVYSxvk=PC z+GvQ_(QJ1*L3(!gLnou@`HKa@Z zp}SzI#aWkK%GU_inP8LRpPX9gNpJsTzSVMgywI}Oxh#`3{j63-Po=a_j%D|>U2vP z6TA8yHn-bS^0)0TA~?|jK3B)A_M(-e1vlTMAJ)VAAuQ_wqJyeAZI&+ z54tYTeMWja;>ZqU!0!&xb{0Zm$B9(~;zfQ}J0&7|ji}_eQ2WiPto?QySS7=y9)(N- z^hzPX=cR>@d#}P(I?>w=GubD8^Kw-~qJZyhZ@5FSV(IdAp!2Jcg@z;X>TTvvVgMO8 zy&*8n^C9B!C@axQyLAJV$W$wACP>@M@oOk7#MfU)-sQ_Lx!QoPBTI(FcU<%y2%n|h ztJ%A`5Qi8(uGH1C($JAK*A2z8)8XKpT^~Cc6&38`9+B!vItXU#p*`n%&5=Jjd29v3tF&|s;cHEcT>PTOtd zVst#r*d__^nGUG?PXzqFh+BfVCl zgKBKM^%h)rSGe~qat_1x3(Yt8V#%15){hPU?Rc{*p)#QAby`ljz)t0$cg2B zI(}MMR8<9_D0w|@jCbzA-5h=VE^ysQu*k$2O^p}EV$A2wDg4t{Gvf$C5&03$7@mVdn}D(P}!_H|5uq zebmAYW-Mqs=^2MgJ`?0o5#5i&3CA1x1SgF&CfHPFDbg7KNgn(qyCmx+NkiFf9~PqiuNQ*EA?;9p?* zk(6KhE2Za&*uQG))chv{=FBIZAXJ;aM`d|c^WV>vwI4RsyZe%)HWXkFzyxu;HE^~P zKml3xrc=oX>&D7pyB$Z?`e*N>ckw79Zu6VzEFz9Ao+N+9#}sdqo#fJW%KwB!5Av|{ zL`y!G16yO?+qtsU7>7|VnPRo;HAjnkNa4>`BTi#B0<7*YD`AImf^Hxs{}Sr!BxRYb zmdH=+_wByf5n3=;2%*8j@XC__@bZ|D#UQYze-I$C{0K2FRxFoseTAbkn&EDC5mcL_ zG~XHs=1M$_&Q?_e^@oYYTH^4wHA;6l(D+iz&%ZWsW7rxHT%AREtwfLORf^tAqsti< z{jO3GsnqaWRLx^wWBxtx&94TRW8ib!UXA!R4Cr4TPQ$LBF(FIIY#e1C!-jZV?6UkV z8KVA*_i0KrM{4fUoA8?nlmw^(fSmWqexP*2i{~uz(O?}!ZYIIhpYaCk5uN4M zn`f-nam?#*?{5rR#%T~jgKCdMGplCj9#^UaL1IX#`Mhgh`fz~I!vyDh+UuVcX()jQ zTU8`%AYhoju&p6?H2fWZU0hD9sdQM!)sh5WeZ3+#H-{Ar%|YC3*&Pn@>dGr7Hy}u&+_TPnehc01;{$NwSMI9|g9>3-_rhhUN5;+sk9#&* z7=S^sWs`53TfAm(J7b|+JfYM(g!}^*=Xm!sP$7tb&yU0QlViJ1Eq3#Qb_cBl#d#0H zG+MkLmYQvr)7h4}$aQoyC8O=z)O-^nZB3^^Hgjjgpq?%mCpXI_q;?T=LPL}Vq}aD} zto4c&?>+kvETL8FmFLPkRwj@aen$^=Y zZMS%L8`8Dj&eFe6c<%HLsCVVB4kwPejz8Uv#9ShF6>P6}-uGpd5Rqqg zvZc}vtu*h+D-rNcI(qNTk}|3SW1J)Viu6wx)!%x)F#4HA57+#_tSJ{4o3-SIyUn_h zuhjh%EfXDOh4`-+v51cKU!!NL78B_2{{e+1Fjs1&#$!)PCp<4H@BJ1qp2a*(%9Q_x z1FbCYq4y@L*?t8X_?dMTl=-U^ExeU0Vx@!~(Gi`_lfmB+t~-^HG+4mz%Nkocw`-Lh zr`l!8zZ+NlOLBx<;!7_E=Y3`=AG-pYmu2aiu%S zxl!x(jLFaRs)8w!MMrsPIyKtaKd5f0_9$r@D)W3$YpnsK;Belm)pK9zf3jtd;Bi=E zV9|gTfSU1o)AbdbB>#KU?bgh#1uN|L!xDCa=SLZXn_$jx?ZfpWd!E z^6B@5te!?x!3JX$vt>IQe)}Ln$Y8=!!JDbj3>=2yQ;UMB|H*48!0*r>lE-KR!cy|K zo7IQjXXBg85(FCc+)VlhC;PudmEW~C36la98Rc6Wz*Xm{N$tn&dO~W%01%JWG12AB z{PPdI=erw;y=(VzNk$1uv*AcjZIjF7Dld$F?aWr&w=g&|o|WlV?@o7~0Q!#rN6TV` zXklt~O9j0|1qYkKZDQNT^LpBYt@H;W5Uo0#JA@F3iNm+Wz`k|PP5@rLc_j)Q24JE+ z!Y1UYkE%U&(R7>0eHB9+mG$4oHPBRzwqck>@=Knfn$d*-^#-A|7^pVR5?3s$py9s^ zJ9{3--1pHuVn|it(isBH8{Z-i<|!$gSTh$U;we^B4c;*kwGzbkuc~zBIfPLd;da+M zT*&Hm$7y?3UCb(s(s9V(8fIMuz6IRcY@+U=*Zw!=ta(x@=nef-DBd7}n#Ca?h5~*( zbHC^T^T=8KSN#_~ix4$*L{`=dqn5#`w@(Un@p^U?*vcKIZ9Z zTp|B{rI_n|-;BlD(A-DU<`NBO@pv)n4A*O~>x^)DZgjDQ)oXBvwkMXWkxe`4QyT4o z{4|-l(=NR_3PG&n&&AfbvHJsFU7@TSE-ga$IsbOqw8H1%gb@Ymqg5flCL)I61CLk# zFCrh!N9OBc2ki8OJ7&!zLcZ&&!3GTXBgz(W2PjJVKL@q7ycOmjAr~yi-vFso7MKhA zb^1OnLxE_J;dVU=kdF=LaU&ib+sUN-Zwnz)6GViN_%)1}-y!;O0RvuZbZ4A9m9Bv z>}dS~kC4mrq#(N`cNtAab9fdMclPNaD{DQa!|l)04fmH-Yn2MP`t85QQs@)NyLH)` zH?Ni6bKC~=Hu!ViZ~aX8#K|lMru6x(M@8OD@w1tIJ+He`^7f(BX}+15-%+ zcr;skVhU3E8Szr-7msh>EK9$Bcgpr$Mm-qJTy8NrPei756*32A zyS7M;6bE*MX#Rpeu8tjOvJuTEkW(>(aBocBXr1ju;N*X~5M0dMM6Df^4zIO5w!yW| zU60;8y^+B)>8nvOkWHzU*sPqOSQCc%b+Ibx^ct-h!psGI0fZi%@VIm4jTN5SH<1C7 zB?-ylT`GFmgn!SIUz2#+bPm!wM>6RJry8}GP2Q;Ix6CA?>Fi`HyUZ*)o2g(?53$vA z9ehxJgc~-TtG9D^=pch=Z;u^S%F+TK@&y*Az2|;K3FiO0v&QdL#?)dAYimuKmbon$ zE|e)gU5$%p{oE1Q3RA#8!=}4;wD?YqdYp1F9-kC1;dn|^fha3{dHIT`(!(3j5BH~F zeeU$;bW&adYd?)}Z+7qr7~#U*m)<^&K2^zD)=2^3HMhZs zl{7e@SJ$;?V_C5Re!ktmq?d@$z}FP!tq8Lg%3%(sm!JOdUFKgj3MGp9E$V6~Utt^H zPM^Wok;LH&4t|jQT<(ovr=5c+Uv$#wNYQCD4nJS#b)4rZ-uEoG>Xe>S;A0@okm~e& zy~ju918DrwTV7q3yq^PDf$%iE4D$k~yh0}>12(6B1&n`f!9rD<_Y4vc4l1}VLinQ3 zhevZ}&BpIlhzh_WD`jY(5n+fb{9jDy2nesU}IKJcQ@o`#m8NL!S__+iBgHrfA#%L+xGAV zM9%J**44cut}Isf4{1^RV$qr&cS75|-_$$b)&G4=yf4qH=AmrEO`Z-2%0EXI9iVN zl-dJDkG)ROM&U-HY(i|o#%QBeq;jE6 z;3fye{M-AplCK1uHt?j|kytN%aYM-*N4=jp+65<&bIibpPr}RXKmYif zD1#(Ph+lSer?Z^*PhOnmAM?*K{hHBJDCh&DY3$E+w^?6Edvrw91%Gq*Rtb>;&^`bJ z$v(X%KDemX|sBuRShn}M%Jf`D0AbnC9Q-r>1ADuNc^B8%BaD}>&*fKFz&()PCv3m1m0 z2aHI2BA77YB75c9n#LGsWzooZX8zRENo#pYWCi4R*zg7L$0 z%mUFvL^2xtEjP&8>q*Yz5ILt;dD|*!c3?tzvsJDu zaYopQC1j)W8uYCZ z_z}je)dNzTME(=|reHhtBmrrtzN)GEc4W07NBox^D5fY$IZ5N5`svm=#tf&MtN6uj zUN^^{TaCPyg}+kSBHpJbo9o_hHwhUo-_uz@ugb5KX2=224)eWzMhYejOy}%g{Q2##?9?EzwLCz?6+~J>0Jct#^ihm(z*jfBKloaj zD^Szf3zDCpCj?H%*4mxDSWnX`JAV8~wx@P#Qd{@^xw{kw;lJO`*Or00(Qt&6Tga%9 z=CpooHFyd(W*xSWo>EF>>kHK&vL=34gJZiAAWjauc= z^xM(}rw6w8houj3$%fx_W< zEBD@FG)SSAJol~1%-fCOk>dUA7n@LOChZS}(;e`wLfJQvD5@wEFoaFQDRMwnKz=9h>5 zWxipaDff?RH0kKd6glp7`;uHqhx2J>)Az4|dk`zhj8~GZEtSO0aV)xKO6Gr+Z7POx z99$PFEz(HFhbb@(_kuezPNlCyjVDN`;J0)J-R%fo!S%OgGu8Y#L5c;L$z+|&k0L&+ z>8}x{(6I-fe?uFb%rYU1=oxdM3fqmo74k7AUkw{BJB}pnB>96@k|=Xy5W2(KUR|%& zHmH?EJw!x2EFDcV)JA?$h_n1sphlu!9u@f$@{Js0mM0m8gNr4Wmf!Akl8f9orz+T+ zMVPr%wNY3~QQ2Q{)QA>!-5+!H|LAYw^L>gQU%j5*gXDPZ0Qru-N_*DK*}JWafvcAs zMsG2ca4wd|>noh0ByX$M&h%(z3PE=$t`@T^Feky8EL`sMHSDh0P+5mXVm^+=JK0sE&=nuYx$-1{iizB zHPYaflV<>;=UH^#&8BWGk=o^84`bsS^L5;T$usnBSytn8EZ=7K zPu4Q9_E(qomQO(YZ^i6*1oE}y0*xBW>+UGdV4#en&dDu46%yFcCrZ6>eB`8`^Y9Xa z)}0Y%T&|yz^TGU=iwoH#>VXw@o4;2wQIHtXtb85r77<}%Mxv!2O174-g|%}~z&>%t z!seeO?N1ZjBEA6FEc^X+>NL2a-lf`sTC{Z1!B|}|xpO0;yp6Tw8N)#v?CrPu<*fvt zgV5sxftF*2Mp?;#W@Ky(ZdsFzRTZ=Cy7qYYVh5onx*mywDL`fJyC(H7z0jmFg!Xq@ zI_B;s+edqZ!t;X+2ACC5(b%nVN4J= zXLoH3Zr?25UTt+*FS!DHZXkzMG251TsO(n4^^m_A(s$6{Ac0`v(4p|^HE z-EkbrGq6VS`fJDvtQODd7481Q1Gw0xpGXk_2oWE^$59R3MhhM_Gi(>`Fo`4y;)3O8 z9j?>3HDb>4V?vC^V20tcxuh@~of?;1G8#V=WTUz__(`E@Avw%ZKy2)VB>0$0x`x7! z!Jk5pA;icnn`>P?x~JYW7v6>z{>QwZDZ@Yco+h+p=gi)cHOpxx)*ZnlE2bPPxw4BD z&q5e&%?B-qMsyNaF1P?fE*un%7%@lTk{ka??nWIODr9@_g8>6PU%o7@{Fz8_3CnLk zM@6)NMlMG*gK!pb*2HdmO+yLU_J&eRG@2ry3O0@mFZ;(y^?y~Q!^<8xnLiEx$Pmy{ zRyHm!DymW~Q>Mo=6-LwcMavORAhWB z8uZ}RM>uH!NV^G_I1AjcsYGX^eGo+g->M#gpIU&02qQuxARw?0Zq^YEX#6xt5t-Jw z($>~swY>BpQbP;duPK5CGc-Cny4Gae%`U~zP>k&t8oF2v*kZNf0Z$qz0&Z8u5%dI~ z#tHt+6Dh&kJSUz=u#p;*wid=$6S3=G(G0_gfqvn?!J2J&4voe!?$_gFplUS}0B=dG z1vHLT6OAs`gg9+_t2Jv3o(^Kp37GYOu3a^a4!7q(mR#{D0`{kneeJaNmm+P3)%Q0H z@~p=*VvC5!f0o?FGYZ7SEZo{sbu6{Zh!;mSBlba*N`@n@9yc?LVzD?4RUxq~#<=}X z*kNMN9iC1%T>_p@EAPEGeG(`;WoUjEtN~~}%=U4FE)2)-PnLUI+rBQy`19QAVG;9V zTG91%;`0?Yyl2y2I19duKBs9Do$EpxIxe!q^R!>f|sZnQK8naotV^6Q=S3X4T8nkVnc@fX= zx32kzI6babN!zD69sc<|-OpiHPKyiB|I-Wb9l@Rqn@CWrz;c=VMsF|2`LxL#50H*3dwhHs+5@(-0e=J(p| zBJQ&Nc1G3n(I5Zebg8m_S3z>d31#P)VgmbA1U&@=b{kATL4ECSW1R>%r0aYl5z{S# zmAVesU#lw1px)( zZKm|MSv()J?QgB6-zHAyVtpFv9&gabddslV^CNjHw;mMY%!8L|dEVS#f4phW&Q|MW zQ1woM19ZF3US!C|R@{n$nYe3qF)7xwh`zadI)iH7YjZVpv@aiRRNA=(S`i%HAo~tP z>UD>hN>9>(4vJ0!$IXtD(N`h~w0F0)SBCXLyMeEGvn?+>#@Z?WBxp}Aj>6Z z!-4)<0WCPEi*g5pPrSSsOUH);arT@HyiToN+$LXmsVo=^@3raxKv!XpSk2ycpy3Vl z{_qicQuL>*Vc_k{Qe`6o!r$_45ANoZq0NZpP`Q=g@MCv$QxvEjoVri_OkTex;IzLg za`zoNjcEsdXt6lSbuaXAPi^GyJQY_iiY0b!+MOdd_CkNP%=(>vd+n?qOU;KV^GgX$ zG;VK|s~>%;_-1+DyYo*Mln*OS_Of^3YopBVS6xuS`fE7{JF|q+SA0Gqx_D_-j#o1d%#nH9fqD_E6aDoPx z1b26b5L|-0ySo!SxVviz?hXm=?(Xgm4fL&d?{oJ3zH#3V=Z zYKgDn3+9Lkrp&_b5j*q|_9hV;KwknY+xvgk!j+U#Egggal1ju+8bICn|6XqWq;X}Z z&z79UjIXb6TpYS$T%2xKH9fE*Ba=Em4#u6H zN|Tb3PEAb#Z{J@X-_P9Gx_tVO|EVq~(oC>zSf2?K3oDDygNBCYI{JLA!@U>__}4LY z)#Rk4xe|H3C<&vsF!t|RUtxAXV#919H~wkJ*}?nx@gok78B1ED-3Ac`1_nCO`Tyqo zIE>nnG4hj^4Kzu||3Ub(EZJ?%(^aW3;qx9JA2Ua|jbXr}` zWQy;YI{A$wQcFjRiNF%@PryiczIBC>IZ=gC>FsW^teE>kr#=U8Z*KAhw z|0);bFFi1%9At9EsaV@wp8l7oc&hoXHHaA$JO9su4RqVnjZ6l;Z~X?FQ7o_Nz4R2^ z?2yCf(t+5;(9CCbvi+rtkW0%NcJn1a{@ioduSe;%FQROJyo2qrM`P+Y{*0+xo$f9M zCOSHL`L!Wfr$5yIcR_;=`wYC*!#GbkRQD|Ag8$aNt61ur{c?nL?dE;CTE5m=Bk0Xf z7G7$^y`C>@N`LFmZikYwq6)%K7$9*l2f@9CVts zPlF~Hrp{N;6taX%wVtHSd^aVW8yj1kp8JV!aoRp7SdOZlEG}-#yg7W>q4IwBqoZAP zbJEkRtVZjPVzAA>VXV3SMI~PD>97;%a6Iet|9hiLv_1}JuXPtZHIrO1b}UHacaL$A zdBp$F_JMFVY(kf3%WovG*c&33L$a*;M{hmNrEq3;VQE4S(pI^*`rsWQb0K4Q13Am` z@Wz;1_TOM-{kF{Zt*KCY8n#t892BiDZzt1|ymrNz(1U1GbH?7 z_$fRB0#$P!-LM?3m-G*jhv3F|rBL%bK6;)+cV zfg}$wwlVU%TUlTEKVHZ?y)Cy}j%n$M(WS>yG4gwDn!8?Z{@h8o=yk-~8kw%GpR3z= zm0h?vf;1pfakpAL{eGeqS$}nl55JQ=eCh?F5xmXMuWWK`)vqm1x2ezAgOZ8Br%?}n z%C2}<-Us#!oHi5vk;goyuVnSr7mMrU3mFt}LuFPnD_++TYc6zXb`_i;2c?Ls(`Rlw z-w{ewuk#w*hL+sHuVzlIGAVxQxA&+rIgpOUk>hR6lL|h{DRQ%k6Go7N(fs&B^4S)T z8*)NmLP9M3cQhD9XHQ{cV!{lk=q#EmsYA@7&oKVx+iiWZdeKE#^0-VEjt5h9`+jem zlsi6MI@Q;f*NH8t$6W6~`g{*}r&vXS*l)bzFU}e!rR_V82vO^mOAP&?&9C#c0nNx0 z5z$sXB^F@tMMOL_8{+7jRezPAHp>?YXwakB=kc(wD|RWOP$xZTkHs+l_A_3ZpbMW@g{Fq)=w@6b2Nv=@hA z`YfkBt~QwOqI{MWJ3}!etGTI9enR71Bd;FVl6}Z}E*|aqsgvh_n25apu&WBzx zeV%^>8@6oI*(b@I^l!zrabK1qaU5wvnyk5>;e!Mxe4Z5B?v*~>+2=Uoj_p!pdJKru{ zx8#{H7SDozZU_q4x#>pW9B3NTX>W8G>l}&Rgh)_>A}h;~gk!a~P}XG()Zb@Do)sqs zxPcFfQLQXHPAL)m*!?VS0v;M!*9K(p@Xz4XT^&v@{vCyt?_KC#Zp;xSfSONUoPib8OmhayO-M0hL5hc~(~SU&OZY9sJIe`i*@d1||rN%AZEw;oT}i5Js15eN5)WFC(tK{eXn zDHeQ9M>{(Ei`Y}7osKo1PbS^kt|e#5JzI9K*St8riDziz_i>)qQnt&nyBY(D;8W`i z-n_Oa;nJU+IIryv6L`PBUkE}x=h@mjRnyaJuy;De7cIanZ1l8YGVy&lk`LZ`Z9NWW zG{c4lU7^gLWM;x#m#En1QCyZ$&iblRPJ5l?NfpxCm2Z4n=M5L(qDdX>zAcgsE) z>%w{m%J_J*IgyDtLm>x2tblH@-7~EWbRR&@WIH{CRDd@#cDZ}f2dzpU zfEv{Sfj}%WNNXd#v%yh$^@e!#G}qPrV>=X;f_-ADfkv{@@vn^0Da2wV_=L3aO0NsA!@A2FE<2Ijq0OPdCOP%Dtv5K`6Kh_wKtMV#BnaDa3b@rZ5lA4<7fYL;Ai9O1ZDpS1P;kir{>w4|(9ihrlieE}eFyPbV z^VQPw_Xy5UVYEV3DJdz}i}kgKEdg&8!WC)9yA(ZYy1_liG~`U!WD|Zex5!nF>CY4l z+C=Y#V_Su&v0#Mr>`lhUSmUt<&j1MPp6!-cC4|=7Az2sIRxK16jnC=WLVyz`5&K>k zQ@ll67wqfu-eol`4>M89#MYL9f);HTMU;AMYz&BSVR*SVsLe+gEycydbG$vQSzJ^< zQo~cmhTpa=JPbW}ij0ix?VV3-J-x;R4uLMNSTc7kD(d&Nmy(-Hk|kF%Wv-r_gbina z`(EvXaIB{YHI}#{ruY%iGuzkK$IZ>XP^GsJ8gg8(iBmZd#ACa9$(Iuwt6)$*I5adg zJWNAP9Vfsx@5dbTgXB)QRo)ia0iM*dfrsReAa_egN_WHo{)nbW7&tF6eT?GMK=3D| zErTr;Lj$A;^j?)kG4@1NiBVH0of3;*>ppFcG=V|>Qk?i=BjRi~q5!5j*(1A!U zL-C=$i0p`;fkV_-xL(-LpDJZ@Qbo0S8G$5jlyd?2$tHlj zNBWt9VqaZ_p=~)#jG;tgP5r5+5$SR(g0x)I0^MfPetG9D%cLmKrm0@(?t# zim(0*60y8Uq+*(QW5F8&z>p-+VA5nlc>eQMii8$>SJ`HaAq0Vkm?~A`c~s&YJWXX2 zLx<(cGfFo8_pXz34YDqDPYfYwikQGT+~*1bhwEWdaz=`x=E07bAmB@MT~n79RL?tn zjJA8orfvy7uXUko$z#fTHM~y!nNyh5R)ru11u8ItX}OV{ssU2&eh{vii_hn1ad?Bl zQ;1KdpcXrI?Y3-kiF@5EVX2UvvIK!7`IpBe%%na=PLxh&Tg9i;2h#^6=Ya{- z4hPqR-;7Ncf>~xTvEbl7w@(7T=JA48^T&6dS@ABSNgv6I2nM)anRD7MZkpCNUep?= zcu(I9ARZpyoblM$EZ%$JLX^6mk(_dX=#`c=Mcmv$|g3zLO#N=m~>G>Nx=T`|+ z8Y;X{J&M!hban07cW#SVy4RtFGt@5+rn$?aVO4JC-`eQ9xnMDPAAh7C1bPY>Rdt>FIDuISxa^I342zkd+&M!8pOzHpQ4x4x*aG#GPA(2;;_WD*{~4O@2Q2ixNlxAsQJRXtT<<%l>@X$b$mZ(kMPbnL{|waoLD( zJI>$i(3h_BwT>3o#dz4iL_!dAM>JD~bQkjU1U`ZA_%#f|kRXQ19o;Mr3S8l>JdS1h zJVt(7vss;iPNxQe&ZUoZpSp`&l#5?iUFX~6C8m_6b24ts`o;pkuj%T%$gl?Y^iOs} zOBd7guDA}j*Ut1-Eor}(RBIdYh-aOzZE>Z*p(#~*+~6YkRSt~MrmjC(*X$^DCSxYEaWLTp!S zhJ%a))8UjzscbDbhZ;A6ewPVXof{159_${&t8gv^P_bW;{QP#{LlOzSgIDRMzHtXj z*ge?d?1-+WYzd>OZT*~L)=PDmgUPEPw@hH3j3>u;(?KONyR?JB?4&&$mzZF6nELSL`P$r9I zm09*0&hX{=UX-+~4AT*h*d46*yRoEo7pvq?=L_7bY=7qI&W-=~bYZugnL0sGu5={L zEkq$x=iP5KWV2F!CUw}9x(E-7$`d~dHv)celta?|us;X&=D>Q#Ew*S8^N zO0^glZX1zI%bqJ%kA2LjRc{+eNK(c_kskdo{X`aw!R<#)k%7y<$^-QZn!|L04Tf)? zKqT+@5iOtIGVt|8S2gX{_)|*AKr5DQBFw|*YSlkQ1t7Of7JW7{^c-zMa|21%-Fm>b?I*92trn{X(6A&>2A9`w4IUdsLO z0c?B>lguah#XFnco{d*fepSOZV&zl})C>nFigZOJ^dZ)rw`2bYjhGKidQNR_&fupF z_XZ6EdZK%ipKYsb;}5ErxtF3bm+}B6&?ZTY5a#k@W#CTRt&jUi`6qmV<@8$p!p`Fr zYW}A^uwZgi4p*Zx$jT!W1>dQRp;2DdK3$(ZQI{6I=xjF8@9e#~h>uASTFvgMo|&xB z=53|V!ZQ-f;O`Vz5KQ66tfT__8`sn3P&NeZH*Oc<60&WKjPzZV=YePblq^&Qba7BD zEIZ;3f_(O1>FR{{tGgyM4t7bx(wW`pGuXJ4ueL?*eLt;*8tL;C=^BO+8F_{T{&y6q zN^%w(YbxrlRB`9`w4N356-5ZN-shz=MVSH|lbwG*_R^NiMhFddrRv?Kge7Nbg12;? zhFOi4!CG=Hb^WuiXIwrRe{D2>(aN2*DF7X_(lfsNw8zVzAL~f4UuvA+#C5YbJDQuTe5YDEKy0A~vi0p(p7YA9uI%}n<5QE3d0^+kPk*9~)&+%VMm*b4e?b}u_W-_oD) zi3!Bj4uhM@tegv4ERed1kYofn{fQZ*t#E+ef$CjvwKu-o%Ut6?ZYp!7c{P{Z=QJW@ zVb1G*to&+(2?N5-sZMtAh2y06On{4h`brs-&iq?G@f~P44qDf{*8VA(asL7vBvgqI zj(A6^(6O6-eyTw#Q1Qlo^JOFH#P8)a%MM0=4xNxl{v3N}=bvk&Z~Wye2R*o0GSO=t7 zZwlAY)9)_5^vL5}uK)j=UJ!aHYD71Ph3=s}*nN$a0FeeM4cC_cS)gRJQr7>!af>!| z{Ta7rxz?^adxD3xd&1JvQU<-x0BO*qrlwx%@N(M-1z)PTSThdI>G>8_lcbE8aM)w3 zC-*^>M&Vn0#K2)d4J47&$xTEE$W>@&X$t94#ODO6yayg%pAdkivIw@7W<*3W!i6w8 z@5TJN9=uj8cHkfmQ|2%hXkvC?}j71S#9UWp0j9R(9Zb) z0OBnV0aDVuZuPi?goLCd6(uDyAMUnjRwM2_}zr%X4ya{^p{x;%W=j&;x8i6rTHbK@W$~6b2SHI5ZUe^rQhU(+WLccg9CA zL^mRgG$YheQCCmR$ne_k9jay$9Y7(}=9)$T22IUC&Fyt>ZD}c=B=tqs5Sb$)Ek6Ri z@J+J2A=&{M0Uv8AqVbu7Vi6A*dwY9-&si2JElrLI$F?O{ z{zV?C1?C>@BL;>O^-a8Rm79uxBtYP_$HwI(C1V8$kk_zbT0(*TM__(RGV&G1kil=jDrNc}L&+S6{->HKz;aboMuc?e~k_AL$ zw)sny3#$IVa|uQp=Q4)Z99-udzrLlcvd+~`h;uf&&^ZqFhRNe&-nX~%J#%KrfEuNb zT+GQFmZ?LfC1YsbBPbU7ZX0<+j6U@vxmy~ z-!Y1fj^~6(lDj~(Zimc6VII?$_yJi|S`4UBjSU7Jm&(3FzXyap5RetgE-Ecwk#eHhynK*M&UVWxMP5Ks>?I}b^ zw!I%5z!Fm`Ts|%5mSOAY)c4Gig|E^u!8?scJBk0z9rF5ch^J1av&Lj{9$jpMnFlGcGs7N+g`& zOSKDEGQI3~!r9xRP1Tr=2NR*>qkO6QL*Zfls$PxPh>y~qBtSXIJNt4LPUo){Bjb%( zEOyq?#1q5Vsa4)xmw|!-a2?OnR~{Fbnw%+FnoUO{LS21~$W}+lY<~}4c4ii=c~%ad z_QT&>(*}@yJdcbR{tqVMHq7c%P}Y`s7ctr0Y2+27ZI@2)+0ByWOAC0W3xKwC< zn*S|3LdD%{QFX@KD!x(rHB?m>#Jqa7v0sukx|i{(u<2~WcQbdEid#sjOp^2l(&+8v zt?nJ(`Z(C%A^u@U7k_;!2gF9GWq;Y%;5DxHx$nP96VGt}A^F>6rtv}=%)P29eh&+t(b_pWkx)RvSG2j=M0w>Sgn=>6&!W zUWI?+ve+$!RH(PIo_~3zpP#T0`L0hx!=ZRd_Qx{dyM1f(s<0h`Tn1Xnvi*xpHg_NG zzZ3>^CpfnQMuDDYEY9Q9xgauA#t@ZR)`iF7+lPitH_qBr09nLRN1L zWGkXb0Y(2ueENwc6~X#&+Y=rLE%tts?XM+Ohboy=MkzI98F@13+3+hjObfF1TZe-Y zCFOqrVx3mIS9uL~6m3#n0~<{kk+(kY^(6*v`v)@!mY>T?dcwR8E^!tD0)wub?5ySg z3yuE`1qa#^N1^`r!nj+HmuPH%3~vIK*xLTk)X))edG^)tQ)j77!Mlz=`~`;0ag-z8 z(Mxbi+h`4azNq(};kWs`3)j84Ute#dMRugrZBlCFUj*(Fl#7RvYd2ko{$?~*JQ{0> zFHo_Mb=u?CSZU1vB&VcF?6>;rrw-Q1Hu!@`uLARj(P9(&&Cb@#44t*`Yk;b1wpUB< zWP?{^%-WXW){iel%XQr!hOv9#IG3KDGTnM83oRLKblOYu`+9|$7c1TYOYXyd^pd|E zfG8LLL6mD{_elsKmMDSyPJ#Bc{|>*60YR2F3pG7{z8*<^1J{GX2{|1#-e>(LU=Psv z*Ofw(`r`4w0y`Mi0LjJ)-c#0i03hajokqT3%UQ140SLR2CAMc`Dy; zXuUfmK?+hD$yn|sYWGd5|5tGL|5-S8@VDNPNbl_p9_b;0SHhtx3Lv4vtQ@`Dx?Jp! z63GJ^U5dS714zz=(`{CRVGW&Eo8w0In$6h)*x>W2hWFT=g_=zi2BL7KgiF8g@9!Jd zz7sxYN}OI@)h<#x>SiRSpv7ZO4A09W1wvgTqN0*~i;mYZa%C=C&oaMu`jIDYK79Cq)gPXjnOR<59v}blNYv;R=LQ#EiMSBFJC7EM zmakd{{q7|pVa1EO-JNJ*Sd>md3P5a;JKabjm(`avHB2FW@Y^)j`FK*aKy!lSqu?^m`ca5F}|}71))loY^f5uUCyV`P7#3>~zdN-EA zsYcULB#$&w%SD7LtR3JSMLlLLO-&Clw~-NPX?eA>*{LZ-hL`+*Fk0etKzBD_;XGe! z(}FfQDiAH*xdmpg39hFaBm{qTmjr%(mJky=U2Ef1z&|`VIiVph015#f9#0Mq4s<;V zQc$lEB(}vY!=ynw&5MhRtE+s1dU|SD(LA=j3Q{8@Bd@Qor3qRdz|#*_3W|h@>GFDS zWZE-{ff@_ImFVuentw0><=o}qx+r2RPVp{N)87CP*R|(93lVaC}hR_pTKg{fnCH>DIwK@Xxfc_Ee{GO2n?@W^dp{C!~#;;^?NX>&$=r z4-I+Vz#kq|T&MTqHl7z$irC-p#p&F(8dRT5Kf;txunPA;M zn!V5>|3b_6ZJ_%OXmzO?uJs%-GP^ydB_GP9f+dkE`Z8dQxH3&*-sw zTg`(0C-d%XTIE19^3APE0mc9BgEDLV?d-9Jlbbe*^_th^W3xV^ldr0$XPl7v-yG?K zavtnOhr?#qElW-By-^QE9r4WXRJ83-fB+C>QG_{+P?fpd_Eg4+Y9^Njk->Lavo#z> z^3ltl0k$-#irZvzk%@qKyB%-)v`k|zmB&;9sOVJ!<=p(zapw`u@`gCTohAE$x}qui zCm$0HDH`a{uSZdo6c^?X^aX_tl@=b$!zR28p{U-kbEM4cNeGA2_@GFO(23O9wSIp7 z+%&+H--opV?L|= zit+lp3*+Wr#Nr_+e@3p(vk1m62yI=WV|r>Rg}l_G>u^A1=za$~o5*|6{-}#G1Z;Hk zsV?5Nqw&;wh5Dwy@z#PZaQWBHVQPAK)m}PTh&=Je^oTP#WO#`Ggp=__FMDG807K>6 z%WgUe-?R>0{wv^IbNf`;o7J*&?birV-Oaj|*)YGb-0+=e6hQ<>pYc0(SUASE%USAU zN}<3MXcX3Ok1o{Vocg1XQ}Ta;`XpHOWce4rf8ii9Qjv>46>p+4=Vrgj`?~soC_*s< zG2Gi3ujh5@G>_aOIFQVlF6@h0%)wy(*We*oAgi)QF|CjVuVH~179khGZoWJX6;yAT zahP*;t94Z3IQCP3W%CBI{x~#z7Fs(jgf)M@MLB>hb$tNJ-QL|c)9Yf=pIU*wB>?4g z*bMhZ$?8GumFlK9k{NZqF1P0l$w7)=KR*ydWFV$A?}VaK{B$~A%5voP(zzfMirOCr zK{k=@0(Vb|A4@?C+Y*E~!JpJ*(UxgO-AnDeyGD4-+JG5IB6gulUSO+3~^fdyYUQ{QL@STJxX_xyhVXKoq-7AElMHi5#0i6t-Q*E3X$X==FPMMx)&fDb^GqEbi z_YAJhy&C=i?wh4s>2^J^YO7SuaDY~y6$jB1<-qCpf&CMU6!#6+c~KC^|H^Ky;M2_% zBPC*+tD+9K=eYG@My^GsTTc0Mq3a5iT*qsb!90B{TnSQyT7de?Lo0FRQ7C=p#7m>-kE(rLhb2Pj+wu|Fci9q1^ z?%?@|8x*#X2|kk4e0_%s(*nInL5pM%@&O}TtHn{p-5s|FcxvjlCf@BP$m4b+q3j?y z)*-0@cSK$KB?-#-tJB=#+Q!HfidbIM1rJxJ^hRjYXnM_7K?OCUgv4;!DY^ilxY4Vy zFgEzbj?0s_T)WQO79}o2XwWw1OX-_U1c|6+esVjuQ#C6a>hGN1t63QFLP^PI2ryfT z(ArIDD>~opuHRX0q@&F2$J}!#4S~Njp(K6-+Y471AHoC~ z`=UcBB>Ran=?MBHJr}W|?*4uu%Z-Zb_a7^{{b9QnO~mi{e0xNqqhM=mYiM`^*XmNX z2e^+Xn(=#t{{<%R<2~FUSj~{3T{G^lMA<1G8yOlIrH8<2X(NGZb4?Ajw}vpdlY-N$ zh~;VbySHsaI$fcOO_tU9mEE`9<>p+`WKTj@JaSf^PJW8QIR^54hT~MlSGIT~fdl!c zF!1s5k+INJx|IBwkUPbQg^WbA?j>1Pw3e8(dWQJxW7DmaHXvAf!S}ET!Nw_p-X(?` zCdCtQycgzs-^K_kN)%xAC&#LQ0u;$2^uc4`jmwj}UMF^p)Yk@%AC1YZ=jEX{50&laz;<_IlF|+S zfo#|`#u+uU)8YwBcLDOI|H)t7U4N*)f4;6;qEDr1<(J~JJ_9W~6z##T@K|@V4rTN~ zsv%$lV$$PvtxZLYnQ=(GmdZjv(QZ~HJ@$eBepTN9R1`Q$Wfn&NoblX0U>R9saDNZM z$2`>vBq0h}`&{qX@&YNA^Ele0uIl1YW=L6hL$?)cx(4|pAKt#S`>)}1Tr783>Xm{> zW)6)mPI@waN@!GjotUj4$bvSDqB z?-cx}N9z*=5c2XrA8f}FH@zz1O_Dd1iu56!ePVN3TOl4MI>G+Ndhgpn%KI4i!REUV zHO?x-7x$fcdBHbR<0f)8bWVYo<>FfUkM=(2)-^O?QXqW{8}(W!*4B04o;jf zSL!s3v}O4VCxXwH&`}b~DHBzc8^g-IQQ%ElFv80=F&;i-a?vsaSzcb+r!}NI)t|_& z{Cw+Fg@MFkQ2LuF0l|LCZErbhPHZ-kR{it7EFDAj+2oK-sH&j9O0f7N%`WOj)lT6~ zg5IOP3G&&s7?rvcmWrPK_g2u-k0`qiptgbOYfwWdA&bA-7R(9il@hebzUsBx4U;EBQ7W^$j zut`v6Ip)re)!i}UFYvS!D!#a$9c7SL;fL=I>1?z7<-+L_npVd9UBJj&i;rb1>MOxq z07Y^acZew8Q%C9EnqG8U6SvW!U^|ytE91NL1hyY^_ zX%LV@7bx82v``6jb&+HN#g!BT+zB08;`A(|>DfA^uBfVN%Z7K=NEFZvLyc{U8-fOm zvxn);*Ei48=Rl6o$J<*wgI9u((-xkTV8DVc-SwfNDEXT&UaKO!;{sVHz0KA? z-kcOaIyAubvAOU+T5|qfJttf{rvc11Tt54eQ|bmRX|favOV;l}X)+WkBY-zbWD5%i zf2Hu7u_z~yfCuMZ9o@HGud^a=?um4oTedFsFRbIZl2bwSjOgc(@p9*mSCSMKI{Mb$ zUY`TONbU5gAKwIG0MNxLF5b7~bP!Fz|7@QVx_jNvy(bW`3gn5h{~Hn6nEoL$bw#-G zw#w1s2d8tF(!0$Hhg#%wd$+8~fBhv(3XV3n&tVCDMDghn%h8+zHB{#4e;8AA6r#M+7yOZ(2!n(?JX(N_C%7v2 zpNhDml}o?x?d=6^^4-C2Yc$J!{e5XVwxa@*>#{P=-+JNU_I!;hXp7F`kqXT*d! zf?gWVW+?3}Sd4~(++pE^2fDNxOb7l(^pRCd*{I*Z<)kf6JY2^AmloV++JYcLT`||E zpXL~*gur!05#Ww{esoBIc>c23^S2m-7iAxTBV#P3Q|G0R)MVltt6A6EaBrT@_6rvX zG|!oLfWbJLdiM;WxSP>?u^lQ2ji_+QFju8S@wOcv!FVrm;N9gsKCEmqC(5Il+~|4V z))qM=53!r4op?|p)L{4Pi<`!S7F^k%b9X;$P_y`Xb=u0guIh|!!jfhJA{h?GZek090Y<1W|d@O|7w&t&9E!n)RBJqY9-Jv*RW#P zne94M{>`$?&Y#FQ`De{ZEn^Q8-H4%kBuREio3r)!w>I;4Hs3*T{TW(&TQP5T7HtJy zO?E4-r%865_?O3JqWMeZcG&GrSw{k<(~IVU&9zonwXbr+g_s1!eAGpoYi}(_J?Wb4 zl9+GD=_XEf9&)IR4!XPsAK=?{7J>-LHR_|fw_nNN(1s(JIudlnmk5cf0MF1g{{ zhyyPNg&3X2hom|GtZan(^KnTa@;2J7@2r&m3>j)uRV|vWEywsO_nj(gA^NTQzKyTP zA4l^yJg5LkL1eu~Fj^PIrbHg^(I1krvaZpKbQG7HlysoW!0dcxyU@`6?FQb((H*&A zBw*zWoZWKcc7hF-PQff2H~>?U_00y{pwLQ=a44rV!Q*xWYC|2q87XEq#OdaN7I74mNm0A@ z>*p)^o)8&a`=jyJHND>G20h4M8w(TXSQOx3AFMtdxY^I-b9#W%{G6|UeJXes13YX0 z1__M}wO+0Er8{XCAdgGD8}NUAlk@OpuhRF2R%qRX#q9K0{UY3r3#1VAGJ0B$8o9p# zWyUmq8!<PcqepDNUxs>#m-k&^X6|3M2jd7mkG$@&>-RytKDK zAU$G422IPCvjtBUNv8niX~TRVYCQ_W7dT`5+-RLp_3YP)94*M;AT5r+;*nO7fS`eT z`L^7wOzB{)b%`7yP;c-sD@;0|JBz)iL~K~sA2emJF7`)C zg>k~v?08YI!Qvhs9z{h(|EYo(Cf3reOjcM)!U$KphLHvR`u^MB-yh^B7%ZaLmRPE; zs+ydk=l=S92dLmur6lmvElI=e zN9HkaZz)JkWbx{0YU2G~;Iv!UK031jt5_V)volQ>{U}tFve5AG(ACuifS+bjbaeFZ zqZfs%@5_R)!LUDmEa&FtPEIOV+;q?x($2mk6|238!sldRVTFEq#n{f6+Zb&0!x`UF zg}D-FcgF|*O1SOghwrKVN2X31@$vB?CnLK*U&H@}e0y`}a!pv$ z^7N!uSC_$QXUmZhB~d^Xu0MqaTHTRIuH^m<0#s&3#;Ri3jN+0KIH0%o{rg!#D}&cI z`?+lLFv^6K6k;5l0Vbr5l$%}`As+63Y`Xx@cXGM`HpnKtpqV~da720^IAjb6^a#kv zDpZ&R1K$=19-1S*0EU%HZue|XyeQ!6OB67(u&{ua?}YsP^tF@4_CY$4Y#*tL066sa z_NH_=KRIRr1BmF7`udxDBPm5AHlb~6RJ1de4Om!vvKbtTG)Z&A_I|AVgdwCzKy9tyM+Pkzc0NioN;@K&*;RrMPO5at+EhLHU6I?EI9tvQ7>5?+6A|P= z)RPnTYo?4TM~0Q;1z>9t#uQUD#&vwiRB!rQO;_~2aMqe*ndPe$`zAV%8&Of!u zX_=LHh{8{xtsoube{_wC_-6O?RQT-%GNZDf@T6+tKWcM`o4JDJG$2_J*h;M-EG_4K zHGHyRYLW1a;@9c%D}|f!W_L*BNAr@BQkO+janFgmePEG)?{-g)Tn@PBZu0(BLN@$^ zu`~nG%Uebar0Js9Z(siSZB`@p=b>GH5ryB~FnOZkBRQv&+{z=>`?O%I> zI5=9#_jCDnb!4IA8LVXU(llM7O`#vK#E12sY~N1w2!~jqsGRA&qSCl(eMsO)cHbJk zrw{5%8uRSBRU!0u@uHU=9+wwiEc;Bjctau8b$>Cc6MTmAT9E` zM?y``MHDc$L;c7ft&)p;fbD61kL-q$HD{P*fAH1+ejH-K+X-&le5;&ZmFO=g-q5*J z^ju|i(vw0q=?h6fR3-~$vZv!tKT1PD@6BHe35_2 zY_Mc5`5qZomX-;^`unMl$}qAVqh=1fKWnJbJjLecFpuvVEt)%Gz-x9~VvrtM5bpZc75_ZyXj#`U@_uN6`eW6Ftw7%V*osLru^w9I!I{YspV5llOLqvVIxzK=jqO22+A!d zE=}`62yG%@J@aNV*xyZi!gV-)qjTM7Nd2rRoc2hK#Pm<~c}03ius9q0uRrVkjq)bT zrtga{AE!#K?PTauGmiY$P zmB~;IK?jX)TjdjfI4#U${wyp^=zT^xTBq};AETWqaSoHjn@HrHm3 zd@)!fio7C~@*^JPt-Tn8COt!1KY!ew<99j@snf)1*W|nMp1Ad}GJUytA@7JUcumV6 z?P+UzbySSIewjJ*`GGLM!LJCK^O2u;aT|irYc(_Nj#>C1U-PbOerUp7`im)YXxPhI znhDV=rx0C8x>zxo=7kztuzfUG81^Z8=Py$bWA(r^A%^7bA+r^VFPPIM4Fa{$G^ee@ z{T@u!WX%L6Dv96tjXevFg){m+KAuHkV*aI;|MEH13geC4>i5Ng-o?x58T~(AiD>!H zZV{@rt>XpHr+SSy5m{$iG0`r8I$`zN;lN@DG?`(-SVU@w9^wiuJs-g$rrT&goK5I4 zEE&F2Es{TE*}vQB*iKCHvjs_01S6nLKDDGw$YwQoPR$2#zUQ=nCk1xVgy(Y+_?9hd z$$5P=QvzFRoqgb;iw5JQLUj5j^r{s@a`zQ2NbrI9aJd1op}c?hnFqe7nr`H~uOd}Z z{vSlLFLVRUNm|q(tkHHMD0tcg=KLi(NqPe=Zn*ZJI8goo^{h=&-U@F|!?9?H`o8-# zTtP6xEXJ1Mp$7T$y>hPi?fRsOdgzRhQTGc%o9}YjjAayskt6uN(&kTv5N@(b1*HZi ztZ;Q?FlD4nKa?Gdmfv?=)&3e1b@|sUG0da9E|j6Y@RyetB2;JC;``6{%PuEa*v2Y= zl()kby`!F7QECPoG89(wmkDX&28r}MeCHQQ7z#x}Vf)gqx!t;Py$4Nd)Vyfvp9qmV zi&+9&7@Ab^gB!hh45`1y98TJ@J9dEUgc=K0G5uq&j%+C`&E>cpG?q;NZ^jSpLvLd1 zr0(l<2xL7>>^Ul0);gMjrda?C0q%A90SAhNA!*W*M5W`~cR&+}bd%BWO~Ya84j1); zAxFmUb;xi(2X+{nRw)$%OWG+m%KsC22!{8ogOMFC&V(*TJQJ2>d7h^VdF50OmFwgo z_7GAz{u%^cs9}w53cztJ6{#qSydcQ&tkwh}gz`KuiXu?pIF8nBr98=~wHnz$&x#t3 zL6C;U-_I{MH&3PVA%sv0gfz^ZC(p<7^(TaooZK9R!fDJ)fCL5v78Vr&rI{I-TCG;0 zkV~uNF$}}99OH_$;2JNYNCklxMd^O0P*Gvb&CLS>yuf>TDM+0spRbFNtM{xx7b6}E z!!SWXy5D}^7ZzsVSQdy#Y2_d~jOQw`>VXhK2tycN5Yp1plaksvOA1p0VTRC?r%nY0 z>GJana`W;DA)+V{%Ws`j(w%z?o&=?$^(0VA8HS~l5&)KCFI~#&)UgAtyN~N&WT&_C z?2kl{hJ_HKP$&!r{mz}cLPA1eqz6`@KEWQ#McXn?=Jvok{ojjWHsiIE-L%0m|;9t$Ca<2a2* z)9${uk}Oae4k0$lqauztcURwO{6?k=_-TdR?) z-^#1DA4(bVKpL)Z>|G6EtoFsPy)E@W8@9iW)wbB~!_@3z)G>k}Nd2jcks15FtxwU# z2!bH>$JVYj7@2Xn)p`IL89@-Fo>VicGb1yAE=CXpaVNwA)M#YJ*}Xe7GJ+t8tFSk+ z{R75+lkG96V+28vdSYu-d(B$+VQO|U>KH)~q@FnRs=bk`-^xQ5BM5@H7HM2xtwyeL zE6?HH4fhrh1VQcw2qASbGULp}7$74Eg17|9rB)+X6Rh46{!f*^>Z zD6QgWT}X;jDm|7SNUN`lq6h%g2HU4n)%J7OR(r|*F@hjSt=PttwyvwTv6=?$!&9(H z8%PhT&G#?CaU8=iEX%Si%W<4cCgV7c<2ZXG+xE4P>f)-Yx|)k^Yqcz8$l5xQWm((i zQc9)A(gR7j48zc>fQ^5hiP)ie?Kh&J5d^Vfe?jl?62F>)ZMWFIWFO4ds$;8*C2Y6X zU}Oo-wpPiT)?;iRSF5br8>^;c$>~xF))*P8M#T1BhB`#Y_Mnat1hL{!zV@#=6froG za<#|y0dh4RJ9DvpbX%=Ju&xGD&Bc;TrGKq;h@vQk#?=gHYj@iNr5uG-$I?;KMnD}S z2;v4@t7EV%J!2csf+cHVpFFVDvGuX^pqi2G%}(r-71oy>x)>}PwS8BDAV~XLvBt$< zqhqj(j=@IC5)RW8m^(%gb*Mvu)3I1YM-N!{+0HZ4y@LdqFT2K`+TvjjvZzsP{#;@+#dDR zG1yHEUoASe7jZQy+nV>5j7)5k71kKp>SF1s)x}ovRSSx#rE{BY&o*iY*!j1PadFMU zMI9puV#T3+oxNH^jBIabVuyXog4o>Fvk#DKH8NL&ivggTi*4H>bu_kSCmiY+oOCyq z3a2$DE1W&82I?3=5G%K#W825XQL+N;vK9_?TrEJp4I^__x7teCw#D`?CYA&RW4VJz zs}A~b78-+d9oufPe_ZoM1VIpII25$Kh;1J`)G^c+Ad{*|WM?{dXk_Ww%G@#IXy!Iz z=}KI!9Zc1J6tvFy;u>6h+tD$CAV?jlH9Cem1ju0LW%~?r%|@;kL_3I%9U7TZ%GwP2 zkam`aM^i`Rp&bIwLu0_`7(ozsavRYx+)99KFJchnrmMM_VVKHMc@B+i|4Sm} zi;2zcyP91LPKJ9pduj{n7(tNwQ>%`vZLyDzp{k3)xs>Z-WY%u9p7p@WWCb`evTa)> z5tFKkW68GFj0{yRT!W6G-Vreh8bJ^%4&__(tF=bQ;6%qz)yp;Hk=d%lLmaxeO0ohh zMkZAk0kQR+ZN>H$t~T5Q>|9*)1HgzFK@fLx+d2m40W#PP4`J*&z}aUfs=1rkCo8}* zK-*!MY+IQmVy5aCJjT*7!(l{R&C4}BcDBVKC~E{ktkfJG*RY#IDT7^f3{|~+8!@tN zP+Vqd4cWruNeWpqp}GqhQ& zw5pjn$|K*Ziyel;br&%z7(o!1P=lJCN!dPFu1}0yZM!W1P?@ZtmQ_5Y;1>X_(XnmT zLfTEr7emzn&<=GBHD)U8pVqL^87ON6L9Emo3)i}H&0e;D>QKjEiDeyz$+l9qE$U|O z*gi%EyE}W5ZSA9DsB@0O-k#2Uik?Lf#7#J}w*B^6bqu%OAGw;itq1-;2IHaZWTq

Pre-requisites

To use Intel(R) Software Guard Extensions Eclipse Plug-in, install the following softwares:

*/ #define SQLITE_FCNTL_LOCKSTATE 1 @@ -2118,6 +2128,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 +#define SQLITE_FCNTL_LOCK_TIMEOUT 34 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE @@ -2155,12 +2166,18 @@ typedef struct sqlite3_api_routines sqlite3_api_routines; ** in the name of the object stands for "virtual file system". See ** the [VFS | VFS documentation] for further information. ** -** The value of the iVersion field is initially 1 but may be larger in -** future versions of SQLite. Additional fields may be appended to this -** object when the iVersion value is increased. Note that the structure -** of the sqlite3_vfs object changes in the transaction between -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not -** modified. +** The VFS interface is sometimes extended by adding new methods onto +** the end. Each time such an extension occurs, the iVersion field +** is incremented. The iVersion value started out as 1 in +** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 +** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased +** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields +** may be appended to the sqlite3_vfs object and the iVersion value +** may increase again in future versions of SQLite. +** Note that the structure +** of the sqlite3_vfs object changes in the transition from +** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] +** and yet the iVersion field was not modified. ** ** The szOsFile field is the size of the subclassed [sqlite3_file] ** structure used by this VFS. mxPathname is the maximum length of @@ -3068,8 +3085,9 @@ struct sqlite3_mem_methods { ** connections at all to the database. If so, it performs a checkpoint ** operation before closing the connection. This option may be used to ** override this behaviour. The first parameter passed to this operation -** is an integer - non-zero to disable checkpoints-on-close, or zero (the -** default) to enable them. The second parameter is a pointer to an integer +** is an integer - positive to disable checkpoints-on-close, or zero (the +** default) to enable them, and negative to leave the setting unchanged. +** The second parameter is a pointer to an integer ** into which is written 0 or 1 to indicate whether checkpoints-on-close ** have been disabled - 0 if they are not disabled, 1 if they are. ** @@ -3083,8 +3101,24 @@ struct sqlite3_mem_methods { ** slower. But the QPSG has the advantage of more predictable behavior. With ** the QPSG active, SQLite will always use the same query plan in the field as ** was used during testing in the lab. +** The first argument to this setting is an integer which is 0 to disable +** the QPSG, positive to enable QPSG, or negative to leave the setting +** unchanged. The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether the QPSG is disabled or enabled +** following this call. ** ** +**
SQLITE_DBCONFIG_TRIGGER_EQP
+**
By default, the output of EXPLAIN QUERY PLAN commands does not +** include output for any operations performed by trigger programs. This +** option is used to set or clear (the default) a flag that governs this +** behavior. The first parameter passed to this operation is an integer - +** positive to enable output for trigger programs, or zero to disable it, +** or negative to leave the setting unchanged. +** The second parameter is a pointer to an integer into which is written +** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if +** it is not disabled, 1 if it is. +**
** */ #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ @@ -3095,7 +3129,8 @@ struct sqlite3_mem_methods { #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ - +#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ +#define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */ /* ** CAPI3REF: Enable Or Disable Extended Result Codes @@ -3501,16 +3536,16 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** These routines are work-alikes of the "printf()" family of functions ** from the standard C library. -** These routines understand most of the common K&R formatting options, -** plus some additional non-standard formats, detailed below. -** Note that some of the more obscure formatting options from recent -** C-library standards are omitted from this implementation. +** These routines understand most of the common formatting options from +** the standard library printf() +** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). +** See the [built-in printf()] documentation for details. ** ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their -** results into memory obtained from [sqlite3_malloc()]. +** results into memory obtained from [sqlite3_malloc64()]. ** The strings returned by these two routines should be ** released by [sqlite3_free()]. ^Both routines return a -** NULL pointer if [sqlite3_malloc()] is unable to allocate enough +** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough ** memory to hold the resulting string. ** ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from @@ -3534,71 +3569,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). ** -** These routines all implement some additional formatting -** options that are useful for constructing SQL statements. -** All of the usual printf() formatting options apply. In addition, there -** is are "%q", "%Q", "%w" and "%z" options. -** -** ^(The %q option works like %s in that it substitutes a nul-terminated -** string from the argument list. But %q also doubles every '\'' character. -** %q is designed for use inside a string literal.)^ By doubling each '\'' -** character it escapes that character and allows it to be inserted into -** the string. -** -** For example, assume the string variable zText contains text as follows: -** -**
-**  char *zText = "It's a happy day!";
-** 
-** -** One can use this text in an SQL statement as follows: -** -**
-**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
-**  sqlite3_exec(db, zSQL, 0, 0, 0);
-**  sqlite3_free(zSQL);
-** 
-** -** Because the %q format string is used, the '\'' character in zText -** is escaped and the SQL generated is as follows: -** -**
-**  INSERT INTO table1 VALUES('It''s a happy day!')
-** 
-** -** This is correct. Had we used %s instead of %q, the generated SQL -** would have looked like this: -** -**
-**  INSERT INTO table1 VALUES('It's a happy day!');
-** 
-** -** This second example is an SQL syntax error. As a general rule you should -** always use %q instead of %s when inserting text into a string literal. -** -** ^(The %Q option works like %q except it also adds single quotes around -** the outside of the total string. Additionally, if the parameter in the -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without -** single quotes).)^ So, for example, one could say: -** -**
-**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
-**  sqlite3_exec(db, zSQL, 0, 0, 0);
-**  sqlite3_free(zSQL);
-** 
-** -** The code above will render a correct SQL statement in the zSQL -** variable even if the zText variable is a NULL pointer. -** -** ^(The "%w" formatting option is like "%q" except that it expects to -** be contained within double-quotes instead of single quotes, and it -** escapes the double-quote character instead of the single-quote -** character.)^ The "%w" formatting option is intended for safely inserting -** table and column names into a constructed SQL statement. -** -** ^(The "%z" formatting option works like "%s" but with the -** addition that after the string has been read and copied into -** the result, [sqlite3_free()] is called on the input string.)^ +** See also: [built-in printf()], [printf() SQL function] */ SQLITE_API char *sqlite3_mprintf(const char*,...); SQLITE_API char *sqlite3_vmprintf(const char*, va_list); @@ -3956,8 +3927,8 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, ** KEYWORDS: SQLITE_TRACE ** ** These constants identify classes of events that can be monitored -** using the [sqlite3_trace_v2()] tracing logic. The third argument -** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of +** using the [sqlite3_trace_v2()] tracing logic. The M argument +** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of ** the following constants. ^The first argument to the trace callback ** is one of the following constants. ** @@ -4664,13 +4635,13 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** or [GLOB] operator or if the parameter is compared to an indexed column ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. ** +** ** **

^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having ** the extra prepFlags parameter, which is a bit array consisting of zero or ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The ** sqlite3_prepare_v2() interface works exactly the same as ** sqlite3_prepare_v3() with a zero prepFlags parameter. -** */ SQLITE_API int sqlite3_prepare( sqlite3 *db, /* Database handle */ @@ -5803,6 +5774,9 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** datatype of the value ** sqlite3_value_numeric_type   ** →  Best numeric datatype of the value +** sqlite3_value_nochange   +** →  True if the column is unchanged in an UPDATE +** against a virtual table. ** ** ** Details: @@ -5851,6 +5825,19 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** then the conversion is performed. Otherwise no conversion occurs. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ ** +** ^Within the [xUpdate] method of a [virtual table], the +** sqlite3_value_nochange(X) interface returns true if and only if +** the column corresponding to X is unchanged by the UPDATE operation +** that the xUpdate method call was invoked to implement and if +** and the prior [xColumn] method call that was invoked to extracted +** the value for that column returned without setting a result (probably +** because it queried [sqlite3_vtab_nochange()] and found that the column +** was unchanging). ^Within an [xUpdate] method, any value for which +** sqlite3_value_nochange(X) is true will in all other respects appear +** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other +** than within an [xUpdate] method call for an UPDATE statement, then +** the return value is arbitrary and meaningless. +** ** Please pay particular attention to the fact that the pointer returned ** from [sqlite3_value_blob()], [sqlite3_value_text()], or ** [sqlite3_value_text16()] can be invalidated by a subsequent call to @@ -5873,6 +5860,7 @@ SQLITE_API int sqlite3_value_bytes(sqlite3_value*); SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); SQLITE_API int sqlite3_value_type(sqlite3_value*); SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); +SQLITE_API int sqlite3_value_nochange(sqlite3_value*); /* ** CAPI3REF: Finding The Subtype Of SQL Values @@ -7975,9 +7963,9 @@ SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); ** the xFileControl method. ^The return value of the xFileControl ** method becomes the return value of this routine. ** -** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes +** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes ** a pointer to the underlying [sqlite3_file] object to be written into -** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER +** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER] ** case is a short-circuit path which does not actually invoke the ** underlying sqlite3_io_methods.xFileControl method. ** @@ -7989,7 +7977,7 @@ SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); ** an incorrect zDbName and an SQLITE_ERROR return from the underlying ** xFileControl method. ** -** See also: [SQLITE_FCNTL_LOCKSTATE] +** See also: [file control opcodes] */ SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); @@ -8046,7 +8034,8 @@ SQLITE_API int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_ISINIT 23 #define SQLITE_TESTCTRL_SORTER_MMAP 24 #define SQLITE_TESTCTRL_IMPOSTER 25 -#define SQLITE_TESTCTRL_LAST 25 +#define SQLITE_TESTCTRL_PARSER_COVERAGE 26 +#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */ /* ** CAPI3REF: SQLite Runtime Status @@ -8281,6 +8270,15 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. ** ** +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(

SQLITE_DBSTATUS_CACHE_SPILL
+**
This parameter returns the number of dirty cache entries that have +** been written to disk in the middle of a transaction due to the page +** cache overflowing. Transactions are more efficient if they are written +** to disk all at once. When pages spill mid-transaction, that introduces +** additional overhead. This parameter can be used help identify +** inefficiencies that can be resolve by increasing the cache size. +**
+** ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(
SQLITE_DBSTATUS_DEFERRED_FKS
**
This parameter returns zero for the current value if and only if ** all foreign key constraints (deferred or immediate) have been @@ -8300,7 +8298,8 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r #define SQLITE_DBSTATUS_CACHE_WRITE 9 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 -#define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */ +#define SQLITE_DBSTATUS_CACHE_SPILL 12 +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ /* @@ -9300,6 +9299,40 @@ SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); */ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); +/* +** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE +** +** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn] +** method of a [virtual table], then it returns true if and only if the +** column is being fetched as part of an UPDATE operation during which the +** column value will not change. Applications might use this to substitute +** a lighter-weight value to return that the corresponding [xUpdate] method +** understands as a "no-change" value. +** +** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that +** the column is not changed by the UPDATE statement, they the xColumn +** method can optionally return without setting a result, without calling +** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces]. +** In that case, [sqlite3_value_nochange(X)] will return true for the +** same column in the [xUpdate] method. +*/ +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); + +/* +** CAPI3REF: Determine The Collation For a Virtual Table Constraint +** +** This function may only be called from within a call to the [xBestIndex] +** method of a [virtual table]. +** +** The first argument must be the sqlite3_index_info object that is the +** first parameter to the xBestIndex() method. The second argument must be +** an index into the aConstraint[] array belonging to the sqlite3_index_info +** structure passed to xBestIndex. This function returns a pointer to a buffer +** containing the name of the collation sequence for the corresponding +** constraint. +*/ +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); + /* ** CAPI3REF: Conflict resolution modes ** KEYWORDS: {conflict resolution mode} @@ -9746,6 +9779,128 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( */ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); +/* +** CAPI3REF: Serialize a database +** +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory +** that is a serialization of the S database on [database connection] D. +** If P is not a NULL pointer, then the size of the database in bytes +** is written into *P. +** +** For an ordinary on-disk database file, the serialization is just a +** copy of the disk file. For an in-memory database or a "TEMP" database, +** the serialization is the same sequence of bytes which would be written +** to disk if that database where backed up to disk. +** +** The usual case is that sqlite3_serialize() copies the serialization of +** the database into memory obtained from [sqlite3_malloc64()] and returns +** a pointer to that memory. The caller is responsible for freeing the +** returned value to avoid a memory leak. However, if the F argument +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations +** are made, and the sqlite3_serialize() function will return a pointer +** to the contiguous memory representation of the database that SQLite +** is currently using for that database, or NULL if the no such contiguous +** memory representation of the database exists. A contiguous memory +** representation of the database will usually only exist if there has +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same +** values of D and S. +** The size of the database is written into *P even if the +** SQLITE_SERIALIZE_NOCOPY bit is set but no contigious copy +** of the database exists. +** +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory +** allocation error occurs. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_serialize +** +** Zero or more of the following constants can be OR-ed together for +** the F argument to [sqlite3_serialize(D,S,P,F)]. +** +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return +** a pointer to contiguous in-memory database that it is currently using, +** without making a copy of the database. If SQLite is not currently using +** a contiguous in-memory database, then this option causes +** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be +** using a contiguous in-memory database if it has been initialized by a +** prior call to [sqlite3_deserialize()]. +*/ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + +/* +** CAPI3REF: Deserialize a database +** +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the +** [database connection] D to disconnect from database S and then +** reopen S as an in-memory database based on the serialization contained +** in P. The serialized database P is N bytes in size. M is the size of +** the buffer P, which might be larger than N. If M is larger than N, and +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is +** permitted to add content to the in-memory database as long as the total +** size does not exceed M bytes. +** +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will +** invoke sqlite3_free() on the serialization buffer when the database +** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then +** SQLite will try to increase the buffer size using sqlite3_realloc64() +** if writes on the database cause it to grow larger than M bytes. +** +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the +** database is currently in a read transaction or is involved in a backup +** operation. +** +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then +** [sqlite3_free()] is invoked on argument P prior to returning. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_deserialize() +** +** The following are allowed values for 6th argument (the F argument) to +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. +** +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization +** in the P argument is held in memory obtained from [sqlite3_malloc64()] +** and that SQLite should take ownership of this memory and automatically +** free it when it has finished using it. Without this flag, the caller +** is resposible for freeing any dynamically allocated memory. +** +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to +** grow the size of the database using calls to [sqlite3_realloc64()]. This +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. +** Without this flag, the deserialized database cannot increase in size beyond +** the number of bytes specified by the M parameter. +** +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database +** should be treated as read-only. +*/ +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ +#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ +#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ + /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. @@ -9893,16 +10048,23 @@ extern "C" { /* ** CAPI3REF: Session Object Handle +** +** An instance of this object is a [session] that can be used to +** record changes to a database. */ typedef struct sqlite3_session sqlite3_session; /* ** CAPI3REF: Changeset Iterator Handle +** +** An instance of this object acts as a cursor for iterating +** over the elements of a [changeset] or [patchset]. */ typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; /* ** CAPI3REF: Create A New Session Object +** CONSTRUCTOR: sqlite3_session ** ** Create a new session object attached to database handle db. If successful, ** a pointer to the new object is written to *ppSession and SQLITE_OK is @@ -9939,6 +10101,7 @@ SQLITE_API int sqlite3session_create( /* ** CAPI3REF: Delete A Session Object +** DESTRUCTOR: sqlite3_session ** ** Delete a session object previously allocated using ** [sqlite3session_create()]. Once a session object has been deleted, the @@ -9954,6 +10117,7 @@ SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); /* ** CAPI3REF: Enable Or Disable A Session Object +** METHOD: sqlite3_session ** ** Enable or disable the recording of changes by a session object. When ** enabled, a session object records changes made to the database. When @@ -9973,6 +10137,7 @@ SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); /* ** CAPI3REF: Set Or Clear the Indirect Change Flag +** METHOD: sqlite3_session ** ** Each change recorded by a session object is marked as either direct or ** indirect. A change is marked as indirect if either: @@ -10002,6 +10167,7 @@ SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect) /* ** CAPI3REF: Attach A Table To A Session Object +** METHOD: sqlite3_session ** ** If argument zTab is not NULL, then it is the name of a table to attach ** to the session object passed as the first argument. All subsequent changes @@ -10027,6 +10193,35 @@ SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect) ** ** SQLITE_OK is returned if the call completes without error. Or, if an error ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned. +** +**

Special sqlite_stat1 Handling

+** +** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to +** some of the rules above. In SQLite, the schema of sqlite_stat1 is: +**
+**        CREATE TABLE sqlite_stat1(tbl,idx,stat)  
+**  
+** +** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are +** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes +** are recorded for rows for which (idx IS NULL) is true. However, for such +** rows a zero-length blob (SQL value X'') is stored in the changeset or +** patchset instead of a NULL value. This allows such changesets to be +** manipulated by legacy implementations of sqlite3changeset_invert(), +** concat() and similar. +** +** The sqlite3changeset_apply() function automatically converts the +** zero-length blob back to a NULL value when updating the sqlite_stat1 +** table. However, if the application calls sqlite3changeset_new(), +** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset +** iterator directly (including on a changeset iterator passed to a +** conflict-handler callback) then the X'' value is returned. The application +** must translate X'' to NULL itself if required. +** +** Legacy (older than 3.22.0) versions of the sessions module cannot capture +** changes made to the sqlite_stat1 table. Legacy versions of the +** sqlite3changeset_apply() function silently ignore any modifications to the +** sqlite_stat1 table that are part of a changeset or patchset. */ SQLITE_API int sqlite3session_attach( sqlite3_session *pSession, /* Session object */ @@ -10035,6 +10230,7 @@ SQLITE_API int sqlite3session_attach( /* ** CAPI3REF: Set a table filter on a Session Object. +** METHOD: sqlite3_session ** ** The second argument (xFilter) is the "filter callback". For changes to rows ** in tables that are not attached to the Session object, the filter is called @@ -10053,6 +10249,7 @@ SQLITE_API void sqlite3session_table_filter( /* ** CAPI3REF: Generate A Changeset From A Session Object +** METHOD: sqlite3_session ** ** Obtain a changeset containing changes to the tables attached to the ** session object passed as the first argument. If successful, @@ -10162,7 +10359,8 @@ SQLITE_API int sqlite3session_changeset( ); /* -** CAPI3REF: Load The Difference Between Tables Into A Session +** CAPI3REF: Load The Difference Between Tables Into A Session +** METHOD: sqlite3_session ** ** If it is not already attached to the session object passed as the first ** argument, this function attaches table zTbl in the same manner as the @@ -10227,6 +10425,7 @@ SQLITE_API int sqlite3session_diff( /* ** CAPI3REF: Generate A Patchset From A Session Object +** METHOD: sqlite3_session ** ** The differences between a patchset and a changeset are that: ** @@ -10278,6 +10477,7 @@ SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); /* ** CAPI3REF: Create An Iterator To Traverse A Changeset +** CONSTRUCTOR: sqlite3_changeset_iter ** ** Create an iterator used to iterate through the contents of a changeset. ** If successful, *pp is set to point to the iterator handle and SQLITE_OK @@ -10318,6 +10518,7 @@ SQLITE_API int sqlite3changeset_start( /* ** CAPI3REF: Advance A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function may only be used with iterators created by function ** [sqlite3changeset_start()]. If it is called on an iterator passed to @@ -10342,6 +10543,7 @@ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); /* ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -10376,6 +10578,7 @@ SQLITE_API int sqlite3changeset_op( /* ** CAPI3REF: Obtain The Primary Key Definition Of A Table +** METHOD: sqlite3_changeset_iter ** ** For each modified table, a changeset includes the following: ** @@ -10407,6 +10610,7 @@ SQLITE_API int sqlite3changeset_pk( /* ** CAPI3REF: Obtain old.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -10437,6 +10641,7 @@ SQLITE_API int sqlite3changeset_old( /* ** CAPI3REF: Obtain new.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -10470,6 +10675,7 @@ SQLITE_API int sqlite3changeset_new( /* ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function should only be used with iterator objects passed to a ** conflict-handler callback by [sqlite3changeset_apply()] with either @@ -10497,6 +10703,7 @@ SQLITE_API int sqlite3changeset_conflict( /* ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations +** METHOD: sqlite3_changeset_iter ** ** This function may only be called with an iterator passed to an ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case @@ -10513,6 +10720,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts( /* ** CAPI3REF: Finalize A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function is used to finalize an iterator allocated with ** [sqlite3changeset_start()]. @@ -10529,6 +10737,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts( ** to that error is returned by this function. Otherwise, SQLITE_OK is ** returned. This is to allow the following pattern (pseudo-code): ** +**
 **   sqlite3changeset_start();
 **   while( SQLITE_ROW==sqlite3changeset_next() ){
 **     // Do something with change.
@@ -10537,6 +10746,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts(
 **   if( rc!=SQLITE_OK ){
 **     // An error has occurred 
 **   }
+** 
*/ SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); @@ -10584,6 +10794,7 @@ SQLITE_API int sqlite3changeset_invert( ** sqlite3_changegroup object. Calling it produces similar results as the ** following code fragment: ** +**
 **   sqlite3_changegroup *pGrp;
 **   rc = sqlite3_changegroup_new(&pGrp);
 **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
@@ -10594,6 +10805,7 @@ SQLITE_API int sqlite3changeset_invert(
 **     *ppOut = 0;
 **     *pnOut = 0;
 **   }
+** 
** ** Refer to the sqlite3_changegroup documentation below for details. */ @@ -10609,11 +10821,15 @@ SQLITE_API int sqlite3changeset_concat( /* ** CAPI3REF: Changegroup Handle +** +** A changegroup is an object used to combine two or more +** [changesets] or [patchsets] */ typedef struct sqlite3_changegroup sqlite3_changegroup; /* ** CAPI3REF: Create A New Changegroup Object +** CONSTRUCTOR: sqlite3_changegroup ** ** An sqlite3_changegroup object is used to combine two or more changesets ** (or patchsets) into a single changeset (or patchset). A single changegroup @@ -10651,6 +10867,7 @@ SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); /* ** CAPI3REF: Add A Changeset To A Changegroup +** METHOD: sqlite3_changegroup ** ** Add all changes within the changeset (or patchset) in buffer pData (size ** nData bytes) to the changegroup. @@ -10728,6 +10945,7 @@ SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pDa /* ** CAPI3REF: Obtain A Composite Changeset From A Changegroup +** METHOD: sqlite3_changegroup ** ** Obtain a buffer containing a changeset (or patchset) representing the ** current contents of the changegroup. If the inputs to the changegroup @@ -10758,25 +10976,25 @@ SQLITE_API int sqlite3changegroup_output( /* ** CAPI3REF: Delete A Changegroup Object +** DESTRUCTOR: sqlite3_changegroup */ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); /* ** CAPI3REF: Apply A Changeset To A Database ** -** Apply a changeset to a database. This function attempts to update the -** "main" database attached to handle db with the changes found in the -** changeset passed via the second and third arguments. +** Apply a changeset or patchset to a database. These functions attempt to +** update the "main" database attached to handle db with the changes found in +** the changeset passed via the second and third arguments. ** -** The fourth argument (xFilter) passed to this function is the "filter +** The fourth argument (xFilter) passed to these functions is the "filter ** callback". If it is not NULL, then for each table affected by at least one ** change in the changeset, the filter callback is invoked with ** the table name as the second argument, and a copy of the context pointer -** passed as the sixth argument to this function as the first. If the "filter -** callback" returns zero, then no attempt is made to apply any changes to -** the table. Otherwise, if the return value is non-zero or the xFilter -** argument to this function is NULL, all changes related to the table are -** attempted. +** passed as the sixth argument as the first. If the "filter callback" +** returns zero, then no attempt is made to apply any changes to the table. +** Otherwise, if the return value is non-zero or the xFilter argument to +** is NULL, all changes related to the table are attempted. ** ** For each table that is not excluded by the filter callback, this function ** tests that the target database contains a compatible table. A table is @@ -10821,7 +11039,7 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** **
**
DELETE Changes
-** For each DELETE change, this function checks if the target database +** For each DELETE change, the function checks if the target database ** contains a row with the same primary key value (or values) as the ** original row values stored in the changeset. If it does, and the values ** stored in all non-primary key columns also match the values stored in @@ -10866,7 +11084,7 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** [SQLITE_CHANGESET_REPLACE]. ** **
UPDATE Changes
-** For each UPDATE change, this function checks if the target database +** For each UPDATE change, the function checks if the target database ** contains a row with the same primary key value (or values) as the ** original row values stored in the changeset. If it does, and the values ** stored in all modified non-primary key columns also match the values @@ -10897,11 +11115,28 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** This can be used to further customize the applications conflict ** resolution strategy. ** -** All changes made by this function are enclosed in a savepoint transaction. +** All changes made by these functions are enclosed in a savepoint transaction. ** If any other error (aside from a constraint failure when attempting to ** write to the target database) occurs, then the savepoint transaction is ** rolled back, restoring the target database to its original state, and an ** SQLite error code returned. +** +** If the output parameters (ppRebase) and (pnRebase) are non-NULL and +** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2() +** may set (*ppRebase) to point to a "rebase" that may be used with the +** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase) +** is set to the size of the buffer in bytes. It is the responsibility of the +** caller to eventually free any such buffer using sqlite3_free(). The buffer +** is only allocated and populated if one or more conflicts were encountered +** while applying the patchset. See comments surrounding the sqlite3_rebaser +** APIs for further details. +** +** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent +** may be modified by passing a combination of +** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter. +** +** Note that the sqlite3changeset_apply_v2() API is still experimental +** and therefore subject to change. */ SQLITE_API int sqlite3changeset_apply( sqlite3 *db, /* Apply change to "main" db of this handle */ @@ -10918,6 +11153,41 @@ SQLITE_API int sqlite3changeset_apply( ), void *pCtx /* First argument passed to xConflict */ ); +SQLITE_API int sqlite3changeset_apply_v2( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, /* OUT: Rebase data */ + int flags /* Combination of SESSION_APPLY_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3changeset_apply_v2 +** +** The following flags may passed via the 9th parameter to +** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]: +** +**
+**
SQLITE_CHANGESETAPPLY_NOSAVEPOINT
+** Usually, the sessions module encloses all operations performed by +** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The +** SAVEPOINT is committed if the changeset or patchset is successfully +** applied, or rolled back if an error occurs. Specifying this flag +** causes the sessions module to omit this savepoint. In this case, if the +** caller has an open transaction or savepoint when apply_v2() is called, +** it may revert the partially applied changeset by rolling it back. +*/ +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 /* ** CAPI3REF: Constants Passed To The Conflict Handler @@ -11015,6 +11285,161 @@ SQLITE_API int sqlite3changeset_apply( #define SQLITE_CHANGESET_REPLACE 1 #define SQLITE_CHANGESET_ABORT 2 +/* +** CAPI3REF: Rebasing changesets +** EXPERIMENTAL +** +** Suppose there is a site hosting a database in state S0. And that +** modifications are made that move that database to state S1 and a +** changeset recorded (the "local" changeset). Then, a changeset based +** on S0 is received from another site (the "remote" changeset) and +** applied to the database. The database is then in state +** (S1+"remote"), where the exact state depends on any conflict +** resolution decisions (OMIT or REPLACE) made while applying "remote". +** Rebasing a changeset is to update it to take those conflict +** resolution decisions into account, so that the same conflicts +** do not have to be resolved elsewhere in the network. +** +** For example, if both the local and remote changesets contain an +** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)": +** +** local: INSERT INTO t1 VALUES(1, 'v1'); +** remote: INSERT INTO t1 VALUES(1, 'v2'); +** +** and the conflict resolution is REPLACE, then the INSERT change is +** removed from the local changeset (it was overridden). Or, if the +** conflict resolution was "OMIT", then the local changeset is modified +** to instead contain: +** +** UPDATE t1 SET b = 'v2' WHERE a=1; +** +** Changes within the local changeset are rebased as follows: +** +**
+**
Local INSERT
+** This may only conflict with a remote INSERT. If the conflict +** resolution was OMIT, then add an UPDATE change to the rebased +** changeset. Or, if the conflict resolution was REPLACE, add +** nothing to the rebased changeset. +** +**
Local DELETE
+** This may conflict with a remote UPDATE or DELETE. In both cases the +** only possible resolution is OMIT. If the remote operation was a +** DELETE, then add no change to the rebased changeset. If the remote +** operation was an UPDATE, then the old.* fields of change are updated +** to reflect the new.* values in the UPDATE. +** +**
Local UPDATE
+** This may conflict with a remote UPDATE or DELETE. If it conflicts +** with a DELETE, and the conflict resolution was OMIT, then the update +** is changed into an INSERT. Any undefined values in the new.* record +** from the update change are filled in using the old.* values from +** the conflicting DELETE. Or, if the conflict resolution was REPLACE, +** the UPDATE change is simply omitted from the rebased changeset. +** +** If conflict is with a remote UPDATE and the resolution is OMIT, then +** the old.* values are rebased using the new.* values in the remote +** change. Or, if the resolution is REPLACE, then the change is copied +** into the rebased changeset with updates to columns also updated by +** the conflicting remote UPDATE removed. If this means no columns would +** be updated, the change is omitted. +**
+** +** A local change may be rebased against multiple remote changes +** simultaneously. If a single key is modified by multiple remote +** changesets, they are combined as follows before the local changeset +** is rebased: +** +**
    +**
  • If there has been one or more REPLACE resolutions on a +** key, it is rebased according to a REPLACE. +** +**
  • If there have been no REPLACE resolutions on a key, then +** the local changeset is rebased according to the most recent +** of the OMIT resolutions. +**
+** +** Note that conflict resolutions from multiple remote changesets are +** combined on a per-field basis, not per-row. This means that in the +** case of multiple remote UPDATE operations, some fields of a single +** local change may be rebased for REPLACE while others are rebased for +** OMIT. +** +** In order to rebase a local changeset, the remote changeset must first +** be applied to the local database using sqlite3changeset_apply_v2() and +** the buffer of rebase information captured. Then: +** +**
    +**
  1. An sqlite3_rebaser object is created by calling +** sqlite3rebaser_create(). +**
  2. The new object is configured with the rebase buffer obtained from +** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure(). +** If the local changeset is to be rebased against multiple remote +** changesets, then sqlite3rebaser_configure() should be called +** multiple times, in the same order that the multiple +** sqlite3changeset_apply_v2() calls were made. +**
  3. Each local changeset is rebased by calling sqlite3rebaser_rebase(). +**
  4. The sqlite3_rebaser object is deleted by calling +** sqlite3rebaser_delete(). +**
+*/ +typedef struct sqlite3_rebaser sqlite3_rebaser; + +/* +** CAPI3REF: Create a changeset rebaser object. +** EXPERIMENTAL +** +** Allocate a new changeset rebaser object. If successful, set (*ppNew) to +** point to the new object and return SQLITE_OK. Otherwise, if an error +** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) +** to NULL. +*/ +SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew); + +/* +** CAPI3REF: Configure a changeset rebaser object. +** EXPERIMENTAL +** +** Configure the changeset rebaser object to rebase changesets according +** to the conflict resolutions described by buffer pRebase (size nRebase +** bytes), which must have been obtained from a previous call to +** sqlite3changeset_apply_v2(). +*/ +SQLITE_API int sqlite3rebaser_configure( + sqlite3_rebaser*, + int nRebase, const void *pRebase +); + +/* +** CAPI3REF: Rebase a changeset +** EXPERIMENTAL +** +** Argument pIn must point to a buffer containing a changeset nIn bytes +** in size. This function allocates and populates a buffer with a copy +** of the changeset rebased rebased according to the configuration of the +** rebaser object passed as the first argument. If successful, (*ppOut) +** is set to point to the new buffer containing the rebased changset and +** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the +** responsibility of the caller to eventually free the new buffer using +** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) +** are set to zero and an SQLite error code returned. +*/ +SQLITE_API int sqlite3rebaser_rebase( + sqlite3_rebaser*, + int nIn, const void *pIn, + int *pnOut, void **ppOut +); + +/* +** CAPI3REF: Delete a changeset rebaser object. +** EXPERIMENTAL +** +** Delete the changeset rebaser object and all associated resources. There +** should be one call to this function for each successful invocation +** of sqlite3rebaser_create(). +*/ +SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); + /* ** CAPI3REF: Streaming Versions of API functions. ** @@ -11024,6 +11449,7 @@ SQLITE_API int sqlite3changeset_apply( ** ** **
Streaming functionNon-streaming equivalent
sqlite3changeset_apply_strm[sqlite3changeset_apply] +**
sqlite3changeset_apply_strm_v2[sqlite3changeset_apply_v2] **
sqlite3changeset_concat_strm[sqlite3changeset_concat] **
sqlite3changeset_invert_strm[sqlite3changeset_invert] **
sqlite3changeset_start_strm[sqlite3changeset_start] @@ -11119,6 +11545,23 @@ SQLITE_API int sqlite3changeset_apply_strm( ), void *pCtx /* First argument passed to xConflict */ ); +SQLITE_API int sqlite3changeset_apply_v2_strm( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, + int flags +); SQLITE_API int sqlite3changeset_concat_strm( int (*xInputA)(void *pIn, void *pData, int *pnData), void *pInA, @@ -11156,6 +11599,13 @@ SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*, int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut ); +SQLITE_API int sqlite3rebaser_rebase_strm( + sqlite3_rebaser *pRebaser, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); /* @@ -12573,23 +13023,25 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*); #define TK_INDEX 140 #define TK_ALTER 141 #define TK_ADD 142 -#define TK_ISNOT 143 -#define TK_FUNCTION 144 -#define TK_COLUMN 145 -#define TK_AGG_FUNCTION 146 -#define TK_AGG_COLUMN 147 -#define TK_UMINUS 148 -#define TK_UPLUS 149 -#define TK_REGISTER 150 -#define TK_VECTOR 151 -#define TK_SELECT_COLUMN 152 -#define TK_IF_NULL_ROW 153 -#define TK_ASTERISK 154 -#define TK_SPAN 155 -#define TK_END_OF_FILE 156 -#define TK_UNCLOSED_STRING 157 -#define TK_SPACE 158 -#define TK_ILLEGAL 159 +#define TK_TRUEFALSE 143 +#define TK_ISNOT 144 +#define TK_FUNCTION 145 +#define TK_COLUMN 146 +#define TK_AGG_FUNCTION 147 +#define TK_AGG_COLUMN 148 +#define TK_UMINUS 149 +#define TK_UPLUS 150 +#define TK_TRUTH 151 +#define TK_REGISTER 152 +#define TK_VECTOR 153 +#define TK_SELECT_COLUMN 154 +#define TK_IF_NULL_ROW 155 +#define TK_ASTERISK 156 +#define TK_SPAN 157 +#define TK_END_OF_FILE 158 +#define TK_UNCLOSED_STRING 159 +#define TK_SPACE 160 +#define TK_ILLEGAL 161 /* The token codes above must all fit in 8 bits */ #define TKFLG_MASK 0xff @@ -13033,9 +13485,10 @@ typedef INT16_TYPE LogEst; */ typedef struct BusyHandler BusyHandler; struct BusyHandler { - int (*xFunc)(void *,int); /* The busy callback */ - void *pArg; /* First arg to busy callback */ - int nBusy; /* Incremented with each busy call */ + int (*xBusyHandler)(void *,int); /* The busy callback */ + void *pBusyArg; /* First arg to busy callback */ + int nBusy; /* Incremented with each busy call */ + u8 bExtraFileArg; /* Include sqlite3_file as callback arg */ }; /* @@ -13135,7 +13588,6 @@ typedef struct Db Db; typedef struct Schema Schema; typedef struct Expr Expr; typedef struct ExprList ExprList; -typedef struct ExprSpan ExprSpan; typedef struct FKey FKey; typedef struct FuncDestructor FuncDestructor; typedef struct FuncDef FuncDef; @@ -13481,6 +13933,9 @@ SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags); SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags); SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*); +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC +SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*); +#endif SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); @@ -13694,6 +14149,7 @@ typedef struct VdbeOpList VdbeOpList; #define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ +#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */ /* Error message codes for OP_Halt */ #define P5_ConstraintNotNull 1 @@ -13832,78 +14288,81 @@ typedef struct VdbeOpList VdbeOpList; #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ #define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */ #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ -#define OP_Column 96 /* synopsis: r[P3]=PX */ +#define OP_IsTrue 96 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ -#define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */ -#define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ -#define OP_Count 100 /* synopsis: r[P2]=count() */ -#define OP_ReadCookie 101 -#define OP_SetCookie 102 -#define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */ -#define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */ -#define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */ -#define OP_OpenDup 106 -#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */ -#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */ -#define OP_SorterOpen 109 -#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ -#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */ -#define OP_Close 112 -#define OP_ColumnsUsed 113 -#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */ -#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */ -#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */ -#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */ -#define OP_Delete 118 -#define OP_ResetCount 119 -#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ -#define OP_SorterData 121 /* synopsis: r[P2]=data */ -#define OP_RowData 122 /* synopsis: r[P2]=data */ -#define OP_Rowid 123 /* synopsis: r[P2]=rowid */ -#define OP_NullRow 124 -#define OP_SeekEnd 125 -#define OP_SorterInsert 126 /* synopsis: key=r[P2] */ -#define OP_IdxInsert 127 /* synopsis: key=r[P2] */ -#define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */ -#define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */ -#define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */ -#define OP_Destroy 131 +#define OP_Offset 98 /* synopsis: r[P3] = sqlite_offset(P1) */ +#define OP_Column 99 /* synopsis: r[P3]=PX */ +#define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */ +#define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ +#define OP_Count 102 /* synopsis: r[P2]=count() */ +#define OP_ReadCookie 103 +#define OP_SetCookie 104 +#define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */ +#define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */ +#define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */ +#define OP_OpenDup 108 +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */ +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */ +#define OP_SorterOpen 111 +#define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ +#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */ +#define OP_Close 114 +#define OP_ColumnsUsed 115 +#define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */ +#define OP_NewRowid 117 /* synopsis: r[P2]=rowid */ +#define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */ +#define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */ +#define OP_Delete 120 +#define OP_ResetCount 121 +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ +#define OP_SorterData 123 /* synopsis: r[P2]=data */ +#define OP_RowData 124 /* synopsis: r[P2]=data */ +#define OP_Rowid 125 /* synopsis: r[P2]=rowid */ +#define OP_NullRow 126 +#define OP_SeekEnd 127 +#define OP_SorterInsert 128 /* synopsis: key=r[P2] */ +#define OP_IdxInsert 129 /* synopsis: key=r[P2] */ +#define OP_IdxDelete 130 /* synopsis: key=r[P2@P3] */ +#define OP_DeferredSeek 131 /* synopsis: Move P3 to P1.rowid if needed */ #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ -#define OP_Clear 133 -#define OP_ResetSorter 134 -#define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ -#define OP_SqlExec 136 -#define OP_ParseSchema 137 -#define OP_LoadAnalysis 138 -#define OP_DropTable 139 -#define OP_DropIndex 140 -#define OP_DropTrigger 141 -#define OP_IntegrityCk 142 -#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */ -#define OP_Param 144 -#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */ -#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */ -#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ -#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */ -#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */ -#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */ -#define OP_Expire 151 -#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */ -#define OP_VBegin 153 -#define OP_VCreate 154 -#define OP_VDestroy 155 -#define OP_VOpen 156 -#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */ -#define OP_VRename 158 -#define OP_Pagecount 159 -#define OP_MaxPgcnt 160 -#define OP_PureFunc0 161 -#define OP_Function0 162 /* synopsis: r[P3]=func(r[P2@P5]) */ -#define OP_PureFunc 163 -#define OP_Function 164 /* synopsis: r[P3]=func(r[P2@P5]) */ -#define OP_CursorHint 165 -#define OP_Noop 166 -#define OP_Explain 167 +#define OP_IdxRowid 133 /* synopsis: r[P2]=rowid */ +#define OP_Destroy 134 +#define OP_Clear 135 +#define OP_ResetSorter 136 +#define OP_CreateBtree 137 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ +#define OP_SqlExec 138 +#define OP_ParseSchema 139 +#define OP_LoadAnalysis 140 +#define OP_DropTable 141 +#define OP_DropIndex 142 +#define OP_DropTrigger 143 +#define OP_IntegrityCk 144 +#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */ +#define OP_Param 146 +#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */ +#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */ +#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ +#define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */ +#define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */ +#define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */ +#define OP_Expire 153 +#define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */ +#define OP_VBegin 155 +#define OP_VCreate 156 +#define OP_VDestroy 157 +#define OP_VOpen 158 +#define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */ +#define OP_VRename 160 +#define OP_Pagecount 161 +#define OP_MaxPgcnt 162 +#define OP_PureFunc0 163 +#define OP_Function0 164 /* synopsis: r[P3]=func(r[P2@P5]) */ +#define OP_PureFunc 165 +#define OP_Function 166 /* synopsis: r[P3]=func(r[P2@P5]) */ +#define OP_Trace 167 +#define OP_CursorHint 168 +#define OP_Noop 169 +#define OP_Explain 170 /* Properties such as "out2" or "jump" that are specified in ** comments following the "case" for each opcode in the vdbe.c @@ -13928,16 +14387,16 @@ typedef struct VdbeOpList VdbeOpList; /* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ /* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\ /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\ -/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ +/* 96 */ 0x12, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\ /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ -/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ -/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\ -/* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\ -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\ -/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\ -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ -/* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ -} +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ +/* 128 */ 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\ +/* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\ +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ +/* 168 */ 0x00, 0x00, 0x00,} /* The sqlite3P2Values() routine is able to run faster if it knows ** the value of the largest JUMP opcode. The smaller the maximum @@ -14238,7 +14697,7 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*); SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); /* Functions used to configure a Pager object. */ -SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); +SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *); SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); #ifdef SQLITE_HAS_CODEC SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); @@ -14324,6 +14783,11 @@ SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*); SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT +SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager); +#else +# define sqlite3PagerResetLockTimeout(X) +#endif /* Functions used to truncate the database file. */ SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); @@ -15143,8 +15607,9 @@ struct sqlite3 { int newTnum; /* Rootpage of table being initialized */ u8 iDb; /* Which db file is being initialized */ u8 busy; /* TRUE if currently initializing */ - u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ - u8 imposterTable; /* Building an imposter table */ + unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ + unsigned imposterTable : 1; /* Building an imposter table */ + unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ } init; int nVdbeActive; /* Number of VDBEs currently running */ int nVdbeRead; /* Number of active VDBEs that read or write */ @@ -15197,7 +15662,7 @@ struct sqlite3 { Hash aModule; /* populated by sqlite3_create_module() */ VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ VTable **aVTrans; /* Virtual tables with open transactions */ - VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ + VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ #endif Hash aFunc; /* Hash table of connection functions */ Hash aCollSeq; /* All collating sequences */ @@ -15272,7 +15737,9 @@ struct sqlite3 { #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */ #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */ #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */ -#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */ +#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/ +#define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */ + /* Flags used only if debugging */ #ifdef SQLITE_DEBUG #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */ @@ -15307,6 +15774,8 @@ struct sqlite3 { #define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */ #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ /* TH3 expects the Stat34 ^^^^^^ value to be 0x0800. Don't change it */ +#define SQLITE_PushDown 0x1000 /* The push-down optimization */ +#define SQLITE_SimplifyJoin 0x2000 /* Convert LEFT JOIN to JOIN */ #define SQLITE_AllOpts 0xffff /* All optimizations */ /* @@ -15405,6 +15874,7 @@ struct FuncDestructor { #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a ** single query - might change over time */ #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */ +#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */ /* ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are @@ -15529,6 +15999,7 @@ struct Column { #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */ +#define COLFLAG_UNIQUE 0x0008 /* Column def contains "UNIQUE" or "PK" */ /* ** A "Collating Sequence" is defined by an instance of the following @@ -15949,6 +16420,7 @@ struct Index { unsigned isCovering:1; /* True if this is a covering index */ unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */ + unsigned bNoQuery:1; /* Do not use this index to optimize queries */ #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 int nSample; /* Number of elements in aSample[] */ int nSampleCol; /* Size of IndexSample.anEq[] and so on */ @@ -16179,7 +16651,7 @@ struct Expr { */ #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */ #define EP_Agg 0x000002 /* Contains one or more aggregate functions */ - /* 0x000004 // available for use */ +#define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */ /* 0x000008 // available for use */ #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */ #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ @@ -16203,9 +16675,10 @@ struct Expr { #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ /* -** Combinations of two or more EP_* flags +** The EP_Propagate mask is a set of properties that automatically propagate +** upwards into parent nodes. */ -#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */ +#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) /* ** These macros can be used to test, set, or clear bits in the @@ -16277,17 +16750,6 @@ struct ExprList { } a[1]; /* One slot for each expression in the list */ }; -/* -** An instance of this structure is used by the parser to record both -** the parse tree for an expression and the span of input text for an -** expression. -*/ -struct ExprSpan { - Expr *pExpr; /* The expression parse tree */ - const char *zStart; /* First character of input text */ - const char *zEnd; /* One character past the end of input text */ -}; - /* ** An instance of this structure can hold a simple list of identifiers, ** such as the list "a,b,c" in the following statements: @@ -16485,6 +16947,7 @@ struct NameContext { #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */ #define NC_VarSelect 0x0040 /* A correlated subquery has been seen */ #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ +#define NC_Complex 0x2000 /* True if a function or subquery seen */ /* ** An instance of the following structure contains all information @@ -16524,7 +16987,6 @@ struct Select { Select *pPrior; /* Prior select in a compound select statement */ Select *pNext; /* Next select to the left in a compound */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ - Expr *pOffset; /* OFFSET expression. NULL means not used. */ With *pWith; /* WITH clause attached to this select. Or NULL. */ }; @@ -16555,6 +17017,7 @@ struct Select { #define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */ #define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */ #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */ +#define SF_ComplexResult 0x40000 /* Result set contains subquery or function */ /* @@ -16759,7 +17222,7 @@ struct Parse { int nMem; /* Number of memory cells used so far */ int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ - int iSelfTab; /* Table for associated with an index on expr, or negative + int iSelfTab; /* Table associated with an index on expr, or negative ** of the base register during check-constraint eval */ int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ int iCacheCnt; /* Counter used to generate aColCache[].lru values */ @@ -16774,7 +17237,6 @@ struct Parse { int nMaxArg; /* Max args passed to user function by sub-program */ #if SELECTTRACE_ENABLED int nSelect; /* Number of SELECT statements seen */ - int nSelectIndent; /* How far to indent SELECTTRACE() output */ #endif #ifndef SQLITE_OMIT_SHARED_CACHE int nTableLock; /* Number of locks in aTableLock */ @@ -16900,6 +17362,7 @@ struct AuthContext { #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */ #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ +#define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */ /* * Each trigger present in the database schema is stored as an instance of @@ -16987,6 +17450,7 @@ struct TriggerStep { Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ ExprList *pExprList; /* SET clause for UPDATE. */ IdList *pIdList; /* Column names for INSERT */ + char *zSpan; /* Original SQL text of this command */ TriggerStep *pNext; /* Next in the link-list */ TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ }; @@ -17136,9 +17600,9 @@ struct Walker { struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ int *aiCol; /* array of column indexes */ struct IdxCover *pIdxCover; /* Check for index coverage */ - struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */ + struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */ ExprList *pGroupBy; /* GROUP BY clause */ - struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */ + Select *pSelect; /* HAVING to WHERE clause ctx */ } u; }; @@ -17206,6 +17670,7 @@ struct TreeView { ** using sqlite3_log(). The routines also provide a convenient place ** to set a debugger breakpoint. */ +SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType); SQLITE_PRIVATE int sqlite3CorruptError(int); SQLITE_PRIVATE int sqlite3MisuseError(int); SQLITE_PRIVATE int sqlite3CantopenError(int); @@ -17296,6 +17761,7 @@ SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64); SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64); SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*); SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64); +SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3*,const char*,const char*); SQLITE_PRIVATE void *sqlite3Realloc(void*, u64); SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64); @@ -17364,6 +17830,12 @@ SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*); SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void); SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void); +#if defined(SQLITE_ENABLE_MULTITHREADED_CHECKS) && !defined(SQLITE_MUTEX_OMIT) +SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex*); +#else +# define sqlite3MutexWarnOnContention(x) +#endif + #ifndef SQLITE_OMIT_FLOATING_POINT SQLITE_PRIVATE int sqlite3IsNaN(double); #else @@ -17428,7 +17900,7 @@ SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); -SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); +SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); @@ -17458,7 +17930,7 @@ SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*); SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); -SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); +SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, @@ -17530,16 +18002,16 @@ SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,i SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int); SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*); SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, - Expr*,ExprList*,u32,Expr*,Expr*); + Expr*,ExprList*,u32,Expr*); SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*); SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*); SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int); SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) -SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*); +SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*); #endif -SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); -SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); +SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*); +SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*); SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); @@ -17594,6 +18066,7 @@ SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int); SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int); SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int); SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int); +SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); @@ -17611,6 +18084,8 @@ SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int); SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*); SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); +SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); +SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); @@ -17663,7 +18138,7 @@ SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) -SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int); +SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int); #endif #ifndef SQLITE_OMIT_TRIGGER @@ -17679,11 +18154,14 @@ SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, i SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int); void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*); SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*); -SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*); +SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*, + const char*,const char*); SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*, - Select*,u8); -SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8); -SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*); + Select*,u8,const char*,const char*); +SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8, + const char*,const char*); +SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*, + const char*,const char*); SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*); SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*); SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int); @@ -17790,6 +18268,10 @@ SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); SQLITE_PRIVATE const char *sqlite3ErrName(int); #endif +#ifdef SQLITE_ENABLE_DESERIALIZE +SQLITE_PRIVATE int sqlite3MemdbInit(void); +#endif + SQLITE_PRIVATE const char *sqlite3ErrStr(int); SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); @@ -17838,6 +18320,9 @@ SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; SQLITE_PRIVATE int sqlite3PendingByte; #endif #endif +#ifdef VDBE_PROFILE +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt; +#endif SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); SQLITE_PRIVATE void sqlite3AlterFunctions(void); @@ -17860,7 +18345,7 @@ SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *); SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); SQLITE_PRIVATE char sqlite3AffinityType(const char*, u8*); SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); -SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*); +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*); SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); @@ -18113,6 +18598,9 @@ SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db); #ifdef SQLITE_DEBUG SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *); #endif +#if defined(YYCOVERAGE) +SQLITE_PRIVATE int sqlite3ParserCoverage(FILE*); +#endif /* ** If the SQLITE_ENABLE IOTRACE exists then the global variable @@ -18458,6 +18946,13 @@ SQLITE_PRIVATE const Token sqlite3IntTokens[] = { { "1", 1 } }; +#ifdef VDBE_PROFILE +/* +** The following performance counter can be used in place of +** sqlite3Hwtime() for profiling. This is a no-op on standard builds. +*/ +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0; +#endif /* ** The value of the "pending" byte must be 0x40000000 (1 byte past the @@ -18834,7 +19329,6 @@ struct sqlite3_context { int iOp; /* Instruction number of OP_Function */ int isError; /* Error code returned by the function. */ u8 skipFlag; /* Skip accumulator loading if true */ - u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ u8 argc; /* Number of arguments */ sqlite3_value *argv[1]; /* Argument set */ }; @@ -19004,6 +19498,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); +SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull); SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); @@ -19397,6 +19892,9 @@ SQLITE_API int sqlite3_db_status( ** pagers the database handle is connected to. *pHighwater is always set ** to zero. */ + case SQLITE_DBSTATUS_CACHE_SPILL: + op = SQLITE_DBSTATUS_CACHE_WRITE+1; + /* Fall through into the next case */ case SQLITE_DBSTATUS_CACHE_HIT: case SQLITE_DBSTATUS_CACHE_MISS: case SQLITE_DBSTATUS_CACHE_WRITE:{ @@ -19479,7 +19977,7 @@ SQLITE_API int sqlite3_db_status( ** ** Jean Meeus ** Astronomical Algorithms, 2nd Edition, 1998 -** ISBM 0-943396-61-1 +** ISBN 0-943396-61-1 ** Willmann-Bell, Inc ** Richmond, Virginia (USA) */ @@ -20817,8 +21315,11 @@ SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ ** routine has no return value since the return value would be meaningless. */ SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ + if( id->pMethods==0 ) return SQLITE_NOTFOUND; #ifdef SQLITE_TEST - if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){ + if( op!=SQLITE_FCNTL_COMMIT_PHASETWO + && op!=SQLITE_FCNTL_LOCK_TIMEOUT + ){ /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite ** is using a regular VFS, it is called after the corresponding ** transaction has been committed. Injecting a fault at this point @@ -20835,7 +21336,7 @@ SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ return id->pMethods->xFileControl(id, op, pArg); } SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){ - (void)id->pMethods->xFileControl(id, op, pArg); + if( id->pMethods ) (void)id->pMethods->xFileControl(id, op, pArg); } SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){ @@ -23384,6 +23885,193 @@ static SQLITE_WSD int mutexIsInit = 0; #ifndef SQLITE_MUTEX_OMIT + +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS +/* +** This block (enclosed by SQLITE_ENABLE_MULTITHREADED_CHECKS) contains +** the implementation of a wrapper around the system default mutex +** implementation (sqlite3DefaultMutex()). +** +** Most calls are passed directly through to the underlying default +** mutex implementation. Except, if a mutex is configured by calling +** sqlite3MutexWarnOnContention() on it, then if contention is ever +** encountered within xMutexEnter() a warning is emitted via sqlite3_log(). +** +** This type of mutex is used as the database handle mutex when testing +** apps that usually use SQLITE_CONFIG_MULTITHREAD mode. +*/ + +/* +** Type for all mutexes used when SQLITE_ENABLE_MULTITHREADED_CHECKS +** is defined. Variable CheckMutex.mutex is a pointer to the real mutex +** allocated by the system mutex implementation. Variable iType is usually set +** to the type of mutex requested - SQLITE_MUTEX_RECURSIVE, SQLITE_MUTEX_FAST +** or one of the static mutex identifiers. Or, if this is a recursive mutex +** that has been configured using sqlite3MutexWarnOnContention(), it is +** set to SQLITE_MUTEX_WARNONCONTENTION. +*/ +typedef struct CheckMutex CheckMutex; +struct CheckMutex { + int iType; + sqlite3_mutex *mutex; +}; + +#define SQLITE_MUTEX_WARNONCONTENTION (-1) + +/* +** Pointer to real mutex methods object used by the CheckMutex +** implementation. Set by checkMutexInit(). +*/ +static SQLITE_WSD const sqlite3_mutex_methods *pGlobalMutexMethods; + +#ifdef SQLITE_DEBUG +static int checkMutexHeld(sqlite3_mutex *p){ + return pGlobalMutexMethods->xMutexHeld(((CheckMutex*)p)->mutex); +} +static int checkMutexNotheld(sqlite3_mutex *p){ + return pGlobalMutexMethods->xMutexNotheld(((CheckMutex*)p)->mutex); +} +#endif + +/* +** Initialize and deinitialize the mutex subsystem. +*/ +static int checkMutexInit(void){ + pGlobalMutexMethods = sqlite3DefaultMutex(); + return SQLITE_OK; +} +static int checkMutexEnd(void){ + pGlobalMutexMethods = 0; + return SQLITE_OK; +} + +/* +** Allocate a mutex. +*/ +static sqlite3_mutex *checkMutexAlloc(int iType){ + static CheckMutex staticMutexes[] = { + {2, 0}, {3, 0}, {4, 0}, {5, 0}, + {6, 0}, {7, 0}, {8, 0}, {9, 0}, + {10, 0}, {11, 0}, {12, 0}, {13, 0} + }; + CheckMutex *p = 0; + + assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 ); + if( iType<2 ){ + p = sqlite3MallocZero(sizeof(CheckMutex)); + if( p==0 ) return 0; + p->iType = iType; + }else{ +#ifdef SQLITE_ENABLE_API_ARMOR + if( iType-2>=ArraySize(staticMutexes) ){ + (void)SQLITE_MISUSE_BKPT; + return 0; + } +#endif + p = &staticMutexes[iType-2]; + } + + if( p->mutex==0 ){ + p->mutex = pGlobalMutexMethods->xMutexAlloc(iType); + if( p->mutex==0 ){ + if( iType<2 ){ + sqlite3_free(p); + } + p = 0; + } + } + + return (sqlite3_mutex*)p; +} + +/* +** Free a mutex. +*/ +static void checkMutexFree(sqlite3_mutex *p){ + assert( SQLITE_MUTEX_RECURSIVE<2 ); + assert( SQLITE_MUTEX_FAST<2 ); + assert( SQLITE_MUTEX_WARNONCONTENTION<2 ); + +#if SQLITE_ENABLE_API_ARMOR + if( ((CheckMutex*)p)->iType<2 ) +#endif + { + CheckMutex *pCheck = (CheckMutex*)p; + pGlobalMutexMethods->xMutexFree(pCheck->mutex); + sqlite3_free(pCheck); + } +#ifdef SQLITE_ENABLE_API_ARMOR + else{ + (void)SQLITE_MISUSE_BKPT; + } +#endif +} + +/* +** Enter the mutex. +*/ +static void checkMutexEnter(sqlite3_mutex *p){ + CheckMutex *pCheck = (CheckMutex*)p; + if( pCheck->iType==SQLITE_MUTEX_WARNONCONTENTION ){ + if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){ + return; + } + sqlite3_log(SQLITE_MISUSE, + "illegal multi-threaded access to database connection" + ); + } + pGlobalMutexMethods->xMutexEnter(pCheck->mutex); +} + +/* +** Enter the mutex (do not block). +*/ +static int checkMutexTry(sqlite3_mutex *p){ + CheckMutex *pCheck = (CheckMutex*)p; + return pGlobalMutexMethods->xMutexTry(pCheck->mutex); +} + +/* +** Leave the mutex. +*/ +static void checkMutexLeave(sqlite3_mutex *p){ + CheckMutex *pCheck = (CheckMutex*)p; + pGlobalMutexMethods->xMutexLeave(pCheck->mutex); +} + +sqlite3_mutex_methods const *multiThreadedCheckMutex(void){ + static const sqlite3_mutex_methods sMutex = { + checkMutexInit, + checkMutexEnd, + checkMutexAlloc, + checkMutexFree, + checkMutexEnter, + checkMutexTry, + checkMutexLeave, +#ifdef SQLITE_DEBUG + checkMutexHeld, + checkMutexNotheld +#else + 0, + 0 +#endif + }; + return &sMutex; +} + +/* +** Mark the SQLITE_MUTEX_RECURSIVE mutex passed as the only argument as +** one on which there should be no contention. +*/ +SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex *p){ + if( sqlite3GlobalConfig.mutex.xMutexAlloc==checkMutexAlloc ){ + CheckMutex *pCheck = (CheckMutex*)p; + assert( pCheck->iType==SQLITE_MUTEX_RECURSIVE ); + pCheck->iType = SQLITE_MUTEX_WARNONCONTENTION; + } +} +#endif /* ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS */ + /* ** Initialize the mutex system. */ @@ -23399,7 +24087,11 @@ SQLITE_PRIVATE int sqlite3MutexInit(void){ sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex; if( sqlite3GlobalConfig.bCoreMutex ){ +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS + pFrom = multiThreadedCheckMutex(); +#else pFrom = sqlite3DefaultMutex(); +#endif }else{ pFrom = sqlite3NoopMutex(); } @@ -23526,6 +24218,7 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){ #endif /* !defined(SQLITE_MUTEX_OMIT) */ + /************** End of mutex.c ***********************************************/ /************** Begin file mutex_noop.c **************************************/ /* @@ -23798,11 +24491,12 @@ struct sqlite3_mutex { #endif }; #if SQLITE_MUTEX_NREF -#define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0} +# define SQLITE3_MUTEX_INITIALIZER(id) \ + {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0} #elif defined(SQLITE_ENABLE_API_ARMOR) -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0 } +# define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER, id } #else -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } +#define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER } #endif /* @@ -23899,18 +24593,18 @@ static int pthreadMutexEnd(void){ return SQLITE_OK; } */ static sqlite3_mutex *pthreadMutexAlloc(int iType){ static sqlite3_mutex staticMutexes[] = { - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER + SQLITE3_MUTEX_INITIALIZER(2), + SQLITE3_MUTEX_INITIALIZER(3), + SQLITE3_MUTEX_INITIALIZER(4), + SQLITE3_MUTEX_INITIALIZER(5), + SQLITE3_MUTEX_INITIALIZER(6), + SQLITE3_MUTEX_INITIALIZER(7), + SQLITE3_MUTEX_INITIALIZER(8), + SQLITE3_MUTEX_INITIALIZER(9), + SQLITE3_MUTEX_INITIALIZER(10), + SQLITE3_MUTEX_INITIALIZER(11), + SQLITE3_MUTEX_INITIALIZER(12), + SQLITE3_MUTEX_INITIALIZER(13) }; sqlite3_mutex *p; switch( iType ){ @@ -23928,6 +24622,9 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&p->mutex, &recursiveAttr); pthread_mutexattr_destroy(&recursiveAttr); +#endif +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) + p->id = SQLITE_MUTEX_RECURSIVE; #endif } break; @@ -23936,6 +24633,9 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ p = sqlite3MallocZero( sizeof(*p) ); if( p ){ pthread_mutex_init(&p->mutex, 0); +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) + p->id = SQLITE_MUTEX_FAST; +#endif } break; } @@ -23951,7 +24651,7 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){ } } #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR) - if( p ) p->id = iType; + assert( p==0 || p->id==iType ); #endif return p; } @@ -24468,7 +25168,7 @@ struct sqlite3_mutex { #ifdef SQLITE_DEBUG volatile int nRef; /* Number of enterances */ volatile DWORD owner; /* Thread holding this mutex */ - volatile int trace; /* True to trace changes */ + volatile LONG trace; /* True to trace changes */ #endif }; @@ -24480,10 +25180,10 @@ struct sqlite3_mutex { #define SQLITE_W32_MUTEX_INITIALIZER { 0 } #ifdef SQLITE_DEBUG -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, \ +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \ 0L, (DWORD)0, 0 } #else -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 } +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id } #endif #ifdef SQLITE_DEBUG @@ -24526,18 +25226,18 @@ SQLITE_PRIVATE void sqlite3MemoryBarrier(void){ ** Initialize and deinitialize the mutex subsystem. */ static sqlite3_mutex winMutex_staticMutexes[] = { - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER, - SQLITE3_MUTEX_INITIALIZER + SQLITE3_MUTEX_INITIALIZER(2), + SQLITE3_MUTEX_INITIALIZER(3), + SQLITE3_MUTEX_INITIALIZER(4), + SQLITE3_MUTEX_INITIALIZER(5), + SQLITE3_MUTEX_INITIALIZER(6), + SQLITE3_MUTEX_INITIALIZER(7), + SQLITE3_MUTEX_INITIALIZER(8), + SQLITE3_MUTEX_INITIALIZER(9), + SQLITE3_MUTEX_INITIALIZER(10), + SQLITE3_MUTEX_INITIALIZER(11), + SQLITE3_MUTEX_INITIALIZER(12), + SQLITE3_MUTEX_INITIALIZER(13) }; static int winMutex_isInit = 0; @@ -24667,15 +25367,15 @@ static sqlite3_mutex *winMutexAlloc(int iType){ } #endif p = &winMutex_staticMutexes[iType-2]; - p->id = iType; #ifdef SQLITE_DEBUG #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC - p->trace = 1; + InterlockedCompareExchange(&p->trace, 1, 0); #endif #endif break; } } + assert( p==0 || p->id==iType ); return p; } @@ -25457,6 +26157,19 @@ SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){ return zNew; } +/* +** The text between zStart and zEnd represents a phrase within a larger +** SQL statement. Make a copy of this phrase in space obtained form +** sqlite3DbMalloc(). Omit leading and trailing whitespace. +*/ +SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){ + int n; + while( sqlite3Isspace(zStart[0]) ) zStart++; + n = (int)(zEnd - zStart); + while( ALWAYS(n>0) && sqlite3Isspace(zStart[n-1]) ) n--; + return sqlite3DbStrNDup(db, zStart, n); +} + /* ** Free any prior content in *pz and replace it with a copy of zNew. */ @@ -25741,6 +26454,11 @@ SQLITE_PRIVATE void sqlite3VXPrintf( PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ char buf[etBUFSIZE]; /* Conversion buffer */ + /* pAccum never starts out with an empty buffer that was obtained from + ** malloc(). This precondition is required by the mprintf("%z...") + ** optimization. */ + assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); + bufpt = 0; if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ pArgList = va_arg(ap, PrintfArguments*); @@ -26159,9 +26877,38 @@ SQLITE_PRIVATE void sqlite3VXPrintf( case etCHARX: if( bArgList ){ bufpt = getTextArg(pArgList); - c = bufpt ? bufpt[0] : 0; + length = 1; + if( bufpt ){ + buf[0] = c = *(bufpt++); + if( (c&0xc0)==0xc0 ){ + while( length<4 && (bufpt[0]&0xc0)==0x80 ){ + buf[length++] = *(bufpt++); + } + } + }else{ + buf[0] = 0; + } }else{ - c = va_arg(ap,int); + unsigned int ch = va_arg(ap,unsigned int); + if( ch<0x00080 ){ + buf[0] = ch & 0xff; + length = 1; + }else if( ch<0x00800 ){ + buf[0] = 0xc0 + (u8)((ch>>6)&0x1f); + buf[1] = 0x80 + (u8)(ch & 0x3f); + length = 2; + }else if( ch<0x10000 ){ + buf[0] = 0xe0 + (u8)((ch>>12)&0x0f); + buf[1] = 0x80 + (u8)((ch>>6) & 0x3f); + buf[2] = 0x80 + (u8)(ch & 0x3f); + length = 3; + }else{ + buf[0] = 0xf0 + (u8)((ch>>18) & 0x07); + buf[1] = 0x80 + (u8)((ch>>12) & 0x3f); + buf[2] = 0x80 + (u8)((ch>>6) & 0x3f); + buf[3] = 0x80 + (u8)(ch & 0x3f); + length = 4; + } } if( precision>1 ){ width -= precision-1; @@ -26169,12 +26916,13 @@ SQLITE_PRIVATE void sqlite3VXPrintf( sqlite3AppendChar(pAccum, width-1, ' '); width = 0; } - sqlite3AppendChar(pAccum, precision-1, c); + while( precision-- > 1 ){ + sqlite3StrAccumAppend(pAccum, buf, length); + } } - length = 1; - buf[0] = c; bufpt = buf; - break; + flag_altform2 = 1; + goto adjust_width_for_utf8; case etSTRING: case etDYNSTRING: if( bArgList ){ @@ -26186,17 +26934,45 @@ SQLITE_PRIVATE void sqlite3VXPrintf( if( bufpt==0 ){ bufpt = ""; }else if( xtype==etDYNSTRING ){ + if( pAccum->nChar==0 && pAccum->mxAlloc && width==0 && precision<0 ){ + /* Special optimization for sqlite3_mprintf("%z..."): + ** Extend an existing memory allocation rather than creating + ** a new one. */ + assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 ); + pAccum->zText = bufpt; + pAccum->nAlloc = sqlite3DbMallocSize(pAccum->db, bufpt); + pAccum->nChar = 0x7fffffff & (int)strlen(bufpt); + pAccum->printfFlags |= SQLITE_PRINTF_MALLOCED; + length = 0; + break; + } zExtra = bufpt; } if( precision>=0 ){ - for(length=0; length 0 && z[0] ){ + SQLITE_SKIP_UTF8(z); + } + length = (int)(z - (unsigned char*)bufpt); + }else{ + for(length=0; length0 ){ + /* Adjust width to account for extra bytes in UTF-8 characters */ + int ii = length - 1; + while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; + } break; - case etSQLESCAPE: /* Escape ' characters */ - case etSQLESCAPE2: /* Escape ' and enclose in '...' */ - case etSQLESCAPE3: { /* Escape " characters */ + case etSQLESCAPE: /* %q: Escape ' characters */ + case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */ + case etSQLESCAPE3: { /* %w: Escape " characters */ int i, j, k, n, isnull; int needQuote; char ch; @@ -26210,9 +26986,17 @@ SQLITE_PRIVATE void sqlite3VXPrintf( } isnull = escarg==0; if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); + /* For %q, %Q, and %w, the precision is the number of byte (or + ** characters if the ! flags is present) to use from the input. + ** Because of the extra quoting characters inserted, the number + ** of output characters may be larger than the precision. + */ k = precision; for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ if( ch==q ) n++; + if( flag_altform2 && (ch&0xc0)==0xc0 ){ + while( (escarg[i+1]&0xc0)==0x80 ){ i++; } + } } needQuote = !isnull && xtype==etSQLESCAPE2; n += i + 3; @@ -26235,10 +27019,7 @@ SQLITE_PRIVATE void sqlite3VXPrintf( if( needQuote ) bufpt[j++] = q; bufpt[j] = 0; length = j; - /* The precision in %q and %Q means how many input characters to - ** consume, not the length of the output... - ** if( precision>=0 && precision0 ){ @@ -26627,8 +27411,15 @@ SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){ sqlite3VXPrintf(&acc, zFormat, ap); va_end(ap); sqlite3StrAccumFinish(&acc); +#ifdef SQLITE_OS_TRACE_PROC + { + extern void SQLITE_OS_TRACE_PROC(const char *zBuf, int nBuf); + SQLITE_OS_TRACE_PROC(zBuf, sizeof(zBuf)); + } +#else fprintf(stdout,"%s", zBuf); fflush(stdout); +#endif } #endif @@ -26785,11 +27576,21 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m sqlite3TreeViewPush(pView, 1); } do{ +#if SELECTTRACE_ENABLED + sqlite3TreeViewLine(pView, + "SELECT%s%s (%s/%p) selFlags=0x%x nSelectRow=%d", + ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), + ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), + p->zSelName, p, p->selFlags, + (int)p->nSelectRow + ); +#else sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d", ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags, (int)p->nSelectRow ); +#endif if( cnt++ ) sqlite3TreeViewPop(pView); if( p->pPrior ){ n = 1000; @@ -26801,7 +27602,6 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m if( p->pHaving ) n++; if( p->pOrderBy ) n++; if( p->pLimit ) n++; - if( p->pOffset ) n++; } sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set"); if( p->pSrc && p->pSrc->nSrc ){ @@ -26858,12 +27658,12 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m } if( p->pLimit ){ sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); - sqlite3TreeViewExpr(pView, p->pLimit, 0); - sqlite3TreeViewPop(pView); - } - if( p->pOffset ){ - sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); - sqlite3TreeViewExpr(pView, p->pOffset, 0); + sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); + if( p->pLimit->pRight ){ + sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); + sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); + sqlite3TreeViewPop(pView); + } sqlite3TreeViewPop(pView); } if( p->pPrior ){ @@ -26941,6 +27741,11 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m sqlite3TreeViewLine(pView,"NULL"); break; } + case TK_TRUEFALSE: { + sqlite3TreeViewLine(pView, + sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE"); + break; + } #ifndef SQLITE_OMIT_BLOB_LITERAL case TK_BLOB: { sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); @@ -26997,6 +27802,19 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m case TK_ISNULL: zUniOp = "ISNULL"; break; case TK_NOTNULL: zUniOp = "NOTNULL"; break; + case TK_TRUTH: { + int x; + const char *azOp[] = { + "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" + }; + assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); + assert( pExpr->pRight ); + assert( pExpr->pRight->op==TK_TRUEFALSE ); + x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); + zUniOp = azOp[x]; + break; + } + case TK_SPAN: { sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); @@ -27156,12 +27974,20 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList( sqlite3TreeViewLine(pView, "%s", zLabel); for(i=0; inExpr; i++){ int j = pList->a[i].u.x.iOrderByCol; - if( j ){ + char *zName = pList->a[i].zName; + if( j || zName ){ sqlite3TreeViewPush(pView, 0); + } + if( zName ){ + sqlite3TreeViewLine(pView, "AS %s", zName); + } + if( j ){ sqlite3TreeViewLine(pView, "iOrderByCol=%d", j); } sqlite3TreeViewExpr(pView, pList->a[i].pExpr, inExpr-1); - if( j ) sqlite3TreeViewPop(pView); + if( j || zName ){ + sqlite3TreeViewPop(pView); + } } } } @@ -28451,6 +29277,45 @@ SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; } +/* +** Compute 10 to the E-th power. Examples: E==1 results in 10. +** E==2 results in 100. E==50 results in 1.0e50. +** +** This routine only works for values of E between 1 and 341. +*/ +static LONGDOUBLE_TYPE sqlite3Pow10(int E){ +#if defined(_MSC_VER) + static const LONGDOUBLE_TYPE x[] = { + 1.0e+001, + 1.0e+002, + 1.0e+004, + 1.0e+008, + 1.0e+016, + 1.0e+032, + 1.0e+064, + 1.0e+128, + 1.0e+256 + }; + LONGDOUBLE_TYPE r = 1.0; + int i; + assert( E>=0 && E<=307 ); + for(i=0; E!=0; i++, E >>=1){ + if( E & 1 ) r *= x[i]; + } + return r; +#else + LONGDOUBLE_TYPE x = 10.0; + LONGDOUBLE_TYPE r = 1.0; + while(1){ + if( E & 1 ) r *= x; + E >>= 1; + if( E==0 ) break; + x *= x; + } + return r; +#endif +} + /* ** The string z[] is an text representation of a real number. ** Convert this string to a double and write it into *pResult. @@ -28518,12 +29383,12 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 en /* copy max significant digits to significand */ while( z=zEnd ) goto do_atof_calc; /* if decimal point is present */ @@ -28536,7 +29401,7 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 en s = s*10 + (*z - '0'); d--; } - z+=incr, nDigits++; + z+=incr; nDigits++; } } if( z>=zEnd ) goto do_atof_calc; @@ -28606,11 +29471,10 @@ do_atof_calc: if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/ result = (double)s; }else{ - LONGDOUBLE_TYPE scale = 1.0; /* attempt to handle extremely small/large numbers better */ if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/ if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/ - while( e%308 ) { scale *= 1.0e+1; e -= 1; } + LONGDOUBLE_TYPE scale = sqlite3Pow10(e-308); if( esign<0 ){ result = s / scale; result /= 1.0e+308; @@ -28630,10 +29494,7 @@ do_atof_calc: } } }else{ - /* 1.0e+22 is the largest power of 10 than can be - ** represented exactly. */ - while( e%22 ) { scale *= 1.0e+1; e -= 1; } - while( e>0 ) { scale *= 1.0e+22; e -= 22; } + LONGDOUBLE_TYPE scale = sqlite3Pow10(e); if( esign<0 ){ result = s / scale; }else{ @@ -28691,7 +29552,7 @@ static int compare2pow63(const char *zNum, int incr){ ** Returns: ** ** 0 Successful transformation. Fits in a 64-bit signed integer. -** 1 Excess text after the integer value +** 1 Excess non-space text after the integer value ** 2 Integer too large for a 64-bit signed integer or is malformed ** 3 Special case of 9223372036854775808 ** @@ -28734,47 +29595,57 @@ SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc for(i=0; &zNum[i]='0' && c<='9'; i+=incr){ u = u*10 + c - '0'; } + testcase( i==18*incr ); + testcase( i==19*incr ); + testcase( i==20*incr ); if( u>LARGEST_INT64 ){ + /* This test and assignment is needed only to suppress UB warnings + ** from clang and -fsanitize=undefined. This test and assignment make + ** the code a little larger and slower, and no harm comes from omitting + ** them, but we must appaise the undefined-behavior pharisees. */ *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; }else if( neg ){ *pNum = -(i64)u; }else{ *pNum = (i64)u; } - testcase( i==18 ); - testcase( i==19 ); - testcase( i==20 ); - if( &zNum[i]19*incr ){ /* Too many digits */ - /* zNum is empty or contains non-numeric text or is longer - ** than 19 digits (thus guaranteeing that it is too large) */ - return 2; - }else if( i<19*incr ){ + if( i<19*incr ){ /* Less than 19 digits, so we know that it fits in 64 bits */ assert( u<=LARGEST_INT64 ); return rc; }else{ /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */ - c = compare2pow63(zNum, incr); + c = i>19*incr ? 1 : compare2pow63(zNum, incr); if( c<0 ){ /* zNum is less than 9223372036854775808 so it fits */ assert( u<=LARGEST_INT64 ); return rc; - }else if( c>0 ){ - /* zNum is greater than 9223372036854775808 so it overflows */ - return 2; }else{ - /* zNum is exactly 9223372036854775808. Fits if negative. The - ** special case 2 overflow if positive */ - assert( u-1==LARGEST_INT64 ); - return neg ? rc : 3; + *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; + if( c>0 ){ + /* zNum is greater than 9223372036854775808 so it overflows */ + return 2; + }else{ + /* zNum is exactly 9223372036854775808. Fits if negative. The + ** special case 2 overflow if positive */ + assert( u-1==LARGEST_INT64 ); + return neg ? rc : 3; + } } } } @@ -30091,78 +30962,81 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), - /* 96 */ "Column" OpHelp("r[P3]=PX"), + /* 96 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), /* 97 */ "String8" OpHelp("r[P2]='P4'"), - /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"), - /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), - /* 100 */ "Count" OpHelp("r[P2]=count()"), - /* 101 */ "ReadCookie" OpHelp(""), - /* 102 */ "SetCookie" OpHelp(""), - /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), - /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"), - /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), - /* 106 */ "OpenDup" OpHelp(""), - /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"), - /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"), - /* 109 */ "SorterOpen" OpHelp(""), - /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), - /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), - /* 112 */ "Close" OpHelp(""), - /* 113 */ "ColumnsUsed" OpHelp(""), - /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), - /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"), - /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), - /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), - /* 118 */ "Delete" OpHelp(""), - /* 119 */ "ResetCount" OpHelp(""), - /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), - /* 121 */ "SorterData" OpHelp("r[P2]=data"), - /* 122 */ "RowData" OpHelp("r[P2]=data"), - /* 123 */ "Rowid" OpHelp("r[P2]=rowid"), - /* 124 */ "NullRow" OpHelp(""), - /* 125 */ "SeekEnd" OpHelp(""), - /* 126 */ "SorterInsert" OpHelp("key=r[P2]"), - /* 127 */ "IdxInsert" OpHelp("key=r[P2]"), - /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"), - /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), - /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"), - /* 131 */ "Destroy" OpHelp(""), + /* 98 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), + /* 99 */ "Column" OpHelp("r[P3]=PX"), + /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"), + /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), + /* 102 */ "Count" OpHelp("r[P2]=count()"), + /* 103 */ "ReadCookie" OpHelp(""), + /* 104 */ "SetCookie" OpHelp(""), + /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), + /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"), + /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), + /* 108 */ "OpenDup" OpHelp(""), + /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"), + /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"), + /* 111 */ "SorterOpen" OpHelp(""), + /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), + /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), + /* 114 */ "Close" OpHelp(""), + /* 115 */ "ColumnsUsed" OpHelp(""), + /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), + /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"), + /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), + /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), + /* 120 */ "Delete" OpHelp(""), + /* 121 */ "ResetCount" OpHelp(""), + /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), + /* 123 */ "SorterData" OpHelp("r[P2]=data"), + /* 124 */ "RowData" OpHelp("r[P2]=data"), + /* 125 */ "Rowid" OpHelp("r[P2]=rowid"), + /* 126 */ "NullRow" OpHelp(""), + /* 127 */ "SeekEnd" OpHelp(""), + /* 128 */ "SorterInsert" OpHelp("key=r[P2]"), + /* 129 */ "IdxInsert" OpHelp("key=r[P2]"), + /* 130 */ "IdxDelete" OpHelp("key=r[P2@P3]"), + /* 131 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), /* 132 */ "Real" OpHelp("r[P2]=P4"), - /* 133 */ "Clear" OpHelp(""), - /* 134 */ "ResetSorter" OpHelp(""), - /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), - /* 136 */ "SqlExec" OpHelp(""), - /* 137 */ "ParseSchema" OpHelp(""), - /* 138 */ "LoadAnalysis" OpHelp(""), - /* 139 */ "DropTable" OpHelp(""), - /* 140 */ "DropIndex" OpHelp(""), - /* 141 */ "DropTrigger" OpHelp(""), - /* 142 */ "IntegrityCk" OpHelp(""), - /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), - /* 144 */ "Param" OpHelp(""), - /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), - /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), - /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), - /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), - /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), - /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), - /* 151 */ "Expire" OpHelp(""), - /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), - /* 153 */ "VBegin" OpHelp(""), - /* 154 */ "VCreate" OpHelp(""), - /* 155 */ "VDestroy" OpHelp(""), - /* 156 */ "VOpen" OpHelp(""), - /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), - /* 158 */ "VRename" OpHelp(""), - /* 159 */ "Pagecount" OpHelp(""), - /* 160 */ "MaxPgcnt" OpHelp(""), - /* 161 */ "PureFunc0" OpHelp(""), - /* 162 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), - /* 163 */ "PureFunc" OpHelp(""), - /* 164 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), - /* 165 */ "CursorHint" OpHelp(""), - /* 166 */ "Noop" OpHelp(""), - /* 167 */ "Explain" OpHelp(""), + /* 133 */ "IdxRowid" OpHelp("r[P2]=rowid"), + /* 134 */ "Destroy" OpHelp(""), + /* 135 */ "Clear" OpHelp(""), + /* 136 */ "ResetSorter" OpHelp(""), + /* 137 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), + /* 138 */ "SqlExec" OpHelp(""), + /* 139 */ "ParseSchema" OpHelp(""), + /* 140 */ "LoadAnalysis" OpHelp(""), + /* 141 */ "DropTable" OpHelp(""), + /* 142 */ "DropIndex" OpHelp(""), + /* 143 */ "DropTrigger" OpHelp(""), + /* 144 */ "IntegrityCk" OpHelp(""), + /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), + /* 146 */ "Param" OpHelp(""), + /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), + /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), + /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), + /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), + /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), + /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), + /* 153 */ "Expire" OpHelp(""), + /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), + /* 155 */ "VBegin" OpHelp(""), + /* 156 */ "VCreate" OpHelp(""), + /* 157 */ "VDestroy" OpHelp(""), + /* 158 */ "VOpen" OpHelp(""), + /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), + /* 160 */ "VRename" OpHelp(""), + /* 161 */ "Pagecount" OpHelp(""), + /* 162 */ "MaxPgcnt" OpHelp(""), + /* 163 */ "PureFunc0" OpHelp(""), + /* 164 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), + /* 165 */ "PureFunc" OpHelp(""), + /* 166 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), + /* 167 */ "Trace" OpHelp(""), + /* 168 */ "CursorHint" OpHelp(""), + /* 169 */ "Noop" OpHelp(""), + /* 170 */ "Explain" OpHelp(""), }; return azName[i]; } @@ -30401,6 +31275,9 @@ struct unixFile { #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) unsigned fsFlags; /* cached details from statfs() */ #endif +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT + unsigned iBusyTimeout; /* Wait this many millisec on locks */ +#endif #if OS_VXWORKS struct vxworksFileId *pId; /* Unique file ID */ #endif @@ -30838,7 +31715,11 @@ static struct unix_syscall { #endif #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) +#if defined(HAVE_FCHOWN) { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, +#else + { "geteuid", (sqlite3_syscall_ptr)0, 0 }, +#endif #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 @@ -30853,7 +31734,7 @@ static struct unix_syscall { #else { "munmap", (sqlite3_syscall_ptr)0, 0 }, #endif -#define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent) +#define osMunmap ((int(*)(void*,size_t))aSyscall[23].pCurrent) #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, @@ -30883,7 +31764,11 @@ static struct unix_syscall { #endif #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent) +#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 }, +#else + { "ioctl", (sqlite3_syscall_ptr)0, 0 }, +#endif #define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent) }; /* End of the overrideable system calls */ @@ -31062,15 +31947,16 @@ static int robust_open(const char *z, int f, mode_t m){ ** assert( unixMutexHeld() ); ** unixEnterLeave() */ +static sqlite3_mutex *unixBigLock = 0; static void unixEnterMutex(void){ - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + sqlite3_mutex_enter(unixBigLock); } static void unixLeaveMutex(void){ - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + sqlite3_mutex_leave(unixBigLock); } #ifdef SQLITE_DEBUG static int unixMutexHeld(void) { - return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + return sqlite3_mutex_held(unixBigLock); } #endif @@ -31826,6 +32712,43 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){ return rc; } +/* +** Set a posix-advisory-lock. +** +** There are two versions of this routine. If compiled with +** SQLITE_ENABLE_SETLK_TIMEOUT then the routine has an extra parameter +** which is a pointer to a unixFile. If the unixFile->iBusyTimeout +** value is set, then it is the number of milliseconds to wait before +** failing the lock. The iBusyTimeout value is always reset back to +** zero on each call. +** +** If SQLITE_ENABLE_SETLK_TIMEOUT is not defined, then do a non-blocking +** attempt to set the lock. +*/ +#ifndef SQLITE_ENABLE_SETLK_TIMEOUT +# define osSetPosixAdvisoryLock(h,x,t) osFcntl(h,F_SETLK,x) +#else +static int osSetPosixAdvisoryLock( + int h, /* The file descriptor on which to take the lock */ + struct flock *pLock, /* The description of the lock */ + unixFile *pFile /* Structure holding timeout value */ +){ + int rc = osFcntl(h,F_SETLK,pLock); + while( rc<0 && pFile->iBusyTimeout>0 ){ + /* On systems that support some kind of blocking file lock with a timeout, + ** make appropriate changes here to invoke that blocking file lock. On + ** generic posix, however, there is no such API. So we simply try the + ** lock once every millisecond until either the timeout expires, or until + ** the lock is obtained. */ + usleep(1000); + rc = osFcntl(h,F_SETLK,pLock); + pFile->iBusyTimeout--; + } + return rc; +} +#endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ + + /* ** Attempt to set a system-lock on the file pFile. The lock is ** described by pLock. @@ -31858,7 +32781,7 @@ static int unixFileLock(unixFile *pFile, struct flock *pLock){ lock.l_start = SHARED_FIRST; lock.l_len = SHARED_SIZE; lock.l_type = F_WRLCK; - rc = osFcntl(pFile->h, F_SETLK, &lock); + rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile); if( rc<0 ) return rc; pInode->bProcessLock = 1; pInode->nLock++; @@ -31866,7 +32789,7 @@ static int unixFileLock(unixFile *pFile, struct flock *pLock){ rc = 0; } }else{ - rc = osFcntl(pFile->h, F_SETLK, pLock); + rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile); } return rc; } @@ -34226,6 +35149,12 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ *(int*)pArg = fileHasMoved(pFile); return SQLITE_OK; } +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT + case SQLITE_FCNTL_LOCK_TIMEOUT: { + pFile->iBusyTimeout = *(int*)pArg; + return SQLITE_OK; + } +#endif #if SQLITE_MAX_MMAP_SIZE>0 case SQLITE_FCNTL_MMAP_SIZE: { i64 newLimit = *(i64*)pArg; @@ -34316,7 +35245,7 @@ static void setDeviceCharacteristics(unixFile *pFile){ pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; pFile->deviceCharacteristics = 0; if( fstatvfs(pFile->h, &fsInfo) == -1 ) { - return pFile->sectorSize; + return; } if( !strcmp(fsInfo.f_basetype, "tmp") ) { @@ -34474,6 +35403,7 @@ struct unixShmNode { int szRegion; /* Size of shared-memory regions */ u16 nRegion; /* Size of array apRegion */ u8 isReadonly; /* True if read-only */ + u8 isUnlocked; /* True if no DMS lock held */ char **apRegion; /* Array of mapped shared-memory regions */ int nRef; /* Number of unixShm objects pointing to this */ unixShm *pFirst; /* All unixShm objects pointing to this */ @@ -34530,7 +35460,7 @@ static int unixShmSystemLock( /* Access to the unixShmNode object is serialized by the caller */ pShmNode = pFile->pInode->pShmNode; - assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 ); + assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->mutex) ); /* Shared locks never span more than one byte */ assert( n==1 || lockType!=F_RDLCK ); @@ -34540,13 +35470,11 @@ static int unixShmSystemLock( if( pShmNode->h>=0 ){ /* Initialize the locking parameters */ - memset(&f, 0, sizeof(f)); f.l_type = lockType; f.l_whence = SEEK_SET; f.l_start = ofst; f.l_len = n; - - rc = osFcntl(pShmNode->h, F_SETLK, &f); + rc = osSetPosixAdvisoryLock(pShmNode->h, &f, pFile); rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; } @@ -34636,6 +35564,64 @@ static void unixShmPurge(unixFile *pFd){ } } +/* +** The DMS lock has not yet been taken on shm file pShmNode. Attempt to +** take it now. Return SQLITE_OK if successful, or an SQLite error +** code otherwise. +** +** If the DMS cannot be locked because this is a readonly_shm=1 +** connection and no other process already holds a lock, return +** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1. +*/ +static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ + struct flock lock; + int rc = SQLITE_OK; + + /* Use F_GETLK to determine the locks other processes are holding + ** on the DMS byte. If it indicates that another process is holding + ** a SHARED lock, then this process may also take a SHARED lock + ** and proceed with opening the *-shm file. + ** + ** Or, if no other process is holding any lock, then this process + ** is the first to open it. In this case take an EXCLUSIVE lock on the + ** DMS byte and truncate the *-shm file to zero bytes in size. Then + ** downgrade to a SHARED lock on the DMS byte. + ** + ** If another process is holding an EXCLUSIVE lock on the DMS byte, + ** return SQLITE_BUSY to the caller (it will try again). An earlier + ** version of this code attempted the SHARED lock at this point. But + ** this introduced a subtle race condition: if the process holding + ** EXCLUSIVE failed just before truncating the *-shm file, then this + ** process might open and use the *-shm file without truncating it. + ** And if the *-shm file has been corrupted by a power failure or + ** system crash, the database itself may also become corrupt. */ + lock.l_whence = SEEK_SET; + lock.l_start = UNIX_SHM_DMS; + lock.l_len = 1; + lock.l_type = F_WRLCK; + if( osFcntl(pShmNode->h, F_GETLK, &lock)!=0 ) { + rc = SQLITE_IOERR_LOCK; + }else if( lock.l_type==F_UNLCK ){ + if( pShmNode->isReadonly ){ + pShmNode->isUnlocked = 1; + rc = SQLITE_READONLY_CANTINIT; + }else{ + rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1); + if( rc==SQLITE_OK && robust_ftruncate(pShmNode->h, 0) ){ + rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename); + } + } + }else if( lock.l_type==F_WRLCK ){ + rc = SQLITE_BUSY; + } + + if( rc==SQLITE_OK ){ + assert( lock.l_type==F_UNLCK || lock.l_type==F_RDLCK ); + rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1); + } + return rc; +} + /* ** Open a shared-memory area associated with open database file pDbFd. ** This particular implementation uses mmapped files. @@ -34674,9 +35660,9 @@ static void unixShmPurge(unixFile *pFd){ static int unixOpenSharedMemory(unixFile *pDbFd){ struct unixShm *p = 0; /* The connection to be opened */ struct unixShmNode *pShmNode; /* The underlying mmapped file */ - int rc; /* Result code */ + int rc = SQLITE_OK; /* Result code */ unixInodeInfo *pInode; /* The inode of fd */ - char *zShmFilename; /* Name of the file used for SHM */ + char *zShm; /* Name of the file used for SHM */ int nShmFilename; /* Size of the SHM filename in bytes */ /* Allocate space for the new unixShm object. */ @@ -34717,14 +35703,14 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ goto shm_open_err; } memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); - zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; + zShm = pShmNode->zFilename = (char*)&pShmNode[1]; #ifdef SQLITE_SHM_DIRECTORY - sqlite3_snprintf(nShmFilename, zShmFilename, + sqlite3_snprintf(nShmFilename, zShm, SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", (u32)sStat.st_ino, (u32)sStat.st_dev); #else - sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath); - sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); + sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath); + sqlite3FileSuffix3(pDbFd->zPath, zShm); #endif pShmNode->h = -1; pDbFd->pInode->pShmNode = pShmNode; @@ -34738,15 +35724,16 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ } if( pInode->bProcessLock==0 ){ - int openFlags = O_RDWR | O_CREAT; - if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ - openFlags = O_RDONLY; - pShmNode->isReadonly = 1; + if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ + pShmNode->h = robust_open(zShm, O_RDWR|O_CREAT, (sStat.st_mode&0777)); } - pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777)); if( pShmNode->h<0 ){ - rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); - goto shm_open_err; + pShmNode->h = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777)); + if( pShmNode->h<0 ){ + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm); + goto shm_open_err; + } + pShmNode->isReadonly = 1; } /* If this process is running as root, make sure that the SHM file @@ -34754,20 +35741,9 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ ** the original owner will not be able to connect. */ robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); - - /* Check to see if another process is holding the dead-man switch. - ** If not, truncate the file to zero length. - */ - rc = SQLITE_OK; - if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){ - if( robust_ftruncate(pShmNode->h, 0) ){ - rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename); - } - } - if( rc==SQLITE_OK ){ - rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1); - } - if( rc ) goto shm_open_err; + + rc = unixLockSharedMemory(pDbFd, pShmNode); + if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err; } } @@ -34791,7 +35767,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ p->pNext = pShmNode->pFirst; pShmNode->pFirst = p; sqlite3_mutex_leave(pShmNode->mutex); - return SQLITE_OK; + return rc; /* Jump here on any error */ shm_open_err: @@ -34843,6 +35819,11 @@ static int unixShmMap( p = pDbFd->pShm; pShmNode = p->pShmNode; sqlite3_mutex_enter(pShmNode->mutex); + if( pShmNode->isUnlocked ){ + rc = unixLockSharedMemory(pDbFd, pShmNode); + if( rc!=SQLITE_OK ) goto shmpage_out; + pShmNode->isUnlocked = 0; + } assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); assert( pShmNode->pInode==pDbFd->pInode ); assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 ); @@ -36111,7 +37092,7 @@ static int unixOpen( ** a file-descriptor on the directory too. The first time unixSync() ** is called the directory file descriptor will be fsync()ed and close()d. */ - int syncDir = (isCreate && ( + int isNewJrnl = (isCreate && ( eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_WAL @@ -36158,7 +37139,6 @@ static int unixOpen( randomnessPid = osGetpid(0); sqlite3_randomness(0,0); } - memset(p, 0, sizeof(unixFile)); if( eType==SQLITE_OPEN_MAIN_DB ){ @@ -36181,7 +37161,7 @@ static int unixOpen( }else if( !zName ){ /* If zName is NULL, the upper layer is requesting a temp file. */ - assert(isDelete && !syncDir); + assert(isDelete && !isNewJrnl); rc = unixGetTempname(pVfs->mxPathname, zTmpname); if( rc!=SQLITE_OK ){ return rc; @@ -36216,17 +37196,24 @@ static int unixOpen( fd = robust_open(zName, openFlags, openMode); OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); assert( !isExclusive || (openFlags & O_CREAT)!=0 ); - if( fd<0 && errno!=EISDIR && isReadWrite ){ - /* Failed to open the file for read/write access. Try read-only. */ - flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); - openFlags &= ~(O_RDWR|O_CREAT); - flags |= SQLITE_OPEN_READONLY; - openFlags |= O_RDONLY; - isReadonly = 1; - fd = robust_open(zName, openFlags, openMode); + if( fd<0 ){ + if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){ + /* If unable to create a journal because the directory is not + ** writable, change the error code to indicate that. */ + rc = SQLITE_READONLY_DIRECTORY; + }else if( errno!=EISDIR && isReadWrite ){ + /* Failed to open the file for read/write access. Try read-only. */ + flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); + openFlags &= ~(O_RDWR|O_CREAT); + flags |= SQLITE_OPEN_READONLY; + openFlags |= O_RDONLY; + isReadonly = 1; + fd = robust_open(zName, openFlags, openMode); + } } if( fd<0 ){ - rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); + int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); + if( rc==SQLITE_OK ) rc = rc2; goto open_finished; } @@ -36286,7 +37273,7 @@ static int unixOpen( if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; noLock = eType!=SQLITE_OPEN_MAIN_DB; if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; - if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; + if( isNewJrnl ) ctrlFlags |= UNIXFILE_DIRSYNC; if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; #if SQLITE_ENABLE_LOCKING_STYLE @@ -38026,6 +39013,7 @@ SQLITE_API int sqlite3_os_init(void){ for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ sqlite3_vfs_register(&aVfs[i], i==0); } + unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); return SQLITE_OK; } @@ -38037,6 +39025,7 @@ SQLITE_API int sqlite3_os_init(void){ ** This routine is a no-op for unix. */ SQLITE_API int sqlite3_os_end(void){ + unixBigLock = 0; return SQLITE_OK; } @@ -41875,15 +42864,16 @@ static SYSTEM_INFO winSysInfo; ** assert( winShmMutexHeld() ); ** winShmLeaveMutex() */ +static sqlite3_mutex *winBigLock = 0; static void winShmEnterMutex(void){ - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + sqlite3_mutex_enter(winBigLock); } static void winShmLeaveMutex(void){ - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + sqlite3_mutex_leave(winBigLock); } #ifndef NDEBUG static int winShmMutexHeld(void) { - return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); + return sqlite3_mutex_held(winBigLock); } #endif @@ -41917,6 +42907,9 @@ struct winShmNode { int szRegion; /* Size of shared-memory regions */ int nRegion; /* Size of array apRegion */ + u8 isReadonly; /* True if read-only */ + u8 isUnlocked; /* True if no DMS lock held */ + struct ShmRegion { HANDLE hMap; /* File handle from CreateFileMapping */ void *pMap; @@ -41983,7 +42976,7 @@ static int winShmSystemLock( int rc = 0; /* Result code form Lock/UnlockFileEx() */ /* Access to the winShmNode object is serialized by the caller */ - assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); + assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) ); OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n", pFile->hFile.h, lockType, ofst, nByte)); @@ -42064,6 +43057,37 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){ } } +/* +** The DMS lock has not yet been taken on shm file pShmNode. Attempt to +** take it now. Return SQLITE_OK if successful, or an SQLite error +** code otherwise. +** +** If the DMS cannot be locked because this is a readonly_shm=1 +** connection and no other process already holds a lock, return +** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1. +*/ +static int winLockSharedMemory(winShmNode *pShmNode){ + int rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1); + + if( rc==SQLITE_OK ){ + if( pShmNode->isReadonly ){ + pShmNode->isUnlocked = 1; + winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); + return SQLITE_READONLY_CANTINIT; + }else if( winTruncate((sqlite3_file*)&pShmNode->hFile, 0) ){ + winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); + return winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), + "winLockSharedMemory", pShmNode->zFilename); + } + } + + if( rc==SQLITE_OK ){ + winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); + } + + return winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1); +} + /* ** Open the shared-memory area associated with database file pDbFd. ** @@ -42073,9 +43097,9 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){ */ static int winOpenSharedMemory(winFile *pDbFd){ struct winShm *p; /* The connection to be opened */ - struct winShmNode *pShmNode = 0; /* The underlying mmapped file */ - int rc; /* Result code */ - struct winShmNode *pNew; /* Newly allocated winShmNode */ + winShmNode *pShmNode = 0; /* The underlying mmapped file */ + int rc = SQLITE_OK; /* Result code */ + winShmNode *pNew; /* Newly allocated winShmNode */ int nName; /* Size of zName in bytes */ assert( pDbFd->pShm==0 ); /* Not previously opened */ @@ -42108,6 +43132,9 @@ static int winOpenSharedMemory(winFile *pDbFd){ if( pShmNode ){ sqlite3_free(pNew); }else{ + int inFlags = SQLITE_OPEN_WAL; + int outFlags = 0; + pShmNode = pNew; pNew = 0; ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; @@ -42122,30 +43149,23 @@ static int winOpenSharedMemory(winFile *pDbFd){ } } - rc = winOpen(pDbFd->pVfs, - pShmNode->zFilename, /* Name of the file (UTF-8) */ - (sqlite3_file*)&pShmNode->hFile, /* File handle here */ - SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, - 0); - if( SQLITE_OK!=rc ){ + if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ + inFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; + }else{ + inFlags |= SQLITE_OPEN_READONLY; + } + rc = winOpen(pDbFd->pVfs, pShmNode->zFilename, + (sqlite3_file*)&pShmNode->hFile, + inFlags, &outFlags); + if( rc!=SQLITE_OK ){ + rc = winLogError(rc, osGetLastError(), "winOpenShm", + pShmNode->zFilename); goto shm_open_err; } + if( outFlags==SQLITE_OPEN_READONLY ) pShmNode->isReadonly = 1; - /* Check to see if another process is holding the dead-man switch. - ** If not, truncate the file to zero length. - */ - if( winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ - rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); - if( rc!=SQLITE_OK ){ - rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), - "winOpenShm", pDbFd->zPath); - } - } - if( rc==SQLITE_OK ){ - winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); - rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1); - } - if( rc ) goto shm_open_err; + rc = winLockSharedMemory(pShmNode); + if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err; } /* Make the new connection a child of the winShmNode */ @@ -42168,7 +43188,7 @@ static int winOpenSharedMemory(winFile *pDbFd){ p->pNext = pShmNode->pFirst; pShmNode->pFirst = p; sqlite3_mutex_leave(pShmNode->mutex); - return SQLITE_OK; + return rc; /* Jump here on any error */ shm_open_err: @@ -42372,6 +43392,8 @@ static int winShmMap( winFile *pDbFd = (winFile*)fd; winShm *pShm = pDbFd->pShm; winShmNode *pShmNode; + DWORD protect = PAGE_READWRITE; + DWORD flags = FILE_MAP_WRITE | FILE_MAP_READ; int rc = SQLITE_OK; if( !pShm ){ @@ -42382,6 +43404,11 @@ static int winShmMap( pShmNode = pShm->pShmNode; sqlite3_mutex_enter(pShmNode->mutex); + if( pShmNode->isUnlocked ){ + rc = winLockSharedMemory(pShmNode); + if( rc!=SQLITE_OK ) goto shmpage_out; + pShmNode->isUnlocked = 0; + } assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); if( pShmNode->nRegion<=iRegion ){ @@ -42428,21 +43455,26 @@ static int winShmMap( } pShmNode->aRegion = apNew; + if( pShmNode->isReadonly ){ + protect = PAGE_READONLY; + flags = FILE_MAP_READ; + } + while( pShmNode->nRegion<=iRegion ){ HANDLE hMap = NULL; /* file-mapping handle */ void *pMap = 0; /* Mapped memory region */ #if SQLITE_OS_WINRT hMap = osCreateFileMappingFromApp(pShmNode->hFile.h, - NULL, PAGE_READWRITE, nByte, NULL + NULL, protect, nByte, NULL ); #elif defined(SQLITE_WIN32_HAS_WIDE) hMap = osCreateFileMappingW(pShmNode->hFile.h, - NULL, PAGE_READWRITE, 0, nByte, NULL + NULL, protect, 0, nByte, NULL ); #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA hMap = osCreateFileMappingA(pShmNode->hFile.h, - NULL, PAGE_READWRITE, 0, nByte, NULL + NULL, protect, 0, nByte, NULL ); #endif OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", @@ -42452,11 +43484,11 @@ static int winShmMap( int iOffset = pShmNode->nRegion*szRegion; int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; #if SQLITE_OS_WINRT - pMap = osMapViewOfFileFromApp(hMap, FILE_MAP_WRITE | FILE_MAP_READ, + pMap = osMapViewOfFileFromApp(hMap, flags, iOffset - iOffsetShift, szRegion + iOffsetShift ); #else - pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, + pMap = osMapViewOfFile(hMap, flags, 0, iOffset - iOffsetShift, szRegion + iOffsetShift ); #endif @@ -42487,6 +43519,7 @@ shmpage_out: }else{ *pp = 0; } + if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; sqlite3_mutex_leave(pShmNode->mutex); return rc; } @@ -43315,8 +44348,10 @@ static int winOpen( &extendedParameters); if( h!=INVALID_HANDLE_VALUE ) break; if( isReadWrite ){ - int isRO = 0; - int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + int rc2, isRO = 0; + sqlite3BeginBenignMalloc(); + rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + sqlite3EndBenignMalloc(); if( rc2==SQLITE_OK && isRO ) break; } }while( winRetryIoerr(&cnt, &lastErrno) ); @@ -43330,8 +44365,10 @@ static int winOpen( NULL); if( h!=INVALID_HANDLE_VALUE ) break; if( isReadWrite ){ - int isRO = 0; - int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + int rc2, isRO = 0; + sqlite3BeginBenignMalloc(); + rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + sqlite3EndBenignMalloc(); if( rc2==SQLITE_OK && isRO ) break; } }while( winRetryIoerr(&cnt, &lastErrno) ); @@ -43348,8 +44385,10 @@ static int winOpen( NULL); if( h!=INVALID_HANDLE_VALUE ) break; if( isReadWrite ){ - int isRO = 0; - int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + int rc2, isRO = 0; + sqlite3BeginBenignMalloc(); + rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO); + sqlite3EndBenignMalloc(); if( rc2==SQLITE_OK && isRO ) break; } }while( winRetryIoerr(&cnt, &lastErrno) ); @@ -44257,6 +45296,10 @@ SQLITE_API int sqlite3_os_init(void){ sqlite3_vfs_register(&winLongPathNolockVfs, 0); #endif +#ifndef SQLITE_OMIT_WAL + winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); +#endif + return SQLITE_OK; } @@ -44267,12 +45310,609 @@ SQLITE_API int sqlite3_os_end(void){ sleepObj = NULL; } #endif + +#ifndef SQLITE_OMIT_WAL + winBigLock = 0; +#endif + return SQLITE_OK; } #endif /* SQLITE_OS_WIN */ /************** End of os_win.c **********************************************/ +/************** Begin file memdb.c *******************************************/ +/* +** 2016-09-07 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +****************************************************************************** +** +** This file implements an in-memory VFS. A database is held as a contiguous +** block of memory. +** +** This file also implements interface sqlite3_serialize() and +** sqlite3_deserialize(). +*/ +#ifdef SQLITE_ENABLE_DESERIALIZE +/* #include "sqliteInt.h" */ + +/* +** Forward declaration of objects used by this utility +*/ +typedef struct sqlite3_vfs MemVfs; +typedef struct MemFile MemFile; + +/* Access to a lower-level VFS that (might) implement dynamic loading, +** access to randomness, etc. +*/ +#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData)) + +/* An open file */ +struct MemFile { + sqlite3_file base; /* IO methods */ + sqlite3_int64 sz; /* Size of the file */ + sqlite3_int64 szMax; /* Space allocated to aData */ + unsigned char *aData; /* content of the file */ + int nMmap; /* Number of memory mapped pages */ + unsigned mFlags; /* Flags */ + int eLock; /* Most recent lock against this file */ +}; + +/* +** Methods for MemFile +*/ +static int memdbClose(sqlite3_file*); +static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); +static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst); +static int memdbTruncate(sqlite3_file*, sqlite3_int64 size); +static int memdbSync(sqlite3_file*, int flags); +static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize); +static int memdbLock(sqlite3_file*, int); +/* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */ +static int memdbFileControl(sqlite3_file*, int op, void *pArg); +/* static int memdbSectorSize(sqlite3_file*); // not used */ +static int memdbDeviceCharacteristics(sqlite3_file*); +static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); +static int memdbUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p); + +/* +** Methods for MemVfs +*/ +static int memdbOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); +/* static int memdbDelete(sqlite3_vfs*, const char *zName, int syncDir); */ +static int memdbAccess(sqlite3_vfs*, const char *zName, int flags, int *); +static int memdbFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); +static void *memdbDlOpen(sqlite3_vfs*, const char *zFilename); +static void memdbDlError(sqlite3_vfs*, int nByte, char *zErrMsg); +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void); +static void memdbDlClose(sqlite3_vfs*, void*); +static int memdbRandomness(sqlite3_vfs*, int nByte, char *zOut); +static int memdbSleep(sqlite3_vfs*, int microseconds); +/* static int memdbCurrentTime(sqlite3_vfs*, double*); */ +static int memdbGetLastError(sqlite3_vfs*, int, char *); +static int memdbCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); + +static sqlite3_vfs memdb_vfs = { + 2, /* iVersion */ + 0, /* szOsFile (set when registered) */ + 1024, /* mxPathname */ + 0, /* pNext */ + "memdb", /* zName */ + 0, /* pAppData (set when registered) */ + memdbOpen, /* xOpen */ + 0, /* memdbDelete, */ /* xDelete */ + memdbAccess, /* xAccess */ + memdbFullPathname, /* xFullPathname */ + memdbDlOpen, /* xDlOpen */ + memdbDlError, /* xDlError */ + memdbDlSym, /* xDlSym */ + memdbDlClose, /* xDlClose */ + memdbRandomness, /* xRandomness */ + memdbSleep, /* xSleep */ + 0, /* memdbCurrentTime, */ /* xCurrentTime */ + memdbGetLastError, /* xGetLastError */ + memdbCurrentTimeInt64 /* xCurrentTimeInt64 */ +}; + +static const sqlite3_io_methods memdb_io_methods = { + 3, /* iVersion */ + memdbClose, /* xClose */ + memdbRead, /* xRead */ + memdbWrite, /* xWrite */ + memdbTruncate, /* xTruncate */ + memdbSync, /* xSync */ + memdbFileSize, /* xFileSize */ + memdbLock, /* xLock */ + memdbLock, /* xUnlock - same as xLock in this case */ + 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */ + memdbFileControl, /* xFileControl */ + 0, /* memdbSectorSize,*/ /* xSectorSize */ + memdbDeviceCharacteristics, /* xDeviceCharacteristics */ + 0, /* xShmMap */ + 0, /* xShmLock */ + 0, /* xShmBarrier */ + 0, /* xShmUnmap */ + memdbFetch, /* xFetch */ + memdbUnfetch /* xUnfetch */ +}; + + + +/* +** Close an memdb-file. +** +** The pData pointer is owned by the application, so there is nothing +** to free. +*/ +static int memdbClose(sqlite3_file *pFile){ + MemFile *p = (MemFile *)pFile; + if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); + return SQLITE_OK; +} + +/* +** Read data from an memdb-file. +*/ +static int memdbRead( + sqlite3_file *pFile, + void *zBuf, + int iAmt, + sqlite_int64 iOfst +){ + MemFile *p = (MemFile *)pFile; + if( iOfst+iAmt>p->sz ){ + memset(zBuf, 0, iAmt); + if( iOfstsz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst); + return SQLITE_IOERR_SHORT_READ; + } + memcpy(zBuf, p->aData+iOfst, iAmt); + return SQLITE_OK; +} + +/* +** Try to enlarge the memory allocation to hold at least sz bytes +*/ +static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ + unsigned char *pNew; + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ + return SQLITE_FULL; + } + pNew = sqlite3_realloc64(p->aData, newSz); + if( pNew==0 ) return SQLITE_NOMEM; + p->aData = pNew; + p->szMax = newSz; + return SQLITE_OK; +} + +/* +** Write data to an memdb-file. +*/ +static int memdbWrite( + sqlite3_file *pFile, + const void *z, + int iAmt, + sqlite_int64 iOfst +){ + MemFile *p = (MemFile *)pFile; + if( iOfst+iAmt>p->sz ){ + int rc; + if( iOfst+iAmt>p->szMax + && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK + ){ + return rc; + } + if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz); + p->sz = iOfst+iAmt; + } + memcpy(p->aData+iOfst, z, iAmt); + return SQLITE_OK; +} + +/* +** Truncate an memdb-file. +** +** In rollback mode (which is always the case for memdb, as it does not +** support WAL mode) the truncate() method is only used to reduce +** the size of a file, never to increase the size. +*/ +static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ + MemFile *p = (MemFile *)pFile; + if( NEVER(size>p->sz) ) return SQLITE_FULL; + p->sz = size; + return SQLITE_OK; +} + +/* +** Sync an memdb-file. +*/ +static int memdbSync(sqlite3_file *pFile, int flags){ + return SQLITE_OK; +} + +/* +** Return the current file-size of an memdb-file. +*/ +static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ + MemFile *p = (MemFile *)pFile; + *pSize = p->sz; + return SQLITE_OK; +} + +/* +** Lock an memdb-file. +*/ +static int memdbLock(sqlite3_file *pFile, int eLock){ + MemFile *p = (MemFile *)pFile; + p->eLock = eLock; + return SQLITE_OK; +} + +#if 0 /* Never used because memdbAccess() always returns false */ +/* +** Check if another file-handle holds a RESERVED lock on an memdb-file. +*/ +static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + *pResOut = 0; + return SQLITE_OK; +} +#endif + +/* +** File control method. For custom operations on an memdb-file. +*/ +static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){ + MemFile *p = (MemFile *)pFile; + int rc = SQLITE_NOTFOUND; + if( op==SQLITE_FCNTL_VFSNAME ){ + *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz); + rc = SQLITE_OK; + } + return rc; +} + +#if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */ +/* +** Return the sector-size in bytes for an memdb-file. +*/ +static int memdbSectorSize(sqlite3_file *pFile){ + return 1024; +} +#endif + +/* +** Return the device characteristic flags supported by an memdb-file. +*/ +static int memdbDeviceCharacteristics(sqlite3_file *pFile){ + return SQLITE_IOCAP_ATOMIC | + SQLITE_IOCAP_POWERSAFE_OVERWRITE | + SQLITE_IOCAP_SAFE_APPEND | + SQLITE_IOCAP_SEQUENTIAL; +} + +/* Fetch a page of a memory-mapped file */ +static int memdbFetch( + sqlite3_file *pFile, + sqlite3_int64 iOfst, + int iAmt, + void **pp +){ + MemFile *p = (MemFile *)pFile; + p->nMmap++; + *pp = (void*)(p->aData + iOfst); + return SQLITE_OK; +} + +/* Release a memory-mapped page */ +static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){ + MemFile *p = (MemFile *)pFile; + p->nMmap--; + return SQLITE_OK; +} + +/* +** Open an mem file handle. +*/ +static int memdbOpen( + sqlite3_vfs *pVfs, + const char *zName, + sqlite3_file *pFile, + int flags, + int *pOutFlags +){ + MemFile *p = (MemFile*)pFile; + if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ + return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags); + } + memset(p, 0, sizeof(*p)); + p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; + assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ + *pOutFlags = flags | SQLITE_OPEN_MEMORY; + p->base.pMethods = &memdb_io_methods; + return SQLITE_OK; +} + +#if 0 /* Only used to delete rollback journals, master journals, and WAL + ** files, none of which exist in memdb. So this routine is never used */ +/* +** Delete the file located at zPath. If the dirSync argument is true, +** ensure the file-system modifications are synced to disk before +** returning. +*/ +static int memdbDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ + return SQLITE_IOERR_DELETE; +} +#endif + +/* +** Test for access permissions. Return true if the requested permission +** is available, or false otherwise. +** +** With memdb, no files ever exist on disk. So always return false. +*/ +static int memdbAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ + *pResOut = 0; + return SQLITE_OK; +} + +/* +** Populate buffer zOut with the full canonical pathname corresponding +** to the pathname in zPath. zOut is guaranteed to point to a buffer +** of at least (INST_MAX_PATHNAME+1) bytes. +*/ +static int memdbFullPathname( + sqlite3_vfs *pVfs, + const char *zPath, + int nOut, + char *zOut +){ + sqlite3_snprintf(nOut, zOut, "%s", zPath); + return SQLITE_OK; +} + +/* +** Open the dynamic library located at zPath and return a handle. +*/ +static void *memdbDlOpen(sqlite3_vfs *pVfs, const char *zPath){ + return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath); +} + +/* +** Populate the buffer zErrMsg (size nByte bytes) with a human readable +** utf-8 string describing the most recent error encountered associated +** with dynamic libraries. +*/ +static void memdbDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ + ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg); +} + +/* +** Return a pointer to the symbol zSymbol in the dynamic library pHandle. +*/ +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){ + return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym); +} + +/* +** Close the dynamic library handle pHandle. +*/ +static void memdbDlClose(sqlite3_vfs *pVfs, void *pHandle){ + ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle); +} + +/* +** Populate the buffer pointed to by zBufOut with nByte bytes of +** random data. +*/ +static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ + return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut); +} + +/* +** Sleep for nMicro microseconds. Return the number of microseconds +** actually slept. +*/ +static int memdbSleep(sqlite3_vfs *pVfs, int nMicro){ + return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro); +} + +#if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */ +/* +** Return the current time as a Julian Day number in *pTimeOut. +*/ +static int memdbCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ + return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut); +} +#endif + +static int memdbGetLastError(sqlite3_vfs *pVfs, int a, char *b){ + return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b); +} +static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){ + return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p); +} + +/* +** Translate a database connection pointer and schema name into a +** MemFile pointer. +*/ +static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ + MemFile *p = 0; + int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p); + if( rc ) return 0; + if( p->base.pMethods!=&memdb_io_methods ) return 0; + return p; +} + +/* +** Return the serialization of a database +*/ +SQLITE_API unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which database within the connection */ + sqlite3_int64 *piSize, /* Write size here, if not NULL */ + unsigned int mFlags /* Maybe SQLITE_SERIALIZE_NOCOPY */ +){ + MemFile *p; + int iDb; + Btree *pBt; + sqlite3_int64 sz; + int szPage = 0; + sqlite3_stmt *pStmt = 0; + unsigned char *pOut; + char *zSql; + int rc; + +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + (void)SQLITE_MISUSE_BKPT; + return 0; + } +#endif + + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; + p = memdbFromDbSchema(db, zSchema); + iDb = sqlite3FindDbName(db, zSchema); + if( piSize ) *piSize = -1; + if( iDb<0 ) return 0; + if( p ){ + if( piSize ) *piSize = p->sz; + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ + pOut = p->aData; + }else{ + pOut = sqlite3_malloc64( p->sz ); + if( pOut ) memcpy(pOut, p->aData, p->sz); + } + return pOut; + } + pBt = db->aDb[iDb].pBt; + if( pBt==0 ) return 0; + szPage = sqlite3BtreeGetPageSize(pBt); + zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema); + rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM; + sqlite3_free(zSql); + if( rc ) return 0; + rc = sqlite3_step(pStmt); + if( rc!=SQLITE_ROW ){ + pOut = 0; + }else{ + sz = sqlite3_column_int64(pStmt, 0)*szPage; + if( piSize ) *piSize = sz; + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ + pOut = 0; + }else{ + pOut = sqlite3_malloc64( sz ); + if( pOut ){ + int nPage = sqlite3_column_int(pStmt, 0); + Pager *pPager = sqlite3BtreePager(pBt); + int pgno; + for(pgno=1; pgno<=nPage; pgno++){ + DbPage *pPage = 0; + unsigned char *pTo = pOut + szPage*(sqlite3_int64)(pgno-1); + rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0); + if( rc==SQLITE_OK ){ + memcpy(pTo, sqlite3PagerGetData(pPage), szPage); + }else{ + memset(pTo, 0, szPage); + } + sqlite3PagerUnref(pPage); + } + } + } + } + sqlite3_finalize(pStmt); + return pOut; +} + +/* Convert zSchema to a MemDB and initialize its content. +*/ +SQLITE_API int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +){ + MemFile *p; + char *zSql; + sqlite3_stmt *pStmt = 0; + int rc; + int iDb; + +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + return SQLITE_MISUSE_BKPT; + } + if( szDb<0 ) return SQLITE_MISUSE_BKPT; + if( szBuf<0 ) return SQLITE_MISUSE_BKPT; +#endif + + sqlite3_mutex_enter(db->mutex); + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; + iDb = sqlite3FindDbName(db, zSchema); + if( iDb<0 ){ + rc = SQLITE_ERROR; + goto end_deserialize; + } + zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + if( rc ) goto end_deserialize; + db->init.iDb = (u8)iDb; + db->init.reopenMemdb = 1; + rc = sqlite3_step(pStmt); + db->init.reopenMemdb = 0; + if( rc!=SQLITE_DONE ){ + rc = SQLITE_ERROR; + goto end_deserialize; + } + p = memdbFromDbSchema(db, zSchema); + if( p==0 ){ + rc = SQLITE_ERROR; + }else{ + p->aData = pData; + p->sz = szDb; + p->szMax = szBuf; + p->mFlags = mFlags; + rc = SQLITE_OK; + } + +end_deserialize: + sqlite3_finalize(pStmt); + sqlite3_mutex_leave(db->mutex); + return rc; +} + +/* +** This routine is called when the extension is loaded. +** Register the new VFS. +*/ +SQLITE_PRIVATE int sqlite3MemdbInit(void){ + sqlite3_vfs *pLower = sqlite3_vfs_find(0); + int sz = pLower->szOsFile; + memdb_vfs.pAppData = pLower; + /* In all known configurations of SQLite, the size of a default + ** sqlite3_file is greater than the size of a memdb sqlite3_file. + ** Should that ever change, remove the following NEVER() */ + if( NEVER(szpgno, pgno, - sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), + sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache), numberOfCachePages(pCache)); #endif pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno)); @@ -45256,16 +46896,15 @@ SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ */ SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){ assert( sqlite3PcachePageSanity(p) ); - if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){ - assert( (p->flags & PGHDR_CLEAN)==0 ); - pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE); - p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE); - p->flags |= PGHDR_CLEAN; - pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno)); - assert( sqlite3PcachePageSanity(p) ); - if( p->nRef==0 ){ - pcacheUnpin(p); - } + assert( (p->flags & PGHDR_DIRTY)!=0 ); + assert( (p->flags & PGHDR_CLEAN)==0 ); + pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE); + p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE); + p->flags |= PGHDR_CLEAN; + pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno)); + assert( sqlite3PcachePageSanity(p) ); + if( p->nRef==0 ){ + pcacheUnpin(p); } } @@ -48178,7 +49817,7 @@ struct Pager { char *zJournal; /* Name of the journal file */ int (*xBusyHandler)(void*); /* Function to call when busy */ void *pBusyHandlerArg; /* Context argument for xBusyHandler */ - int aStat[3]; /* Total cache hits, misses and writes */ + int aStat[4]; /* Total cache hits, misses, writes, spills */ #ifdef SQLITE_TEST int nRead; /* Database pages read */ #endif @@ -48206,6 +49845,7 @@ struct Pager { #define PAGER_STAT_HIT 0 #define PAGER_STAT_MISS 1 #define PAGER_STAT_WRITE 2 +#define PAGER_STAT_SPILL 3 /* ** The following global variables hold counters used for @@ -48692,7 +50332,7 @@ static int jrnlBufferSize(Pager *pPager){ #endif #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE - if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){ + if( pPager->dbSize>0 && (dc&SQLITE_IOCAP_BATCH_ATOMIC) ){ return -1; } #endif @@ -49608,7 +51248,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){ rc = pager_truncate(pPager, pPager->dbSize); } - if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){ + if( rc==SQLITE_OK && bCommit ){ rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0); if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; } @@ -50427,9 +52067,7 @@ end_playback: ** assertion that the transaction counter was modified. */ #ifdef SQLITE_DEBUG - if( pPager->fd->pMethods ){ - sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0); - } + sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0); #endif /* If this playback is happening automatically as a result of an IO or @@ -51182,20 +52820,18 @@ static int pagerOpentemp( ** retried. If it returns zero, then the SQLITE_BUSY error is ** returned to the caller of the pager API function. */ -SQLITE_PRIVATE void sqlite3PagerSetBusyhandler( +SQLITE_PRIVATE void sqlite3PagerSetBusyHandler( Pager *pPager, /* Pager object */ int (*xBusyHandler)(void *), /* Pointer to busy-handler function */ void *pBusyHandlerArg /* Argument to pass to xBusyHandler */ ){ + void **ap; pPager->xBusyHandler = xBusyHandler; pPager->pBusyHandlerArg = pBusyHandlerArg; - - if( isOpen(pPager->fd) ){ - void **ap = (void **)&pPager->xBusyHandler; - assert( ((int(*)(void *))(ap[0]))==xBusyHandler ); - assert( ap[1]==pBusyHandlerArg ); - sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_BUSYHANDLER, (void *)ap); - } + ap = (void **)&pPager->xBusyHandler; + assert( ((int(*)(void *))(ap[0]))==xBusyHandler ); + assert( ap[1]==pBusyHandlerArg ); + sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_BUSYHANDLER, (void *)ap); } /* @@ -51581,6 +53217,30 @@ static void pagerFreeMapHdrs(Pager *pPager){ } } +/* Verify that the database file has not be deleted or renamed out from +** under the pager. Return SQLITE_OK if the database is still where it ought +** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error +** code from sqlite3OsAccess()) if the database has gone missing. +*/ +static int databaseIsUnmoved(Pager *pPager){ + int bHasMoved = 0; + int rc; + + if( pPager->tempFile ) return SQLITE_OK; + if( pPager->dbSize==0 ) return SQLITE_OK; + assert( pPager->zFilename && pPager->zFilename[0] ); + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); + if( rc==SQLITE_NOTFOUND ){ + /* If the HAS_MOVED file-control is unimplemented, assume that the file + ** has not been moved. That is the historical behavior of SQLite: prior to + ** version 3.8.3, it never checked */ + rc = SQLITE_OK; + }else if( rc==SQLITE_OK && bHasMoved ){ + rc = SQLITE_READONLY_DBMOVED; + } + return rc; +} + /* ** Shutdown the page cache. Free all memory and close all files. @@ -51597,8 +53257,7 @@ static void pagerFreeMapHdrs(Pager *pPager){ ** to the caller. */ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ - u8 *pTmp = (u8 *)pPager->pTmpSpace; - + u8 *pTmp = (u8*)pPager->pTmpSpace; assert( db || pagerUseWal(pPager)==0 ); assert( assert_pager_state(pPager) ); disable_simulated_io_errors(); @@ -51607,11 +53266,17 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ /* pPager->errCode = 0; */ pPager->exclusiveMode = 0; #ifndef SQLITE_OMIT_WAL - assert( db || pPager->pWal==0 ); - sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize, - (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp) - ); - pPager->pWal = 0; + { + u8 *a = 0; + assert( db || pPager->pWal==0 ); + if( db && 0==(db->flags & SQLITE_NoCkptOnClose) + && SQLITE_OK==databaseIsUnmoved(pPager) + ){ + a = pTmp; + } + sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,a); + pPager->pWal = 0; + } #endif pager_reset(pPager); if( MEMDB ){ @@ -52068,6 +53733,7 @@ static int pagerStress(void *p, PgHdr *pPg){ return SQLITE_OK; } + pPager->aStat[PAGER_STAT_SPILL]++; pPg->pDirty = 0; if( pagerUseWal(pPager) ){ /* Write a single frame for this page to the log. */ @@ -52173,6 +53839,11 @@ SQLITE_PRIVATE int sqlite3PagerOpen( int rc = SQLITE_OK; /* Return code */ int tempFile = 0; /* True for temp files (incl. in-memory files) */ int memDb = 0; /* True if this is an in-memory file */ +#ifdef SQLITE_ENABLE_DESERIALIZE + int memJM = 0; /* Memory journal mode */ +#else +# define memJM 0 +#endif int readOnly = 0; /* True if this is a read-only file */ int journalFileSize; /* Bytes to allocate for each journal fd */ char *zPathname = 0; /* Full path to database file */ @@ -52300,7 +53971,10 @@ SQLITE_PRIVATE int sqlite3PagerOpen( int fout = 0; /* VFS flags returned by xOpen() */ rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); assert( !memDb ); - readOnly = (fout&SQLITE_OPEN_READONLY); +#ifdef SQLITE_ENABLE_DESERIALIZE + memJM = (fout&SQLITE_OPEN_MEMORY)!=0; +#endif + readOnly = (fout&SQLITE_OPEN_READONLY)!=0; /* If the file was successfully opened for read/write access, ** choose a default page size in case we have to create the @@ -52431,7 +54105,7 @@ act_like_temp_file: setSectorSize(pPager); if( !useJournal ){ pPager->journalMode = PAGER_JOURNALMODE_OFF; - }else if( memDb ){ + }else if( memDb || memJM ){ pPager->journalMode = PAGER_JOURNALMODE_MEMORY; } /* pPager->xBusyHandler = 0; */ @@ -52446,30 +54120,6 @@ act_like_temp_file: } -/* Verify that the database file has not be deleted or renamed out from -** under the pager. Return SQLITE_OK if the database is still were it ought -** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error -** code from sqlite3OsAccess()) if the database has gone missing. -*/ -static int databaseIsUnmoved(Pager *pPager){ - int bHasMoved = 0; - int rc; - - if( pPager->tempFile ) return SQLITE_OK; - if( pPager->dbSize==0 ) return SQLITE_OK; - assert( pPager->zFilename && pPager->zFilename[0] ); - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); - if( rc==SQLITE_NOTFOUND ){ - /* If the HAS_MOVED file-control is unimplemented, assume that the file - ** has not been moved. That is the historical behavior of SQLite: prior to - ** version 3.8.3, it never checked */ - rc = SQLITE_OK; - }else if( rc==SQLITE_OK && bHasMoved ){ - rc = SQLITE_READONLY_DBMOVED; - } - return rc; -} - /* ** This function is called after transitioning from PAGER_UNLOCK to @@ -53058,7 +54708,7 @@ static int getPageMMap( } if( pPg==0 ){ rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg); - }else{ + }else{ sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData); } if( pPg ){ @@ -53157,6 +54807,7 @@ SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){ assert( pPg->pgno==1 ); assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */ pPager = pPg->pPager; + sqlite3PagerResetLockTimeout(pPager); sqlite3PcacheRelease(pPg); pagerUnlockIfUnused(pPager); } @@ -53752,12 +55403,9 @@ static int pager_incr_changecounter(Pager *pPager, int isDirectMode){ */ SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){ int rc = SQLITE_OK; - - if( isOpen(pPager->fd) ){ - void *pArg = (void*)zMaster; - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); - if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; - } + void *pArg = (void*)zMaster; + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); + if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; if( rc==SQLITE_OK && !pPager->noSync ){ assert( !MEMDB ); rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); @@ -53978,8 +55626,9 @@ SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne( if( bBatch ){ if( rc==SQLITE_OK ){ rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0); - }else{ - sqlite3OsFileControl(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0); + } + if( rc!=SQLITE_OK ){ + sqlite3OsFileControlHint(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0); } } @@ -54203,8 +55852,12 @@ SQLITE_PRIVATE int *sqlite3PagerStats(Pager *pPager){ #endif /* -** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or -** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the +** Parameter eStat must be one of SQLITE_DBSTATUS_CACHE_HIT, _MISS, _WRITE, +** or _WRITE+1. The SQLITE_DBSTATUS_CACHE_WRITE+1 case is a translation +** of SQLITE_DBSTATUS_CACHE_SPILL. The _SPILL case is not contiguous because +** it was added later. +** +** Before returning, *pnVal is incremented by the ** current cache hit or miss count, according to the value of eStat. If the ** reset parameter is non-zero, the cache hit or miss count is zeroed before ** returning. @@ -54214,15 +55867,18 @@ SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, i assert( eStat==SQLITE_DBSTATUS_CACHE_HIT || eStat==SQLITE_DBSTATUS_CACHE_MISS || eStat==SQLITE_DBSTATUS_CACHE_WRITE + || eStat==SQLITE_DBSTATUS_CACHE_WRITE+1 ); assert( SQLITE_DBSTATUS_CACHE_HIT+1==SQLITE_DBSTATUS_CACHE_MISS ); assert( SQLITE_DBSTATUS_CACHE_HIT+2==SQLITE_DBSTATUS_CACHE_WRITE ); - assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 && PAGER_STAT_WRITE==2 ); + assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 + && PAGER_STAT_WRITE==2 && PAGER_STAT_SPILL==3 ); - *pnVal += pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT]; + eStat -= SQLITE_DBSTATUS_CACHE_HIT; + *pnVal += pPager->aStat[eStat]; if( reset ){ - pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; + pPager->aStat[eStat] = 0; } } @@ -54426,6 +56082,16 @@ SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager *pPager){ return pPager->fd; } +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT +/* +** Reset the lock timeout for pager. +*/ +SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager){ + int x = 0; + sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_LOCK_TIMEOUT, &x); +} +#endif + /* ** Return the file handle for the journal file (if it exists). ** This will be either the rollback journal or the WAL file. @@ -54886,6 +56552,7 @@ SQLITE_PRIVATE int sqlite3PagerCheckpoint( pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, pnLog, pnCkpt ); + sqlite3PagerResetLockTimeout(pPager); } return rc; } @@ -55246,6 +56913,10 @@ SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){ ** on a network filesystem. All users of the database must be able to ** share memory. ** +** In the default unix and windows implementation, the wal-index is a mmapped +** file whose name is the database name with a "-shm" suffix added. For that +** reason, the wal-index is sometimes called the "shm" file. +** ** The wal-index is transient. After a crash, the wal-index can (and should ** be) reconstructed from the original WAL file. In fact, the VFS is required ** to either truncate or zero the header of the wal-index when the last @@ -55385,9 +57056,18 @@ SQLITE_PRIVATE int sqlite3WalTrace = 0; #define WALINDEX_MAX_VERSION 3007000 /* -** Indices of various locking bytes. WAL_NREADER is the number +** Index numbers for various locking bytes. WAL_NREADER is the number ** of available reader locks and should be at least 3. The default ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5. +** +** Technically, the various VFSes are free to implement these locks however +** they see fit. However, compatibility is encouraged so that VFSes can +** interoperate. The standard implemention used on both unix and windows +** is for the index number to indicate a byte offset into the +** WalCkptInfo.aLock[] array in the wal-index header. In other words, all +** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which +** should be 120) is the location in the shm file for the first locking +** byte. */ #define WAL_WRITE_LOCK 0 #define WAL_ALL_BUT_WRITE 1 @@ -55511,7 +57191,6 @@ struct WalCkptInfo { #define WAL_FRAME_HDRSIZE 24 /* Size of write ahead log header, including checksum. */ -/* #define WAL_HDRSIZE 24 */ #define WAL_HDRSIZE 32 /* WAL magic value. Either this value, or the same value with the least @@ -55557,6 +57236,7 @@ struct Wal { u8 truncateOnCommit; /* True to truncate WAL file on commit */ u8 syncHeader; /* Fsync the WAL header if true */ u8 padToSectorBoundary; /* Pad transactions out to the next sector */ + u8 bShmUnreliable; /* SHM content is read-only and unreliable */ WalIndexHdr hdr; /* Wal-index header for current transaction */ u32 minFrame; /* Ignore wal frames before this one */ u32 iReCksum; /* On commit, recalculate checksums from here */ @@ -55646,11 +57326,20 @@ struct WalIterator { ** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are ** numbered from zero. ** +** If the wal-index is currently smaller the iPage pages then the size +** of the wal-index might be increased, but only if it is safe to do +** so. It is safe to enlarge the wal-index if pWal->writeLock is true +** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE. +** ** If this call is successful, *ppPage is set to point to the wal-index ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs, ** then an SQLite error code is returned and *ppPage is set to 0. */ -static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){ +static SQLITE_NOINLINE int walIndexPageRealloc( + Wal *pWal, /* The WAL context */ + int iPage, /* The page we seek */ + volatile u32 **ppPage /* Write the page pointer here */ +){ int rc = SQLITE_OK; /* Enlarge the pWal->apWiData[] array if required */ @@ -55669,16 +57358,19 @@ static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){ } /* Request a pointer to the required page from the VFS */ - if( pWal->apWiData[iPage]==0 ){ - if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){ - pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ); - if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; - }else{ - rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, - pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] - ); + assert( pWal->apWiData[iPage]==0 ); + if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){ + pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ); + if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; + }else{ + rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, + pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] + ); + assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); + testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK ); + if( (rc&0xff)==SQLITE_READONLY ){ + pWal->readOnly |= WAL_SHM_RDONLY; if( rc==SQLITE_READONLY ){ - pWal->readOnly |= WAL_SHM_RDONLY; rc = SQLITE_OK; } } @@ -55688,6 +57380,16 @@ static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){ assert( iPage==0 || *ppPage || rc!=SQLITE_OK ); return rc; } +static int walIndexPage( + Wal *pWal, /* The WAL context */ + int iPage, /* The page we seek */ + volatile u32 **ppPage /* Write the page pointer here */ +){ + if( pWal->nWiData<=iPage || (*ppPage = pWal->apWiData[iPage])==0 ){ + return walIndexPageRealloc(pWal, iPage, ppPage); + } + return SQLITE_OK; +} /* ** Return a pointer to the WalCkptInfo structure in the wal-index. @@ -56201,7 +57903,6 @@ static int walIndexRecover(Wal *pWal){ i64 nSize; /* Size of log file */ u32 aFrameCksum[2] = {0, 0}; int iLock; /* Lock offset to lock for checkpoint */ - int nLock; /* Number of locks to hold */ /* Obtain an exclusive lock on all byte in the locking range not already ** locked by the caller. The caller is guaranteed to have locked the @@ -56214,11 +57915,17 @@ static int walIndexRecover(Wal *pWal){ assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE ); assert( pWal->writeLock ); iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock; - nLock = SQLITE_SHM_NLOCK - iLock; - rc = walLockExclusive(pWal, iLock, nLock); + rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock); + if( rc==SQLITE_OK ){ + rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); + if( rc!=SQLITE_OK ){ + walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock); + } + } if( rc ){ return rc; } + WALTRACE(("WAL%p: recovery begin...\n", pWal)); memset(&pWal->hdr, 0, sizeof(WalIndexHdr)); @@ -56356,7 +58063,8 @@ finished: recovery_error: WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok")); - walUnlockExclusive(pWal, iLock, nLock); + walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock); + walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); return rc; } @@ -56364,13 +58072,14 @@ recovery_error: ** Close an open wal-index. */ static void walIndexClose(Wal *pWal, int isDelete){ - if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){ + if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE || pWal->bShmUnreliable ){ int i; for(i=0; inWiData; i++){ sqlite3_free((void *)pWal->apWiData[i]); pWal->apWiData[i] = 0; } - }else{ + } + if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){ sqlite3OsShmUnmap(pWal->pDbFd, isDelete); } } @@ -56657,8 +58366,9 @@ static void walIteratorFree(WalIterator *p){ /* ** Construct a WalInterator object that can be used to loop over all -** pages in the WAL in ascending order. The caller must hold the checkpoint -** lock. +** pages in the WAL following frame nBackfill in ascending order. Frames +** nBackfill or earlier may be included - excluding them is an optimization +** only. The caller must hold the checkpoint lock. ** ** On success, make *pp point to the newly allocated WalInterator object ** return SQLITE_OK. Otherwise, return an error code. If this routine @@ -56667,7 +58377,7 @@ static void walIteratorFree(WalIterator *p){ ** The calling routine should invoke walIteratorFree() to destroy the ** WalIterator object when it has finished with it. */ -static int walIteratorInit(Wal *pWal, WalIterator **pp){ +static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ WalIterator *p; /* Return value */ int nSegment; /* Number of segments to merge */ u32 iLast; /* Last frame in log */ @@ -56704,7 +58414,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){ rc = SQLITE_NOMEM_BKPT; } - for(i=0; rc==SQLITE_OK && inBackfillhdr.mxFrame ){ - /* Allocate the iterator */ - rc = walIteratorInit(pWal, &pIter); - if( rc!=SQLITE_OK ){ - return rc; - } - assert( pIter ); - /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); @@ -56903,7 +58607,13 @@ static int walCheckpoint( } } - if( pInfo->nBackfillnBackfillnBackfill, &pIter); + assert( rc==SQLITE_OK || pIter==0 ); + } + + if( pIter && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK ){ i64 nSize; /* Current size of database file */ @@ -57163,6 +58873,12 @@ static int walIndexTryHdr(Wal *pWal, int *pChanged){ return 0; } +/* +** This is the value that walTryBeginRead returns when it needs to +** be retried. +*/ +#define WAL_RETRY (-1) + /* ** Read the wal-index header from the wal-index and into pWal->hdr. ** If the wal-header appears to be corrupt, try to reconstruct the @@ -57186,9 +58902,29 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ assert( pChanged ); rc = walIndexPage(pWal, 0, &page0); if( rc!=SQLITE_OK ){ - return rc; - }; - assert( page0 || pWal->writeLock==0 ); + assert( rc!=SQLITE_READONLY ); /* READONLY changed to OK in walIndexPage */ + if( rc==SQLITE_READONLY_CANTINIT ){ + /* The SQLITE_READONLY_CANTINIT return means that the shared-memory + ** was openable but is not writable, and this thread is unable to + ** confirm that another write-capable connection has the shared-memory + ** open, and hence the content of the shared-memory is unreliable, + ** since the shared-memory might be inconsistent with the WAL file + ** and there is no writer on hand to fix it. */ + assert( page0==0 ); + assert( pWal->writeLock==0 ); + assert( pWal->readOnly & WAL_SHM_RDONLY ); + pWal->bShmUnreliable = 1; + pWal->exclusiveMode = WAL_HEAPMEMORY_MODE; + *pChanged = 1; + }else{ + return rc; /* Any other non-OK return is just an error */ + } + }else{ + /* page0 can be NULL if the SHM is zero bytes in size and pWal->writeLock + ** is zero, which prevents the SHM from growing */ + testcase( page0!=0 ); + } + assert( page0!=0 || pWal->writeLock==0 ); /* If the first page of the wal-index has been mapped, try to read the ** wal-index header immediately, without holding any lock. This usually @@ -57202,7 +58938,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ */ assert( badHdr==0 || pWal->writeLock==0 ); if( badHdr ){ - if( pWal->readOnly & WAL_SHM_RDONLY ){ + if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){ if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){ walUnlockShared(pWal, WAL_WRITE_LOCK); rc = SQLITE_READONLY_RECOVERY; @@ -57232,15 +58968,193 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){ rc = SQLITE_CANTOPEN_BKPT; } + if( pWal->bShmUnreliable ){ + if( rc!=SQLITE_OK ){ + walIndexClose(pWal, 0); + pWal->bShmUnreliable = 0; + assert( pWal->nWiData>0 && pWal->apWiData[0]==0 ); + /* walIndexRecover() might have returned SHORT_READ if a concurrent + ** writer truncated the WAL out from under it. If that happens, it + ** indicates that a writer has fixed the SHM file for us, so retry */ + if( rc==SQLITE_IOERR_SHORT_READ ) rc = WAL_RETRY; + } + pWal->exclusiveMode = WAL_NORMAL_MODE; + } return rc; } /* -** This is the value that walTryBeginRead returns when it needs to -** be retried. +** Open a transaction in a connection where the shared-memory is read-only +** and where we cannot verify that there is a separate write-capable connection +** on hand to keep the shared-memory up-to-date with the WAL file. +** +** This can happen, for example, when the shared-memory is implemented by +** memory-mapping a *-shm file, where a prior writer has shut down and +** left the *-shm file on disk, and now the present connection is trying +** to use that database but lacks write permission on the *-shm file. +** Other scenarios are also possible, depending on the VFS implementation. +** +** Precondition: +** +** The *-wal file has been read and an appropriate wal-index has been +** constructed in pWal->apWiData[] using heap memory instead of shared +** memory. +** +** If this function returns SQLITE_OK, then the read transaction has +** been successfully opened. In this case output variable (*pChanged) +** is set to true before returning if the caller should discard the +** contents of the page cache before proceeding. Or, if it returns +** WAL_RETRY, then the heap memory wal-index has been discarded and +** the caller should retry opening the read transaction from the +** beginning (including attempting to map the *-shm file). +** +** If an error occurs, an SQLite error code is returned. */ -#define WAL_RETRY (-1) +static int walBeginShmUnreliable(Wal *pWal, int *pChanged){ + i64 szWal; /* Size of wal file on disk in bytes */ + i64 iOffset; /* Current offset when reading wal file */ + u8 aBuf[WAL_HDRSIZE]; /* Buffer to load WAL header into */ + u8 *aFrame = 0; /* Malloc'd buffer to load entire frame */ + int szFrame; /* Number of bytes in buffer aFrame[] */ + u8 *aData; /* Pointer to data part of aFrame buffer */ + volatile void *pDummy; /* Dummy argument for xShmMap */ + int rc; /* Return code */ + u32 aSaveCksum[2]; /* Saved copy of pWal->hdr.aFrameCksum */ + + assert( pWal->bShmUnreliable ); + assert( pWal->readOnly & WAL_SHM_RDONLY ); + assert( pWal->nWiData>0 && pWal->apWiData[0] ); + + /* Take WAL_READ_LOCK(0). This has the effect of preventing any + ** writers from running a checkpoint, but does not stop them + ** from running recovery. */ + rc = walLockShared(pWal, WAL_READ_LOCK(0)); + if( rc!=SQLITE_OK ){ + if( rc==SQLITE_BUSY ) rc = WAL_RETRY; + goto begin_unreliable_shm_out; + } + pWal->readLock = 0; + + /* Check to see if a separate writer has attached to the shared-memory area, + ** thus making the shared-memory "reliable" again. Do this by invoking + ** the xShmMap() routine of the VFS and looking to see if the return + ** is SQLITE_READONLY instead of SQLITE_READONLY_CANTINIT. + ** + ** If the shared-memory is now "reliable" return WAL_RETRY, which will + ** cause the heap-memory WAL-index to be discarded and the actual + ** shared memory to be used in its place. + ** + ** This step is important because, even though this connection is holding + ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might + ** have already checkpointed the WAL file and, while the current + ** is active, wrap the WAL and start overwriting frames that this + ** process wants to use. + ** + ** Once sqlite3OsShmMap() has been called for an sqlite3_file and has + ** returned any SQLITE_READONLY value, it must return only SQLITE_READONLY + ** or SQLITE_READONLY_CANTINIT or some error for all subsequent invocations, + ** even if some external agent does a "chmod" to make the shared-memory + ** writable by us, until sqlite3OsShmUnmap() has been called. + ** This is a requirement on the VFS implementation. + */ + rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy); + assert( rc!=SQLITE_OK ); /* SQLITE_OK not possible for read-only connection */ + if( rc!=SQLITE_READONLY_CANTINIT ){ + rc = (rc==SQLITE_READONLY ? WAL_RETRY : rc); + goto begin_unreliable_shm_out; + } + + /* We reach this point only if the real shared-memory is still unreliable. + ** Assume the in-memory WAL-index substitute is correct and load it + ** into pWal->hdr. + */ + memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr)); + + /* Make sure some writer hasn't come in and changed the WAL file out + ** from under us, then disconnected, while we were not looking. + */ + rc = sqlite3OsFileSize(pWal->pWalFd, &szWal); + if( rc!=SQLITE_OK ){ + goto begin_unreliable_shm_out; + } + if( szWalhdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY); + goto begin_unreliable_shm_out; + } + + /* Check the salt keys at the start of the wal file still match. */ + rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); + if( rc!=SQLITE_OK ){ + goto begin_unreliable_shm_out; + } + if( memcmp(&pWal->hdr.aSalt, &aBuf[16], 8) ){ + /* Some writer has wrapped the WAL file while we were not looking. + ** Return WAL_RETRY which will cause the in-memory WAL-index to be + ** rebuilt. */ + rc = WAL_RETRY; + goto begin_unreliable_shm_out; + } + + /* Allocate a buffer to read frames into */ + szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE; + aFrame = (u8 *)sqlite3_malloc64(szFrame); + if( aFrame==0 ){ + rc = SQLITE_NOMEM_BKPT; + goto begin_unreliable_shm_out; + } + aData = &aFrame[WAL_FRAME_HDRSIZE]; + + /* Check to see if a complete transaction has been appended to the + ** wal file since the heap-memory wal-index was created. If so, the + ** heap-memory wal-index is discarded and WAL_RETRY returned to + ** the caller. */ + aSaveCksum[0] = pWal->hdr.aFrameCksum[0]; + aSaveCksum[1] = pWal->hdr.aFrameCksum[1]; + for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage); + iOffset+szFrame<=szWal; + iOffset+=szFrame + ){ + u32 pgno; /* Database page number for frame */ + u32 nTruncate; /* dbsize field from frame header */ + + /* Read and decode the next log frame. */ + rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset); + if( rc!=SQLITE_OK ) break; + if( !walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame) ) break; + + /* If nTruncate is non-zero, then a complete transaction has been + ** appended to this wal file. Set rc to WAL_RETRY and break out of + ** the loop. */ + if( nTruncate ){ + rc = WAL_RETRY; + break; + } + } + pWal->hdr.aFrameCksum[0] = aSaveCksum[0]; + pWal->hdr.aFrameCksum[1] = aSaveCksum[1]; + + begin_unreliable_shm_out: + sqlite3_free(aFrame); + if( rc!=SQLITE_OK ){ + int i; + for(i=0; inWiData; i++){ + sqlite3_free((void*)pWal->apWiData[i]); + pWal->apWiData[i] = 0; + } + pWal->bShmUnreliable = 0; + sqlite3WalEndReadTransaction(pWal); + *pChanged = 1; + } + return rc; +} /* ** Attempt to start a read transaction. This might fail due to a race or @@ -57256,7 +59170,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ ** checkpointed. If useWal==0 then this routine calls walIndexReadHdr() ** to make a copy of the wal-index header into pWal->hdr. If the ** wal-index header has changed, *pChanged is set to 1 (as an indication -** to the caller that the local paget cache is obsolete and needs to be +** to the caller that the local page cache is obsolete and needs to be ** flushed.) When useWal==1, the wal-index header is assumed to already ** be loaded and the pChanged parameter is unused. ** @@ -57302,6 +59216,9 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ assert( pWal->readLock<0 ); /* Not currently locked */ + /* useWal may only be set for read/write connections */ + assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 ); + /* Take steps to avoid spinning forever if there is a protocol error. ** ** Circumstances that cause a RETRY should only last for the briefest @@ -57330,7 +59247,10 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ } if( !useWal ){ - rc = walIndexReadHdr(pWal, pChanged); + assert( rc==SQLITE_OK ); + if( pWal->bShmUnreliable==0 ){ + rc = walIndexReadHdr(pWal, pChanged); + } if( rc==SQLITE_BUSY ){ /* If there is not a recovery running in another thread or process ** then convert BUSY errors to WAL_RETRY. If recovery is known to @@ -57359,13 +59279,17 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ if( rc!=SQLITE_OK ){ return rc; } + else if( pWal->bShmUnreliable ){ + return walBeginShmUnreliable(pWal, pChanged); + } } + assert( pWal->nWiData>0 ); + assert( pWal->apWiData[0]!=0 ); pInfo = walCkptInfo(pWal); - if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame + if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame #ifdef SQLITE_ENABLE_SNAPSHOT - && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0 - || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr))) + && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0) #endif ){ /* The WAL has been completely backfilled (or it is empty). @@ -57436,7 +59360,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ } if( mxI==0 ){ assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 ); - return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK; + return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT; } rc = walLockShared(pWal, WAL_READ_LOCK(mxI)); @@ -57708,7 +59632,7 @@ SQLITE_PRIVATE int sqlite3WalFindFrame( ** then the WAL is ignored by the reader so return early, as if the ** WAL were empty. */ - if( iLast==0 || pWal->readLock==0 ){ + if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){ *piRead = 0; return SQLITE_OK; } @@ -57739,7 +59663,7 @@ SQLITE_PRIVATE int sqlite3WalFindFrame( ** table after the current read-transaction had started. */ iMinHash = walFramePage(pWal->minFrame); - for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){ + for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){ volatile ht_slot *aHash; /* Pointer to hash table */ volatile u32 *aPgno; /* Pointer to array of page numbers */ u32 iZero; /* Frame number corresponding to aPgno[0] */ @@ -57762,6 +59686,7 @@ SQLITE_PRIVATE int sqlite3WalFindFrame( return SQLITE_CORRUPT_BKPT; } } + if( iRead ) break; } #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT @@ -57771,8 +59696,8 @@ SQLITE_PRIVATE int sqlite3WalFindFrame( { u32 iRead2 = 0; u32 iTest; - assert( pWal->minFrame>0 ); - for(iTest=iLast; iTest>=pWal->minFrame; iTest--){ + assert( pWal->bShmUnreliable || pWal->minFrame>0 ); + for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){ if( walFramePgno(pWal, iTest)==pgno ){ iRead2 = iTest; break; @@ -58548,24 +60473,24 @@ SQLITE_PRIVATE int sqlite3WalExclusiveMode(Wal *pWal, int op){ assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) ); if( op==0 ){ - if( pWal->exclusiveMode ){ - pWal->exclusiveMode = 0; + if( pWal->exclusiveMode!=WAL_NORMAL_MODE ){ + pWal->exclusiveMode = WAL_NORMAL_MODE; if( walLockShared(pWal, WAL_READ_LOCK(pWal->readLock))!=SQLITE_OK ){ - pWal->exclusiveMode = 1; + pWal->exclusiveMode = WAL_EXCLUSIVE_MODE; } - rc = pWal->exclusiveMode==0; + rc = pWal->exclusiveMode==WAL_NORMAL_MODE; }else{ /* Already in locking_mode=NORMAL */ rc = 0; } }else if( op>0 ){ - assert( pWal->exclusiveMode==0 ); + assert( pWal->exclusiveMode==WAL_NORMAL_MODE ); assert( pWal->readLock>=0 ); walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock)); - pWal->exclusiveMode = 1; + pWal->exclusiveMode = WAL_EXCLUSIVE_MODE; rc = 1; }else{ - rc = pWal->exclusiveMode==0; + rc = pWal->exclusiveMode==WAL_NORMAL_MODE; } return rc; } @@ -59176,20 +61101,20 @@ struct BtCursor { u8 curFlags; /* zero or more BTCF_* flags defined below */ u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ u8 hints; /* As configured by CursorSetHints() */ - int nOvflAlloc; /* Allocated size of aOverflow[] array */ - Btree *pBtree; /* The Btree to which this cursor belongs */ - BtShared *pBt; /* The BtShared this cursor points to */ - BtCursor *pNext; /* Forms a linked list of all cursors */ - Pgno *aOverflow; /* Cache of overflow page locations */ - CellInfo info; /* A parse of the cell we are pointing at */ - i64 nKey; /* Size of pKey, or last integer key */ - void *pKey; /* Saved key that was cursor last known position */ - Pgno pgnoRoot; /* The root page of this tree */ int skipNext; /* Prev() is noop if negative. Next() is noop if positive. ** Error code if eState==CURSOR_FAULT */ + Btree *pBtree; /* The Btree to which this cursor belongs */ + Pgno *aOverflow; /* Cache of overflow page locations */ + void *pKey; /* Saved key that was cursor last known position */ /* All fields above are zeroed when the cursor is allocated. See ** sqlite3BtreeCursorZero(). Fields that follow must be manually ** initialized. */ +#define BTCURSOR_FIRST_UNINIT pBt /* Name of first uninitialized field */ + BtShared *pBt; /* The BtShared this cursor points to */ + BtCursor *pNext; /* Forms a linked list of all cursors */ + CellInfo info; /* A parse of the cell we are pointing at */ + i64 nKey; /* Size of pKey, or last integer key */ + Pgno pgnoRoot; /* The root page of this tree */ i8 iPage; /* Index of current page in apPage */ u8 curIntKey; /* Value of apPage[0]->intKey */ u16 ix; /* Current index for apPage[iPage] */ @@ -59239,8 +61164,8 @@ struct BtCursor { ** Do nothing else with this cursor. Any attempt to use the cursor ** should return the error code stored in BtCursor.skipNext */ -#define CURSOR_INVALID 0 -#define CURSOR_VALID 1 +#define CURSOR_VALID 0 +#define CURSOR_INVALID 1 #define CURSOR_SKIPNEXT 2 #define CURSOR_REQUIRESEEK 3 #define CURSOR_FAULT 4 @@ -59785,6 +61710,34 @@ SQLITE_API int sqlite3_enable_shared_cache(int enable){ #define hasReadConflicts(a, b) 0 #endif +/* +** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single +** (MemPage*) as an argument. The (MemPage*) must not be NULL. +** +** If SQLITE_DEBUG is not defined, then this macro is equivalent to +** SQLITE_CORRUPT_BKPT. Or, if SQLITE_DEBUG is set, then the log message +** normally produced as a side-effect of SQLITE_CORRUPT_BKPT is augmented +** with the page number and filename associated with the (MemPage*). +*/ +#ifdef SQLITE_DEBUG +int corruptPageError(int lineno, MemPage *p){ + char *zMsg; + sqlite3BeginBenignMalloc(); + zMsg = sqlite3_mprintf("database corruption page %d of %s", + (int)p->pgno, sqlite3PagerFilename(p->pBt->pPager, 0) + ); + sqlite3EndBenignMalloc(); + if( zMsg ){ + sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); + } + sqlite3_free(zMsg); + return SQLITE_CORRUPT_BKPT; +} +# define SQLITE_CORRUPT_PAGE(pMemPage) corruptPageError(__LINE__, pMemPage) +#else +# define SQLITE_CORRUPT_PAGE(pMemPage) SQLITE_CORRUPT_PGNO(pMemPage->pgno) +#endif + #ifndef SQLITE_OMIT_SHARED_CACHE #ifdef SQLITE_DEBUG @@ -61073,7 +63026,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ int sz = get2byte(&data[iFree+2]); int top = get2byte(&data[hdr+5]); if( top>=iFree ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } if( iFree2 ){ assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */ @@ -61107,13 +63060,13 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ ** if PRAGMA cell_size_check=ON. */ if( pciCellLast ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } assert( pc>=iCellFirst && pc<=iCellLast ); size = pPage->xCellSize(pPage, &src[pc]); cbrk -= size; if( cbrkusableSize ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } assert( cbrk+size<=usableSize && cbrk>=iCellFirst ); testcase( cbrk+size==usableSize ); @@ -61133,7 +63086,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ defragment_out: if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } assert( cbrk>=iCellFirst ); put2byte(&data[hdr+5], cbrk); @@ -61177,7 +63130,7 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ testcase( x==4 ); testcase( x==3 ); if( size+pc > usableSize ){ - *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno); + *pRc = SQLITE_CORRUPT_PAGE(pPg); return 0; }else if( x<4 ){ /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total @@ -61200,7 +63153,7 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ if( pcpgno); + *pRc = SQLITE_CORRUPT_PAGE(pPg); } return 0; @@ -61248,7 +63201,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ if( top==0 && pPage->pBt->usableSize==65536 ){ top = 65536; }else{ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } } @@ -61338,12 +63291,12 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ while( (iFreeBlk = get2byte(&data[iPtr]))pgno); + return SQLITE_CORRUPT_PAGE(pPage); } iPtr = iFreeBlk; } if( iFreeBlk>pPage->pBt->usableSize-4 ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } assert( iFreeBlk>iPtr || iFreeBlk==0 ); @@ -61355,10 +63308,10 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ */ if( iFreeBlk && iEnd+3>=iFreeBlk ){ nFrag = iFreeBlk - iEnd; - if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PGNO(pPage->pgno); + if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); if( iEnd > pPage->pBt->usableSize ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } iSize = iEnd - iStart; iFreeBlk = get2byte(&data[iFreeBlk]); @@ -61371,13 +63324,13 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ if( iPtr>hdr+1 ){ int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); if( iPtrEnd+3>=iStart ){ - if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PGNO(pPage->pgno); + if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage); nFrag += iStart - iPtrEnd; iSize = iEnd - iPtr; iStart = iPtr; } } - if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno); + if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); data[hdr+7] -= nFrag; } x = get2byte(&data[hdr+5]); @@ -61385,7 +63338,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ /* The new freeblock is at the beginning of the cell content area, ** so just extend the cell content area rather than create another ** freelist entry */ - if( iStartpgno); + if( iStartpgno); + return SQLITE_CORRUPT_PAGE(pPage); } pPage->max1bytePayload = pBt->max1bytePayload; return SQLITE_OK; @@ -61499,7 +63452,7 @@ static int btreeInitPage(MemPage *pPage){ /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating ** the b-tree page type. */ if( decodeFlags(pPage, data[hdr]) ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); pPage->maskPage = (u16)(pBt->pageSize - 1); @@ -61518,7 +63471,7 @@ static int btreeInitPage(MemPage *pPage){ pPage->nCell = get2byte(&data[hdr+3]); if( pPage->nCell>MX_CELL(pBt) ){ /* To many cells for a single page. The page must be corrupt */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } testcase( pPage->nCell==MX_CELL(pBt) ); /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only @@ -61546,12 +63499,12 @@ static int btreeInitPage(MemPage *pPage){ testcase( pc==iCellFirst ); testcase( pc==iCellLast ); if( pciCellLast ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } sz = pPage->xCellSize(pPage, &data[pc]); testcase( pc+sz==usableSize ); if( pc+sz>usableSize ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } } if( !pPage->leaf ) iCellLast++; @@ -61569,12 +63522,12 @@ static int btreeInitPage(MemPage *pPage){ /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will ** always be at least one cell before the first freeblock. */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } while( 1 ){ if( pc>iCellLast ){ /* Freeblock off the end of the page */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } next = get2byte(&data[pc]); size = get2byte(&data[pc+2]); @@ -61584,11 +63537,11 @@ static int btreeInitPage(MemPage *pPage){ } if( next>0 ){ /* Freeblock not in ascending order */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } if( pc+size>(unsigned int)usableSize ){ /* Last freeblock extends past page end */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } } @@ -61600,7 +63553,7 @@ static int btreeInitPage(MemPage *pPage){ ** area, according to the page header, lies within the page. */ if( nFree>usableSize ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } pPage->nFree = (u16)(nFree - iCellFirst); pPage->isInit = 1; @@ -61876,7 +63829,8 @@ static int btreeInvokeBusyHandler(void *pArg){ BtShared *pBt = (BtShared*)pArg; assert( pBt->db ); assert( sqlite3_mutex_held(pBt->db->mutex) ); - return sqlite3InvokeBusyHandler(&pBt->db->busyHandler); + return sqlite3InvokeBusyHandler(&pBt->db->busyHandler, + sqlite3PagerFile(pBt->pPager)); } /* @@ -62054,7 +64008,7 @@ SQLITE_PRIVATE int sqlite3BtreeOpen( } pBt->openFlags = (u8)flags; pBt->db = db; - sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt); + sqlite3PagerSetBusyHandler(pBt->pPager, btreeInvokeBusyHandler, pBt); p->pBt = pBt; pBt->pCursor = 0; @@ -63017,6 +64971,7 @@ SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag){ } }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE && btreeInvokeBusyHandler(pBt) ); + sqlite3PagerResetLockTimeout(pBt->pPager); if( rc==SQLITE_OK ){ if( p->inTrans==TRANS_NONE ){ @@ -63131,7 +65086,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( eType==PTRMAP_OVERFLOW2 ){ /* The pointer is always the first 4 bytes of the page in this case. */ if( get4byte(pPage->aData)!=iFrom ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } put4byte(pPage->aData, iTo); }else{ @@ -63150,7 +65105,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ pPage->xParseCell(pPage, pCell, &info); if( info.nLocal pPage->aData+pPage->pBt->usableSize ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } if( iFrom==get4byte(pCell+info.nSize-4) ){ put4byte(pCell+info.nSize-4, iTo); @@ -63168,7 +65123,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( i==nCell ){ if( eType!=PTRMAP_BTREE || get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } put4byte(&pPage->aData[pPage->hdrOffset+8], iTo); } @@ -63990,7 +65945,7 @@ SQLITE_PRIVATE int sqlite3BtreeCursorSize(void){ ** of run-time by skipping the initialization of those elements. */ SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){ - memset(p, 0, offsetof(BtCursor, iPage)); + memset(p, 0, offsetof(BtCursor, BTCURSOR_FIRST_UNINIT)); } /* @@ -64033,11 +65988,19 @@ SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){ ** Using this cache reduces the number of calls to btreeParseCell(). */ #ifndef NDEBUG + static int cellInfoEqual(CellInfo *a, CellInfo *b){ + if( a->nKey!=b->nKey ) return 0; + if( a->pPayload!=b->pPayload ) return 0; + if( a->nPayload!=b->nPayload ) return 0; + if( a->nLocal!=b->nLocal ) return 0; + if( a->nSize!=b->nSize ) return 0; + return 1; + } static void assertCellInfo(BtCursor *pCur){ CellInfo info; memset(&info, 0, sizeof(info)); btreeParseCell(pCur->pPage, pCur->ix, &info); - assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 ); + assert( CORRUPT_DB || cellInfoEqual(&info, &pCur->info) ); } #else #define assertCellInfo(x) @@ -64080,6 +66043,20 @@ SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor *pCur){ return pCur->info.nKey; } +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC +/* +** Return the offset into the database file for the start of the +** payload to which the cursor is pointing. +*/ +SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor *pCur){ + assert( cursorHoldsMutex(pCur) ); + assert( pCur->eState==CURSOR_VALID ); + getCellInfo(pCur); + return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) + + (i64)(pCur->info.pPayload - pCur->pPage->aData); +} +#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */ + /* ** Return the number of bytes of payload for the entry that pCur is ** currently pointing to. For table btrees, this will be the amount @@ -64266,7 +66243,7 @@ static int accessPayload( ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ** but is recast into its current form to avoid integer overflow problems */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } /* Check if data must be read/written to/from the btree page itself. */ @@ -64299,14 +66276,15 @@ static int accessPayload( */ if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; - if( nOvfl>pCur->nOvflAlloc ){ + if( pCur->aOverflow==0 + || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) + ){ Pgno *aNew = (Pgno*)sqlite3Realloc( pCur->aOverflow, nOvfl*2*sizeof(Pgno) ); if( aNew==0 ){ return SQLITE_NOMEM_BKPT; }else{ - pCur->nOvflAlloc = nOvfl*2; pCur->aOverflow = aNew; } } @@ -64414,7 +66392,7 @@ static int accessPayload( if( rc==SQLITE_OK && amt>0 ){ /* Overflow chain ends prematurely */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } return rc; } @@ -64692,7 +66670,7 @@ static int moveToRoot(BtCursor *pCur){ ** (or the freelist). */ assert( pRoot->intKey==1 || pRoot->intKey==0 ); if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ - return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno); + return SQLITE_CORRUPT_PAGE(pCur->pPage); } skip_init: @@ -64965,7 +66943,7 @@ SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( if( pPage->intKeyLeaf ){ while( 0x80 <= *(pCell++) ){ if( pCell>=pPage->aDataEnd ){ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } } } @@ -65039,7 +67017,7 @@ SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */ testcase( nCell==2 ); /* Minimum legal index key size */ if( nCell<2 ){ - rc = SQLITE_CORRUPT_PGNO(pPage->pgno); + rc = SQLITE_CORRUPT_PAGE(pPage); goto moveto_finish; } pCellKey = sqlite3Malloc( nCell+18 ); @@ -65820,9 +67798,8 @@ static void freePage(MemPage *pPage, int *pRC){ } /* -** Free any overflow pages associated with the given Cell. Write the -** local Cell size (the number of bytes on the original page, omitting -** overflow) into *pnSize. +** Free any overflow pages associated with the given Cell. Store +** size information about the cell in pInfo. */ static int clearCell( MemPage *pPage, /* The page that contains the Cell */ @@ -65842,7 +67819,7 @@ static int clearCell( } if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){ /* Cell extends past end of page */ - return SQLITE_CORRUPT_PGNO(pPage->pgno); + return SQLITE_CORRUPT_PAGE(pPage); } ovflPgno = get4byte(pCell + pInfo->nSize - 4); pBt = pPage->pBt; @@ -67026,7 +69003,7 @@ static int balance_nonroot( } /* Load b.apCell[] with pointers to all cells in pOld. If pOld - ** constains overflow cells, include them in the b.apCell[] array + ** contains overflow cells, include them in the b.apCell[] array ** in the correct spot. ** ** Note that when there are multiple overflow cells, it is always the @@ -70461,7 +72438,7 @@ SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){ if( p->flags & MEM_Null ){ /* Cannot be both MEM_Null and some other type */ assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob - |MEM_RowSet|MEM_Frame|MEM_Agg|MEM_Zero))==0 ); + |MEM_RowSet|MEM_Frame|MEM_Agg))==0 ); /* If MEM_Null is set, then either the value is a pure NULL (the usual ** case) or it is a pointer set using sqlite3_bind_pointer() or @@ -70511,6 +72488,51 @@ SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){ } #endif +#ifdef SQLITE_DEBUG +/* +** Check that string value of pMem agrees with its integer or real value. +** +** A single int or real value always converts to the same strings. But +** many different strings can be converted into the same int or real. +** If a table contains a numeric value and an index is based on the +** corresponding string value, then it is important that the string be +** derived from the numeric value, not the other way around, to ensure +** that the index and table are consistent. See ticket +** https://www.sqlite.org/src/info/343634942dd54ab (2018-01-31) for +** an example. +** +** This routine looks at pMem to verify that if it has both a numeric +** representation and a string representation then the string rep has +** been derived from the numeric and not the other way around. It returns +** true if everything is ok and false if there is a problem. +** +** This routine is for use inside of assert() statements only. +*/ +SQLITE_PRIVATE int sqlite3VdbeMemConsistentDualRep(Mem *p){ + char zBuf[100]; + char *z; + int i, j, incr; + if( (p->flags & MEM_Str)==0 ) return 1; + if( (p->flags & (MEM_Int|MEM_Real))==0 ) return 1; + if( p->flags & MEM_Int ){ + sqlite3_snprintf(sizeof(zBuf),zBuf,"%lld",p->u.i); + }else{ + sqlite3_snprintf(sizeof(zBuf),zBuf,"%!.15g",p->u.r); + } + z = p->z; + i = j = 0; + incr = 1; + if( p->enc!=SQLITE_UTF8 ){ + incr = 2; + if( p->enc==SQLITE_UTF16BE ) z++; + } + while( zBuf[j] ){ + if( zBuf[j++]!=z[i] ) return 0; + i += incr; + } + return 1; +} +#endif /* SQLITE_DEBUG */ /* ** If pMem is an object with a valid string representation, this routine @@ -70768,26 +72790,24 @@ SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){ ** otherwise. */ SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){ - int rc = SQLITE_OK; - if( ALWAYS(pFunc && pFunc->xFinalize) ){ - sqlite3_context ctx; - Mem t; - assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef ); - assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); - memset(&ctx, 0, sizeof(ctx)); - memset(&t, 0, sizeof(t)); - t.flags = MEM_Null; - t.db = pMem->db; - ctx.pOut = &t; - ctx.pMem = pMem; - ctx.pFunc = pFunc; - pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */ - assert( (pMem->flags & MEM_Dyn)==0 ); - if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc); - memcpy(pMem, &t, sizeof(t)); - rc = ctx.isError; - } - return rc; + sqlite3_context ctx; + Mem t; + assert( pFunc!=0 ); + assert( pFunc->xFinalize!=0 ); + assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef ); + assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); + memset(&ctx, 0, sizeof(ctx)); + memset(&t, 0, sizeof(t)); + t.flags = MEM_Null; + t.db = pMem->db; + ctx.pOut = &t; + ctx.pMem = pMem; + ctx.pFunc = pFunc; + pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */ + assert( (pMem->flags & MEM_Dyn)==0 ); + if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc); + memcpy(pMem, &t, sizeof(t)); + return ctx.isError; } /* @@ -70947,6 +72967,16 @@ SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){ } } +/* +** Return 1 if pMem represents true, and return 0 if pMem represents false. +** Return the value ifNull if pMem is NULL. +*/ +SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){ + if( pMem->flags & MEM_Int ) return pMem->u.i!=0; + if( pMem->flags & MEM_Null ) return ifNull; + return sqlite3VdbeRealValue(pMem)!=0.0; +} + /* ** The MEM structure is already a MEM_Real. Try to also make it a ** MEM_Int if we can. @@ -71002,6 +73032,18 @@ SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){ return SQLITE_OK; } +/* Compare a floating point value to an integer. Return true if the two +** values are the same within the precision of the floating point value. +** +** For some versions of GCC on 32-bit machines, if you do the more obvious +** comparison of "r1==(double)i" you sometimes get an answer of false even +** though the r1 and (double)i values are bit-for-bit the same. +*/ +static int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){ + double r2 = (double)i; + return memcmp(&r1, &r2, sizeof(r1))==0; +} + /* ** Convert pMem so that it has types MEM_Real or MEM_Int or both. ** Invalidate any prior representations. @@ -71021,7 +73063,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){ }else{ i64 i = pMem->u.i; sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc); - if( rc==1 && pMem->u.r==(double)i ){ + if( rc==1 && sqlite3RealSameAsInt(pMem->u.r, i) ){ pMem->u.i = i; MemSetTypeFlag(pMem, MEM_Int); }else{ @@ -71504,6 +73546,7 @@ static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){ assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0 || pVal->db->mallocFailed ); if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){ + assert( sqlite3VdbeMemConsistentDualRep(pVal) ); return pVal->z; }else{ return 0; @@ -71526,6 +73569,7 @@ SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){ assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) ); assert( (pVal->flags & MEM_RowSet)==0 ); if( (pVal->flags&(MEM_Str|MEM_Term))==(MEM_Str|MEM_Term) && pVal->enc==enc ){ + assert( sqlite3VdbeMemConsistentDualRep(pVal) ); return pVal->z; } if( pVal->flags&MEM_Null ){ @@ -71741,7 +73785,11 @@ static int valueFromExpr( assert( pExpr!=0 ); while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft; +#if defined(SQLITE_ENABLE_STAT3_OR_STAT4) + if( op==TK_REGISTER ) op = pExpr->op2; +#else if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; +#endif /* Compressed expressions only appear when parsing the DEFAULT clause ** on a table column definition, and hence only when pCtx==0. This @@ -71836,7 +73884,10 @@ static int valueFromExpr( return rc; no_mem: - sqlite3OomFault(db); +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 + if( pCtx==0 || pCtx->pParse->nErr==0 ) +#endif + sqlite3OomFault(db); sqlite3DbFree(db, zVal); assert( *ppVal==0 ); #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 @@ -73049,6 +75100,7 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){ case P4_REAL: case P4_INT64: case P4_DYNAMIC: + case P4_DYNBLOB: case P4_INTARRAY: { sqlite3DbFree(db, p4); break; @@ -73590,6 +75642,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ sqlite3XPrintf(&x, "program"); break; } + case P4_DYNBLOB: case P4_ADVANCE: { zTemp[0] = 0; break; @@ -73822,6 +75875,8 @@ SQLITE_PRIVATE int sqlite3VdbeList( int i; /* Loop counter */ int rc = SQLITE_OK; /* Return code */ Mem *pMem = &p->aMem[1]; /* First Mem of result set */ + int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); + Op *pOp = 0; assert( p->explain ); assert( p->magic==VDBE_MAGIC_RUN ); @@ -73834,7 +75889,7 @@ SQLITE_PRIVATE int sqlite3VdbeList( releaseMemArray(pMem, 8); p->pResultSet = 0; - if( p->rc==SQLITE_NOMEM_BKPT ){ + if( p->rc==SQLITE_NOMEM ){ /* This happens if a malloc() inside a call to sqlite3_column_text() or ** sqlite3_column_text16() failed. */ sqlite3OomFault(db); @@ -73849,7 +75904,7 @@ SQLITE_PRIVATE int sqlite3VdbeList( ** encountered, but p->pc will eventually catch up to nRow. */ nRow = p->nOp; - if( p->explain==1 ){ + if( bListSubprogs ){ /* The first 8 memory cells are used for the result set. So we will ** commandeer the 9th cell to use as storage for an array of pointers ** to trigger subprograms. The VDBE is guaranteed to have at least 9 @@ -73869,17 +75924,11 @@ SQLITE_PRIVATE int sqlite3VdbeList( do{ i = p->pc++; - }while( iexplain==2 && p->aOp[i].opcode!=OP_Explain ); - if( i>=nRow ){ - p->rc = SQLITE_OK; - rc = SQLITE_DONE; - }else if( db->u1.isInterrupted ){ - p->rc = SQLITE_INTERRUPT; - rc = SQLITE_ERROR; - sqlite3VdbeError(p, sqlite3ErrStr(p->rc)); - }else{ - char *zP4; - Op *pOp; + if( i>=nRow ){ + p->rc = SQLITE_OK; + rc = SQLITE_DONE; + break; + } if( inOp ){ /* The output line number is small enough that we are still in the ** main program. */ @@ -73894,94 +75943,110 @@ SQLITE_PRIVATE int sqlite3VdbeList( } pOp = &apSub[j]->aOp[i]; } - if( p->explain==1 ){ - pMem->flags = MEM_Int; - pMem->u.i = i; /* Program counter */ - pMem++; - - pMem->flags = MEM_Static|MEM_Str|MEM_Term; - pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ - assert( pMem->z!=0 ); - pMem->n = sqlite3Strlen30(pMem->z); - pMem->enc = SQLITE_UTF8; - pMem++; - /* When an OP_Program opcode is encounter (the only opcode that has - ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms - ** kept in p->aMem[9].z to hold the new program - assuming this subprogram - ** has not already been seen. - */ - if( pOp->p4type==P4_SUBPROGRAM ){ - int nByte = (nSub+1)*sizeof(SubProgram*); - int j; - for(j=0; jp4.pProgram ) break; - } - if( j==nSub && SQLITE_OK==sqlite3VdbeMemGrow(pSub, nByte, nSub!=0) ){ - apSub = (SubProgram **)pSub->z; - apSub[nSub++] = pOp->p4.pProgram; - pSub->flags |= MEM_Blob; - pSub->n = nSub*sizeof(SubProgram*); + /* When an OP_Program opcode is encounter (the only opcode that has + ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms + ** kept in p->aMem[9].z to hold the new program - assuming this subprogram + ** has not already been seen. + */ + if( bListSubprogs && pOp->p4type==P4_SUBPROGRAM ){ + int nByte = (nSub+1)*sizeof(SubProgram*); + int j; + for(j=0; jp4.pProgram ) break; + } + if( j==nSub ){ + p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0); + if( p->rc!=SQLITE_OK ){ + rc = SQLITE_ERROR; + break; } + apSub = (SubProgram **)pSub->z; + apSub[nSub++] = pOp->p4.pProgram; + pSub->flags |= MEM_Blob; + pSub->n = nSub*sizeof(SubProgram*); + nRow += pOp->p4.pProgram->nOp; } } + }while( p->explain==2 && pOp->opcode!=OP_Explain ); - pMem->flags = MEM_Int; - pMem->u.i = pOp->p1; /* P1 */ - pMem++; - - pMem->flags = MEM_Int; - pMem->u.i = pOp->p2; /* P2 */ - pMem++; - - pMem->flags = MEM_Int; - pMem->u.i = pOp->p3; /* P3 */ - pMem++; - - if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */ - assert( p->db->mallocFailed ); - return SQLITE_ERROR; - } - pMem->flags = MEM_Str|MEM_Term; - zP4 = displayP4(pOp, pMem->z, pMem->szMalloc); - if( zP4!=pMem->z ){ - pMem->n = 0; - sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0); + if( rc==SQLITE_OK ){ + if( db->u1.isInterrupted ){ + p->rc = SQLITE_INTERRUPT; + rc = SQLITE_ERROR; + sqlite3VdbeError(p, sqlite3ErrStr(p->rc)); }else{ - assert( pMem->z!=0 ); - pMem->n = sqlite3Strlen30(pMem->z); - pMem->enc = SQLITE_UTF8; - } - pMem++; - - if( p->explain==1 ){ - if( sqlite3VdbeMemClearAndResize(pMem, 4) ){ - assert( p->db->mallocFailed ); - return SQLITE_ERROR; + char *zP4; + if( p->explain==1 ){ + pMem->flags = MEM_Int; + pMem->u.i = i; /* Program counter */ + pMem++; + + pMem->flags = MEM_Static|MEM_Str|MEM_Term; + pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ + assert( pMem->z!=0 ); + pMem->n = sqlite3Strlen30(pMem->z); + pMem->enc = SQLITE_UTF8; + pMem++; } - pMem->flags = MEM_Str|MEM_Term; - pMem->n = 2; - sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */ - pMem->enc = SQLITE_UTF8; + + pMem->flags = MEM_Int; + pMem->u.i = pOp->p1; /* P1 */ pMem++; - -#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS - if( sqlite3VdbeMemClearAndResize(pMem, 500) ){ + + pMem->flags = MEM_Int; + pMem->u.i = pOp->p2; /* P2 */ + pMem++; + + pMem->flags = MEM_Int; + pMem->u.i = pOp->p3; /* P3 */ + pMem++; + + if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */ assert( p->db->mallocFailed ); return SQLITE_ERROR; } pMem->flags = MEM_Str|MEM_Term; - pMem->n = displayComment(pOp, zP4, pMem->z, 500); - pMem->enc = SQLITE_UTF8; -#else - pMem->flags = MEM_Null; /* Comment */ -#endif - } + zP4 = displayP4(pOp, pMem->z, pMem->szMalloc); + if( zP4!=pMem->z ){ + pMem->n = 0; + sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0); + }else{ + assert( pMem->z!=0 ); + pMem->n = sqlite3Strlen30(pMem->z); + pMem->enc = SQLITE_UTF8; + } + pMem++; - p->nResColumn = 8 - 4*(p->explain-1); - p->pResultSet = &p->aMem[1]; - p->rc = SQLITE_OK; - rc = SQLITE_ROW; + if( p->explain==1 ){ + if( sqlite3VdbeMemClearAndResize(pMem, 4) ){ + assert( p->db->mallocFailed ); + return SQLITE_ERROR; + } + pMem->flags = MEM_Str|MEM_Term; + pMem->n = 2; + sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */ + pMem->enc = SQLITE_UTF8; + pMem++; + +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS + if( sqlite3VdbeMemClearAndResize(pMem, 500) ){ + assert( p->db->mallocFailed ); + return SQLITE_ERROR; + } + pMem->flags = MEM_Str|MEM_Term; + pMem->n = displayComment(pOp, zP4, pMem->z, 500); + pMem->enc = SQLITE_UTF8; +#else + pMem->flags = MEM_Null; /* Comment */ +#endif + } + + p->nResColumn = 8 - 4*(p->explain-1); + p->pResultSet = &p->aMem[1]; + p->rc = SQLITE_OK; + rc = SQLITE_ROW; + } } return rc; } @@ -74451,6 +76516,7 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){ pPager = sqlite3BtreePager(pBt); if( db->aDb[i].safety_level!=PAGER_SYNCHRONOUS_OFF && aMJNeeded[sqlite3PagerGetJournalMode(pPager)] + && sqlite3PagerIsMemdb(pPager)==0 ){ assert( i!=1 ); nTrans++; @@ -75226,7 +77292,7 @@ SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){ SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){ sqlite3 *db; - if( NEVER(p==0) ) return; + assert( p!=0 ); db = p->db; assert( sqlite3_mutex_held(db->mutex) ); sqlite3VdbeClearObject(db, p); @@ -75622,7 +77688,13 @@ SQLITE_PRIVATE u32 sqlite3VdbeSerialGet( Mem *pMem /* Memory cell to write value into */ ){ switch( serial_type ){ - case 10: /* Reserved for future use */ + case 10: { /* Internal use only: NULL with virtual table + ** UPDATE no-change flag set */ + pMem->flags = MEM_Null|MEM_Zero; + pMem->n = 0; + pMem->u.nZero = 0; + break; + } case 11: /* Reserved for future use */ case 0: { /* Null */ /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */ @@ -77175,6 +79247,11 @@ SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){ return aType[pVal->flags&MEM_AffMask]; } +/* Return true if a parameter to xUpdate represents an unchanged column */ +SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){ + return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero); +} + /* Make a copy of an sqlite3_value object */ SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){ @@ -77274,14 +79351,12 @@ SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); pCtx->isError = SQLITE_ERROR; - pCtx->fErrorOrAux = 1; sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); } #ifndef SQLITE_OMIT_UTF16 SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); pCtx->isError = SQLITE_ERROR; - pCtx->fErrorOrAux = 1; sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); } #endif @@ -77387,8 +79462,7 @@ SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){ return SQLITE_OK; } SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ - pCtx->isError = errCode; - pCtx->fErrorOrAux = 1; + pCtx->isError = errCode ? errCode : -1; #ifdef SQLITE_DEBUG if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; #endif @@ -77402,7 +79476,6 @@ SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); pCtx->isError = SQLITE_TOOBIG; - pCtx->fErrorOrAux = 1; sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1, SQLITE_UTF8, SQLITE_STATIC); } @@ -77412,7 +79485,6 @@ SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); sqlite3VdbeMemSetNull(pCtx->pOut); pCtx->isError = SQLITE_NOMEM_BKPT; - pCtx->fErrorOrAux = 1; sqlite3OomFault(pCtx->pOut->db); } @@ -77652,6 +79724,25 @@ SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){ return p->pOut->db; } +/* +** If this routine is invoked from within an xColumn method of a virtual +** table, then it returns true if and only if the the call is during an +** UPDATE operation and the value of the column will not be modified +** by the UPDATE. +** +** If this routine is called from any context other than within the +** xColumn method of a virtual table, then the return value is meaningless +** and arbitrary. +** +** Virtual table implements might use this routine to optimize their +** performance by substituting a NULL result, or some other light-weight +** value, as a signal to the xUpdate routine that the column is unchanged. +*/ +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){ + assert( p ); + return sqlite3_value_nochange(p->pOut); +} + /* ** Return the current time for a statement. If the current time ** is requested more than once within the same run of a single prepared @@ -77800,10 +79891,7 @@ SQLITE_API void sqlite3_set_auxdata( pAuxData->iAuxArg = iArg; pAuxData->pNextAux = pVdbe->pAuxData; pVdbe->pAuxData = pAuxData; - if( pCtx->fErrorOrAux==0 ){ - pCtx->isError = 0; - pCtx->fErrorOrAux = 1; - } + if( pCtx->isError==0 ) pCtx->isError = -1; }else if( pAuxData->xDeleteAux ){ pAuxData->xDeleteAux(pAuxData->pAux); } @@ -78559,7 +80647,9 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ Vdbe *pVdbe = (Vdbe*)pStmt; u32 v; #ifdef SQLITE_ENABLE_API_ARMOR - if( !pStmt ){ + if( !pStmt + || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter))) + ){ (void)SQLITE_MISUSE_BKPT; return 0; } @@ -79333,6 +81423,11 @@ static void applyNumericAffinity(Mem *pRec, int bTryForInt){ pRec->flags |= MEM_Real; if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec); } + /* TEXT->NUMERIC is many->one. Hence, it is important to invalidate the + ** string representation after computing a numeric equivalent, because the + ** string representation might not be the canonical representation for the + ** numeric value. Ticket [343634942dd54ab57b7024] 2018-01-31. */ + pRec->flags &= ~MEM_Str; } /* @@ -79533,7 +81628,7 @@ static void memTracePrint(Mem *p){ if( p->flags & MEM_Undefined ){ printf(" undefined"); }else if( p->flags & MEM_Null ){ - printf(" NULL"); + printf(p->flags & MEM_Zero ? " NULL-nochng" : " NULL"); }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ printf(" si:%lld", p->u.i); }else if( p->flags & MEM_Int ){ @@ -79801,7 +81896,7 @@ SQLITE_PRIVATE int sqlite3VdbeExec( assert( pOp>=aOp && pOp<&aOp[p->nOp]); #ifdef VDBE_PROFILE - start = sqlite3Hwtime(); + start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime(); #endif nVmStep++; #ifdef SQLITE_ENABLE_STMT_SCANSTATUS @@ -81325,18 +83420,8 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ - pIn1 = &aMem[pOp->p1]; - if( pIn1->flags & MEM_Null ){ - v1 = 2; - }else{ - v1 = sqlite3VdbeIntValue(pIn1)!=0; - } - pIn2 = &aMem[pOp->p2]; - if( pIn2->flags & MEM_Null ){ - v2 = 2; - }else{ - v2 = sqlite3VdbeIntValue(pIn2)!=0; - } + v1 = sqlite3VdbeBooleanValue(&aMem[pOp->p1], 2); + v2 = sqlite3VdbeBooleanValue(&aMem[pOp->p2], 2); if( pOp->opcode==OP_And ){ static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; v1 = and_logic[v1*3+v2]; @@ -81354,6 +83439,35 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ break; } +/* Opcode: IsTrue P1 P2 P3 P4 * +** Synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 +** +** This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and +** IS NOT FALSE operators. +** +** Interpret the value in register P1 as a boolean value. Store that +** boolean (a 0 or 1) in register P2. Or if the value in register P1 is +** NULL, then the P3 is stored in register P2. Invert the answer if P4 +** is 1. +** +** The logic is summarized like this: +** +**
    +**
  • If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE +**
  • If P3==1 and P4==1 then r[P2] := r[P1] IS FALSE +**
  • If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE +**
  • If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE +**
+*/ +case OP_IsTrue: { /* in1, out2 */ + assert( pOp->p4type==P4_INT32 ); + assert( pOp->p4.i==0 || pOp->p4.i==1 ); + assert( pOp->p3==0 || pOp->p3==1 ); + sqlite3VdbeMemSetInt64(&aMem[pOp->p2], + sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3) ^ pOp->p4.i); + break; +} + /* Opcode: Not P1 P2 * * * ** Synopsis: r[P2]= !r[P1] ** @@ -81364,10 +83478,10 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ case OP_Not: { /* same as TK_NOT, in1, out2 */ pIn1 = &aMem[pOp->p1]; pOut = &aMem[pOp->p2]; - sqlite3VdbeMemSetNull(pOut); if( (pIn1->flags & MEM_Null)==0 ){ - pOut->flags = MEM_Int; - pOut->u.i = !sqlite3VdbeIntValue(pIn1); + sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0)); + }else{ + sqlite3VdbeMemSetNull(pOut); } break; } @@ -81434,30 +83548,25 @@ case OP_Once: { /* jump */ ** is considered true if it is numeric and non-zero. If the value ** in P1 is NULL then take the jump if and only if P3 is non-zero. */ +case OP_If: { /* jump, in1 */ + int c; + c = sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3); + VdbeBranchTaken(c!=0, 2); + if( c ) goto jump_to_p2; + break; +} + /* Opcode: IfNot P1 P2 P3 * * ** ** Jump to P2 if the value in register P1 is False. The value ** is considered false if it has a numeric value of zero. If the value ** in P1 is NULL then take the jump if and only if P3 is non-zero. */ -case OP_If: /* jump, in1 */ case OP_IfNot: { /* jump, in1 */ int c; - pIn1 = &aMem[pOp->p1]; - if( pIn1->flags & MEM_Null ){ - c = pOp->p3; - }else{ -#ifdef SQLITE_OMIT_FLOATING_POINT - c = sqlite3VdbeIntValue(pIn1)!=0; -#else - c = sqlite3VdbeRealValue(pIn1)!=0.0; -#endif - if( pOp->opcode==OP_IfNot ) c = !c; - } + c = !sqlite3VdbeBooleanValue(&aMem[pOp->p1], !pOp->p3); VdbeBranchTaken(c!=0, 2); - if( c ){ - goto jump_to_p2; - } + if( c ) goto jump_to_p2; break; } @@ -81507,6 +83616,36 @@ case OP_IfNullRow: { /* jump */ break; } +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC +/* Opcode: Offset P1 P2 P3 * * +** Synopsis: r[P3] = sqlite_offset(P1) +** +** Store in register r[P3] the byte offset into the database file that is the +** start of the payload for the record at which that cursor P1 is currently +** pointing. +** +** P2 is the column number for the argument to the sqlite_offset() function. +** This opcode does not use P2 itself, but the P2 value is used by the +** code generator. The P1, P2, and P3 operands to this opcode are the +** same as for OP_Column. +** +** This opcode is only available if SQLite is compiled with the +** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option. +*/ +case OP_Offset: { /* out3 */ + VdbeCursor *pC; /* The VDBE cursor */ + assert( pOp->p1>=0 && pOp->p1nCursor ); + pC = p->apCsr[pOp->p1]; + pOut = &p->aMem[pOp->p3]; + if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){ + sqlite3VdbeMemSetNull(pOut); + }else{ + sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); + } + break; +} +#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */ + /* Opcode: Column P1 P2 P3 P4 P5 ** Synopsis: r[P3]=PX ** @@ -81920,9 +84059,18 @@ case OP_MakeRecord: { pRec = pLast; do{ assert( memIsValid(pRec) ); - pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format, &len); + serial_type = sqlite3VdbeSerialType(pRec, file_format, &len); if( pRec->flags & MEM_Zero ){ - if( nData ){ + if( serial_type==0 ){ + /* Values with MEM_Null and MEM_Zero are created by xColumn virtual + ** table methods that never invoke sqlite3_result_xxxxx() while + ** computing an unchanging column value in an UPDATE statement. + ** Give such values a special internal-use-only serial-type of 10 + ** so that they can be passed through to xUpdate and have + ** a true sqlite3_value_nochange(). */ + assert( pOp->p5==OPFLAG_NOCHNG_MAGIC || CORRUPT_DB ); + serial_type = 10; + }else if( nData ){ if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem; }else{ nZero += pRec->u.nZero; @@ -81933,6 +84081,7 @@ case OP_MakeRecord: { testcase( serial_type==127 ); testcase( serial_type==128 ); nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); + pRec->uTemp = serial_type; if( pRec==pData0 ) break; pRec--; }while(1); @@ -83386,6 +85535,10 @@ case OP_NewRowid: { /* out2 */ pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; + if( !pC->isTable ){ + rc = SQLITE_CORRUPT_BKPT; + goto abort_due_to_error; + } assert( pC!=0 ); assert( pC->eCurType==CURTYPE_BTREE ); assert( pC->uc.pCursor!=0 ); @@ -83543,10 +85696,8 @@ case OP_InsertInt: { int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ const char *zDb; /* database name - used by the update hook */ Table *pTab; /* Table structure - used by update and pre-update hooks */ - int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ BtreePayload x; /* Payload to be inserted */ - op = 0; pData = &aMem[pOp->p2]; assert( pOp->p1>=0 && pOp->p1nCursor ); assert( memIsValid(pData) ); @@ -83574,19 +85725,21 @@ case OP_InsertInt: { zDb = db->aDb[pC->iDb].zDbSName; pTab = pOp->p4.pTab; assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) ); - op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); }else{ - pTab = 0; /* Not needed. Silence a compiler warning. */ + pTab = 0; zDb = 0; /* Not needed. Silence a compiler warning. */ } #ifdef SQLITE_ENABLE_PREUPDATE_HOOK /* Invoke the pre-update hook, if any */ - if( db->xPreUpdateCallback - && pOp->p4type==P4_TABLE - && !(pOp->p5 & OPFLAG_ISUPDATE) - ){ - sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2); + if( pTab ){ + if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){ + sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2); + } + if( db->xUpdateCallback==0 || pTab->aCol==0 ){ + /* Prevent post-update hook from running in cases when it should not */ + pTab = 0; + } } if( pOp->p5 & OPFLAG_ISNOOP ) break; #endif @@ -83611,8 +85764,12 @@ case OP_InsertInt: { /* Invoke the update-hook if required. */ if( rc ) goto abort_due_to_error; - if( db->xUpdateCallback && op ){ - db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, x.nKey); + if( pTab ){ + assert( db->xUpdateCallback!=0 ); + assert( pTab->aCol!=0 ); + db->xUpdateCallback(db->pUpdateArg, + (pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT, + zDb, pTab->zName, x.nKey); } break; } @@ -85318,12 +87475,17 @@ case OP_AggStep0: { assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) ); assert( pOp->p3p2 || pOp->p3>=pOp->p2+n ); - pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*)); + pCtx = sqlite3DbMallocRawNN(db, n*sizeof(sqlite3_value*) + + (sizeof(pCtx[0]) + sizeof(Mem) - sizeof(sqlite3_value*))); if( pCtx==0 ) goto no_mem; pCtx->pMem = 0; + pCtx->pOut = (Mem*)&(pCtx->argv[n]); + sqlite3VdbeMemInit(pCtx->pOut, db, MEM_Null); pCtx->pFunc = pOp->p4.pFunc; pCtx->iOp = (int)(pOp - aOp); pCtx->pVdbe = p; + pCtx->skipFlag = 0; + pCtx->isError = 0; pCtx->argc = n; pOp->p4type = P4_FUNCCTX; pOp->p4.pCtx = pCtx; @@ -85334,7 +87496,6 @@ case OP_AggStep: { int i; sqlite3_context *pCtx; Mem *pMem; - Mem t; assert( pOp->p4type==P4_FUNCCTX ); pCtx = pOp->p4.pCtx; @@ -85357,26 +87518,28 @@ case OP_AggStep: { #endif pMem->n++; - sqlite3VdbeMemInit(&t, db, MEM_Null); - pCtx->pOut = &t; - pCtx->fErrorOrAux = 0; - pCtx->skipFlag = 0; + assert( pCtx->pOut->flags==MEM_Null ); + assert( pCtx->isError==0 ); + assert( pCtx->skipFlag==0 ); (pCtx->pFunc->xSFunc)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ - if( pCtx->fErrorOrAux ){ - if( pCtx->isError ){ - sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); + if( pCtx->isError ){ + if( pCtx->isError>0 ){ + sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); rc = pCtx->isError; } - sqlite3VdbeMemRelease(&t); + if( pCtx->skipFlag ){ + assert( pOp[-1].opcode==OP_CollSeq ); + i = pOp[-1].p1; + if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); + pCtx->skipFlag = 0; + } + sqlite3VdbeMemRelease(pCtx->pOut); + pCtx->pOut->flags = MEM_Null; + pCtx->isError = 0; if( rc ) goto abort_due_to_error; - }else{ - assert( t.flags==MEM_Null ); - } - if( pCtx->skipFlag ){ - assert( pOp[-1].opcode==OP_CollSeq ); - i = pOp[-1].p1; - if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); } + assert( pCtx->pOut->flags==MEM_Null ); + assert( pCtx->skipFlag==0 ); break; } @@ -85821,12 +87984,18 @@ case OP_VFilter: { /* jump */ #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifndef SQLITE_OMIT_VIRTUALTABLE -/* Opcode: VColumn P1 P2 P3 * * +/* Opcode: VColumn P1 P2 P3 * P5 ** Synopsis: r[P3]=vcolumn(P2) ** -** Store the value of the P2-th column of -** the row of the virtual-table that the -** P1 cursor is pointing to into register P3. +** Store in register P3 the value of the P2-th column of +** the current row of the virtual-table of cursor P1. +** +** If the VColumn opcode is being used to fetch the value of +** an unchanging column during an UPDATE operation, then the P5 +** value is 1. Otherwise, P5 is 0. The P5 value is returned +** by sqlite3_vtab_nochange() routine can can be used +** by virtual table implementations to return special "no-change" +** marks which can be more efficient, depending on the virtual table. */ case OP_VColumn: { sqlite3_vtab *pVtab; @@ -85848,10 +88017,17 @@ case OP_VColumn: { assert( pModule->xColumn ); memset(&sContext, 0, sizeof(sContext)); sContext.pOut = pDest; - MemSetTypeFlag(pDest, MEM_Null); + if( pOp->p5 ){ + sqlite3VdbeMemSetNull(pDest); + pDest->flags = MEM_Null|MEM_Zero; + pDest->u.nZero = 0; + }else{ + MemSetTypeFlag(pDest, MEM_Null); + } rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2); sqlite3VtabImportErrmsg(p, pVtab); - if( sContext.isError ){ + if( sContext.isError>0 ){ + sqlite3VdbeError(p, "%s", sqlite3_value_text(pDest)); rc = sContext.isError; } sqlite3VdbeChangeEncoding(pDest, encoding); @@ -86116,6 +88292,7 @@ case OP_Function0: { pCtx->pFunc = pOp->p4.pFunc; pCtx->iOp = (int)(pOp - aOp); pCtx->pVdbe = p; + pCtx->isError = 0; pCtx->argc = n; pOp->p4type = P4_FUNCCTX; pOp->p4.pCtx = pCtx; @@ -86150,16 +88327,17 @@ case OP_Function: { } #endif MemSetTypeFlag(pOut, MEM_Null); - pCtx->fErrorOrAux = 0; + assert( pCtx->isError==0 ); (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ /* If the function returned an error, throw an exception */ - if( pCtx->fErrorOrAux ){ - if( pCtx->isError ){ + if( pCtx->isError ){ + if( pCtx->isError>0 ){ sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut)); rc = pCtx->isError; } sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1); + pCtx->isError = 0; if( rc ) goto abort_due_to_error; } @@ -86174,7 +88352,13 @@ case OP_Function: { break; } - +/* Opcode: Trace P1 P2 * P4 * +** +** Write P4 on the statement trace output if statement tracing is +** enabled. +** +** Operand P1 must be 0x7fffffff and P2 must positive. +*/ /* Opcode: Init P1 P2 P3 P4 * ** Synopsis: Start at P2 ** @@ -86193,9 +88377,12 @@ case OP_Function: { ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT ** error is encountered. */ +case OP_Trace: case OP_Init: { /* jump */ - char *zTrace; int i; +#ifndef SQLITE_OMIT_TRACE + char *zTrace; +#endif /* If the P4 argument is not NULL, then it must be an SQL comment string. ** The "--" string is broken up to prevent false-positives with srcck1.c. @@ -86207,7 +88394,9 @@ case OP_Init: { /* jump */ ** sqlite3_expanded_sql(P) otherwise. */ assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 ); - assert( pOp==p->aOp ); /* Always instruction 0 */ + + /* OP_Init is always instruction 0 */ + assert( pOp==p->aOp || pOp->opcode==OP_Trace ); #ifndef SQLITE_OMIT_TRACE if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0 @@ -86250,6 +88439,7 @@ case OP_Init: { /* jump */ #endif /* SQLITE_OMIT_TRACE */ assert( pOp->p2>0 ); if( pOp->p1>=sqlite3GlobalConfig.iOnceResetThreshold ){ + if( pOp->opcode==OP_Trace ) break; for(i=1; inOp; i++){ if( p->aOp[i].opcode==OP_Once ) p->aOp[i].p1 = 0; } @@ -86309,7 +88499,7 @@ default: { /* This is really OP_Noop and OP_Explain */ #ifdef VDBE_PROFILE { - u64 endTime = sqlite3Hwtime(); + u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime(); if( endTime>start ) pOrigOp->cycles += endTime - start; pOrigOp->cnt++; } @@ -90194,7 +92384,6 @@ SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker *pWalker, Select *p){ if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort; if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort; if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort; - if( sqlite3WalkExpr(pWalker, p->pOffset) ) return WRC_Abort; return WRC_Continue; } @@ -90211,16 +92400,15 @@ SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker *pWalker, Select *p){ struct SrcList_item *pItem; pSrc = p->pSrc; - if( ALWAYS(pSrc) ){ - for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ - if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){ - return WRC_Abort; - } - if( pItem->fg.isTabFunc - && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg) - ){ - return WRC_Abort; - } + assert( pSrc!=0 ); + for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ + if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){ + return WRC_Abort; + } + if( pItem->fg.isTabFunc + && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg) + ){ + return WRC_Abort; } } return WRC_Continue; @@ -90698,10 +92886,16 @@ static int lookupName( ** Because no reference was made to outer contexts, the pNC->nRef ** fields are not changed in any context. */ - if( cnt==0 && zTab==0 && ExprHasProperty(pExpr,EP_DblQuoted) ){ - pExpr->op = TK_STRING; - pExpr->pTab = 0; - return WRC_Prune; + if( cnt==0 && zTab==0 ){ + assert( pExpr->op==TK_ID ); + if( ExprHasProperty(pExpr,EP_DblQuoted) ){ + pExpr->op = TK_STRING; + pExpr->pTab = 0; + return WRC_Prune; + } + if( sqlite3ExprIdToTrueFalse(pExpr) ){ + return WRC_Prune; + } } /* @@ -90863,7 +93057,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ SrcList *pSrcList = pNC->pSrcList; struct SrcList_item *pItem; assert( pSrcList && pSrcList->nSrc==1 ); - pItem = pSrcList->a; + pItem = pSrcList->a; + assert( HasRowid(pItem->pTab) && pItem->pTab->pSelect==0 ); pExpr->op = TK_COLUMN; pExpr->pTab = pItem->pTab; pExpr->iTable = pItem->iCursor; @@ -91049,15 +93244,30 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr); break; } + case TK_IS: + case TK_ISNOT: { + Expr *pRight; + assert( !ExprHasProperty(pExpr, EP_Reduced) ); + /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE", + ** and "x IS NOT FALSE". */ + if( (pRight = pExpr->pRight)->op==TK_ID ){ + int rc = resolveExprStep(pWalker, pRight); + if( rc==WRC_Abort ) return WRC_Abort; + if( pRight->op==TK_TRUEFALSE ){ + pExpr->op2 = pExpr->op; + pExpr->op = TK_TRUTH; + return WRC_Continue; + } + } + /* Fall thru */ + } case TK_BETWEEN: case TK_EQ: case TK_NE: case TK_LT: case TK_LE: case TK_GT: - case TK_GE: - case TK_IS: - case TK_ISNOT: { + case TK_GE: { int nLeft, nRight; if( pParse->db->mallocFailed ) break; assert( pExpr->pLeft!=0 ); @@ -91462,8 +93672,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ */ memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; - if( sqlite3ResolveExprNames(&sNC, p->pLimit) || - sqlite3ResolveExprNames(&sNC, p->pOffset) ){ + if( sqlite3ResolveExprNames(&sNC, p->pLimit) ){ return WRC_Abort; } @@ -92459,16 +94668,15 @@ static void heightOfExprList(ExprList *p, int *pnHeight){ } } } -static void heightOfSelect(Select *p, int *pnHeight){ - if( p ){ +static void heightOfSelect(Select *pSelect, int *pnHeight){ + Select *p; + for(p=pSelect; p; p=p->pPrior){ heightOfExpr(p->pWhere, pnHeight); heightOfExpr(p->pHaving, pnHeight); heightOfExpr(p->pLimit, pnHeight); - heightOfExpr(p->pOffset, pnHeight); heightOfExprList(p->pEList, pnHeight); heightOfExprList(p->pGroupBy, pnHeight); heightOfExprList(p->pOrderBy, pnHeight); - heightOfSelect(p->pPrior, pnHeight); } } @@ -92753,6 +94961,7 @@ SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token * return 0; } pNew->x.pList = pList; + ExprSetProperty(pNew, EP_HasFunc); assert( !ExprHasProperty(pNew, EP_xIsSelect) ); sqlite3ExprSetHeightAndFlags(pParse, pNew); return pNew; @@ -93262,7 +95471,6 @@ SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){ pNew->pNext = pNext; pNew->pPrior = 0; pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); - pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); pNew->iLimit = 0; pNew->iOffset = 0; pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; @@ -93456,17 +95664,16 @@ SQLITE_PRIVATE void sqlite3ExprListSetName( SQLITE_PRIVATE void sqlite3ExprListSetSpan( Parse *pParse, /* Parsing context */ ExprList *pList, /* List to which to add the span. */ - ExprSpan *pSpan /* The span to be added */ + const char *zStart, /* Start of the span */ + const char *zEnd /* End of the span */ ){ sqlite3 *db = pParse->db; assert( pList!=0 || db->mallocFailed!=0 ); if( pList ){ struct ExprList_item *pItem = &pList->a[pList->nExpr-1]; assert( pList->nExpr>0 ); - assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr ); sqlite3DbFree(db, pItem->zSpan); - pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart, - (int)(pSpan->zEnd - pSpan->zStart)); + pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd); } } @@ -93535,6 +95742,34 @@ SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){ return WRC_Abort; } +/* +** If the input expression is an ID with the name "true" or "false" +** then convert it into an TK_TRUEFALSE term. Return non-zero if +** the conversion happened, and zero if the expression is unaltered. +*/ +SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ + assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); + if( sqlite3StrICmp(pExpr->u.zToken, "true")==0 + || sqlite3StrICmp(pExpr->u.zToken, "false")==0 + ){ + pExpr->op = TK_TRUEFALSE; + return 1; + } + return 0; +} + +/* +** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE +** and 0 if it is FALSE. +*/ +SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ + assert( pExpr->op==TK_TRUEFALSE ); + assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 + || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); + return pExpr->u.zToken[4]==0; +} + + /* ** These routines are Walker callbacks used to check expressions to ** see if they are "constant" for some definition of constant. The @@ -93582,6 +95817,12 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ return WRC_Abort; } case TK_ID: + /* Convert "true" or "false" in a DEFAULT clause into the + ** appropriate TK_TRUEFALSE operator */ + if( sqlite3ExprIdToTrueFalse(pExpr) ){ + return WRC_Prune; + } + /* Fall thru */ case TK_COLUMN: case TK_AGG_FUNCTION: case TK_AGG_COLUMN: @@ -93899,7 +96140,6 @@ static Select *isCandidateForInOpt(Expr *pX){ } assert( p->pGroupBy==0 ); /* Has no GROUP BY clause */ if( p->pLimit ) return 0; /* Has no LIMIT clause */ - assert( p->pOffset==0 ); /* No LIMIT means no OFFSET */ if( p->pWhere ) return 0; /* Has no WHERE clause */ pSrc = p->pSrc; assert( pSrc!=0 ); @@ -93989,16 +96229,15 @@ static int sqlite3InRhsIsConstant(Expr *pIn){ ** pX->iTable made to point to the ephemeral table instead of an ** existing table. ** -** The inFlags parameter must contain exactly one of the bits -** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains -** IN_INDEX_MEMBERSHIP, then the generated table will be used for a -** fast membership test. When the IN_INDEX_LOOP bit is set, the -** IN index will be used to loop over all values of the RHS of the -** IN operator. +** The inFlags parameter must contain, at a minimum, one of the bits +** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains +** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast +** membership test. When the IN_INDEX_LOOP bit is set, the IN index will +** be used to loop over all values of the RHS of the IN operator. ** ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate ** through the set members) then the b-tree must not contain duplicates. -** An epheremal table must be used unless the selected columns are guaranteed +** An epheremal table will be created unless the selected columns are guaranteed ** to be unique - either because it is an INTEGER PRIMARY KEY or due to ** a UNIQUE constraint or index. ** @@ -94539,6 +96778,7 @@ SQLITE_PRIVATE int sqlite3CodeSubselect( Select *pSel; /* SELECT statement to encode */ SelectDest dest; /* How to deal with SELECT result */ int nReg; /* Registers to allocate */ + Expr *pLimit; /* New limit expression */ testcase( pExpr->op==TK_EXISTS ); testcase( pExpr->op==TK_SELECT ); @@ -94560,11 +96800,14 @@ SQLITE_PRIVATE int sqlite3CodeSubselect( sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm); VdbeComment((v, "Init EXISTS result")); } - sqlite3ExprDelete(pParse->db, pSel->pLimit); - pSel->pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER, - &sqlite3IntTokens[1], 0); + pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0); + if( pSel->pLimit ){ + sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft); + pSel->pLimit->pLeft = pLimit; + }else{ + pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0); + } pSel->iLimit = 0; - pSel->selFlags &= ~SF_MultiValue; if( sqlite3Select(pParse, pSel, &dest) ){ return 0; } @@ -95344,6 +97587,10 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) codeInteger(pParse, pExpr, 0, target); return target; } + case TK_TRUEFALSE: { + sqlite3VdbeAddOp2(v, OP_Integer, sqlite3ExprTruthValue(pExpr), target); + return target; + } #ifndef SQLITE_OMIT_FLOATING_POINT case TK_FLOAT: { assert( !ExprHasProperty(pExpr, EP_IntValue) ); @@ -95499,6 +97746,18 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) sqlite3VdbeAddOp2(v, op, r1, inReg); break; } + case TK_TRUTH: { + int isTrue; /* IS TRUE or IS NOT TRUE */ + int bNormal; /* IS TRUE or IS FALSE */ + r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); + testcase( regFree1==0 ); + isTrue = sqlite3ExprTruthValue(pExpr->pRight); + bNormal = pExpr->op2==TK_IS; + testcase( isTrue && bNormal); + testcase( !isTrue && bNormal); + sqlite3VdbeAddOp4Int(v, OP_IsTrue, r1, inReg, !isTrue, isTrue ^ bNormal); + break; + } case TK_ISNULL: case TK_NOTNULL: { int addr; @@ -95670,9 +97929,21 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target) if( !pColl ) pColl = db->pDfltColl; sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); } - sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0, - constMask, r1, target, (char*)pDef, P4_FUNCDEF); - sqlite3VdbeChangeP5(v, (u8)nFarg); +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC + if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){ + Expr *pArg = pFarg->a[0].pExpr; + if( pArg->op==TK_COLUMN ){ + sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target); + }else{ + sqlite3VdbeAddOp2(v, OP_Null, 0, target); + } + }else +#endif + { + sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0, + constMask, r1, target, (char*)pDef, P4_FUNCDEF); + sqlite3VdbeChangeP5(v, (u8)nFarg); + } if( nFarg && constMask==0 ){ sqlite3ReleaseTempRange(pParse, r1, nFarg); } @@ -96262,6 +98533,23 @@ SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); break; } + case TK_TRUTH: { + int isNot; /* IS NOT TRUE or IS NOT FALSE */ + int isTrue; /* IS TRUE or IS NOT TRUE */ + testcase( jumpIfNull==0 ); + isNot = pExpr->op2==TK_ISNOT; + isTrue = sqlite3ExprTruthValue(pExpr->pRight); + testcase( isTrue && isNot ); + testcase( !isTrue && isNot ); + if( isTrue ^ isNot ){ + sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, + isNot ? SQLITE_JUMPIFNULL : 0); + }else{ + sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, + isNot ? SQLITE_JUMPIFNULL : 0); + } + break; + } case TK_IS: case TK_ISNOT: testcase( op==TK_IS ); @@ -96416,6 +98704,26 @@ SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); break; } + case TK_TRUTH: { + int isNot; /* IS NOT TRUE or IS NOT FALSE */ + int isTrue; /* IS TRUE or IS NOT TRUE */ + testcase( jumpIfNull==0 ); + isNot = pExpr->op2==TK_ISNOT; + isTrue = sqlite3ExprTruthValue(pExpr->pRight); + testcase( isTrue && isNot ); + testcase( !isTrue && isNot ); + if( isTrue ^ isNot ){ + /* IS TRUE and IS NOT FALSE */ + sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, + isNot ? 0 : SQLITE_JUMPIFNULL); + + }else{ + /* IS FALSE and IS NOT TRUE */ + sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, + isNot ? 0 : SQLITE_JUMPIFNULL); + } + break; + } case TK_IS: case TK_ISNOT: testcase( pExpr->op==TK_IS ); @@ -96703,6 +99011,105 @@ SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse *pParse, Expr *pE1, Expr *pE2, i return 0; } +/* +** This is the Expr node callback for sqlite3ExprImpliesNotNullRow(). +** If the expression node requires that the table at pWalker->iCur +** have a non-NULL column, then set pWalker->eCode to 1 and abort. +*/ +static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ + /* This routine is only called for WHERE clause expressions and so it + ** cannot have any TK_AGG_COLUMN entries because those are only found + ** in HAVING clauses. We can get a TK_AGG_FUNCTION in a WHERE clause, + ** but that is an illegal construct and the query will be rejected at + ** a later stage of processing, so the TK_AGG_FUNCTION case does not + ** need to be considered here. */ + assert( pExpr->op!=TK_AGG_COLUMN ); + testcase( pExpr->op==TK_AGG_FUNCTION ); + + if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune; + switch( pExpr->op ){ + case TK_ISNOT: + case TK_NOT: + case TK_ISNULL: + case TK_IS: + case TK_OR: + case TK_CASE: + case TK_IN: + case TK_FUNCTION: + testcase( pExpr->op==TK_ISNOT ); + testcase( pExpr->op==TK_NOT ); + testcase( pExpr->op==TK_ISNULL ); + testcase( pExpr->op==TK_IS ); + testcase( pExpr->op==TK_OR ); + testcase( pExpr->op==TK_CASE ); + testcase( pExpr->op==TK_IN ); + testcase( pExpr->op==TK_FUNCTION ); + return WRC_Prune; + case TK_COLUMN: + if( pWalker->u.iCur==pExpr->iTable ){ + pWalker->eCode = 1; + return WRC_Abort; + } + return WRC_Prune; + + /* Virtual tables are allowed to use constraints like x=NULL. So + ** a term of the form x=y does not prove that y is not null if x + ** is the column of a virtual table */ + case TK_EQ: + case TK_NE: + case TK_LT: + case TK_LE: + case TK_GT: + case TK_GE: + testcase( pExpr->op==TK_EQ ); + testcase( pExpr->op==TK_NE ); + testcase( pExpr->op==TK_LT ); + testcase( pExpr->op==TK_LE ); + testcase( pExpr->op==TK_GT ); + testcase( pExpr->op==TK_GE ); + if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->pTab)) + || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->pTab)) + ){ + return WRC_Prune; + } + default: + return WRC_Continue; + } +} + +/* +** Return true (non-zero) if expression p can only be true if at least +** one column of table iTab is non-null. In other words, return true +** if expression p will always be NULL or false if every column of iTab +** is NULL. +** +** False negatives are acceptable. In other words, it is ok to return +** zero even if expression p will never be true of every column of iTab +** is NULL. A false negative is merely a missed optimization opportunity. +** +** False positives are not allowed, however. A false positive may result +** in an incorrect answer. +** +** Terms of p that are marked with EP_FromJoin (and hence that come from +** the ON or USING clauses of LEFT JOINS) are excluded from the analysis. +** +** This routine is used to check if a LEFT JOIN can be converted into +** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE +** clause requires that some column of the right table of the LEFT JOIN +** be non-NULL, then the LEFT JOIN can be safely converted into an +** ordinary join. +*/ +SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){ + Walker w; + w.xExprCallback = impliesNotNullRow; + w.xSelectCallback = 0; + w.xSelectCallback2 = 0; + w.eCode = 0; + w.u.iCur = iTab; + sqlite3WalkExpr(&w, p); + return w.eCode; +} + /* ** An instance of the following structure is used by the tree walker ** to determine if an expression can be evaluated by reference to the @@ -98166,6 +100573,10 @@ static void openStatTable( "DELETE FROM %Q.%s WHERE %s=%Q", pDb->zDbSName, zTab, zWhereType, zWhere ); +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK + }else if( db->xPreUpdateCallback ){ + sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab); +#endif }else{ /* The sqlite_stat[134] table already exists. Delete all rows. */ sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb); @@ -98930,6 +101341,9 @@ static void analyzeOneTable( int regIdxname = iMem++; /* Register containing index name */ int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */ int regPrev = iMem; /* MUST BE LAST (see below) */ +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK + Table *pStat1 = 0; +#endif pParse->nMem = MAX(pParse->nMem, iMem); v = sqlite3GetVdbe(pParse); @@ -98940,7 +101354,7 @@ static void analyzeOneTable( /* Do not gather statistics on views or virtual tables */ return; } - if( sqlite3_strlike("sqlite_%", pTab->zName, 0)==0 ){ + if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){ /* Do not gather statistics on system tables */ return; } @@ -98955,6 +101369,18 @@ static void analyzeOneTable( } #endif +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK + if( db->xPreUpdateCallback ){ + pStat1 = (Table*)sqlite3DbMallocZero(db, sizeof(Table) + 13); + if( pStat1==0 ) return; + pStat1->zName = (char*)&pStat1[1]; + memcpy(pStat1->zName, "sqlite_stat1", 13); + pStat1->nCol = 3; + pStat1->iPKey = -1; + sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); + } +#endif + /* Establish a read-lock on the table at the shared-cache level. ** Open a read-only cursor on the table. Also allocate a cursor number ** to use for scanning indexes (iIdxCur). No index cursor is opened at @@ -99156,6 +101582,9 @@ static void analyzeOneTable( sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0); sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK + sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE); +#endif sqlite3VdbeChangeP5(v, OPFLAG_APPEND); /* Add the entries to the stat3 or stat4 table. */ @@ -99219,6 +101648,9 @@ static void analyzeOneTable( sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); sqlite3VdbeChangeP5(v, OPFLAG_APPEND); +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK + sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE); +#endif sqlite3VdbeJumpHere(v, jZeroRows); } } @@ -99901,6 +102333,10 @@ static int resolveAttachExpr(NameContext *pName, Expr *pExpr) ** ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the ** third argument. +** +** If the db->init.reopenMemdb flags is set, then instead of attaching a +** new database, close the database on db->init.iDb and reopen it as an +** empty MemDB. */ static void attachFunc( sqlite3_context *context, @@ -99921,65 +102357,85 @@ static void attachFunc( sqlite3_vfs *pVfs; UNUSED_PARAMETER(NotUsed); - zFile = (const char *)sqlite3_value_text(argv[0]); zName = (const char *)sqlite3_value_text(argv[1]); if( zFile==0 ) zFile = ""; if( zName==0 ) zName = ""; - /* Check for the following errors: - ** - ** * Too many attached databases, - ** * Transaction currently open - ** * Specified database name already being used. - */ - if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ - zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", - db->aLimit[SQLITE_LIMIT_ATTACHED] - ); - goto attach_error; - } - for(i=0; inDb; i++){ - char *z = db->aDb[i].zDbSName; - assert( z && zName ); - if( sqlite3StrICmp(z, zName)==0 ){ - zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); +#ifdef SQLITE_ENABLE_DESERIALIZE +# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb) +#else +# define REOPEN_AS_MEMDB(db) (0) +#endif + + if( REOPEN_AS_MEMDB(db) ){ + /* This is not a real ATTACH. Instead, this routine is being called + ** from sqlite3_deserialize() to close database db->init.iDb and + ** reopen it as a MemDB */ + pVfs = sqlite3_vfs_find("memdb"); + if( pVfs==0 ) return; + pNew = &db->aDb[db->init.iDb]; + if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt); + pNew->pBt = 0; + pNew->pSchema = 0; + rc = sqlite3BtreeOpen(pVfs, "x", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB); + }else{ + /* This is a real ATTACH + ** + ** Check for the following errors: + ** + ** * Too many attached databases, + ** * Transaction currently open + ** * Specified database name already being used. + */ + if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ + zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", + db->aLimit[SQLITE_LIMIT_ATTACHED] + ); goto attach_error; } + for(i=0; inDb; i++){ + char *z = db->aDb[i].zDbSName; + assert( z && zName ); + if( sqlite3StrICmp(z, zName)==0 ){ + zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); + goto attach_error; + } + } + + /* Allocate the new entry in the db->aDb[] array and initialize the schema + ** hash tables. + */ + if( db->aDb==db->aDbStatic ){ + aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); + if( aNew==0 ) return; + memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); + }else{ + aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); + if( aNew==0 ) return; + } + db->aDb = aNew; + pNew = &db->aDb[db->nDb]; + memset(pNew, 0, sizeof(*pNew)); + + /* Open the database file. If the btree is successfully opened, use + ** it to obtain the database schema. At this point the schema may + ** or may not be initialized. + */ + flags = db->openFlags; + rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); + if( rc!=SQLITE_OK ){ + if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); + sqlite3_result_error(context, zErr, -1); + sqlite3_free(zErr); + return; + } + assert( pVfs ); + flags |= SQLITE_OPEN_MAIN_DB; + rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); + sqlite3_free( zPath ); + db->nDb++; } - - /* Allocate the new entry in the db->aDb[] array and initialize the schema - ** hash tables. - */ - if( db->aDb==db->aDbStatic ){ - aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); - if( aNew==0 ) return; - memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); - }else{ - aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); - if( aNew==0 ) return; - } - db->aDb = aNew; - pNew = &db->aDb[db->nDb]; - memset(pNew, 0, sizeof(*pNew)); - - /* Open the database file. If the btree is successfully opened, use - ** it to obtain the database schema. At this point the schema may - ** or may not be initialized. - */ - flags = db->openFlags; - rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); - if( rc!=SQLITE_OK ){ - if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); - sqlite3_result_error(context, zErr, -1); - sqlite3_free(zErr); - return; - } - assert( pVfs ); - flags |= SQLITE_OPEN_MAIN_DB; - rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); - sqlite3_free( zPath ); - db->nDb++; db->skipBtreeMutex = 0; if( rc==SQLITE_CONSTRAINT ){ rc = SQLITE_ERROR; @@ -100006,7 +102462,7 @@ static void attachFunc( sqlite3BtreeLeave(pNew->pBt); } pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; - pNew->zDbSName = sqlite3DbStrDup(db, zName); + if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && pNew->zDbSName==0 ){ rc = SQLITE_NOMEM_BKPT; } @@ -100046,13 +102502,15 @@ static void attachFunc( /* If the file was opened successfully, read the schema for the new database. ** If this fails, or if opening the file failed, then close the file and - ** remove the entry from the db->aDb[] array. i.e. put everything back the way - ** we found it. + ** remove the entry from the db->aDb[] array. i.e. put everything back the + ** way we found it. */ if( rc==SQLITE_OK ){ sqlite3BtreeEnterAll(db); + db->init.iDb = 0; rc = sqlite3Init(db, &zErrDyn); sqlite3BtreeLeaveAll(db); + assert( zErrDyn==0 || rc!=SQLITE_OK ); } #ifdef SQLITE_USER_AUTHENTICATION if( rc==SQLITE_OK ){ @@ -100064,21 +102522,23 @@ static void attachFunc( } #endif if( rc ){ - int iDb = db->nDb - 1; - assert( iDb>=2 ); - if( db->aDb[iDb].pBt ){ - sqlite3BtreeClose(db->aDb[iDb].pBt); - db->aDb[iDb].pBt = 0; - db->aDb[iDb].pSchema = 0; - } - sqlite3ResetAllSchemasOfConnection(db); - db->nDb = iDb; - if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ - sqlite3OomFault(db); - sqlite3DbFree(db, zErrDyn); - zErrDyn = sqlite3MPrintf(db, "out of memory"); - }else if( zErrDyn==0 ){ - zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); + if( !REOPEN_AS_MEMDB(db) ){ + int iDb = db->nDb - 1; + assert( iDb>=2 ); + if( db->aDb[iDb].pBt ){ + sqlite3BtreeClose(db->aDb[iDb].pBt); + db->aDb[iDb].pBt = 0; + db->aDb[iDb].pSchema = 0; + } + sqlite3ResetAllSchemasOfConnection(db); + db->nDb = iDb; + if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ + sqlite3OomFault(db); + sqlite3DbFree(db, zErrDyn); + zErrDyn = sqlite3MPrintf(db, "out of memory"); + }else if( zErrDyn==0 ){ + zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); + } } goto attach_error; } @@ -100350,8 +102810,13 @@ SQLITE_PRIVATE int sqlite3FixSelect( if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ return 1; } - if( sqlite3FixExpr(pFix, pSelect->pOffset) ){ - return 1; + if( pSelect->pWith ){ + int i; + for(i=0; ipWith->nCte; i++){ + if( sqlite3FixSelect(pFix, pSelect->pWith->a[i].pSelect) ){ + return 1; + } + } } pSelect = pSelect->pPrior; } @@ -101816,10 +104281,24 @@ SQLITE_PRIVATE void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ */ SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){ Table *p; + Column *pCol; p = pParse->pNewTable; if( p==0 || NEVER(p->nCol<1) ) return; - p->aCol[p->nCol-1].notNull = (u8)onError; + pCol = &p->aCol[p->nCol-1]; + pCol->notNull = (u8)onError; p->tabFlags |= TF_HasNotNull; + + /* Set the uniqNotNull flag on any UNIQUE or PK indexes already created + ** on this column. */ + if( pCol->colFlags & COLFLAG_UNIQUE ){ + Index *pIdx; + for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ + assert( pIdx->nKeyCol==1 && pIdx->onError!=OE_None ); + if( pIdx->aiColumn[0]==p->nCol-1 ){ + pIdx->uniqNotNull = 1; + } + } + } } /* @@ -101919,34 +104398,37 @@ SQLITE_PRIVATE char sqlite3AffinityType(const char *zIn, u8 *pszEst){ ** This routine is called by the parser while in the middle of ** parsing a CREATE TABLE statement. */ -SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse *pParse, ExprSpan *pSpan){ +SQLITE_PRIVATE void sqlite3AddDefaultValue( + Parse *pParse, /* Parsing context */ + Expr *pExpr, /* The parsed expression of the default value */ + const char *zStart, /* Start of the default value text */ + const char *zEnd /* First character past end of defaut value text */ +){ Table *p; Column *pCol; sqlite3 *db = pParse->db; p = pParse->pNewTable; if( p!=0 ){ pCol = &(p->aCol[p->nCol-1]); - if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){ + if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){ sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", pCol->zName); }else{ /* A copy of pExpr is used instead of the original, as pExpr contains - ** tokens that point to volatile memory. The 'span' of the expression - ** is required by pragma table_info. + ** tokens that point to volatile memory. */ Expr x; sqlite3ExprDelete(db, pCol->pDflt); memset(&x, 0, sizeof(x)); x.op = TK_SPAN; - x.u.zToken = sqlite3DbStrNDup(db, (char*)pSpan->zStart, - (int)(pSpan->zEnd - pSpan->zStart)); - x.pLeft = pSpan->pExpr; + x.u.zToken = sqlite3DbSpanDup(db, zStart, zEnd); + x.pLeft = pExpr; x.flags = EP_Skip; pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE); sqlite3DbFree(db, x.u.zToken); } } - sqlite3ExprDelete(db, pSpan->pExpr); + sqlite3ExprDelete(db, pExpr); } /* @@ -102177,7 +104659,7 @@ SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){ Vdbe *v = pParse->pVdbe; assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, - db->aDb[iDb].pSchema->schema_cookie+1); + (int)(1+(unsigned)db->aDb[iDb].pSchema->schema_cookie)); } /* @@ -102551,8 +105033,6 @@ SQLITE_PRIVATE void sqlite3EndTable( p = pParse->pNewTable; if( p==0 ) return; - assert( !db->init.busy || !pSelect ); - /* If the db->init.busy is 1 it means we are reading the SQL off the ** "sqlite_master" or "sqlite_temp_master" table on the disk. ** So do not write to the disk again. Extract the root page number @@ -102563,6 +105043,10 @@ SQLITE_PRIVATE void sqlite3EndTable( ** table itself. So mark it read-only. */ if( db->init.busy ){ + if( pSelect ){ + sqlite3ErrorMsg(pParse, ""); + return; + } p->tnum = db->init.newTnum; if( p->tnum==1 ) p->tabFlags |= TF_Readonly; } @@ -102663,10 +105147,6 @@ SQLITE_PRIVATE void sqlite3EndTable( pParse->nTab = 2; addrTop = sqlite3VdbeCurrentAddr(v) + 1; sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); - sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); - sqlite3Select(pParse, pSelect, &dest); - sqlite3VdbeEndCoroutine(v, regYield); - sqlite3VdbeJumpHere(v, addrTop - 1); if( pParse->nErr ) return; pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); if( pSelTab==0 ) return; @@ -102676,6 +105156,11 @@ SQLITE_PRIVATE void sqlite3EndTable( pSelTab->nCol = 0; pSelTab->aCol = 0; sqlite3DeleteTable(db, pSelTab); + sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); + sqlite3Select(pParse, pSelect, &dest); + if( pParse->nErr ) return; + sqlite3VdbeEndCoroutine(v, regYield); + sqlite3VdbeJumpHere(v, addrTop - 1); addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec); @@ -102818,7 +105303,7 @@ SQLITE_PRIVATE void sqlite3CreateView( ** the end. */ sEnd = pParse->sLastToken; - assert( sEnd.z[0]!=0 ); + assert( sEnd.z[0]!=0 || sEnd.n==0 ); if( sEnd.z[0]!=';' ){ sEnd.z += sEnd.n; } @@ -102852,7 +105337,7 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ int nErr = 0; /* Number of errors encountered */ int n; /* Temporarily holds the number of cursors assigned */ sqlite3 *db = pParse->db; /* Database connection for malloc errors */ -#ifndef SQLITE_OMIT_VIRTUALTABLE +#ifndef SQLITE_OMIT_VIRTUALTABLE int rc; #endif #ifndef SQLITE_OMIT_AUTHORIZATION @@ -103779,7 +106264,9 @@ SQLITE_PRIVATE void sqlite3CreateIndex( */ if( pList==0 ){ Token prevCol; - sqlite3TokenInit(&prevCol, pTab->aCol[pTab->nCol-1].zName); + Column *pCol = &pTab->aCol[pTab->nCol-1]; + pCol->colFlags |= COLFLAG_UNIQUE; + sqlite3TokenInit(&prevCol, pCol->zName); pList = sqlite3ExprListAppend(pParse, 0, sqlite3ExprAlloc(db, TK_ID, &prevCol, 0)); if( pList==0 ) goto exit_create_index; @@ -104550,9 +107037,10 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm( goto append_from_error; } p = sqlite3SrcListAppend(db, p, pTable, pDatabase); - if( p==0 || NEVER(p->nSrc==0) ){ + if( p==0 ){ goto append_from_error; } + assert( p->nSrc>0 ); pItem = &p->a[p->nSrc-1]; assert( pAlias!=0 ); if( pAlias->n ){ @@ -105061,6 +107549,18 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){ pKey->aSortOrder[i] = pIdx->aSortOrder[i]; } if( pParse->nErr ){ + assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ ); + if( pIdx->bNoQuery==0 ){ + /* Deactivate the index because it contains an unknown collating + ** sequence. The only way to reactive the index is to reload the + ** schema. Adding the missing collating sequence later does not + ** reactive the index. The application had the chance to register + ** the missing index using the collation-needed callback. For + ** simplicity, SQLite will not give the application a second chance. + */ + pIdx->bNoQuery = 1; + pParse->rc = SQLITE_ERROR_RETRY; + } sqlite3KeyInfoUnref(pKey); pKey = 0; } @@ -105246,6 +107746,7 @@ SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq( assert( !p || p->xCmp ); if( p==0 ){ sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); + pParse->rc = SQLITE_ERROR_MISSING_COLLSEQ; } return p; } @@ -105719,6 +108220,8 @@ SQLITE_PRIVATE void sqlite3MaterializeView( Parse *pParse, /* Parsing context */ Table *pView, /* View definition */ Expr *pWhere, /* Optional WHERE clause to be added */ + ExprList *pOrderBy, /* Optional ORDER BY clause */ + Expr *pLimit, /* Optional LIMIT clause */ int iCur /* Cursor number for ephemeral table */ ){ SelectDest dest; @@ -105735,8 +108238,8 @@ SQLITE_PRIVATE void sqlite3MaterializeView( assert( pFrom->a[0].pOn==0 ); assert( pFrom->a[0].pUsing==0 ); } - pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, - SF_IncludeHidden, 0, 0); + pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy, + SF_IncludeHidden, pLimit); sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); sqlite3Select(pParse, pSel, &dest); sqlite3SelectDelete(db, pSel); @@ -105758,29 +108261,29 @@ SQLITE_PRIVATE Expr *sqlite3LimitWhere( Expr *pWhere, /* The WHERE clause. May be null */ ExprList *pOrderBy, /* The ORDER BY clause. May be null */ Expr *pLimit, /* The LIMIT clause. May be null */ - Expr *pOffset, /* The OFFSET clause. May be null */ char *zStmtType /* Either DELETE or UPDATE. For err msgs. */ ){ - Expr *pWhereRowid = NULL; /* WHERE rowid .. */ + sqlite3 *db = pParse->db; + Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */ Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ - Expr *pSelectRowid = NULL; /* SELECT rowid ... */ ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */ SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */ Select *pSelect = NULL; /* Complete SELECT tree */ + Table *pTab; /* Check that there isn't an ORDER BY without a LIMIT clause. */ - if( pOrderBy && (pLimit == 0) ) { + if( pOrderBy && pLimit==0 ) { sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType); - goto limit_where_cleanup; + sqlite3ExprDelete(pParse->db, pWhere); + sqlite3ExprListDelete(pParse->db, pOrderBy); + return 0; } /* We only need to generate a select expression if there ** is a limit/offset term to enforce. */ if( pLimit == 0 ) { - /* if pLimit is null, pOffset will always be null as well. */ - assert( pOffset == 0 ); return pWhere; } @@ -105793,36 +108296,47 @@ SQLITE_PRIVATE Expr *sqlite3LimitWhere( ** ); */ - pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0); - if( pSelectRowid == 0 ) goto limit_where_cleanup; - pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid); - if( pEList == 0 ) goto limit_where_cleanup; + pTab = pSrc->a[0].pTab; + if( HasRowid(pTab) ){ + pLhs = sqlite3PExpr(pParse, TK_ROW, 0, 0); + pEList = sqlite3ExprListAppend( + pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) + ); + }else{ + Index *pPk = sqlite3PrimaryKeyIndex(pTab); + if( pPk->nKeyCol==1 ){ + const char *zName = pTab->aCol[pPk->aiColumn[0]].zName; + pLhs = sqlite3Expr(db, TK_ID, zName); + pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); + }else{ + int i; + for(i=0; inKeyCol; i++){ + Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName); + pEList = sqlite3ExprListAppend(pParse, pEList, p); + } + pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); + if( pLhs ){ + pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); + } + } + } /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree ** and the SELECT subtree. */ + pSrc->a[0].pTab = 0; pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0); - if( pSelectSrc == 0 ) { - sqlite3ExprListDelete(pParse->db, pEList); - goto limit_where_cleanup; - } + pSrc->a[0].pTab = pTab; + pSrc->a[0].pIBIndex = 0; /* generate the SELECT expression tree. */ - pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0, - pOrderBy,0,pLimit,pOffset); - if( pSelect == 0 ) return 0; + pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, + pOrderBy,0,pLimit + ); /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ - pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0); - pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0; + pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0); sqlite3PExprAddSelect(pParse, pInClause, pSelect); return pInClause; - -limit_where_cleanup: - sqlite3ExprDelete(pParse->db, pWhere); - sqlite3ExprListDelete(pParse->db, pOrderBy); - sqlite3ExprDelete(pParse->db, pLimit); - sqlite3ExprDelete(pParse->db, pOffset); - return 0; } #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ /* && !defined(SQLITE_OMIT_SUBQUERY) */ @@ -105837,7 +108351,9 @@ limit_where_cleanup: SQLITE_PRIVATE void sqlite3DeleteFrom( Parse *pParse, /* The parser context */ SrcList *pTabList, /* The table from which we should delete things */ - Expr *pWhere /* The WHERE clause. May be null */ + Expr *pWhere, /* The WHERE clause. May be null */ + ExprList *pOrderBy, /* ORDER BY clause. May be null */ + Expr *pLimit /* LIMIT clause. May be null */ ){ Vdbe *v; /* The virtual database engine */ Table *pTab; /* The table from which records will be deleted */ @@ -105882,6 +108398,7 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( } assert( pTabList->nSrc==1 ); + /* Locate the table which we want to delete. This table has to be ** put in an SrcList structure because some of the subroutines we ** will be calling are designed to work with multiple tables and expect @@ -105896,16 +108413,26 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( #ifndef SQLITE_OMIT_TRIGGER pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); isView = pTab->pSelect!=0; - bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); #else # define pTrigger 0 # define isView 0 #endif + bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); #ifdef SQLITE_OMIT_VIEW # undef isView # define isView 0 #endif +#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT + if( !isView ){ + pWhere = sqlite3LimitWhere( + pParse, pTabList, pWhere, pOrderBy, pLimit, "DELETE" + ); + pOrderBy = 0; + pLimit = 0; + } +#endif + /* If pTab is really a view, make sure it has been initialized. */ if( sqlite3ViewGetColumnNames(pParse, pTab) ){ @@ -105953,8 +108480,12 @@ SQLITE_PRIVATE void sqlite3DeleteFrom( */ #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) if( isView ){ - sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur); + sqlite3MaterializeView(pParse, pTab, + pWhere, pOrderBy, pLimit, iTabCur + ); iDataCur = iIdxCur = iTabCur; + pOrderBy = 0; + pLimit = 0; } #endif @@ -106198,6 +108729,10 @@ delete_from_cleanup: sqlite3AuthContextPop(&sContext); sqlite3SrcListDelete(db, pTabList); sqlite3ExprDelete(db, pWhere); +#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) + sqlite3ExprListDelete(db, pOrderBy); + sqlite3ExprDelete(db, pLimit); +#endif sqlite3DbFree(db, aToOpen); return; } @@ -106355,7 +108890,7 @@ SQLITE_PRIVATE void sqlite3GenerateRowDelete( u8 p5 = 0; sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); - if( pParse->nested==0 ){ + if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){ sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); } if( eMode!=ONEPASS_OFF ){ @@ -106576,6 +109111,8 @@ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ ** iteration of the aggregate loop. */ static void sqlite3SkipAccumulatorLoad(sqlite3_context *context){ + assert( context->isError<=0 ); + context->isError = -1; context->skipFlag = 1; } @@ -106642,8 +109179,6 @@ static void lengthFunc( int argc, sqlite3_value **argv ){ - int len; - assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ @@ -106655,13 +109190,17 @@ static void lengthFunc( } case SQLITE_TEXT: { const unsigned char *z = sqlite3_value_text(argv[0]); + const unsigned char *z0; + unsigned char c; if( z==0 ) return; - len = 0; - while( *z ){ - len++; - SQLITE_SKIP_UTF8(z); + z0 = z; + while( (c = *z)!=0 ){ + z++; + if( c>=0xc0 ){ + while( (*z & 0xc0)==0x80 ){ z++; z0++; } + } } - sqlite3_result_int(context, len); + sqlite3_result_int(context, (int)(z-z0)); break; } default: { @@ -107239,16 +109778,20 @@ static int patternCompare( ** c or cx. */ if( c<=0x80 ){ - u32 cx; + char zStop[3]; int bMatch; if( noCase ){ - cx = sqlite3Toupper(c); - c = sqlite3Tolower(c); + zStop[0] = sqlite3Toupper(c); + zStop[1] = sqlite3Tolower(c); + zStop[2] = 0; }else{ - cx = c; + zStop[0] = c; + zStop[1] = 0; } - while( (c2 = *(zString++))!=0 ){ - if( c2!=c && c2!=cx ) continue; + while(1){ + zString += strcspn((const char*)zString, zStop); + if( zString[0]==0 ) break; + zString++; bMatch = patternCompare(zPattern,zString,pInfo,matchOther); if( bMatch!=SQLITE_NOMATCH ) return bMatch; } @@ -107732,6 +110275,8 @@ static void replaceFunc( i64 nOut; /* Maximum size of zOut */ int loopLimit; /* Last zStr[] that might match zPattern[] */ int i, j; /* Loop counters */ + unsigned cntExpand; /* Number zOut expansions */ + sqlite3 *db = sqlite3_context_db_handle(context); assert( argc==3 ); UNUSED_PARAMETER(argc); @@ -107763,33 +110308,40 @@ static void replaceFunc( return; } loopLimit = nStr - nPattern; + cntExpand = 0; for(i=j=0; i<=loopLimit; i++){ if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){ zOut[j++] = zStr[i]; }else{ - u8 *zOld; - sqlite3 *db = sqlite3_context_db_handle(context); - nOut += nRep - nPattern; - testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] ); - testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] ); - if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ - sqlite3_result_error_toobig(context); - sqlite3_free(zOut); - return; - } - zOld = zOut; - zOut = sqlite3_realloc64(zOut, (int)nOut); - if( zOut==0 ){ - sqlite3_result_error_nomem(context); - sqlite3_free(zOld); - return; + if( nRep>nPattern ){ + nOut += nRep - nPattern; + testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] ); + testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] ); + if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ + sqlite3_result_error_toobig(context); + sqlite3_free(zOut); + return; + } + cntExpand++; + if( (cntExpand&(cntExpand-1))==0 ){ + /* Grow the size of the output buffer only on substitutions + ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */ + u8 *zOld; + zOld = zOut; + zOut = sqlite3_realloc64(zOut, (int)nOut + (nOut - nStr - 1)); + if( zOut==0 ){ + sqlite3_result_error_nomem(context); + sqlite3_free(zOld); + return; + } + } } memcpy(&zOut[j], zRep, nRep); j += nRep; i += nPattern-1; } } - assert( j+nStr-i+1==nOut ); + assert( j+nStr-i+1<=nOut ); memcpy(&zOut[j], &zStr[i], nStr-i); j += nStr - i; assert( j<=nOut ); @@ -108335,6 +110887,10 @@ SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void){ FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), #ifdef SQLITE_DEBUG FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY), +#endif +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC + FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET| + SQLITE_FUNC_TYPEOF), #endif FUNCTION(ltrim, 1, 1, 0, trimFunc ), FUNCTION(ltrim, 2, 1, 0, trimFunc ), @@ -109158,7 +111714,7 @@ SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTa } pParse->disableTriggers = 1; - sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0); + sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0); pParse->disableTriggers = 0; /* If the DELETE has generated immediate foreign key constraint @@ -109716,7 +112272,7 @@ static Trigger *fkActionTrigger( sqlite3ExprListAppend(pParse, 0, pRaise), sqlite3SrcListAppend(db, 0, &tFrom, 0), pWhere, - 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0 ); pWhere = 0; } @@ -110067,11 +112623,12 @@ static int readsTable(Parse *p, int iDb, Table *pTab){ ** first use of table pTab. On 2nd and subsequent uses, the original ** AutoincInfo structure is used. ** -** Three memory locations are allocated: +** Four consecutive registers are allocated: ** -** (1) Register to hold the name of the pTab table. -** (2) Register to hold the maximum ROWID of pTab. -** (3) Register to hold the rowid in sqlite_sequence of pTab +** (1) The name of the pTab table. +** (2) The maximum ROWID of pTab. +** (3) The rowid in sqlite_sequence of pTab +** (4) The original value of the max ROWID in pTab, or NULL if none ** ** The 2nd register is the one that is returned. That is all the ** insert routine needs to know about. @@ -110099,7 +112656,7 @@ static int autoIncBegin( pInfo->iDb = iDb; pToplevel->nMem++; /* Register to hold name of table */ pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */ - pToplevel->nMem++; /* Rowid in sqlite_sequence */ + pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */ } memId = pInfo->regCtr; } @@ -110127,15 +112684,17 @@ SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse){ static const int iLn = VDBE_OFFSET_LINENO(2); static const VdbeOpList autoInc[] = { /* 0 */ {OP_Null, 0, 0, 0}, - /* 1 */ {OP_Rewind, 0, 9, 0}, + /* 1 */ {OP_Rewind, 0, 10, 0}, /* 2 */ {OP_Column, 0, 0, 0}, - /* 3 */ {OP_Ne, 0, 7, 0}, + /* 3 */ {OP_Ne, 0, 9, 0}, /* 4 */ {OP_Rowid, 0, 0, 0}, /* 5 */ {OP_Column, 0, 1, 0}, - /* 6 */ {OP_Goto, 0, 9, 0}, - /* 7 */ {OP_Next, 0, 2, 0}, - /* 8 */ {OP_Integer, 0, 0, 0}, - /* 9 */ {OP_Close, 0, 0, 0} + /* 6 */ {OP_AddImm, 0, 0, 0}, + /* 7 */ {OP_Copy, 0, 0, 0}, + /* 8 */ {OP_Goto, 0, 11, 0}, + /* 9 */ {OP_Next, 0, 2, 0}, + /* 10 */ {OP_Integer, 0, 0, 0}, + /* 11 */ {OP_Close, 0, 0, 0} }; VdbeOp *aOp; pDb = &db->aDb[p->iDb]; @@ -110146,14 +112705,17 @@ SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse){ aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn); if( aOp==0 ) break; aOp[0].p2 = memId; - aOp[0].p3 = memId+1; + aOp[0].p3 = memId+2; aOp[2].p3 = memId; aOp[3].p1 = memId-1; aOp[3].p3 = memId; aOp[3].p5 = SQLITE_JUMPIFNULL; aOp[4].p2 = memId+1; aOp[5].p3 = memId; - aOp[8].p2 = memId; + aOp[6].p1 = memId; + aOp[7].p2 = memId+2; + aOp[7].p1 = memId; + aOp[10].p2 = memId; } } @@ -110200,6 +112762,8 @@ static SQLITE_NOINLINE void autoIncrementEnd(Parse *pParse){ iRec = sqlite3GetTempReg(pParse); assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); + sqlite3VdbeAddOp3(v, OP_Le, memId+2, sqlite3VdbeCurrentAddr(v)+7, memId); + VdbeCoverage(v); sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn); if( aOp==0 ) break; @@ -110766,7 +113330,8 @@ SQLITE_PRIVATE void sqlite3Insert( VdbeOp *pOp; sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid); pOp = sqlite3VdbeGetOp(v, -1); - if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){ + assert( pOp!=0 ); + if( pOp->opcode==OP_Null && !IsVirtual(pTab) ){ appendFlag = 1; pOp->opcode = OP_NewRowid; pOp->p1 = iDataCur; @@ -111427,6 +113992,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks( } /* Check to see if the new index entry will be unique */ + sqlite3ExprCachePush(pParse); sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk, regIdx, pIdx->nKeyCol); VdbeCoverage(v); @@ -111515,6 +114081,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks( } } sqlite3VdbeResolveLabel(v, addrUniqueOk); + sqlite3ExprCachePop(pParse); if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField); } if( ipkTop ){ @@ -111863,7 +114430,6 @@ static int xferOptimization( if( pSelect->pLimit ){ return 0; /* SELECT may not have a LIMIT clause */ } - assert( pSelect->pOffset==0 ); /* Must be so if pLimit==0 */ if( pSelect->pPrior ){ return 0; /* SELECT may not be a compound query */ } @@ -112575,6 +115141,9 @@ struct sqlite3_api_routines { int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*)); void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*)); void *(*value_pointer)(sqlite3_value*,const char*); + int (*vtab_nochange)(sqlite3_context*); + int (*value_nochange)(sqlite3_value*); + const char *(*vtab_collation)(sqlite3_index_info*,int); }; /* @@ -112841,6 +115410,10 @@ typedef int (*sqlite3_loadext_entry)( #define sqlite3_bind_pointer sqlite3_api->bind_pointer #define sqlite3_result_pointer sqlite3_api->result_pointer #define sqlite3_value_pointer sqlite3_api->value_pointer +/* Version 3.22.0 and later */ +#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange +#define sqlite3_value_nochange sqlite3_api->value_nochange +#define sqlite3_vtab_collation sqlite3_api->vtab_collation #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) @@ -113275,7 +115848,11 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_prepare16_v3, sqlite3_bind_pointer, sqlite3_result_pointer, - sqlite3_value_pointer + sqlite3_value_pointer, + /* Version 3.22.0 and later */ + sqlite3_vtab_nochange, + sqlite3_value_nochange, + sqlite3_vtab_collation }; /* @@ -113341,8 +115918,10 @@ static int sqlite3LoadExtension( #if SQLITE_OS_UNIX || SQLITE_OS_WIN for(ii=0; iipzErrMsg); *pData->pzErrMsg = z; } @@ -117261,7 +119841,8 @@ SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){ */ assert( sqlite3_mutex_held(db->mutex) ); if( pSchema ){ - for(i=0; ALWAYS(inDb); i++){ + for(i=0; 1; i++){ + assert( inDb ); if( db->aDb[i].pSchema==pSchema ){ break; } @@ -117442,8 +120023,6 @@ static int sqlite3Prepare( end_prepare: sqlite3ParserReset(&sParse); - rc = sqlite3ApiExit(db, rc); - assert( (rc&db->errMask)==rc ); return rc; } static int sqlite3LockAndPrepare( @@ -117456,6 +120035,7 @@ static int sqlite3LockAndPrepare( const char **pzTail /* OUT: End of parsed string */ ){ int rc; + int cnt = 0; #ifdef SQLITE_ENABLE_API_ARMOR if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; @@ -117466,15 +120046,18 @@ static int sqlite3LockAndPrepare( } sqlite3_mutex_enter(db->mutex); sqlite3BtreeEnterAll(db); - rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); - if( rc==SQLITE_SCHEMA ){ - sqlite3ResetOneSchema(db, -1); - sqlite3_finalize(*ppStmt); + do{ + /* Make multiple attempts to compile the SQL, until it either succeeds + ** or encounters a permanent error. A schema problem after one schema + ** reset is considered a permanent error. */ rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); - } + assert( rc==SQLITE_OK || *ppStmt==0 ); + }while( rc==SQLITE_ERROR_RETRY + || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); sqlite3BtreeLeaveAll(db); + rc = sqlite3ApiExit(db, rc); + assert( (rc&db->errMask)==rc ); sqlite3_mutex_leave(db->mutex); - assert( rc==SQLITE_OK || *ppStmt==0 ); return rc; } @@ -117708,8 +120291,7 @@ SQLITE_API int sqlite3_prepare16_v3( /***/ int sqlite3SelectTrace = 0; # define SELECTTRACE(K,P,S,X) \ if(sqlite3SelectTrace&(K)) \ - sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",\ - (S)->zSelName,(S)),\ + sqlite3DebugPrintf("%s/%p: ",(S)->zSelName,(S)),\ sqlite3DebugPrintf X #else # define SELECTTRACE(K,P,S,X) @@ -117761,7 +120343,6 @@ static void clearSelect(sqlite3 *db, Select *p, int bFree){ sqlite3ExprDelete(db, p->pHaving); sqlite3ExprListDelete(db, p->pOrderBy); sqlite3ExprDelete(db, p->pLimit); - sqlite3ExprDelete(db, p->pOffset); if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith); if( bFree ) sqlite3DbFreeNN(db, p); p = pPrior; @@ -117794,8 +120375,7 @@ SQLITE_PRIVATE Select *sqlite3SelectNew( Expr *pHaving, /* the HAVING clause */ ExprList *pOrderBy, /* the ORDER BY clause */ u32 selFlags, /* Flag parameters, such as SF_Distinct */ - Expr *pLimit, /* LIMIT value. NULL means not used */ - Expr *pOffset /* OFFSET value. NULL means no offset */ + Expr *pLimit /* LIMIT value. NULL means not used */ ){ Select *pNew; Select standin; @@ -117828,10 +120408,7 @@ SQLITE_PRIVATE Select *sqlite3SelectNew( pNew->pPrior = 0; pNew->pNext = 0; pNew->pLimit = pLimit; - pNew->pOffset = pOffset; pNew->pWith = 0; - assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 - || pParse->db->mallocFailed!=0 ); if( pParse->db->mallocFailed ) { clearSelect(pParse->db, pNew, pNew!=&standin); pNew = 0; @@ -118075,6 +120652,29 @@ static void setJoinExpr(Expr *p, int iTable){ } } +/* Undo the work of setJoinExpr(). In the expression tree p, convert every +** term that is marked with EP_FromJoin and iRightJoinTable==iTable into +** an ordinary term that omits the EP_FromJoin mark. +** +** This happens when a LEFT JOIN is simplified into an ordinary JOIN. +*/ +static void unsetJoinExpr(Expr *p, int iTable){ + while( p ){ + if( ExprHasProperty(p, EP_FromJoin) + && (iTable<0 || p->iRightJoinTable==iTable) ){ + ExprClearProperty(p, EP_FromJoin); + } + if( p->op==TK_FUNCTION && p->x.pList ){ + int i; + for(i=0; ix.pList->nExpr; i++){ + unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); + } + } + unsetJoinExpr(p->pLeft, iTable); + p = p->pRight; + } +} + /* ** This routine processes the join information for a SELECT statement. ** ON and USING clauses are converted into extra terms of the WHERE clause. @@ -118958,12 +121558,15 @@ static void generateSortTail( iSortTab = iTab; bSeq = 1; } - for(i=0, iCol=nKey+bSeq; i=0; i--){ int iRead; if( aOutEx[i].u.x.iOrderByCol ){ iRead = aOutEx[i].u.x.iOrderByCol-1; }else{ - iRead = iCol++; + iRead = iCol--; } sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i); VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan)); @@ -119073,8 +121676,9 @@ static const char *columnTypeImpl( assert( pExpr!=0 ); assert( pNC->pSrcList!=0 ); + assert( pExpr->op!=TK_AGG_COLUMN ); /* This routine runes before aggregates + ** are processed */ switch( pExpr->op ){ - case TK_AGG_COLUMN: case TK_COLUMN: { /* The expression is a column. Locate the table the column is being ** extracted from in NameContext.pSrcList. This table may be real @@ -119083,8 +121687,6 @@ static const char *columnTypeImpl( Table *pTab = 0; /* Table structure column is extracted from */ Select *pS = 0; /* Select the column is extracted from */ int iCol = pExpr->iColumn; /* Index of column in pTab */ - testcase( pExpr->op==TK_AGG_COLUMN ); - testcase( pExpr->op==TK_COLUMN ); while( pNC && !pTab ){ SrcList *pTabList = pNC->pSrcList; for(j=0;jnSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++); @@ -119288,6 +121890,7 @@ static void generateColumnNames( if( pParse->colNamesSet || db->mallocFailed ) return; /* Column names are determined by the left-most term of a compound select */ while( pSelect->pPrior ) pSelect = pSelect->pPrior; + SELECTTRACE(1,pParse,pSelect,("generating column names\n")); pTabList = pSelect->pSrc; pEList = pSelect->pEList; assert( v!=0 ); @@ -119396,12 +121999,12 @@ SQLITE_PRIVATE int sqlite3ColumnsFromExprList( pColExpr = pColExpr->pRight; assert( pColExpr!=0 ); } - if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN) - && pColExpr->pTab!=0 - ){ + assert( pColExpr->op!=TK_AGG_COLUMN ); + if( pColExpr->op==TK_COLUMN ){ /* For columns use the column name name */ int iCol = pColExpr->iColumn; Table *pTab = pColExpr->pTab; + assert( pTab!=0 ); if( iCol<0 ) iCol = pTab->iPKey; zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; }else if( pColExpr->op==TK_ID ){ @@ -119561,7 +122164,7 @@ SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ /* ** Compute the iLimit and iOffset fields of the SELECT based on the -** pLimit and pOffset expressions. pLimit and pOffset hold the expressions +** pLimit expressions. pLimit->pLeft and pLimit->pRight hold the expressions ** that appear in the original SQL statement after the LIMIT and OFFSET ** keywords. Or NULL if those keywords are omitted. iLimit and iOffset ** are the integer memory register numbers for counters used to compute @@ -119569,15 +122172,15 @@ SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ ** iLimit and iOffset are negative. ** ** This routine changes the values of iLimit and iOffset only if -** a limit or offset is defined by pLimit and pOffset. iLimit and -** iOffset should have been preset to appropriate default values (zero) +** a limit or offset is defined by pLimit->pLeft and pLimit->pRight. iLimit +** and iOffset should have been preset to appropriate default values (zero) ** prior to calling this routine. ** ** The iOffset register (if it exists) is initialized to the value ** of the OFFSET. The iLimit register is initialized to LIMIT. Register ** iOffset+1 is initialized to LIMIT+OFFSET. ** -** Only if pLimit!=0 or pOffset!=0 do the limit registers get +** Only if pLimit->pLeft!=0 do the limit registers get ** redefined. The UNION ALL operator uses this property to force ** the reuse of the same limit and offset registers across multiple ** SELECT statements. @@ -119587,6 +122190,8 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ int iLimit = 0; int iOffset; int n; + Expr *pLimit = p->pLimit; + if( p->iLimit ) return; /* @@ -119596,12 +122201,13 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ ** no rows. */ sqlite3ExprCacheClear(pParse); - assert( p->pOffset==0 || p->pLimit!=0 ); - if( p->pLimit ){ + if( pLimit ){ + assert( pLimit->op==TK_LIMIT ); + assert( pLimit->pLeft!=0 ); p->iLimit = iLimit = ++pParse->nMem; v = sqlite3GetVdbe(pParse); assert( v!=0 ); - if( sqlite3ExprIsInteger(p->pLimit, &n) ){ + if( sqlite3ExprIsInteger(pLimit->pLeft, &n) ){ sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit); VdbeComment((v, "LIMIT counter")); if( n==0 ){ @@ -119611,15 +122217,15 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ p->selFlags |= SF_FixedLimit; } }else{ - sqlite3ExprCode(pParse, p->pLimit, iLimit); + sqlite3ExprCode(pParse, pLimit->pLeft, iLimit); sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v); VdbeComment((v, "LIMIT counter")); sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v); } - if( p->pOffset ){ + if( pLimit->pRight ){ p->iOffset = iOffset = ++pParse->nMem; pParse->nMem++; /* Allocate an extra register for limit+offset */ - sqlite3ExprCode(pParse, p->pOffset, iOffset); + sqlite3ExprCode(pParse, pLimit->pRight, iOffset); sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v); VdbeComment((v, "OFFSET counter")); sqlite3VdbeAddOp3(v, OP_OffsetLimit, iLimit, iOffset+1, iOffset); @@ -119749,7 +122355,7 @@ static void generateWithRecursiveQuery( int i; /* Loop counter */ int rc; /* Result code */ ExprList *pOrderBy; /* The ORDER BY clause */ - Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */ + Expr *pLimit; /* Saved LIMIT and OFFSET */ int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ /* Obtain authorization to do a recursive query */ @@ -119760,10 +122366,9 @@ static void generateWithRecursiveQuery( p->nSelectRow = 320; /* 4 billion rows */ computeLimitRegisters(pParse, p, addrBreak); pLimit = p->pLimit; - pOffset = p->pOffset; regLimit = p->iLimit; regOffset = p->iOffset; - p->pLimit = p->pOffset = 0; + p->pLimit = 0; p->iLimit = p->iOffset = 0; pOrderBy = p->pOrderBy; @@ -119856,7 +122461,6 @@ end_of_recursive_query: sqlite3ExprListDelete(pParse->db, p->pOrderBy); p->pOrderBy = pOrderBy; p->pLimit = pLimit; - p->pOffset = pOffset; return; } #endif /* SQLITE_OMIT_CTE */ @@ -119875,9 +122479,14 @@ static int multiSelectOrderBy( ** on a VALUES clause. ** ** Because the Select object originates from a VALUES clause: -** (1) It has no LIMIT or OFFSET +** (1) There is no LIMIT or OFFSET or else there is a LIMIT of exactly 1 ** (2) All terms are UNION ALL ** (3) There is no ORDER BY clause +** +** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES +** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))"). +** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case. +** Since the limit is exactly 1, we only need to evalutes the left-most VALUES. */ static int multiSelectValues( Parse *pParse, /* Parsing context */ @@ -119885,14 +122494,13 @@ static int multiSelectValues( SelectDest *pDest /* What to do with query results */ ){ Select *pPrior; + Select *pRightmost = p; int nRow = 1; int rc = 0; assert( p->selFlags & SF_MultiValue ); do{ assert( p->selFlags & SF_Values ); assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); - assert( p->pLimit==0 ); - assert( p->pOffset==0 ); assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr ); if( p->pPrior==0 ) break; assert( p->pPrior->pNext==p ); @@ -119904,7 +122512,7 @@ static int multiSelectValues( p->pPrior = 0; rc = sqlite3Select(pParse, p, pDest); p->pPrior = pPrior; - if( rc ) break; + if( rc || pRightmost->pLimit ) break; p->nSelectRow = nRow; p = p->pNext; } @@ -120019,11 +122627,9 @@ static int multiSelect( pPrior->iLimit = p->iLimit; pPrior->iOffset = p->iOffset; pPrior->pLimit = p->pLimit; - pPrior->pOffset = p->pOffset; explainSetInteger(iSub1, pParse->iNextSelectId); rc = sqlite3Select(pParse, pPrior, &dest); p->pLimit = 0; - p->pOffset = 0; if( rc ){ goto multi_select_end; } @@ -120045,7 +122651,7 @@ static int multiSelect( p->pPrior = pPrior; p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow); if( pPrior->pLimit - && sqlite3ExprIsInteger(pPrior->pLimit, &nLimit) + && sqlite3ExprIsInteger(pPrior->pLimit->pLeft, &nLimit) && nLimit>0 && p->nSelectRow > sqlite3LogEst((u64)nLimit) ){ p->nSelectRow = sqlite3LogEst((u64)nLimit); @@ -120060,7 +122666,7 @@ static int multiSelect( int unionTab; /* Cursor number of the temporary table holding result */ u8 op = 0; /* One of the SRT_ operations to apply to self */ int priorOp; /* The SRT_ operation to apply to prior selects */ - Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */ + Expr *pLimit; /* Saved values of p->nLimit */ int addr; SelectDest uniondest; @@ -120072,7 +122678,6 @@ static int multiSelect( ** right. */ assert( p->pLimit==0 ); /* Not allowed on leftward elements */ - assert( p->pOffset==0 ); /* Not allowed on leftward elements */ unionTab = dest.iSDParm; }else{ /* We will need to create our own temporary table to hold the @@ -120108,8 +122713,6 @@ static int multiSelect( p->pPrior = 0; pLimit = p->pLimit; p->pLimit = 0; - pOffset = p->pOffset; - p->pOffset = 0; uniondest.eDest = op; explainSetInteger(iSub2, pParse->iNextSelectId); rc = sqlite3Select(pParse, p, &uniondest); @@ -120125,7 +122728,6 @@ static int multiSelect( } sqlite3ExprDelete(db, p->pLimit); p->pLimit = pLimit; - p->pOffset = pOffset; p->iLimit = 0; p->iOffset = 0; @@ -120153,7 +122755,7 @@ static int multiSelect( default: assert( p->op==TK_INTERSECT ); { int tab1, tab2; int iCont, iBreak, iStart; - Expr *pLimit, *pOffset; + Expr *pLimit; int addr; SelectDest intersectdest; int r1; @@ -120189,8 +122791,6 @@ static int multiSelect( p->pPrior = 0; pLimit = p->pLimit; p->pLimit = 0; - pOffset = p->pOffset; - p->pOffset = 0; intersectdest.iSDParm = tab2; explainSetInteger(iSub2, pParse->iNextSelectId); rc = sqlite3Select(pParse, p, &intersectdest); @@ -120200,7 +122800,6 @@ static int multiSelect( if( p->nSelectRow>pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow; sqlite3ExprDelete(db, p->pLimit); p->pLimit = pLimit; - p->pOffset = pOffset; /* Generate code to take the intersection of the two temporary ** tables. @@ -120679,8 +123278,6 @@ static int multiSelectOrderBy( } sqlite3ExprDelete(db, p->pLimit); p->pLimit = 0; - sqlite3ExprDelete(db, p->pOffset); - p->pOffset = 0; regAddrA = ++pParse->nMem; regAddrB = ++pParse->nMem; @@ -121070,12 +123667,11 @@ static void substSelect( ** (19) If the subquery uses LIMIT then the outer query may not ** have a WHERE clause. ** -** (**) Subsumed into (17d3). Was: If the sub-query is a compound select, -** then it must not use an ORDER BY clause - Ticket #3773. Because -** of (17d3), then only way to have a compound subquery is if it is -** the only term in the FROM clause of the outer query. But if the -** only term in the FROM clause has an ORDER BY, then it will be -** implemented as a co-routine and the flattener will never be called. +** (20) If the sub-query is a compound select, then it must not use +** an ORDER BY clause. Ticket #3773. We could relax this constraint +** somewhat by saying that the terms of the ORDER BY clause must +** appear as unmodified result columns in the outer query. But we +** have other optimizations in mind to deal with that case. ** ** (21) If the subquery uses LIMIT then the outer query may not be ** DISTINCT. (See ticket [752e1646fc]). @@ -121145,7 +123741,7 @@ static int flattenSubquery( ** became arbitrary expressions, we were forced to add restrictions (13) ** and (14). */ if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */ - if( pSub->pOffset ) return 0; /* Restriction (14) */ + if( pSub->pLimit && pSub->pLimit->pRight ) return 0; /* Restriction (14) */ if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){ return 0; /* Restriction (15) */ } @@ -121209,6 +123805,9 @@ static int flattenSubquery( ** queries. */ if( pSub->pPrior ){ + if( pSub->pOrderBy ){ + return 0; /* Restriction (20) */ + } if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){ return 0; /* (17d1), (17d2), or (17d3) */ } @@ -121243,15 +123842,6 @@ static int flattenSubquery( */ assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 ); - /* Ex-restriction (20): - ** A compound subquery must be the only term in the FROM clause of the - ** outer query by restriction (17d3). But if that term also has an - ** ORDER BY clause, then the subquery will be implemented by co-routine - ** and so the flattener will never be invoked. Hence, it is not possible - ** for the subquery to be a compound and have an ORDER BY clause. - */ - assert( pSub->pPrior==0 || pSub->pOrderBy==0 ); - /***** If we reach this point, flattening is permitted. *****/ SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n", pSub->zSelName, pSub, iFrom)); @@ -121299,16 +123889,13 @@ static int flattenSubquery( Select *pNew; ExprList *pOrderBy = p->pOrderBy; Expr *pLimit = p->pLimit; - Expr *pOffset = p->pOffset; Select *pPrior = p->pPrior; p->pOrderBy = 0; p->pSrc = 0; p->pPrior = 0; p->pLimit = 0; - p->pOffset = 0; pNew = sqlite3SelectDup(db, p, 0); sqlite3SelectSetName(pNew, pSub->zSelName); - p->pOffset = pOffset; p->pLimit = pLimit; p->pOrderBy = pOrderBy; p->pSrc = pSrc; @@ -121456,7 +124043,6 @@ static int flattenSubquery( pOrderBy->a[i].u.x.iOrderByCol = 0; } assert( pParent->pOrderBy==0 ); - assert( pSub->pPrior==0 ); pParent->pOrderBy = pOrderBy; pSub->pOrderBy = 0; } @@ -121540,12 +124126,22 @@ static int flattenSubquery( ** (3) The inner query has a LIMIT clause (since the changes to the WHERE ** close would change the meaning of the LIMIT). ** -** (4) The inner query is the right operand of a LEFT JOIN. (The caller -** enforces this restriction since this routine does not have enough -** information to know.) +** (4) The inner query is the right operand of a LEFT JOIN and the +** expression to be pushed down does not come from the ON clause +** on that LEFT JOIN. ** ** (5) The WHERE clause expression originates in the ON or USING clause -** of a LEFT JOIN. +** of a LEFT JOIN where iCursor is not the right-hand table of that +** left join. An example: +** +** SELECT * +** FROM (SELECT 1 AS a1 UNION ALL SELECT 2) AS aa +** JOIN (SELECT 1 AS b2 UNION ALL SELECT 2) AS bb ON (a1=b2) +** LEFT JOIN (SELECT 8 AS c3 UNION ALL SELECT 9) AS cc ON (b2=2); +** +** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9). +** But if the (b2=2) term were to be pushed down into the bb subquery, +** then the (1,1,NULL) row would be suppressed. ** ** Return 0 if no changes are made and non-zero if one or more WHERE clause ** terms are duplicated into the subquery. @@ -121554,7 +124150,8 @@ static int pushDownWhereTerms( Parse *pParse, /* Parse context (for malloc() and error reporting) */ Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ Expr *pWhere, /* The WHERE clause of the outer query */ - int iCursor /* Cursor number of the subquery */ + int iCursor, /* Cursor number of the subquery */ + int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ ){ Expr *pNew; int nChng = 0; @@ -121578,15 +124175,25 @@ static int pushDownWhereTerms( return 0; /* restriction (3) */ } while( pWhere->op==TK_AND ){ - nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor); + nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, + iCursor, isLeftJoin); pWhere = pWhere->pLeft; } - if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction (5) */ + if( isLeftJoin + && (ExprHasProperty(pWhere,EP_FromJoin)==0 + || pWhere->iRightJoinTable!=iCursor) + ){ + return 0; /* restriction (4) */ + } + if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){ + return 0; /* restriction (5) */ + } if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ nChng++; while( pSubq ){ SubstContext x; pNew = sqlite3ExprDup(pParse->db, pWhere, 0); + unsetJoinExpr(pNew, -1); x.pParse = pParse; x.iTable = iCursor; x.iNewTable = iCursor; @@ -121606,42 +124213,44 @@ static int pushDownWhereTerms( #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ /* -** Based on the contents of the AggInfo structure indicated by the first -** argument, this function checks if the following are true: +** The pFunc is the only aggregate function in the query. Check to see +** if the query is a candidate for the min/max optimization. ** -** * the query contains just a single aggregate function, -** * the aggregate function is either min() or max(), and -** * the argument to the aggregate function is a column value. +** If the query is a candidate for the min/max optimization, then set +** *ppMinMax to be an ORDER BY clause to be used for the optimization +** and return either WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX depending on +** whether pFunc is a min() or max() function. ** -** If all of the above are true, then WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX -** is returned as appropriate. Also, *ppMinMax is set to point to the -** list of arguments passed to the aggregate before returning. +** If the query is not a candidate for the min/max optimization, return +** WHERE_ORDERBY_NORMAL (which must be zero). ** -** Or, if the conditions above are not met, *ppMinMax is set to 0 and -** WHERE_ORDERBY_NORMAL is returned. +** This routine must be called after aggregate functions have been +** located but before their arguments have been subjected to aggregate +** analysis. */ -static u8 minMaxQuery(AggInfo *pAggInfo, ExprList **ppMinMax){ - int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ +static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ + int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ + ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ + const char *zFunc; /* Name of aggregate function pFunc */ + ExprList *pOrderBy; + u8 sortOrder; - *ppMinMax = 0; - if( pAggInfo->nFunc==1 ){ - Expr *pExpr = pAggInfo->aFunc[0].pExpr; /* Aggregate function */ - ExprList *pEList = pExpr->x.pList; /* Arguments to agg function */ - - assert( pExpr->op==TK_AGG_FUNCTION ); - if( pEList && pEList->nExpr==1 && pEList->a[0].pExpr->op==TK_AGG_COLUMN ){ - const char *zFunc = pExpr->u.zToken; - if( sqlite3StrICmp(zFunc, "min")==0 ){ - eRet = WHERE_ORDERBY_MIN; - *ppMinMax = pEList; - }else if( sqlite3StrICmp(zFunc, "max")==0 ){ - eRet = WHERE_ORDERBY_MAX; - *ppMinMax = pEList; - } - } + assert( *ppMinMax==0 ); + assert( pFunc->op==TK_AGG_FUNCTION ); + if( pEList==0 || pEList->nExpr!=1 ) return eRet; + zFunc = pFunc->u.zToken; + if( sqlite3StrICmp(zFunc, "min")==0 ){ + eRet = WHERE_ORDERBY_MIN; + sortOrder = SQLITE_SO_ASC; + }else if( sqlite3StrICmp(zFunc, "max")==0 ){ + eRet = WHERE_ORDERBY_MAX; + sortOrder = SQLITE_SO_DESC; + }else{ + return eRet; } - - assert( *ppMinMax==0 || (*ppMinMax)->nExpr==1 ); + *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0); + assert( pOrderBy!=0 || db->mallocFailed ); + if( pOrderBy ) pOrderBy->a[0].sortOrder = sortOrder; return eRet; } @@ -121772,7 +124381,6 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ assert( pNew->pPrior!=0 ); pNew->pPrior->pNext = pNew; pNew->pLimit = 0; - pNew->pOffset = 0; return WRC_Continue; } @@ -122028,19 +124636,19 @@ static int selectExpander(Walker *pWalker, Select *p){ sqlite3 *db = pParse->db; Expr *pE, *pRight, *pExpr; u16 selFlags = p->selFlags; + u32 elistFlags = 0; p->selFlags |= SF_Expanded; if( db->mallocFailed ){ return WRC_Abort; } - if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ + assert( p->pSrc!=0 ); + if( (selFlags & SF_Expanded)!=0 ){ return WRC_Prune; } pTabList = p->pSrc; pEList = p->pEList; - if( OK_IF_ALWAYS_TRUE(p->pWith) ){ - sqlite3WithPush(pParse, p->pWith, 0); - } + sqlite3WithPush(pParse, p->pWith, 0); /* Make sure cursor numbers have been assigned to all entries in ** the FROM clause of the SELECT statement. @@ -122140,6 +124748,7 @@ static int selectExpander(Walker *pWalker, Select *p){ assert( pE->op!=TK_DOT || pE->pRight!=0 ); assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) ); if( pE->op==TK_DOT && pE->pRight->op==TK_ASTERISK ) break; + elistFlags |= pE->flags; } if( knExpr ){ /* @@ -122155,6 +124764,7 @@ static int selectExpander(Walker *pWalker, Select *p){ for(k=0; knExpr; k++){ pE = a[k].pExpr; + elistFlags |= pE->flags; pRight = pE->pRight; assert( pE->op!=TK_DOT || pRight!=0 ); if( pE->op!=TK_ASTERISK @@ -122284,9 +124894,14 @@ static int selectExpander(Walker *pWalker, Select *p){ sqlite3ExprListDelete(db, pEList); p->pEList = pNew; } - if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ - sqlite3ErrorMsg(pParse, "too many columns in result set"); - return WRC_Abort; + if( p->pEList ){ + if( p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ + sqlite3ErrorMsg(pParse, "too many columns in result set"); + return WRC_Abort; + } + if( (elistFlags & (EP_HasFunc|EP_Subquery))!=0 ){ + p->selFlags |= SF_ComplexResult; + } } return WRC_Continue; } @@ -122608,14 +125223,6 @@ static void explainSimpleCount( # define explainSimpleCount(a,b,c) #endif -/* -** Context object for havingToWhereExprCb(). -*/ -struct HavingToWhereCtx { - Expr **ppWhere; - ExprList *pGroupBy; -}; - /* ** sqlite3WalkExpr() callback used by havingToWhere(). ** @@ -122629,15 +125236,16 @@ struct HavingToWhereCtx { */ static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){ if( pExpr->op!=TK_AND ){ - struct HavingToWhereCtx *p = pWalker->u.pHavingCtx; - if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){ + Select *pS = pWalker->u.pSelect; + if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){ sqlite3 *db = pWalker->pParse->db; Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0); if( pNew ){ - Expr *pWhere = *(p->ppWhere); + Expr *pWhere = pS->pWhere; SWAP(Expr, *pNew, *pExpr); pNew = sqlite3ExprAnd(db, pWhere, pNew); - *(p->ppWhere) = pNew; + pS->pWhere = pNew; + pWalker->eCode = 1; } } return WRC_Prune; @@ -122660,23 +125268,19 @@ static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){ ** entirely of constants and expressions that are also GROUP BY terms that ** use the "BINARY" collation sequence. */ -static void havingToWhere( - Parse *pParse, - ExprList *pGroupBy, - Expr *pHaving, - Expr **ppWhere -){ - struct HavingToWhereCtx sCtx; +static void havingToWhere(Parse *pParse, Select *p){ Walker sWalker; - - sCtx.ppWhere = ppWhere; - sCtx.pGroupBy = pGroupBy; - memset(&sWalker, 0, sizeof(sWalker)); sWalker.pParse = pParse; sWalker.xExprCallback = havingToWhereExprCb; - sWalker.u.pHavingCtx = &sCtx; - sqlite3WalkExpr(&sWalker, pHaving); + sWalker.u.pSelect = p; + sqlite3WalkExpr(&sWalker, p->pHaving); +#if SELECTTRACE_ENABLED + if( sWalker.eCode && (sqlite3SelectTrace & 0x100)!=0 ){ + SELECTTRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n")); + sqlite3TreeViewSelect(0, p, 0); + } +#endif } /* @@ -122822,6 +125426,8 @@ SQLITE_PRIVATE int sqlite3Select( AggInfo sAggInfo; /* Information used by aggregate queries */ int iEnd; /* Address of the end of the query */ sqlite3 *db; /* The database connection */ + ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */ + u8 minMaxFlag; /* Flag for min/max queries */ #ifndef SQLITE_OMIT_EXPLAIN int iRestoreSelectId = pParse->iSelectId; @@ -122835,7 +125441,6 @@ SQLITE_PRIVATE int sqlite3Select( if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; memset(&sAggInfo, 0, sizeof(sAggInfo)); #if SELECTTRACE_ENABLED - pParse->nSelectIndent++; SELECTTRACE(1,pParse,p, ("begin processing:\n")); if( sqlite3SelectTrace & 0x100 ){ sqlite3TreeViewSelect(0, p, 0); @@ -122881,13 +125486,29 @@ SQLITE_PRIVATE int sqlite3Select( generateColumnNames(pParse, p); } - /* Try to flatten subqueries in the FROM clause up into the main query + /* Try to various optimizations (flattening subqueries, and strength + ** reduction of join operators) in the FROM clause up into the main query */ #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) for(i=0; !p->pPrior && inSrc; i++){ struct SrcList_item *pItem = &pTabList->a[i]; Select *pSub = pItem->pSelect; Table *pTab = pItem->pTab; + + /* Convert LEFT JOIN into JOIN if there are terms of the right table + ** of the LEFT JOIN used in the WHERE clause. + */ + if( (pItem->fg.jointype & JT_LEFT)!=0 + && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor) + && OptimizationEnabled(db, SQLITE_SimplifyJoin) + ){ + SELECTTRACE(0x100,pParse,p, + ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); + pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); + unsetJoinExpr(p->pWhere, pItem->iCursor); + } + + /* No futher action if this term of the FROM clause is no a subquery */ if( pSub==0 ) continue; /* Catch mismatch in the declared columns of a view and the number of @@ -122908,7 +125529,9 @@ SQLITE_PRIVATE int sqlite3Select( if( (pSub->selFlags & SF_Aggregate)!=0 ) continue; assert( pSub->pGroupBy==0 ); - /* If the subquery contains an ORDER BY clause and if + /* If the outer query contains a "complex" result set (that is, + ** if the result set of the outer query uses functions or subqueries) + ** and if the subquery contains an ORDER BY clause and if ** it will be implemented as a co-routine, then do not flatten. This ** restriction allows SQL constructs like this: ** @@ -122917,9 +125540,16 @@ SQLITE_PRIVATE int sqlite3Select( ** ** The expensive_function() is only computed on the 10 rows that ** are output, rather than every row of the table. + ** + ** The requirement that the outer query have a complex result set + ** means that flattening does occur on simpler SQL constraints without + ** the expensive_function() like: + ** + ** SELECT x FROM (SELECT x FROM tab ORDER BY y LIMIT 10); */ if( pSub->pOrderBy!=0 && i==0 + && (p->selFlags & SF_ComplexResult)!=0 && (pTabList->nSrc==1 || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) ){ @@ -122947,7 +125577,6 @@ SQLITE_PRIVATE int sqlite3Select( explainSetInteger(pParse->iSelectId, iRestoreSelectId); #if SELECTTRACE_ENABLED SELECTTRACE(1,pParse,p,("end compound-select processing\n")); - pParse->nSelectIndent--; #endif return rc; } @@ -123020,8 +125649,9 @@ SQLITE_PRIVATE int sqlite3Select( /* Make copies of constant WHERE-clause terms in the outer query down ** inside the subquery. This can help the subquery to run more efficiently. */ - if( (pItem->fg.jointype & JT_OUTER)==0 - && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor) + if( OptimizationEnabled(db, SQLITE_PushDown) + && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor, + (pItem->fg.jointype & JT_OUTER)!=0) ){ #if SELECTTRACE_ENABLED if( sqlite3SelectTrace & 0x100 ){ @@ -123029,6 +125659,8 @@ SQLITE_PRIVATE int sqlite3Select( sqlite3TreeViewSelect(0, p, 0); } #endif + }else{ + SELECTTRACE(0x100,pParse,p,("Push-down not possible\n")); } zSavedAuthContext = pParse->zAuthContext; @@ -123231,6 +125863,7 @@ SQLITE_PRIVATE int sqlite3Select( wctrlFlags |= p->selFlags & SF_FixedLimit; /* Begin the database scan. */ + SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy, p->pEList, wctrlFlags, p->nSelectRow); if( pWInfo==0 ) goto select_end; @@ -123332,12 +125965,19 @@ SQLITE_PRIVATE int sqlite3Select( if( pHaving ){ if( pGroupBy ){ assert( pWhere==p->pWhere ); - havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere); + assert( pHaving==p->pHaving ); + assert( pGroupBy==p->pGroupBy ); + havingToWhere(pParse, p); pWhere = p->pWhere; } sqlite3ExprAnalyzeAggregates(&sNC, pHaving); } sAggInfo.nAccumulator = sAggInfo.nColumn; + if( p->pGroupBy==0 && p->pHaving==0 && sAggInfo.nFunc==1 ){ + minMaxFlag = minMaxQuery(db, sAggInfo.aFunc[0].pExpr, &pMinMaxOrderBy); + }else{ + minMaxFlag = WHERE_ORDERBY_NORMAL; + } for(i=0; inMem; if( db->mallocFailed ) goto select_end; +#if SELECTTRACE_ENABLED + if( sqlite3SelectTrace & 0x400 ){ + int ii; + SELECTTRACE(0x400,pParse,p,("After aggregate analysis:\n")); + sqlite3TreeViewSelect(0, p, 0); + for(ii=0; iipGroupBy==0 ); - assert( flag==0 ); - if( p->pHaving==0 ){ - flag = minMaxQuery(&sAggInfo, &pMinMax); - } - assert( flag==0 || (pMinMax!=0 && pMinMax->nExpr==1) ); - - if( flag ){ - pMinMax = sqlite3ExprListDup(db, pMinMax, 0); - pDel = pMinMax; - assert( db->mallocFailed || pMinMax!=0 ); - if( !db->mallocFailed ){ - pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0; - pMinMax->a[0].pExpr->op = TK_COLUMN; - } - } - /* This case runs if the aggregate has no GROUP BY clause. The ** processing is much simpler since there is only a single row ** of output. */ + assert( p->pGroupBy==0 ); resetAccumulator(pParse, &sAggInfo); - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0); + + /* If this query is a candidate for the min/max optimization, then + ** minMaxFlag will have been previously set to either + ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will + ** be an appropriate ORDER BY expression for the optimization. + */ + assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); + assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); + + SELECTTRACE(1,pParse,p,("WhereBegin\n")); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, + 0, minMaxFlag, 0); if( pWInfo==0 ){ - sqlite3ExprListDelete(db, pDel); goto select_end; } updateAccumulator(pParse, &sAggInfo); - assert( pMinMax==0 || pMinMax->nExpr==1 ); if( sqlite3WhereIsOrdered(pWInfo)>0 ){ sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo)); VdbeComment((v, "%s() by index", - (flag==WHERE_ORDERBY_MIN?"min":"max"))); + (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max"))); } sqlite3WhereEnd(pWInfo); finalizeAggFunctions(pParse, &sAggInfo); @@ -123707,7 +126330,6 @@ SQLITE_PRIVATE int sqlite3Select( sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL); selectInnerLoop(pParse, p, -1, 0, 0, pDest, addrEnd, addrEnd); - sqlite3ExprListDelete(db, pDel); } sqlite3VdbeResolveLabel(v, addrEnd); @@ -123739,12 +126361,11 @@ SQLITE_PRIVATE int sqlite3Select( */ select_end: explainSetInteger(pParse->iSelectId, iRestoreSelectId); - + sqlite3ExprListDelete(db, pMinMaxOrderBy); sqlite3DbFree(db, sAggInfo.aCol); sqlite3DbFree(db, sAggInfo.aFunc); #if SELECTTRACE_ENABLED SELECTTRACE(1,pParse,p,("end processing\n")); - pParse->nSelectIndent--; #endif return rc; } @@ -123979,6 +126600,7 @@ SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerS sqlite3ExprListDelete(db, pTmp->pExprList); sqlite3SelectDelete(db, pTmp->pSelect); sqlite3IdListDelete(db, pTmp->pIdList); + sqlite3DbFree(db, pTmp->zSpan); sqlite3DbFree(db, pTmp); } @@ -124293,6 +126915,17 @@ triggerfinish_cleanup: sqlite3DeleteTriggerStep(db, pStepList); } +/* +** Duplicate a range of text from an SQL statement, then convert all +** whitespace characters into ordinary space characters. +*/ +static char *triggerSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){ + char *z = sqlite3DbSpanDup(db, zStart, zEnd); + int i; + if( z ) for(i=0; z[i]; i++) if( sqlite3Isspace(z[i]) ) z[i] = ' '; + return z; +} + /* ** Turn a SELECT statement (that the pSelect parameter points to) into ** a trigger step. Return a pointer to a TriggerStep structure. @@ -124300,7 +126933,12 @@ triggerfinish_cleanup: ** The parser calls this routine when it finds a SELECT statement in ** body of a TRIGGER. */ -SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){ +SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep( + sqlite3 *db, /* Database connection */ + Select *pSelect, /* The SELECT statement */ + const char *zStart, /* Start of SQL text */ + const char *zEnd /* End of SQL text */ +){ TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep)); if( pTriggerStep==0 ) { sqlite3SelectDelete(db, pSelect); @@ -124309,6 +126947,7 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelec pTriggerStep->op = TK_SELECT; pTriggerStep->pSelect = pSelect; pTriggerStep->orconf = OE_Default; + pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd); return pTriggerStep; } @@ -124321,7 +126960,9 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelec static TriggerStep *triggerStepAllocate( sqlite3 *db, /* Database connection */ u8 op, /* Trigger opcode */ - Token *pName /* The target name */ + Token *pName, /* The target name */ + const char *zStart, /* Start of SQL text */ + const char *zEnd /* End of SQL text */ ){ TriggerStep *pTriggerStep; @@ -124332,6 +126973,7 @@ static TriggerStep *triggerStepAllocate( sqlite3Dequote(z); pTriggerStep->zTarget = z; pTriggerStep->op = op; + pTriggerStep->zSpan = triggerSpanDup(db, zStart, zEnd); } return pTriggerStep; } @@ -124348,13 +126990,15 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep( Token *pTableName, /* Name of the table into which we insert */ IdList *pColumn, /* List of columns in pTableName to insert into */ Select *pSelect, /* A SELECT statement that supplies values */ - u8 orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */ + u8 orconf, /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */ + const char *zStart, /* Start of SQL text */ + const char *zEnd /* End of SQL text */ ){ TriggerStep *pTriggerStep; assert(pSelect != 0 || db->mallocFailed); - pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName); + pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName, zStart, zEnd); if( pTriggerStep ){ pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); pTriggerStep->pIdList = pColumn; @@ -124377,11 +127021,13 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep( Token *pTableName, /* Name of the table to be updated */ ExprList *pEList, /* The SET clause: list of column and new values */ Expr *pWhere, /* The WHERE clause */ - u8 orconf /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */ + u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */ + const char *zStart, /* Start of SQL text */ + const char *zEnd /* End of SQL text */ ){ TriggerStep *pTriggerStep; - pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName); + pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName, zStart, zEnd); if( pTriggerStep ){ pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE); pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); @@ -124400,11 +127046,13 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep( SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep( sqlite3 *db, /* Database connection */ Token *pTableName, /* The table from which rows are deleted */ - Expr *pWhere /* The WHERE clause */ + Expr *pWhere, /* The WHERE clause */ + const char *zStart, /* Start of SQL text */ + const char *zEnd /* End of SQL text */ ){ TriggerStep *pTriggerStep; - pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName); + pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName, zStart, zEnd); if( pTriggerStep ){ pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); pTriggerStep->orconf = OE_Default; @@ -124659,13 +127307,21 @@ static int codeTriggerProgram( pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; assert( pParse->okConstFactor==0 ); +#ifndef SQLITE_OMIT_TRACE + if( pStep->zSpan ){ + sqlite3VdbeAddOp4(v, OP_Trace, 0x7fffffff, 1, 0, + sqlite3MPrintf(db, "-- %s", pStep->zSpan), + P4_DYNAMIC); + } +#endif + switch( pStep->op ){ case TK_UPDATE: { sqlite3Update(pParse, targetSrcList(pParse, pStep), sqlite3ExprListDup(db, pStep->pExprList, 0), sqlite3ExprDup(db, pStep->pWhere, 0), - pParse->eOrconf + pParse->eOrconf, 0, 0 ); break; } @@ -124681,7 +127337,7 @@ static int codeTriggerProgram( case TK_DELETE: { sqlite3DeleteFrom(pParse, targetSrcList(pParse, pStep), - sqlite3ExprDup(db, pStep->pWhere, 0) + sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0 ); break; } @@ -124799,9 +127455,11 @@ static TriggerPrg *codeRowTrigger( pTab->zName )); #ifndef SQLITE_OMIT_TRACE - sqlite3VdbeChangeP4(v, -1, - sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC - ); + if( pTrigger->zName ){ + sqlite3VdbeChangeP4(v, -1, + sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC + ); + } #endif /* If one was specified, code the WHEN clause. If it evaluates to false @@ -124829,7 +127487,7 @@ static TriggerPrg *codeRowTrigger( VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf))); transferParseError(pParse, pSubParse); - if( db->mallocFailed==0 ){ + if( db->mallocFailed==0 && pParse->nErr==0 ){ pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); } pProgram->nMem = pSubParse->nMem; @@ -125148,7 +127806,9 @@ SQLITE_PRIVATE void sqlite3Update( SrcList *pTabList, /* The table in which we should change things */ ExprList *pChanges, /* Things to be changed */ Expr *pWhere, /* The WHERE clause. May be null */ - int onError /* How to handle constraint errors */ + int onError, /* How to handle constraint errors */ + ExprList *pOrderBy, /* ORDER BY clause. May be null */ + Expr *pLimit /* LIMIT clause. May be null */ ){ int i, j; /* Loop counters */ Table *pTab; /* The table to be updated */ @@ -125233,6 +127893,16 @@ SQLITE_PRIVATE void sqlite3Update( # define isView 0 #endif +#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT + if( !isView ){ + pWhere = sqlite3LimitWhere( + pParse, pTabList, pWhere, pOrderBy, pLimit, "UPDATE" + ); + pOrderBy = 0; + pLimit = 0; + } +#endif + if( sqlite3ViewGetColumnNames(pParse, pTab) ){ goto update_cleanup; } @@ -125401,7 +128071,11 @@ SQLITE_PRIVATE void sqlite3Update( */ #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) if( isView ){ - sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur); + sqlite3MaterializeView(pParse, pTab, + pWhere, pOrderBy, pLimit, iDataCur + ); + pOrderBy = 0; + pLimit = 0; } #endif @@ -125437,7 +128111,7 @@ SQLITE_PRIVATE void sqlite3Update( regKey = ++pParse->nMem; iEph = pParse->nTab++; - sqlite3VdbeAddOp2(v, OP_Null, 0, iPk); + sqlite3VdbeAddOp3(v, OP_Null, 0, iPk, iPk+nPk-1); addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk); sqlite3VdbeSetP4KeyInfo(pParse, pPk); } @@ -125785,6 +128459,10 @@ update_cleanup: sqlite3SrcListDelete(db, pTabList); sqlite3ExprListDelete(db, pChanges); sqlite3ExprDelete(db, pWhere); +#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) + sqlite3ExprListDelete(db, pOrderBy); + sqlite3ExprDelete(db, pLimit); +#endif return; } /* Make sure "isView" and other macros defined above are undefined. Otherwise @@ -125844,7 +128522,7 @@ static void updateVirtualTable( int bOnePass; /* True to use onepass strategy */ int addr; /* Address of OP_OpenEphemeral */ - /* Allocate nArg registers to martial the arguments to VUpdate. Then + /* Allocate nArg registers in which to gather the arguments for VUpdate. Then ** create and open the ephemeral table in which the records created from ** these arguments will be temporarily stored. */ assert( v ); @@ -125865,6 +128543,7 @@ static void updateVirtualTable( sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i); }else{ sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i); + sqlite3VdbeChangeP5(v, 1); /* Enable sqlite3_vtab_nochange() */ } } if( HasRowid(pTab) ){ @@ -125899,6 +128578,11 @@ static void updateVirtualTable( /* Create a record from the argument register contents and insert it into ** the ephemeral table. */ sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec); +#ifdef SQLITE_DEBUG + /* Signal an assert() within OP_MakeRecord that it is allowed to + ** accept no-change records with serial_type 10 */ + sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG_MAGIC); +#endif sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid); } @@ -125977,8 +128661,8 @@ static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){ while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){ const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0); assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 ); - if( zSubSql ){ - assert( zSubSql[0]!='S' ); + assert( sqlite3_strnicmp(zSubSql,"SELECT",6)!=0 || CORRUPT_DB ); + if( zSubSql && zSubSql[0]!='S' ){ rc = execSql(db, pzErrMsg, zSubSql); if( rc!=SQLITE_OK ) break; } @@ -127599,7 +130283,7 @@ SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ ** Trace output macros */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) -/***/ int sqlite3WhereTrace; +/***/ extern int sqlite3WhereTrace; #endif #if defined(SQLITE_DEBUG) \ && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_WHERETRACE)) @@ -128249,7 +130933,7 @@ SQLITE_PRIVATE int sqlite3WhereExplainOneScan( ){ int ret = 0; #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS) - if( pParse->explain==2 ) + if( sqlite3ParseToplevel(pParse)->explain==2 ) #endif { struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; @@ -128415,8 +131099,8 @@ SQLITE_PRIVATE void sqlite3WhereAddScanStatus( */ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){ int nLoop = 0; - while( ALWAYS(pTerm!=0) - && (pTerm->wtFlags & TERM_CODED)==0 + assert( pTerm!=0 ); + while( (pTerm->wtFlags & TERM_CODED)==0 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin)) && (pLevel->notReady & pTerm->prereqAll)==0 ){ @@ -128427,6 +131111,7 @@ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){ } if( pTerm->iParent<0 ) break; pTerm = &pTerm->pWC->a[pTerm->iParent]; + assert( pTerm!=0 ); pTerm->nChild--; if( pTerm->nChild!=0 ) break; nLoop++; @@ -128497,6 +131182,102 @@ static void updateRangeAffinityStr( } } + +/* +** pX is an expression of the form: (vector) IN (SELECT ...) +** In other words, it is a vector IN operator with a SELECT clause on the +** LHS. But not all terms in the vector are indexable and the terms might +** not be in the correct order for indexing. +** +** This routine makes a copy of the input pX expression and then adjusts +** the vector on the LHS with corresponding changes to the SELECT so that +** the vector contains only index terms and those terms are in the correct +** order. The modified IN expression is returned. The caller is responsible +** for deleting the returned expression. +** +** Example: +** +** CREATE TABLE t1(a,b,c,d,e,f); +** CREATE INDEX t1x1 ON t1(e,c); +** SELECT * FROM t1 WHERE (a,b,c,d,e) IN (SELECT v,w,x,y,z FROM t2) +** \_______________________________________/ +** The pX expression +** +** Since only columns e and c can be used with the index, in that order, +** the modified IN expression that is returned will be: +** +** (e,c) IN (SELECT z,x FROM t2) +** +** The reduced pX is different from the original (obviously) and thus is +** only used for indexing, to improve performance. The original unaltered +** IN expression must also be run on each output row for correctness. +*/ +static Expr *removeUnindexableInClauseTerms( + Parse *pParse, /* The parsing context */ + int iEq, /* Look at loop terms starting here */ + WhereLoop *pLoop, /* The current loop */ + Expr *pX /* The IN expression to be reduced */ +){ + sqlite3 *db = pParse->db; + Expr *pNew = sqlite3ExprDup(db, pX, 0); + if( db->mallocFailed==0 ){ + ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */ + ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */ + ExprList *pRhs = 0; /* New RHS after modifications */ + ExprList *pLhs = 0; /* New LHS after mods */ + int i; /* Loop counter */ + Select *pSelect; /* Pointer to the SELECT on the RHS */ + + for(i=iEq; inLTerm; i++){ + if( pLoop->aLTerm[i]->pExpr==pX ){ + int iField = pLoop->aLTerm[i]->iField - 1; + assert( pOrigRhs->a[iField].pExpr!=0 ); + pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); + pOrigRhs->a[iField].pExpr = 0; + assert( pOrigLhs->a[iField].pExpr!=0 ); + pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); + pOrigLhs->a[iField].pExpr = 0; + } + } + sqlite3ExprListDelete(db, pOrigRhs); + sqlite3ExprListDelete(db, pOrigLhs); + pNew->pLeft->x.pList = pLhs; + pNew->x.pSelect->pEList = pRhs; + if( pLhs && pLhs->nExpr==1 ){ + /* Take care here not to generate a TK_VECTOR containing only a + ** single value. Since the parser never creates such a vector, some + ** of the subroutines do not handle this case. */ + Expr *p = pLhs->a[0].pExpr; + pLhs->a[0].pExpr = 0; + sqlite3ExprDelete(db, pNew->pLeft); + pNew->pLeft = p; + } + pSelect = pNew->x.pSelect; + if( pSelect->pOrderBy ){ + /* If the SELECT statement has an ORDER BY clause, zero the + ** iOrderByCol variables. These are set to non-zero when an + ** ORDER BY term exactly matches one of the terms of the + ** result-set. Since the result-set of the SELECT statement may + ** have been modified or reordered, these variables are no longer + ** set correctly. Since setting them is just an optimization, + ** it's easiest just to zero them here. */ + ExprList *pOrderBy = pSelect->pOrderBy; + for(i=0; inExpr; i++){ + pOrderBy->a[i].u.x.iOrderByCol = 0; + } + } + +#if 0 + printf("For indexing, change the IN expr:\n"); + sqlite3TreeViewExpr(0, pX, 0); + printf("Into:\n"); + sqlite3TreeViewExpr(0, pNew, 0); +#endif + } + return pNew; +} + + /* ** Generate code for a single equality term of the WHERE clause. An equality ** term can be either X=expr or X IN (...). pTerm is the term to be @@ -128559,68 +131340,23 @@ static int codeEqualityTerm( } } for(i=iEq;inLTerm; i++){ - if( ALWAYS(pLoop->aLTerm[i]) && pLoop->aLTerm[i]->pExpr==pX ) nEq++; + assert( pLoop->aLTerm[i]!=0 ); + if( pLoop->aLTerm[i]->pExpr==pX ) nEq++; } if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0); }else{ - Select *pSelect = pX->x.pSelect; sqlite3 *db = pParse->db; - u16 savedDbOptFlags = db->dbOptFlags; - ExprList *pOrigRhs = pSelect->pEList; - ExprList *pOrigLhs = pX->pLeft->x.pList; - ExprList *pRhs = 0; /* New Select.pEList for RHS */ - ExprList *pLhs = 0; /* New pX->pLeft vector */ + pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); - for(i=iEq;inLTerm; i++){ - if( pLoop->aLTerm[i]->pExpr==pX ){ - int iField = pLoop->aLTerm[i]->iField - 1; - Expr *pNewRhs = sqlite3ExprDup(db, pOrigRhs->a[iField].pExpr, 0); - Expr *pNewLhs = sqlite3ExprDup(db, pOrigLhs->a[iField].pExpr, 0); - - pRhs = sqlite3ExprListAppend(pParse, pRhs, pNewRhs); - pLhs = sqlite3ExprListAppend(pParse, pLhs, pNewLhs); - } - } if( !db->mallocFailed ){ - Expr *pLeft = pX->pLeft; - - if( pSelect->pOrderBy ){ - /* If the SELECT statement has an ORDER BY clause, zero the - ** iOrderByCol variables. These are set to non-zero when an - ** ORDER BY term exactly matches one of the terms of the - ** result-set. Since the result-set of the SELECT statement may - ** have been modified or reordered, these variables are no longer - ** set correctly. Since setting them is just an optimization, - ** it's easiest just to zero them here. */ - ExprList *pOrderBy = pSelect->pOrderBy; - for(i=0; inExpr; i++){ - pOrderBy->a[i].u.x.iOrderByCol = 0; - } - } - - /* Take care here not to generate a TK_VECTOR containing only a - ** single value. Since the parser never creates such a vector, some - ** of the subroutines do not handle this case. */ - if( pLhs->nExpr==1 ){ - pX->pLeft = pLhs->a[0].pExpr; - }else{ - pLeft->x.pList = pLhs; - aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq); - testcase( aiMap==0 ); - } - pSelect->pEList = pRhs; - db->dbOptFlags |= SQLITE_QueryFlattener; + aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap); - db->dbOptFlags = savedDbOptFlags; - testcase( aiMap!=0 && aiMap[0]!=0 ); - pSelect->pEList = pOrigRhs; - pLeft->x.pList = pOrigLhs; - pX->pLeft = pLeft; + pTerm->pExpr->iTable = pX->iTable; } - sqlite3ExprListDelete(pParse->db, pLhs); - sqlite3ExprListDelete(pParse->db, pRhs); + sqlite3ExprDelete(db, pX); + pX = pTerm->pExpr; } if( eType==IN_INDEX_INDEX_DESC ){ @@ -129464,7 +132200,15 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( if( sqlite3ExprIsVector(pX->pRight) ){ r1 = rTemp = sqlite3GetTempReg(pParse); codeExprOrVector(pParse, pX->pRight, r1, 1); - op = aMoveOp[(pX->op - TK_GT) | 0x0001]; + testcase( pX->op==TK_GT ); + testcase( pX->op==TK_GE ); + testcase( pX->op==TK_LT ); + testcase( pX->op==TK_LE ); + op = aMoveOp[((pX->op - TK_GT - 1) & 0x3) | 0x1]; + assert( pX->op!=TK_GT || op==OP_SeekGE ); + assert( pX->op!=TK_GE || op==OP_SeekGE ); + assert( pX->op!=TK_LT || op==OP_SeekLE ); + assert( pX->op!=TK_LE || op==OP_SeekLE ); }else{ r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp); disableTerm(pLevel, pStart); @@ -129759,6 +132503,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( } }else if( bStopAtNull ){ sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq); + sqlite3ExprCacheRemove(pParse, regBase+nEq, 1); endEq = 0; nConstraint++; } @@ -130187,7 +132932,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( continue; } - if( pTerm->wtFlags & TERM_LIKECOND ){ + if( (pTerm->wtFlags & TERM_LIKECOND)!=0 ){ /* If the TERM_LIKECOND flag is set, that means that the range search ** is sufficient to guarantee that the LIKE operator is true, so we ** can skip the call to the like(A,B) function. But this only works @@ -130197,8 +132942,9 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( continue; #else u32 x = pLevel->iLikeRepCntr; - assert( x>0 ); - skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1)); + if( x>0 ){ + skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1)); + } VdbeCoverage(v); #endif } @@ -130238,6 +132984,12 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( WO_EQ|WO_IN|WO_IS, 0); if( pAlt==0 ) continue; if( pAlt->wtFlags & (TERM_CODED) ) continue; + if( (pAlt->eOperator & WO_IN) + && (pAlt->pExpr->flags & EP_xIsSelect) + && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) + ){ + continue; + } testcase( pAlt->eOperator & WO_EQ ); testcase( pAlt->eOperator & WO_IS ); testcase( pAlt->eOperator & WO_IN ); @@ -131152,6 +133904,9 @@ static Bitmask exprSelectUsage(WhereMaskSet *pMaskSet, Select *pS){ for(i=0; inSrc; i++){ mask |= exprSelectUsage(pMaskSet, pSrc->a[i].pSelect); mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn); + if( pSrc->a[i].fg.isTabFunc ){ + mask |= sqlite3WhereExprListUsage(pMaskSet, pSrc->a[i].u1.pFuncArg); + } } } pS = pS->pPrior; @@ -131259,7 +134014,7 @@ static void exprAnalyze( int op; /* Top-level operator. pExpr->op */ Parse *pParse = pWInfo->pParse; /* Parsing context */ sqlite3 *db = pParse->db; /* Database connection */ - unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */ + unsigned char eOp2 = 0; /* op2 value for LIKE/REGEXP/GLOB */ int nLeft; /* Number of elements on left side vector */ if( db->mallocFailed ){ @@ -131503,7 +134258,7 @@ static void exprAnalyze( ** to do anything with MATCH functions. */ if( pWC->op==TK_AND ){ - Expr *pRight, *pLeft; + Expr *pRight = 0, *pLeft = 0; int res = isAuxiliaryVtabOperator(pExpr, &eOp2, &pLeft, &pRight); while( res-- > 0 ){ int idxNew; @@ -131564,7 +134319,7 @@ static void exprAnalyze( exprAnalyze(pSrc, pWC, idxNew); } pTerm = &pWC->a[idxTerm]; - pTerm->wtFlags = TERM_CODED|TERM_VIRTUAL; /* Disable the original */ + pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ pTerm->eOperator = 0; } @@ -131827,6 +134582,21 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs( /* #include "sqliteInt.h" */ /* #include "whereInt.h" */ +/* +** Extra information appended to the end of sqlite3_index_info but not +** visible to the xBestIndex function, at least not directly. The +** sqlite3_vtab_collation() interface knows how to reach it, however. +** +** This object is not an API and can be changed from one release to the +** next. As long as allocateIndexInfo() and sqlite3_vtab_collation() +** agree on the structure, all will be well. +*/ +typedef struct HiddenIndexInfo HiddenIndexInfo; +struct HiddenIndexInfo { + WhereClause *pWC; /* The Where clause being analyzed */ + Parse *pParse; /* The parsing context */ +}; + /* Forward declaration of methods */ static int whereLoopResize(sqlite3*, WhereLoop*, int); @@ -132649,11 +135419,11 @@ end_auto_index_create: ** by passing the pointer returned by this function to sqlite3_free(). */ static sqlite3_index_info *allocateIndexInfo( - Parse *pParse, - WhereClause *pWC, + Parse *pParse, /* The parsing context */ + WhereClause *pWC, /* The WHERE clause being analyzed */ Bitmask mUnusable, /* Ignore terms with these prereqs */ - struct SrcList_item *pSrc, - ExprList *pOrderBy, + struct SrcList_item *pSrc, /* The FROM clause term that is the vtab */ + ExprList *pOrderBy, /* The ORDER BY clause */ u16 *pmNoOmit /* Mask of terms not to omit */ ){ int i, j; @@ -132661,6 +135431,7 @@ static sqlite3_index_info *allocateIndexInfo( struct sqlite3_index_constraint *pIdxCons; struct sqlite3_index_orderby *pIdxOrderBy; struct sqlite3_index_constraint_usage *pUsage; + struct HiddenIndexInfo *pHidden; WhereTerm *pTerm; int nOrderBy; sqlite3_index_info *pIdxInfo; @@ -132702,7 +135473,7 @@ static sqlite3_index_info *allocateIndexInfo( */ pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo) + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm - + sizeof(*pIdxOrderBy)*nOrderBy ); + + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) ); if( pIdxInfo==0 ){ sqlite3ErrorMsg(pParse, "out of memory"); return 0; @@ -132713,7 +135484,8 @@ static sqlite3_index_info *allocateIndexInfo( ** changing them. We have to do some funky casting in order to ** initialize those fields. */ - pIdxCons = (struct sqlite3_index_constraint*)&pIdxInfo[1]; + pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1]; + pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1]; pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm]; pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy]; *(int*)&pIdxInfo->nConstraint = nTerm; @@ -132723,6 +135495,8 @@ static sqlite3_index_info *allocateIndexInfo( *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = pUsage; + pHidden->pWC = pWC; + pHidden->pParse = pParse; for(i=j=0, pTerm=pWC->a; inTerm; i++, pTerm++){ u16 op; if( pTerm->leftCursor != pSrc->iCursor ) continue; @@ -133671,22 +136445,21 @@ static void whereLoopDelete(sqlite3 *db, WhereLoop *p){ ** Free a WhereInfo structure */ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ - if( ALWAYS(pWInfo) ){ - int i; - for(i=0; inLevel; i++){ - WhereLevel *pLevel = &pWInfo->a[i]; - if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ - sqlite3DbFree(db, pLevel->u.in.aInLoop); - } + int i; + assert( pWInfo!=0 ); + for(i=0; inLevel; i++){ + WhereLevel *pLevel = &pWInfo->a[i]; + if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ + sqlite3DbFree(db, pLevel->u.in.aInLoop); } - sqlite3WhereClauseClear(&pWInfo->sWC); - while( pWInfo->pLoops ){ - WhereLoop *p = pWInfo->pLoops; - pWInfo->pLoops = p->pNextLoop; - whereLoopDelete(db, p); - } - sqlite3DbFreeNN(db, pWInfo); } + sqlite3WhereClauseClear(&pWInfo->sWC); + while( pWInfo->pLoops ){ + WhereLoop *p = pWInfo->pLoops; + pWInfo->pLoops = p->pNextLoop; + whereLoopDelete(db, p); + } + sqlite3DbFreeNN(db, pWInfo); } /* @@ -134163,8 +136936,8 @@ static int whereLoopAddBtreeIndex( pNew = pBuilder->pNew; if( db->mallocFailed ) return SQLITE_NOMEM_BKPT; - WHERETRACE(0x800, ("BEGIN addBtreeIdx(%s), nEq=%d\n", - pProbe->zName, pNew->u.btree.nEq)); + WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d\n", + pProbe->pTable->zName,pProbe->zName, pNew->u.btree.nEq)); assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 ); assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 ); @@ -134269,12 +137042,14 @@ static int whereLoopAddBtreeIndex( pNew->wsFlags |= WHERE_COLUMN_EQ; assert( saved_nEq==pNew->u.btree.nEq ); if( iCol==XN_ROWID - || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) + || (iCol>=0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){ - if( iCol>=0 && pProbe->uniqNotNull==0 ){ - pNew->wsFlags |= WHERE_UNQ_WANTED; - }else{ + if( iCol==XN_ROWID || pProbe->uniqNotNull + || (pProbe->nKeyCol==1 && pProbe->onError && eOp==WO_EQ) + ){ pNew->wsFlags |= WHERE_ONEROW; + }else{ + pNew->wsFlags |= WHERE_UNQ_WANTED; } } }else if( eOp & WO_ISNULL ){ @@ -134448,8 +137223,8 @@ static int whereLoopAddBtreeIndex( pNew->wsFlags = saved_wsFlags; } - WHERETRACE(0x800, ("END addBtreeIdx(%s), nEq=%d, rc=%d\n", - pProbe->zName, saved_nEq, rc)); + WHERETRACE(0x800, ("END %s.addBtreeIdx(%s), nEq=%d, rc=%d\n", + pProbe->pTable->zName, pProbe->zName, saved_nEq, rc)); return rc; } @@ -134678,14 +137453,17 @@ static int whereLoopAddBtree( } #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ - /* Loop over all indices - */ - for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){ + /* Loop over all indices. If there was an INDEXED BY clause, then only + ** consider index pProbe. */ + for(; rc==SQLITE_OK && pProbe; + pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++ + ){ if( pProbe->pPartIdxWhere!=0 && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){ testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ continue; /* Partial index inappropriate for this query */ } + if( pProbe->bNoQuery ) continue; rSize = pProbe->aiRowLogEst[0]; pNew->u.btree.nEq = 0; pNew->u.btree.nBtm = 0; @@ -134790,10 +137568,6 @@ static int whereLoopAddBtree( pBuilder->nRecValid = 0; pBuilder->pRec = 0; #endif - - /* If there was an INDEXED BY clause, then only that one index is - ** considered. */ - if( pSrc->pIBIndex ) break; } return rc; } @@ -134888,9 +137662,9 @@ static int whereLoopAddVirtualOne( || pNew->aLTerm[iTerm]!=0 || pIdxCons->usable==0 ){ - rc = SQLITE_ERROR; sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName); - return rc; + testcase( pIdxInfo->needToFreeIdxStr ); + return SQLITE_ERROR; } testcase( iTerm==nConstraint-1 ); testcase( j==0 ); @@ -134918,6 +137692,15 @@ static int whereLoopAddVirtualOne( pNew->u.vtab.omitMask &= ~mNoOmit; pNew->nLTerm = mxTerm+1; + for(i=0; i<=mxTerm; i++){ + if( pNew->aLTerm[i]==0 ){ + /* The non-zero argvIdx values must be contiguous. Raise an + ** error if they are not */ + sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName); + testcase( pIdxInfo->needToFreeIdxStr ); + return SQLITE_ERROR; + } + } assert( pNew->nLTerm<=pNew->nLSlot ); pNew->u.vtab.idxNum = pIdxInfo->idxNum; pNew->u.vtab.needFree = pIdxInfo->needToFreeIdxStr; @@ -134948,6 +137731,27 @@ static int whereLoopAddVirtualOne( return rc; } +/* +** If this function is invoked from within an xBestIndex() callback, it +** returns a pointer to a buffer containing the name of the collation +** sequence associated with element iCons of the sqlite3_index_info.aConstraint +** array. Or, if iCons is out of range or there is no active xBestIndex +** call, return NULL. +*/ +SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info *pIdxInfo, int iCons){ + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; + const char *zRet = 0; + if( iCons>=0 && iConsnConstraint ){ + CollSeq *pC = 0; + int iTerm = pIdxInfo->aConstraint[iCons].iTermOffset; + Expr *pX = pHidden->pWC->a[iTerm].pExpr; + if( pX->pLeft ){ + pC = sqlite3BinaryCompareCollSeq(pHidden->pParse, pX->pLeft, pX->pRight); + } + zRet = (pC ? pC->zName : "BINARY"); + } + return zRet; +} /* ** Add all WhereLoop objects for a table of the join identified by @@ -135012,6 +137816,7 @@ static int whereLoopAddVirtual( } /* First call xBestIndex() with all constraints usable. */ + WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName)); WHERETRACE(0x40, (" VirtualOne: all usable\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn); @@ -135087,6 +137892,7 @@ static int whereLoopAddVirtual( if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr); sqlite3DbFreeNN(pParse->db, p); + WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc)); return rc; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -136401,6 +139207,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( */ for(ii=0; iinTerm; ii++){ WhereTerm *pT = &sWLB.pWC->a[ii]; + if( pT->wtFlags & TERM_VIRTUAL ) continue; if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){ sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL); pT->wtFlags |= TERM_CODED; @@ -136488,35 +139295,80 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( } } #endif - /* Attempt to omit tables from the join that do not effect the result */ + + /* Attempt to omit tables from the join that do not affect the result. + ** For a table to not affect the result, the following must be true: + ** + ** 1) The query must not be an aggregate. + ** 2) The table must be the RHS of a LEFT JOIN. + ** 3) Either the query must be DISTINCT, or else the ON or USING clause + ** must contain a constraint that limits the scan of the table to + ** at most a single row. + ** 4) The table must not be referenced by any part of the query apart + ** from its own USING or ON clause. + ** + ** For example, given: + ** + ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); + ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); + ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); + ** + ** then table t2 can be omitted from the following: + ** + ** SELECT v1, v3 FROM t1 + ** LEFT JOIN t2 USING (t1.ipk=t2.ipk) + ** LEFT JOIN t3 USING (t1.ipk=t3.ipk) + ** + ** or from: + ** + ** SELECT DISTINCT v1, v3 FROM t1 + ** LEFT JOIN t2 + ** LEFT JOIN t3 USING (t1.ipk=t3.ipk) + */ + notReady = ~(Bitmask)0; if( pWInfo->nLevel>=2 - && pResultSet!=0 + && pResultSet!=0 /* guarantees condition (1) above */ && OptimizationEnabled(db, SQLITE_OmitNoopJoin) ){ + int i; Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); if( sWLB.pOrderBy ){ tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); } - while( pWInfo->nLevel>=2 ){ + for(i=pWInfo->nLevel-1; i>=1; i--){ WhereTerm *pTerm, *pEnd; - pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop; - if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break; + struct SrcList_item *pItem; + pLoop = pWInfo->a[i].pWLoop; + pItem = &pWInfo->pTabList->a[pLoop->iTab]; + if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; if( (wctrlFlags & WHERE_WANT_DISTINCT)==0 && (pLoop->wsFlags & WHERE_ONEROW)==0 ){ - break; + continue; } - if( (tabUsed & pLoop->maskSelf)!=0 ) break; + if( (tabUsed & pLoop->maskSelf)!=0 ) continue; pEnd = sWLB.pWC->a + sWLB.pWC->nTerm; for(pTerm=sWLB.pWC->a; pTermprereqAll & pLoop->maskSelf)!=0 - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) - ){ - break; + if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ + if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + || pTerm->pExpr->iRightJoinTable!=pItem->iCursor + ){ + break; + } } } - if( pTerm drop loop %c not used\n", pLoop->cId)); + notReady &= ~pLoop->maskSelf; + for(pTerm=sWLB.pWC->a; pTermprereqAll & pLoop->maskSelf)!=0 ){ + pTerm->wtFlags |= TERM_CODED; + } + } + if( i!=pWInfo->nLevel-1 ){ + int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel); + memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte); + } pWInfo->nLevel--; nTabList--; } @@ -136526,15 +139378,32 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( /* If the caller is an UPDATE or DELETE statement that is requesting ** to use a one-pass algorithm, determine if this is appropriate. + ** + ** A one-pass approach can be used if the caller has requested one + ** and either (a) the scan visits at most one row or (b) each + ** of the following are true: + ** + ** * the caller has indicated that a one-pass approach can be used + ** with multiple rows (by setting WHERE_ONEPASS_MULTIROW), and + ** * the table is not a virtual table, and + ** * either the scan does not use the OR optimization or the caller + ** is a DELETE operation (WHERE_DUPLICATES_OK is only specified + ** for DELETE). + ** + ** The last qualification is because an UPDATE statement uses + ** WhereInfo.aiCurOnePass[1] to determine whether or not it really can + ** use a one-pass approach, and this is not set accurately for scans + ** that use the OR optimization. */ assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 ){ int wsFlags = pWInfo->a[0].pWLoop->wsFlags; int bOnerow = (wsFlags & WHERE_ONEROW)!=0; - if( bOnerow - || ((wctrlFlags & WHERE_ONEPASS_MULTIROW)!=0 - && 0==(wsFlags & WHERE_VIRTUALTABLE)) - ){ + if( bOnerow || ( + 0!=(wctrlFlags & WHERE_ONEPASS_MULTIROW) + && 0==(wsFlags & WHERE_VIRTUALTABLE) + && (0==(wsFlags & WHERE_MULTI_OR) || (wctrlFlags & WHERE_DUPLICATES_OK)) + )){ pWInfo->eOnePass = bOnerow ? ONEPASS_SINGLE : ONEPASS_MULTI; if( HasRowid(pTabList->a[0].pTab) && (wsFlags & WHERE_IDX_ONLY) ){ if( wctrlFlags & WHERE_ONEPASS_MULTIROW ){ @@ -136671,7 +139540,6 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( ** loop below generates code for a single nested loop of the VM ** program. */ - notReady = ~(Bitmask)0; for(ii=0; iieDistinct==WHERE_DISTINCT_ORDERED + && i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */ && (pLoop->wsFlags & WHERE_INDEXED)!=0 && (pIdx = pLoop->u.btree.pIndex)->hasStat1 && (n = pLoop->u.btree.nIdxCol)>0 @@ -136801,7 +139670,8 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 ); if( (ws & WHERE_IDX_ONLY)==0 ){ - sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor); + assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor ); + sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); } if( (ws & WHERE_INDEXED) || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) @@ -136870,7 +139740,11 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ pOp = sqlite3VdbeGetOp(v, k); for(; kp1!=pLevel->iTabCur ) continue; - if( pOp->opcode==OP_Column ){ + if( pOp->opcode==OP_Column +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC + || pOp->opcode==OP_Offset +#endif + ){ int x = pOp->p2; assert( pIdx->pTable==pTab ); if( !HasRowid(pTab) ){ @@ -136969,15 +139843,6 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ */ #define YYMALLOCARGTYPE u64 -/* -** An instance of this structure holds information about the -** LIMIT clause of a SELECT statement. -*/ -struct LimitVal { - Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ - Expr *pOffset; /* The OFFSET expression. NULL if there is none */ -}; - /* ** An instance of the following structure describes the event of a ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, @@ -137021,20 +139886,12 @@ static void disableLookaside(Parse *pParse){ } } - /* This is a utility routine used to set the ExprSpan.zStart and - ** ExprSpan.zEnd values of pOut so that the span covers the complete - ** range of text beginning with pStart and going to the end of pEnd. - */ - static void spanSet(ExprSpan *pOut, Token *pStart, Token *pEnd){ - pOut->zStart = pStart->z; - pOut->zEnd = &pEnd->z[pEnd->n]; - } /* Construct a new Expr object from a single identifier. Use the ** new Expr to populate pOut. Set the span of pOut to be the identifier ** that created the expression. */ - static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token t){ + static Expr *tokenExpr(Parse *pParse, int op, Token t){ Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1); if( p ){ memset(p, 0, sizeof(Expr)); @@ -137052,45 +139909,9 @@ static void disableLookaside(Parse *pParse){ p->nHeight = 1; #endif } - pOut->pExpr = p; - pOut->zStart = t.z; - pOut->zEnd = &t.z[t.n]; + return p; } - /* This routine constructs a binary expression node out of two ExprSpan - ** objects and uses the result to populate a new ExprSpan object. - */ - static void spanBinaryExpr( - Parse *pParse, /* The parsing context. Errors accumulate here */ - int op, /* The binary operation */ - ExprSpan *pLeft, /* The left operand, and output */ - ExprSpan *pRight /* The right operand */ - ){ - pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr); - pLeft->zEnd = pRight->zEnd; - } - - /* If doNot is true, then add a TK_NOT Expr-node wrapper around the - ** outside of *ppExpr. - */ - static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){ - if( doNot ){ - pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0); - } - } - - /* Construct an expression node for a unary postfix operator - */ - static void spanUnaryPostfix( - Parse *pParse, /* Parsing context to record errors */ - int op, /* The operator */ - ExprSpan *pOperand, /* The operand, and output */ - Token *pPostOp /* The operand token for setting the span */ - ){ - pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); - pOperand->zEnd = &pPostOp->z[pPostOp->n]; - } - /* A routine to convert a binary TK_IS or TK_ISNOT expression into a ** unary TK_ISNULL or TK_NOTNULL expression. */ static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){ @@ -137102,20 +139923,6 @@ static void disableLookaside(Parse *pParse){ } } - /* Construct an expression node for a unary prefix operator - */ - static void spanUnaryPrefix( - ExprSpan *pOut, /* Write the new expression node here */ - Parse *pParse, /* Parsing context to record errors */ - int op, /* The operator */ - ExprSpan *pOperand, /* The operand */ - Token *pPreOp /* The operand token for setting the span */ - ){ - pOut->zStart = pPreOp->z; - pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); - pOut->zEnd = pOperand->zEnd; - } - /* Add a single new term to an ExprList that is used to store a ** list of identifiers. Report an error if the ID list contains ** a COLLATE clause or an ASC or DESC keyword, except ignore the @@ -137184,39 +139991,39 @@ static void disableLookaside(Parse *pParse){ ** defined, then do no error processing. ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar +** YYNTOKEN Number of terminal symbols ** YY_MAX_SHIFT Maximum value for shift actions ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** YY_MIN_REDUCE Minimum value for reduce actions -** YY_MAX_REDUCE Maximum value for reduce actions ** YY_ERROR_ACTION The yy_action[] code for syntax error ** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_NO_ACTION The yy_action[] code for no-op +** YY_MIN_REDUCE Minimum value for reduce actions +** YY_MAX_REDUCE Maximum value for reduce actions */ #ifndef INTERFACE # define INTERFACE 1 #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char -#define YYNOCODE 252 +#define YYNOCODE 253 #define YYACTIONTYPE unsigned short int #define YYWILDCARD 83 #define sqlite3ParserTOKENTYPE Token typedef union { int yyinit; sqlite3ParserTOKENTYPE yy0; - Expr* yy72; - TriggerStep* yy145; - ExprList* yy148; - SrcList* yy185; - ExprSpan yy190; - int yy194; - Select* yy243; - IdList* yy254; - With* yy285; - struct TrigEvent yy332; - struct LimitVal yy354; - struct {int value; int mask;} yy497; + int yy4; + struct TrigEvent yy90; + TriggerStep* yy203; + struct {int value; int mask;} yy215; + SrcList* yy259; + Expr* yy314; + ExprList* yy322; + const char* yy336; + IdList* yy384; + Select* yy387; + With* yy451; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -137226,16 +140033,17 @@ typedef union { #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse #define sqlite3ParserARG_STORE yypParser->pParse = pParse #define YYFALLBACK 1 -#define YYNSTATE 455 -#define YYNRULE 329 -#define YY_MAX_SHIFT 454 -#define YY_MIN_SHIFTREDUCE 664 -#define YY_MAX_SHIFTREDUCE 992 -#define YY_MIN_REDUCE 993 -#define YY_MAX_REDUCE 1321 -#define YY_ERROR_ACTION 1322 -#define YY_ACCEPT_ACTION 1323 -#define YY_NO_ACTION 1324 +#define YYNSTATE 472 +#define YYNRULE 333 +#define YYNTOKEN 143 +#define YY_MAX_SHIFT 471 +#define YY_MIN_SHIFTREDUCE 681 +#define YY_MAX_SHIFTREDUCE 1013 +#define YY_ERROR_ACTION 1014 +#define YY_ACCEPT_ACTION 1015 +#define YY_NO_ACTION 1016 +#define YY_MIN_REDUCE 1017 +#define YY_MAX_REDUCE 1349 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -137265,9 +140073,6 @@ typedef union { ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** -** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE -** and YY_MAX_REDUCE -** ** N == YY_ERROR_ACTION A syntax error has occurred. ** ** N == YY_ACCEPT_ACTION The parser accepts its input. @@ -137275,25 +140080,22 @@ typedef union { ** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** +** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE +** and YY_MAX_REDUCE +** ** The action table is constructed as a single large table named yy_action[]. ** Given state S and lookahead X, the action is computed as either: ** ** (A) N = yy_action[ yy_shift_ofst[S] + X ] ** (B) N = yy_default[S] ** -** The (A) formula is preferred. The B formula is used instead if: -** (1) The yy_shift_ofst[S]+X value is out of range, or -** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or -** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT. -** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that -** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X. -** Hence only tests (1) and (2) need to be evaluated.) +** The (A) formula is preferred. The B formula is used instead if +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. ** ** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. +** the yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** @@ -137309,461 +140111,479 @@ typedef union { *********** Begin parsing tables **********************************************/ #define YY_ACTTAB_COUNT (1566) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93, - /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94, - /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847, - /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350, - /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94, - /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94, - /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95, - /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132, - /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950, - /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132, - /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99, - /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, - /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369, - /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398, - /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396, - /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, - /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839, - /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261, - /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324, - /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818, - /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94, - /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850, - /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372, - /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178, - /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52, - /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95, - /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971, - /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, - /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995, - /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347, - /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96, - /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90, - /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, - /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951, - /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701, - /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96, - /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99, - /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, - /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427, - /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058, - /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374, - /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, - /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839, - /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449, - /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324, - /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36, - /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94, - /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850, - /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316, - /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318, - /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950, - /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95, - /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971, - /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98, - /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410, - /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771, - /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96, - /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90, - /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, - /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207, - /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298, - /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96, - /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697, - /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839, - /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120, - /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170, - /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268, - /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94, - /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90, - /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98, - /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133, - /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333, - /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96, - /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99, - /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97, - /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223, - /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246, - /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280, - /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, - /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839, - /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722, - /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202, - /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069, - /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94, - /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839, - /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232, - /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342, - /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202, - /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94, - /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839, - /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877, - /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689, - /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444, - /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94, - /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212, - /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419, - /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153, - /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433, - /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818, - /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86, - /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5, - /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140, - /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38, - /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351, - /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1, - /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449, - /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84, - /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10, - /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303, - /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447, - /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950, - /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447, - /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951, - /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291, - /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360, - /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351, - /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211, - /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351, - /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173, - /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19, - /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95, - /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19, - /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276, - /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247, - /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41, - /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31, - /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449, - /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137, - /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46, - /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48, - /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185, - /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449, - /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122, - /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35, - /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449, - /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449, - /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112, - /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55, - /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26, - /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006, - /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029, - /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204, - /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292, - /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22, - /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304, - /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235, - /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883, - /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899, - /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187, - /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387, - /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151, - /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825, - /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222, - /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852, - /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210, - /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87, - /* 1560 */ 211, 309, 1281, 940, 995, 1280, + /* 0 */ 1169, 1015, 167, 167, 1, 168, 466, 1313, 466, 1083, + /* 10 */ 1062, 466, 97, 94, 183, 1057, 466, 329, 1083, 342, + /* 20 */ 97, 94, 183, 459, 459, 459, 436, 57, 57, 57, + /* 30 */ 57, 807, 57, 57, 367, 367, 367, 57, 57, 808, + /* 40 */ 1270, 1088, 1088, 104, 105, 95, 991, 991, 868, 871, + /* 50 */ 860, 860, 102, 102, 103, 103, 103, 103, 233, 233, + /* 60 */ 326, 1011, 449, 437, 449, 446, 351, 449, 461, 1142, + /* 70 */ 463, 342, 449, 426, 1316, 209, 180, 742, 80, 299, + /* 80 */ 857, 857, 869, 872, 101, 101, 101, 101, 100, 100, + /* 90 */ 99, 99, 99, 98, 368, 104, 105, 95, 991, 991, + /* 100 */ 868, 871, 860, 860, 102, 102, 103, 103, 103, 103, + /* 110 */ 99, 99, 99, 98, 368, 355, 97, 94, 183, 228, + /* 120 */ 106, 1012, 407, 342, 101, 101, 101, 101, 100, 100, + /* 130 */ 99, 99, 99, 98, 368, 861, 101, 101, 101, 101, + /* 140 */ 100, 100, 99, 99, 99, 98, 368, 104, 105, 95, + /* 150 */ 991, 991, 868, 871, 860, 860, 102, 102, 103, 103, + /* 160 */ 103, 103, 201, 368, 375, 420, 417, 416, 387, 273, + /* 170 */ 65, 97, 94, 183, 168, 342, 415, 951, 1343, 396, + /* 180 */ 66, 1343, 320, 959, 371, 970, 334, 340, 101, 101, + /* 190 */ 101, 101, 100, 100, 99, 99, 99, 98, 368, 104, + /* 200 */ 105, 95, 991, 991, 868, 871, 860, 860, 102, 102, + /* 210 */ 103, 103, 103, 103, 373, 100, 100, 99, 99, 99, + /* 220 */ 98, 368, 970, 971, 972, 201, 1100, 342, 420, 417, + /* 230 */ 416, 287, 366, 365, 337, 970, 1162, 463, 949, 415, + /* 240 */ 101, 101, 101, 101, 100, 100, 99, 99, 99, 98, + /* 250 */ 368, 104, 105, 95, 991, 991, 868, 871, 860, 860, + /* 260 */ 102, 102, 103, 103, 103, 103, 777, 241, 233, 233, + /* 270 */ 9, 847, 970, 971, 972, 390, 998, 1141, 998, 342, + /* 280 */ 463, 252, 829, 719, 98, 368, 840, 298, 338, 142, + /* 290 */ 839, 339, 101, 101, 101, 101, 100, 100, 99, 99, + /* 300 */ 99, 98, 368, 104, 105, 95, 991, 991, 868, 871, + /* 310 */ 860, 860, 102, 102, 103, 103, 103, 103, 272, 466, + /* 320 */ 392, 839, 839, 841, 97, 94, 183, 390, 1317, 253, + /* 330 */ 456, 342, 125, 166, 807, 712, 208, 407, 386, 970, + /* 340 */ 57, 57, 808, 238, 101, 101, 101, 101, 100, 100, + /* 350 */ 99, 99, 99, 98, 368, 104, 105, 95, 991, 991, + /* 360 */ 868, 871, 860, 860, 102, 102, 103, 103, 103, 103, + /* 370 */ 466, 108, 466, 267, 465, 442, 970, 971, 972, 261, + /* 380 */ 951, 1344, 909, 342, 1344, 142, 829, 848, 1292, 959, + /* 390 */ 371, 55, 55, 57, 57, 242, 101, 101, 101, 101, + /* 400 */ 100, 100, 99, 99, 99, 98, 368, 104, 105, 95, + /* 410 */ 991, 991, 868, 871, 860, 860, 102, 102, 103, 103, + /* 420 */ 103, 103, 272, 382, 262, 253, 456, 310, 364, 253, + /* 430 */ 456, 86, 264, 84, 266, 342, 441, 176, 175, 834, + /* 440 */ 464, 949, 767, 767, 332, 313, 1094, 396, 101, 101, + /* 450 */ 101, 101, 100, 100, 99, 99, 99, 98, 368, 104, + /* 460 */ 105, 95, 991, 991, 868, 871, 860, 860, 102, 102, + /* 470 */ 103, 103, 103, 103, 227, 227, 233, 233, 233, 233, + /* 480 */ 387, 273, 234, 234, 326, 950, 463, 342, 463, 298, + /* 490 */ 463, 914, 914, 404, 463, 1037, 123, 265, 27, 970, + /* 500 */ 101, 101, 101, 101, 100, 100, 99, 99, 99, 98, + /* 510 */ 368, 104, 105, 95, 991, 991, 868, 871, 860, 860, + /* 520 */ 102, 102, 103, 103, 103, 103, 435, 233, 233, 466, + /* 530 */ 285, 686, 687, 688, 127, 271, 970, 971, 972, 463, + /* 540 */ 1345, 327, 342, 407, 157, 1012, 988, 13, 13, 181, + /* 550 */ 41, 41, 101, 101, 101, 101, 100, 100, 99, 99, + /* 560 */ 99, 98, 368, 715, 794, 378, 104, 105, 95, 991, + /* 570 */ 991, 868, 871, 860, 860, 102, 102, 103, 103, 103, + /* 580 */ 103, 970, 378, 377, 346, 239, 847, 1086, 1086, 280, + /* 590 */ 1169, 283, 204, 203, 202, 177, 298, 342, 407, 298, + /* 600 */ 715, 840, 169, 299, 407, 839, 82, 101, 101, 101, + /* 610 */ 101, 100, 100, 99, 99, 99, 98, 368, 970, 971, + /* 620 */ 972, 104, 105, 95, 991, 991, 868, 871, 860, 860, + /* 630 */ 102, 102, 103, 103, 103, 103, 839, 839, 841, 362, + /* 640 */ 240, 124, 1169, 172, 126, 378, 1269, 1169, 1066, 342, + /* 650 */ 253, 456, 407, 407, 407, 396, 352, 401, 407, 429, + /* 660 */ 398, 85, 101, 101, 101, 101, 100, 100, 99, 99, + /* 670 */ 99, 98, 368, 104, 105, 95, 991, 991, 868, 871, + /* 680 */ 860, 860, 102, 102, 103, 103, 103, 103, 1169, 466, + /* 690 */ 230, 233, 233, 792, 1235, 1095, 1091, 1293, 1, 77, + /* 700 */ 278, 342, 205, 463, 974, 911, 1040, 348, 353, 911, + /* 710 */ 42, 42, 79, 403, 101, 101, 101, 101, 100, 100, + /* 720 */ 99, 99, 99, 98, 368, 104, 93, 95, 991, 991, + /* 730 */ 868, 871, 860, 860, 102, 102, 103, 103, 103, 103, + /* 740 */ 402, 9, 974, 243, 772, 458, 348, 232, 180, 771, + /* 750 */ 946, 312, 342, 328, 363, 349, 143, 831, 389, 1278, + /* 760 */ 211, 211, 21, 347, 432, 182, 101, 101, 101, 101, + /* 770 */ 100, 100, 99, 99, 99, 98, 368, 105, 95, 991, + /* 780 */ 991, 868, 871, 860, 860, 102, 102, 103, 103, 103, + /* 790 */ 103, 792, 724, 22, 732, 731, 233, 233, 1239, 256, + /* 800 */ 391, 274, 342, 211, 79, 360, 257, 413, 463, 397, + /* 810 */ 207, 288, 260, 450, 79, 1239, 1241, 101, 101, 101, + /* 820 */ 101, 100, 100, 99, 99, 99, 98, 368, 95, 991, + /* 830 */ 991, 868, 871, 860, 860, 102, 102, 103, 103, 103, + /* 840 */ 103, 91, 457, 296, 3, 233, 233, 5, 438, 212, + /* 850 */ 331, 394, 739, 740, 295, 898, 894, 463, 460, 207, + /* 860 */ 801, 1237, 722, 211, 698, 843, 1283, 101, 101, 101, + /* 870 */ 101, 100, 100, 99, 99, 99, 98, 368, 1239, 380, + /* 880 */ 357, 369, 233, 233, 989, 219, 236, 297, 423, 292, + /* 890 */ 422, 206, 454, 898, 463, 970, 91, 457, 290, 3, + /* 900 */ 722, 142, 268, 843, 847, 466, 1258, 149, 388, 425, + /* 910 */ 88, 89, 769, 460, 930, 87, 447, 90, 369, 468, + /* 920 */ 467, 385, 989, 839, 1257, 439, 57, 57, 395, 931, + /* 930 */ 1065, 158, 970, 971, 972, 772, 369, 471, 1019, 399, + /* 940 */ 771, 253, 456, 254, 932, 119, 891, 454, 233, 233, + /* 950 */ 4, 970, 1096, 275, 839, 839, 841, 842, 19, 847, + /* 960 */ 463, 449, 448, 163, 453, 88, 89, 776, 970, 1127, + /* 970 */ 279, 930, 90, 369, 468, 467, 91, 457, 839, 3, + /* 980 */ 235, 1064, 466, 1228, 233, 233, 931, 970, 970, 971, + /* 990 */ 972, 970, 908, 460, 908, 2, 463, 81, 457, 212, + /* 1000 */ 3, 932, 282, 10, 10, 970, 971, 972, 189, 839, + /* 1010 */ 839, 841, 842, 19, 460, 284, 369, 354, 907, 286, + /* 1020 */ 907, 753, 466, 1079, 970, 971, 972, 454, 970, 971, + /* 1030 */ 972, 754, 970, 1063, 989, 372, 792, 369, 1118, 847, + /* 1040 */ 291, 452, 466, 10, 10, 88, 89, 142, 454, 168, + /* 1050 */ 300, 412, 90, 369, 468, 467, 793, 356, 839, 706, + /* 1060 */ 847, 341, 121, 10, 10, 301, 88, 89, 379, 970, + /* 1070 */ 971, 972, 989, 90, 369, 468, 467, 244, 205, 839, + /* 1080 */ 1306, 245, 1135, 245, 250, 1168, 1114, 253, 456, 839, + /* 1090 */ 839, 841, 842, 19, 1125, 237, 122, 451, 1174, 733, + /* 1100 */ 324, 324, 323, 222, 321, 466, 1046, 695, 182, 225, + /* 1110 */ 839, 839, 841, 842, 19, 103, 103, 103, 103, 96, + /* 1120 */ 185, 466, 259, 1039, 1028, 170, 10, 10, 1027, 421, + /* 1130 */ 258, 1029, 1300, 708, 792, 466, 408, 734, 8, 347, + /* 1140 */ 444, 174, 12, 12, 290, 101, 101, 101, 101, 100, + /* 1150 */ 100, 99, 99, 99, 98, 368, 32, 32, 466, 187, + /* 1160 */ 466, 1111, 103, 103, 103, 103, 188, 466, 325, 138, + /* 1170 */ 186, 708, 303, 305, 307, 358, 970, 270, 393, 43, + /* 1180 */ 43, 44, 44, 1157, 333, 178, 418, 294, 45, 45, + /* 1190 */ 1232, 318, 101, 101, 101, 101, 100, 100, 99, 99, + /* 1200 */ 99, 98, 368, 381, 343, 366, 365, 466, 263, 253, + /* 1210 */ 456, 466, 1062, 970, 971, 972, 1231, 997, 309, 466, + /* 1220 */ 455, 466, 427, 466, 995, 173, 996, 1303, 46, 46, + /* 1230 */ 145, 376, 37, 37, 1006, 1277, 466, 214, 1275, 64, + /* 1240 */ 47, 47, 33, 33, 34, 34, 1003, 67, 466, 998, + /* 1250 */ 350, 998, 466, 155, 233, 233, 466, 36, 36, 24, + /* 1260 */ 140, 77, 1154, 466, 383, 466, 463, 428, 466, 48, + /* 1270 */ 48, 466, 147, 49, 49, 466, 150, 50, 50, 466, + /* 1280 */ 151, 152, 466, 384, 11, 11, 51, 51, 466, 110, + /* 1290 */ 110, 153, 52, 52, 411, 466, 38, 38, 466, 191, + /* 1300 */ 53, 53, 466, 54, 54, 466, 400, 466, 330, 39, + /* 1310 */ 39, 466, 1164, 466, 25, 466, 56, 56, 466, 131, + /* 1320 */ 131, 72, 466, 132, 132, 159, 133, 133, 61, 61, + /* 1330 */ 1226, 195, 40, 40, 111, 111, 58, 58, 406, 112, + /* 1340 */ 112, 466, 277, 113, 113, 466, 226, 466, 1246, 466, + /* 1350 */ 197, 466, 164, 466, 409, 466, 198, 466, 199, 466, + /* 1360 */ 335, 281, 109, 109, 466, 1030, 130, 130, 129, 129, + /* 1370 */ 117, 117, 116, 116, 114, 114, 115, 115, 60, 60, + /* 1380 */ 62, 62, 466, 359, 466, 59, 59, 424, 1082, 1081, + /* 1390 */ 1080, 724, 1073, 1054, 336, 293, 1053, 1052, 1315, 431, + /* 1400 */ 361, 76, 248, 31, 31, 35, 35, 1072, 249, 440, + /* 1410 */ 302, 434, 213, 1122, 6, 311, 1212, 107, 83, 251, + /* 1420 */ 78, 1123, 445, 220, 443, 1036, 304, 23, 1121, 469, + /* 1430 */ 965, 221, 223, 1104, 314, 224, 344, 317, 315, 316, + /* 1440 */ 470, 306, 1025, 1120, 308, 1262, 1020, 134, 120, 246, + /* 1450 */ 682, 370, 171, 255, 1263, 135, 184, 1261, 1260, 374, + /* 1460 */ 118, 906, 904, 827, 1050, 146, 136, 137, 148, 1049, + /* 1470 */ 63, 1047, 756, 190, 269, 920, 154, 156, 68, 69, + /* 1480 */ 70, 71, 139, 923, 192, 193, 144, 919, 345, 128, + /* 1490 */ 14, 194, 276, 211, 1000, 405, 196, 161, 912, 160, + /* 1500 */ 26, 697, 410, 295, 200, 289, 414, 162, 419, 73, + /* 1510 */ 15, 16, 141, 74, 28, 247, 846, 845, 735, 874, + /* 1520 */ 954, 75, 430, 955, 29, 433, 179, 229, 231, 800, + /* 1530 */ 165, 795, 87, 210, 889, 79, 875, 17, 873, 877, + /* 1540 */ 929, 18, 928, 216, 215, 878, 20, 30, 462, 844, + /* 1550 */ 707, 92, 766, 770, 7, 322, 217, 218, 319, 1308, + /* 1560 */ 960, 1016, 1016, 1016, 1016, 1307, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93, - /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91, - /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48, - /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94, - /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92, - /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90, - /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88, - /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79, - /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96, - /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79, - /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43, - /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109, - /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103, - /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113, - /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, - /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110, - /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19, - /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101, - /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91, - /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, - /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152, - /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223, - /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173, - /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89, - /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, - /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149, - /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89, - /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87, - /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, - /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97, - /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23, - /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85, - /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, - /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207, - /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179, - /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152, - /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, - /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152, - /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19, - /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172, - /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91, - /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, - /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22, - /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247, - /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59, - /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89, - /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, - /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115, - /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26, - /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87, - /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, - /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193, - /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152, - /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85, - /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59, - /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50, - /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196, - /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89, - /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152, - /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90, - /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45, - /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246, - /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217, - /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85, - /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, - /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211, - /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152, - /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112, - /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, - /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8, - /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26, - /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163, - /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91, - /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50, - /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238, - /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19, - /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26, - /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90, - /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50, - /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97, - /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23, - /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20, - /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90, - /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99, - /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96, - /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71, - /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70, - /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101, - /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19, - /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22, - /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152, - /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173, - /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59, - /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22, - /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152, - /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89, - /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172, - /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152, - /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36, - /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96, - /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36, - /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97, - /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210, - /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152, - /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96, - /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152, - /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96, - /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184, - /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136, - /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89, - /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136, - /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155, - /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159, - /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173, - /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173, - /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152, - /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189, - /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172, - /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173, - /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158, - /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152, - /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173, - /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172, - /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152, - /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152, - /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172, - /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172, - /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173, - /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159, - /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174, - /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159, - /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215, - /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26, - /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204, - /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178, - /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23, - /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1, - /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122, - /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41, - /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22, - /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23, - /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23, - /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23, - /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122, - /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22, - /* 1560 */ 122, 23, 122, 1, 251, 122, + /* 0 */ 152, 144, 145, 146, 147, 152, 152, 172, 152, 180, + /* 10 */ 181, 152, 223, 224, 225, 180, 152, 164, 189, 19, + /* 20 */ 223, 224, 225, 168, 169, 170, 163, 173, 174, 173, + /* 30 */ 174, 31, 173, 174, 168, 169, 170, 173, 174, 39, + /* 40 */ 243, 191, 192, 43, 44, 45, 46, 47, 48, 49, + /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 195, 196, + /* 60 */ 22, 23, 208, 209, 208, 209, 218, 208, 209, 176, + /* 70 */ 207, 19, 208, 209, 23, 212, 213, 26, 26, 152, + /* 80 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89, + /* 90 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, + /* 100 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 110 */ 90, 91, 92, 93, 94, 188, 223, 224, 225, 171, + /* 120 */ 68, 83, 152, 19, 84, 85, 86, 87, 88, 89, + /* 130 */ 90, 91, 92, 93, 94, 101, 84, 85, 86, 87, + /* 140 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, + /* 150 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + /* 160 */ 56, 57, 99, 94, 194, 102, 103, 104, 109, 110, + /* 170 */ 66, 223, 224, 225, 152, 19, 113, 22, 23, 152, + /* 180 */ 24, 26, 160, 1, 2, 59, 164, 173, 84, 85, + /* 190 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, + /* 200 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + /* 210 */ 54, 55, 56, 57, 244, 88, 89, 90, 91, 92, + /* 220 */ 93, 94, 96, 97, 98, 99, 196, 19, 102, 103, + /* 230 */ 104, 23, 88, 89, 173, 59, 163, 207, 83, 113, + /* 240 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, + /* 250 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, + /* 260 */ 52, 53, 54, 55, 56, 57, 90, 240, 195, 196, + /* 270 */ 171, 82, 96, 97, 98, 152, 132, 176, 134, 19, + /* 280 */ 207, 200, 72, 23, 93, 94, 97, 152, 173, 79, + /* 290 */ 101, 210, 84, 85, 86, 87, 88, 89, 90, 91, + /* 300 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, + /* 310 */ 50, 51, 52, 53, 54, 55, 56, 57, 108, 152, + /* 320 */ 152, 132, 133, 134, 223, 224, 225, 152, 186, 119, + /* 330 */ 120, 19, 197, 234, 31, 23, 26, 152, 239, 59, + /* 340 */ 173, 174, 39, 220, 84, 85, 86, 87, 88, 89, + /* 350 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, + /* 360 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 370 */ 152, 22, 152, 16, 152, 208, 96, 97, 98, 194, + /* 380 */ 22, 23, 11, 19, 26, 79, 72, 23, 0, 1, + /* 390 */ 2, 173, 174, 173, 174, 220, 84, 85, 86, 87, + /* 400 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45, + /* 410 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + /* 420 */ 56, 57, 108, 109, 110, 119, 120, 152, 208, 119, + /* 430 */ 120, 137, 75, 139, 77, 19, 152, 88, 89, 23, + /* 440 */ 115, 83, 117, 118, 163, 227, 163, 152, 84, 85, + /* 450 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43, + /* 460 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + /* 470 */ 54, 55, 56, 57, 195, 196, 195, 196, 195, 196, + /* 480 */ 109, 110, 195, 196, 22, 23, 207, 19, 207, 152, + /* 490 */ 207, 108, 109, 110, 207, 163, 22, 140, 24, 59, + /* 500 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, + /* 510 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51, + /* 520 */ 52, 53, 54, 55, 56, 57, 152, 195, 196, 152, + /* 530 */ 16, 7, 8, 9, 197, 240, 96, 97, 98, 207, + /* 540 */ 249, 250, 19, 152, 22, 83, 26, 173, 174, 152, + /* 550 */ 173, 174, 84, 85, 86, 87, 88, 89, 90, 91, + /* 560 */ 92, 93, 94, 59, 124, 152, 43, 44, 45, 46, + /* 570 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + /* 580 */ 57, 59, 169, 170, 157, 194, 82, 191, 192, 75, + /* 590 */ 152, 77, 108, 109, 110, 26, 152, 19, 152, 152, + /* 600 */ 96, 97, 24, 152, 152, 101, 138, 84, 85, 86, + /* 610 */ 87, 88, 89, 90, 91, 92, 93, 94, 96, 97, + /* 620 */ 98, 43, 44, 45, 46, 47, 48, 49, 50, 51, + /* 630 */ 52, 53, 54, 55, 56, 57, 132, 133, 134, 188, + /* 640 */ 194, 197, 152, 123, 197, 232, 194, 152, 182, 19, + /* 650 */ 119, 120, 152, 152, 152, 152, 218, 230, 152, 163, + /* 660 */ 233, 138, 84, 85, 86, 87, 88, 89, 90, 91, + /* 670 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49, + /* 680 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152, + /* 690 */ 23, 195, 196, 26, 194, 194, 194, 146, 147, 130, + /* 700 */ 194, 19, 46, 207, 59, 29, 166, 167, 218, 33, + /* 710 */ 173, 174, 26, 218, 84, 85, 86, 87, 88, 89, + /* 720 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47, + /* 730 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 740 */ 64, 171, 97, 240, 116, 166, 167, 212, 213, 121, + /* 750 */ 23, 152, 19, 26, 218, 247, 248, 23, 23, 152, + /* 760 */ 26, 26, 22, 107, 163, 98, 84, 85, 86, 87, + /* 770 */ 88, 89, 90, 91, 92, 93, 94, 44, 45, 46, + /* 780 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + /* 790 */ 57, 124, 106, 53, 100, 101, 195, 196, 152, 152, + /* 800 */ 23, 23, 19, 26, 26, 19, 152, 23, 207, 239, + /* 810 */ 26, 23, 152, 163, 26, 169, 170, 84, 85, 86, + /* 820 */ 87, 88, 89, 90, 91, 92, 93, 94, 45, 46, + /* 830 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + /* 840 */ 57, 19, 20, 101, 22, 195, 196, 22, 19, 24, + /* 850 */ 163, 19, 7, 8, 112, 59, 23, 207, 36, 26, + /* 860 */ 23, 152, 59, 26, 21, 59, 152, 84, 85, 86, + /* 870 */ 87, 88, 89, 90, 91, 92, 93, 94, 232, 221, + /* 880 */ 94, 59, 195, 196, 59, 99, 100, 101, 102, 103, + /* 890 */ 104, 105, 70, 97, 207, 59, 19, 20, 112, 22, + /* 900 */ 97, 79, 152, 97, 82, 152, 152, 71, 221, 90, + /* 910 */ 88, 89, 23, 36, 12, 26, 163, 95, 96, 97, + /* 920 */ 98, 78, 97, 101, 152, 96, 173, 174, 96, 27, + /* 930 */ 182, 22, 96, 97, 98, 116, 59, 148, 149, 152, + /* 940 */ 121, 119, 120, 154, 42, 156, 103, 70, 195, 196, + /* 950 */ 22, 59, 163, 152, 132, 133, 134, 135, 136, 82, + /* 960 */ 207, 208, 209, 71, 62, 88, 89, 90, 59, 152, + /* 970 */ 152, 12, 95, 96, 97, 98, 19, 20, 101, 22, + /* 980 */ 22, 182, 152, 140, 195, 196, 27, 59, 96, 97, + /* 990 */ 98, 59, 132, 36, 134, 22, 207, 19, 20, 24, + /* 1000 */ 22, 42, 152, 173, 174, 96, 97, 98, 219, 132, + /* 1010 */ 133, 134, 135, 136, 36, 152, 59, 187, 132, 152, + /* 1020 */ 134, 62, 152, 152, 96, 97, 98, 70, 96, 97, + /* 1030 */ 98, 72, 59, 152, 59, 246, 26, 59, 214, 82, + /* 1040 */ 152, 192, 152, 173, 174, 88, 89, 79, 70, 152, + /* 1050 */ 152, 19, 95, 96, 97, 98, 124, 187, 101, 23, + /* 1060 */ 82, 164, 26, 173, 174, 152, 88, 89, 100, 96, + /* 1070 */ 97, 98, 97, 95, 96, 97, 98, 187, 46, 101, + /* 1080 */ 122, 184, 152, 186, 211, 152, 152, 119, 120, 132, + /* 1090 */ 133, 134, 135, 136, 152, 5, 22, 152, 152, 35, + /* 1100 */ 10, 11, 12, 13, 14, 152, 152, 17, 98, 235, + /* 1110 */ 132, 133, 134, 135, 136, 54, 55, 56, 57, 58, + /* 1120 */ 30, 152, 32, 152, 152, 198, 173, 174, 152, 65, + /* 1130 */ 40, 152, 152, 59, 124, 152, 236, 73, 199, 107, + /* 1140 */ 187, 171, 173, 174, 112, 84, 85, 86, 87, 88, + /* 1150 */ 89, 90, 91, 92, 93, 94, 173, 174, 152, 69, + /* 1160 */ 152, 211, 54, 55, 56, 57, 76, 152, 150, 79, + /* 1170 */ 80, 97, 211, 211, 211, 111, 59, 241, 241, 173, + /* 1180 */ 174, 173, 174, 202, 202, 185, 177, 176, 173, 174, + /* 1190 */ 176, 201, 84, 85, 86, 87, 88, 89, 90, 91, + /* 1200 */ 92, 93, 94, 215, 114, 88, 89, 152, 215, 119, + /* 1210 */ 120, 152, 181, 96, 97, 98, 176, 100, 215, 152, + /* 1220 */ 229, 152, 163, 152, 107, 199, 109, 155, 173, 174, + /* 1230 */ 245, 141, 173, 174, 60, 159, 152, 122, 159, 242, + /* 1240 */ 173, 174, 173, 174, 173, 174, 38, 242, 152, 132, + /* 1250 */ 159, 134, 152, 22, 195, 196, 152, 173, 174, 222, + /* 1260 */ 43, 130, 202, 152, 18, 152, 207, 208, 152, 173, + /* 1270 */ 174, 152, 190, 173, 174, 152, 193, 173, 174, 152, + /* 1280 */ 193, 193, 152, 159, 173, 174, 173, 174, 152, 173, + /* 1290 */ 174, 193, 173, 174, 18, 152, 173, 174, 152, 158, + /* 1300 */ 173, 174, 152, 173, 174, 152, 159, 152, 202, 173, + /* 1310 */ 174, 152, 190, 152, 222, 152, 173, 174, 152, 173, + /* 1320 */ 174, 137, 152, 173, 174, 190, 173, 174, 173, 174, + /* 1330 */ 202, 158, 173, 174, 173, 174, 173, 174, 61, 173, + /* 1340 */ 174, 152, 237, 173, 174, 152, 159, 152, 238, 152, + /* 1350 */ 158, 152, 22, 152, 178, 152, 158, 152, 158, 152, + /* 1360 */ 178, 159, 173, 174, 152, 159, 173, 174, 173, 174, + /* 1370 */ 173, 174, 173, 174, 173, 174, 173, 174, 173, 174, + /* 1380 */ 173, 174, 152, 63, 152, 173, 174, 107, 175, 175, + /* 1390 */ 175, 106, 183, 175, 178, 175, 177, 175, 175, 178, + /* 1400 */ 94, 107, 231, 173, 174, 173, 174, 183, 231, 125, + /* 1410 */ 216, 178, 159, 217, 22, 159, 226, 129, 137, 228, + /* 1420 */ 128, 217, 126, 25, 127, 162, 216, 26, 217, 161, + /* 1430 */ 13, 153, 153, 206, 205, 6, 251, 202, 204, 203, + /* 1440 */ 151, 216, 151, 217, 216, 171, 151, 165, 179, 179, + /* 1450 */ 4, 3, 22, 142, 171, 165, 15, 171, 171, 81, + /* 1460 */ 16, 23, 23, 120, 171, 131, 165, 111, 123, 171, + /* 1470 */ 171, 171, 20, 125, 16, 1, 123, 131, 53, 53, + /* 1480 */ 53, 53, 111, 96, 34, 122, 248, 1, 251, 5, + /* 1490 */ 22, 107, 140, 26, 74, 41, 122, 107, 67, 67, + /* 1500 */ 24, 20, 19, 112, 105, 23, 66, 22, 66, 22, + /* 1510 */ 22, 22, 37, 22, 22, 66, 23, 23, 28, 23, + /* 1520 */ 23, 26, 24, 23, 22, 24, 122, 23, 23, 96, + /* 1530 */ 22, 124, 26, 34, 23, 26, 23, 34, 23, 23, + /* 1540 */ 23, 34, 23, 22, 26, 11, 22, 22, 26, 23, + /* 1550 */ 23, 22, 116, 23, 22, 15, 122, 122, 23, 122, + /* 1560 */ 1, 252, 252, 252, 252, 122, 252, 252, 252, 252, + /* 1570 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1580 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1590 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1600 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1610 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1620 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1630 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1640 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1650 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1660 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1670 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1680 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1690 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, + /* 1700 */ 252, 252, 252, 252, 252, 252, 252, 252, 252, }; -#define YY_SHIFT_USE_DFLT (1566) -#define YY_SHIFT_COUNT (454) -#define YY_SHIFT_MIN (-84) -#define YY_SHIFT_MAX (1562) -static const short yy_shift_ofst[] = { - /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19, - /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063, - /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326, - /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696, - /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696, - /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063, - /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, - /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, - /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, - /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, - /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120, - /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309, - /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626, - /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242, - /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336, - /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570, - /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242, - /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242, - /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242, - /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531, - /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863, - /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145, - /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119, - /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147, - /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119, - /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294, - /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306, - /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285, - /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412, - /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566, - /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497, - /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768, - /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896, - /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445, - /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357, - /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489, - /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393, - /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484, - /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499, - /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503, - /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516, - /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527, - /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438, - /* 450 */ 1440, 1443, 1538, 1542, 1562, +#define YY_SHIFT_COUNT (471) +#define YY_SHIFT_MIN (0) +#define YY_SHIFT_MAX (1559) +static const unsigned short int yy_shift_ofst[] = { + /* 0 */ 182, 1090, 822, 822, 306, 957, 957, 957, 957, 210, + /* 10 */ 0, 0, 104, 630, 957, 957, 957, 957, 957, 957, + /* 20 */ 957, 1117, 1117, 126, 968, 306, 306, 306, 306, 306, + /* 30 */ 306, 52, 156, 208, 260, 312, 364, 416, 468, 523, + /* 40 */ 578, 630, 630, 630, 630, 630, 630, 630, 630, 630, + /* 50 */ 630, 630, 630, 630, 630, 630, 630, 630, 682, 630, + /* 60 */ 733, 783, 783, 877, 957, 957, 957, 957, 957, 957, + /* 70 */ 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, + /* 80 */ 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, + /* 90 */ 957, 957, 957, 957, 957, 978, 957, 957, 957, 957, + /* 100 */ 957, 957, 957, 957, 957, 957, 957, 957, 957, 1061, + /* 110 */ 1108, 1108, 1108, 1108, 1108, 40, 127, 20, 280, 843, + /* 120 */ 1032, 144, 144, 280, 310, 310, 310, 310, 59, 191, + /* 130 */ 69, 1566, 1566, 1566, 786, 786, 786, 522, 836, 522, + /* 140 */ 959, 959, 892, 155, 358, 280, 280, 280, 280, 280, + /* 150 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, + /* 160 */ 280, 280, 280, 280, 280, 280, 371, 388, 645, 645, + /* 170 */ 531, 1566, 1566, 1566, 504, 189, 189, 909, 63, 176, + /* 180 */ 928, 440, 932, 973, 280, 280, 280, 280, 280, 314, + /* 190 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, + /* 200 */ 280, 280, 1064, 1064, 1064, 280, 280, 280, 280, 667, + /* 210 */ 280, 280, 280, 825, 280, 280, 902, 280, 280, 280, + /* 220 */ 280, 280, 280, 280, 280, 383, 676, 325, 975, 975, + /* 230 */ 975, 975, 1010, 325, 325, 819, 349, 524, 569, 829, + /* 240 */ 829, 832, 569, 832, 686, 51, 656, 303, 303, 303, + /* 250 */ 829, 294, 520, 628, 474, 1174, 1115, 1115, 1208, 1208, + /* 260 */ 1115, 1231, 1217, 1131, 1246, 1246, 1246, 1246, 1115, 1276, + /* 270 */ 1131, 1231, 1217, 1217, 1131, 1115, 1276, 1184, 1277, 1115, + /* 280 */ 1276, 1330, 1115, 1276, 1115, 1276, 1330, 1280, 1280, 1280, + /* 290 */ 1320, 1330, 1280, 1285, 1280, 1320, 1280, 1280, 1330, 1306, + /* 300 */ 1306, 1330, 1284, 1294, 1284, 1294, 1284, 1294, 1284, 1294, + /* 310 */ 1115, 1392, 1115, 1281, 1288, 1296, 1292, 1297, 1131, 1398, + /* 320 */ 1401, 1417, 1417, 1429, 1429, 1429, 1566, 1566, 1566, 1566, + /* 330 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 340 */ 1566, 1566, 34, 357, 38, 462, 514, 484, 1074, 727, + /* 350 */ 740, 734, 735, 777, 778, 784, 788, 803, 694, 845, + /* 360 */ 742, 796, 833, 837, 889, 860, 886, 1036, 806, 958, + /* 370 */ 1446, 1448, 1430, 1311, 1441, 1378, 1444, 1438, 1439, 1343, + /* 380 */ 1334, 1356, 1345, 1452, 1348, 1458, 1474, 1353, 1346, 1425, + /* 390 */ 1426, 1427, 1428, 1371, 1387, 1450, 1363, 1486, 1484, 1468, + /* 400 */ 1384, 1352, 1431, 1467, 1432, 1420, 1454, 1374, 1390, 1476, + /* 410 */ 1481, 1483, 1391, 1399, 1485, 1440, 1487, 1488, 1482, 1489, + /* 420 */ 1442, 1490, 1491, 1449, 1475, 1493, 1494, 1496, 1495, 1497, + /* 430 */ 1492, 1498, 1500, 1502, 1501, 1404, 1504, 1505, 1433, 1499, + /* 440 */ 1508, 1407, 1506, 1503, 1509, 1507, 1511, 1513, 1515, 1506, + /* 450 */ 1516, 1517, 1518, 1519, 1521, 1534, 1524, 1525, 1526, 1527, + /* 460 */ 1529, 1530, 1532, 1522, 1436, 1434, 1435, 1437, 1443, 1535, + /* 470 */ 1540, 1559, }; -#define YY_REDUCE_USE_DFLT (-144) -#define YY_REDUCE_COUNT (323) -#define YY_REDUCE_MIN (-143) -#define YY_REDUCE_MAX (1305) +#define YY_REDUCE_COUNT (341) +#define YY_REDUCE_MIN (-211) +#define YY_REDUCE_MAX (1301) static const short yy_reduce_ofst[] = { - /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25, - /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285, - /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171, - /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, - /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, - /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287, - /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084, - /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128, - /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172, - /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207, - /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171, - /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171, - /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77, - /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403, - /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553, - /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571, - /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28, - /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560, - /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813, - /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835, - /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937, - /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899, - /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969, - /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019, - /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109, - /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111, - /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234, - /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230, - /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201, - /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220, - /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276, - /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290, - /* 320 */ 1292, 1280, 1281, 1295, + /* 0 */ -143, 789, 753, 1059, -137, -146, -144, -141, -136, 687, + /* 10 */ -107, 101, -203, -52, 830, 870, 890, 167, 953, 218, + /* 20 */ 220, 413, 646, 897, 73, 281, 283, 332, 496, 601, + /* 30 */ 650, -211, -211, -211, -211, -211, -211, -211, -211, -211, + /* 40 */ -211, -211, -211, -211, -211, -211, -211, -211, -211, -211, + /* 50 */ -211, -211, -211, -211, -211, -211, -211, -211, -211, -211, + /* 60 */ -211, -211, -211, 374, 377, 537, 969, 983, 1006, 1008, + /* 70 */ 1015, 1055, 1067, 1069, 1071, 1084, 1096, 1100, 1104, 1111, + /* 80 */ 1113, 1116, 1119, 1123, 1127, 1130, 1136, 1143, 1146, 1150, + /* 90 */ 1153, 1155, 1159, 1161, 1163, 1166, 1170, 1189, 1193, 1195, + /* 100 */ 1197, 1199, 1201, 1203, 1205, 1207, 1212, 1230, 1232, -211, + /* 110 */ -211, -211, -211, -211, -211, -211, -211, -211, -30, 427, + /* 120 */ -171, -145, -134, 22, 279, 287, 279, 287, 99, -211, + /* 130 */ -211, -211, -211, -211, -165, -165, -165, 123, 135, 175, + /* 140 */ -150, 396, 337, 291, 291, -147, 185, 391, 446, 444, + /* 150 */ 452, 500, 501, 502, 27, -152, 295, 438, 490, 503, + /* 160 */ 495, 506, -73, 447, 451, 536, 570, 551, 540, 579, + /* 170 */ 30, 508, 535, 81, 14, 61, 115, 168, 142, 222, + /* 180 */ 275, 284, 397, 599, 607, 647, 654, 660, 709, 658, + /* 190 */ 714, 750, 754, 772, 787, 801, 817, 818, 850, 863, + /* 200 */ 867, 871, 466, 748, 799, 881, 888, 898, 913, 824, + /* 210 */ 930, 933, 934, 873, 942, 945, 849, 946, 222, 954, + /* 220 */ 971, 972, 976, 979, 980, 900, 874, 927, 950, 961, + /* 230 */ 962, 963, 824, 927, 927, 939, 970, 1018, 981, 988, + /* 240 */ 993, 936, 982, 937, 1009, 1000, 1031, 1011, 1014, 1040, + /* 250 */ 1003, 991, 990, 1026, 1072, 985, 1076, 1079, 997, 1005, + /* 260 */ 1091, 1037, 1082, 1060, 1083, 1087, 1088, 1098, 1124, 1141, + /* 270 */ 1106, 1092, 1122, 1135, 1128, 1147, 1173, 1110, 1105, 1187, + /* 280 */ 1192, 1176, 1202, 1198, 1206, 1200, 1182, 1213, 1214, 1215, + /* 290 */ 1209, 1216, 1218, 1219, 1220, 1224, 1222, 1223, 1221, 1171, + /* 300 */ 1177, 1233, 1196, 1194, 1204, 1210, 1211, 1225, 1226, 1228, + /* 310 */ 1253, 1190, 1256, 1191, 1227, 1229, 1234, 1236, 1235, 1263, + /* 320 */ 1268, 1278, 1279, 1289, 1291, 1295, 1185, 1237, 1238, 1282, + /* 330 */ 1274, 1283, 1286, 1287, 1290, 1269, 1270, 1293, 1298, 1299, + /* 340 */ 1300, 1301, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088, - /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192, - /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322, - /* 30 */ 1322, 1194, 1195, 1322, 1322, 1322, 1243, 1245, 1133, 1132, - /* 40 */ 1131, 1130, 1226, 1104, 1128, 1121, 1125, 1194, 1188, 1189, - /* 50 */ 1187, 1191, 1195, 1322, 1124, 1158, 1172, 1157, 1322, 1322, - /* 60 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 70 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 80 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 90 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 100 */ 1322, 1322, 1322, 1322, 1166, 1171, 1178, 1170, 1167, 1160, - /* 110 */ 1159, 1161, 1162, 1322, 1011, 1059, 1322, 1322, 1322, 1163, - /* 120 */ 1322, 1164, 1175, 1174, 1173, 1251, 1278, 1277, 1322, 1322, - /* 130 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 140 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 150 */ 1322, 1322, 1322, 1322, 1322, 1270, 1260, 1017, 1017, 1322, - /* 160 */ 1260, 1260, 1260, 1260, 1260, 1260, 1256, 1092, 1083, 1322, - /* 170 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 180 */ 1248, 1246, 1322, 1208, 1322, 1322, 1322, 1322, 1322, 1322, - /* 190 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 200 */ 1322, 1322, 1322, 1322, 1088, 1322, 1322, 1322, 1322, 1322, - /* 210 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1272, 1322, 1221, - /* 220 */ 1088, 1088, 1088, 1090, 1072, 1082, 997, 1127, 1106, 1106, - /* 230 */ 1311, 1127, 1311, 1034, 1292, 1031, 1117, 1106, 1190, 1117, - /* 240 */ 1117, 1089, 1082, 1322, 1314, 1097, 1097, 1313, 1313, 1097, - /* 250 */ 1138, 1062, 1127, 1068, 1068, 1068, 1068, 1097, 1008, 1127, - /* 260 */ 1138, 1062, 1062, 1127, 1097, 1008, 1225, 1308, 1097, 1097, - /* 270 */ 1008, 1201, 1097, 1008, 1097, 1008, 1201, 1060, 1060, 1060, - /* 280 */ 1049, 1201, 1060, 1034, 1060, 1049, 1060, 1060, 1110, 1105, - /* 290 */ 1110, 1105, 1110, 1105, 1110, 1105, 1097, 1196, 1097, 1322, - /* 300 */ 1201, 1205, 1205, 1201, 1122, 1111, 1120, 1118, 1127, 1014, - /* 310 */ 1052, 1275, 1275, 1271, 1271, 1271, 1319, 1319, 1256, 1287, - /* 320 */ 1287, 1036, 1036, 1287, 1322, 1322, 1322, 1322, 1322, 1322, - /* 330 */ 1282, 1322, 1210, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 340 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 350 */ 1322, 1143, 1322, 993, 1253, 1322, 1322, 1252, 1322, 1322, - /* 360 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 370 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1310, 1322, - /* 380 */ 1322, 1322, 1322, 1322, 1322, 1224, 1223, 1322, 1322, 1322, - /* 390 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 400 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - /* 410 */ 1074, 1322, 1322, 1322, 1296, 1322, 1322, 1322, 1322, 1322, - /* 420 */ 1322, 1322, 1119, 1322, 1112, 1322, 1322, 1301, 1322, 1322, - /* 430 */ 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1322, 1262, 1322, - /* 440 */ 1322, 1322, 1261, 1322, 1322, 1322, 1322, 1322, 1145, 1322, - /* 450 */ 1144, 1148, 1322, 1002, 1322, + /* 0 */ 1297, 1349, 1221, 1014, 1119, 1221, 1221, 1221, 1221, 1014, + /* 10 */ 1145, 1145, 1272, 1045, 1014, 1014, 1014, 1014, 1014, 1220, + /* 20 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 30 */ 1014, 1151, 1014, 1014, 1014, 1014, 1222, 1223, 1014, 1014, + /* 40 */ 1014, 1271, 1273, 1161, 1160, 1159, 1158, 1254, 1132, 1156, + /* 50 */ 1149, 1153, 1216, 1217, 1215, 1219, 1222, 1223, 1014, 1152, + /* 60 */ 1186, 1200, 1185, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 70 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 80 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 90 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 100 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1194, + /* 110 */ 1199, 1206, 1198, 1195, 1188, 1187, 1189, 1190, 1014, 1035, + /* 120 */ 1084, 1014, 1014, 1014, 1289, 1288, 1014, 1014, 1045, 1191, + /* 130 */ 1192, 1203, 1202, 1201, 1279, 1305, 1304, 1014, 1014, 1014, + /* 140 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 150 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 160 */ 1014, 1014, 1014, 1014, 1014, 1014, 1045, 1297, 1041, 1041, + /* 170 */ 1014, 1284, 1119, 1110, 1014, 1014, 1014, 1014, 1014, 1014, + /* 180 */ 1014, 1014, 1014, 1014, 1014, 1276, 1274, 1014, 1236, 1014, + /* 190 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 200 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 210 */ 1014, 1014, 1014, 1115, 1014, 1014, 1014, 1014, 1014, 1014, + /* 220 */ 1014, 1014, 1014, 1014, 1299, 1014, 1249, 1098, 1115, 1115, + /* 230 */ 1115, 1115, 1117, 1099, 1097, 1109, 1045, 1021, 1155, 1134, + /* 240 */ 1134, 1338, 1155, 1338, 1059, 1319, 1056, 1145, 1145, 1145, + /* 250 */ 1134, 1218, 1116, 1109, 1014, 1341, 1124, 1124, 1340, 1340, + /* 260 */ 1124, 1166, 1087, 1155, 1093, 1093, 1093, 1093, 1124, 1032, + /* 270 */ 1155, 1166, 1087, 1087, 1155, 1124, 1032, 1253, 1335, 1124, + /* 280 */ 1032, 1229, 1124, 1032, 1124, 1032, 1229, 1085, 1085, 1085, + /* 290 */ 1074, 1229, 1085, 1059, 1085, 1074, 1085, 1085, 1229, 1233, + /* 300 */ 1233, 1229, 1138, 1133, 1138, 1133, 1138, 1133, 1138, 1133, + /* 310 */ 1124, 1224, 1124, 1014, 1150, 1139, 1148, 1146, 1155, 1038, + /* 320 */ 1077, 1302, 1302, 1298, 1298, 1298, 1346, 1346, 1284, 1314, + /* 330 */ 1045, 1045, 1045, 1045, 1314, 1061, 1061, 1045, 1045, 1045, + /* 340 */ 1045, 1314, 1014, 1014, 1014, 1014, 1014, 1014, 1309, 1014, + /* 350 */ 1238, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 360 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1171, + /* 370 */ 1014, 1017, 1281, 1014, 1014, 1280, 1014, 1014, 1014, 1014, + /* 380 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 390 */ 1014, 1014, 1014, 1014, 1014, 1014, 1337, 1014, 1014, 1014, + /* 400 */ 1014, 1014, 1014, 1252, 1251, 1014, 1014, 1126, 1014, 1014, + /* 410 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 420 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 430 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 440 */ 1014, 1014, 1147, 1014, 1140, 1014, 1014, 1014, 1014, 1328, + /* 450 */ 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1014, + /* 460 */ 1014, 1014, 1014, 1323, 1101, 1173, 1014, 1172, 1176, 1014, + /* 470 */ 1026, 1014, }; /********** End of lemon-generated parsing tables *****************************/ @@ -137948,75 +140768,264 @@ SQLITE_PRIVATE void sqlite3ParserTrace(FILE *TraceFILE, char *zTracePrompt){ } #endif /* NDEBUG */ -#ifndef NDEBUG +#if defined(YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { - "$", "SEMI", "EXPLAIN", "QUERY", - "PLAN", "BEGIN", "TRANSACTION", "DEFERRED", - "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", - "ROLLBACK", "SAVEPOINT", "RELEASE", "TO", - "TABLE", "CREATE", "IF", "NOT", - "EXISTS", "TEMP", "LP", "RP", - "AS", "WITHOUT", "COMMA", "ABORT", - "ACTION", "AFTER", "ANALYZE", "ASC", - "ATTACH", "BEFORE", "BY", "CASCADE", - "CAST", "CONFLICT", "DATABASE", "DESC", - "DETACH", "EACH", "FAIL", "OR", - "AND", "IS", "MATCH", "LIKE_KW", - "BETWEEN", "IN", "ISNULL", "NOTNULL", - "NE", "EQ", "GT", "LE", - "LT", "GE", "ESCAPE", "ID", - "COLUMNKW", "FOR", "IGNORE", "INITIALLY", - "INSTEAD", "NO", "KEY", "OF", - "OFFSET", "PRAGMA", "RAISE", "RECURSIVE", - "REPLACE", "RESTRICT", "ROW", "TRIGGER", - "VACUUM", "VIEW", "VIRTUAL", "WITH", - "REINDEX", "RENAME", "CTIME_KW", "ANY", - "BITAND", "BITOR", "LSHIFT", "RSHIFT", - "PLUS", "MINUS", "STAR", "SLASH", - "REM", "CONCAT", "COLLATE", "BITNOT", - "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT", - "DEFAULT", "NULL", "PRIMARY", "UNIQUE", - "CHECK", "REFERENCES", "AUTOINCR", "ON", - "INSERT", "DELETE", "UPDATE", "SET", - "DEFERRABLE", "FOREIGN", "DROP", "UNION", - "ALL", "EXCEPT", "INTERSECT", "SELECT", - "VALUES", "DISTINCT", "DOT", "FROM", - "JOIN", "USING", "ORDER", "GROUP", - "HAVING", "LIMIT", "WHERE", "INTO", - "FLOAT", "BLOB", "INTEGER", "VARIABLE", - "CASE", "WHEN", "THEN", "ELSE", - "INDEX", "ALTER", "ADD", "error", - "input", "cmdlist", "ecmd", "explain", - "cmdx", "cmd", "transtype", "trans_opt", - "nm", "savepoint_opt", "create_table", "create_table_args", - "createkw", "temp", "ifnotexists", "dbnm", - "columnlist", "conslist_opt", "table_options", "select", - "columnname", "carglist", "typetoken", "typename", - "signed", "plus_num", "minus_num", "ccons", - "term", "expr", "onconf", "sortorder", - "autoinc", "eidlist_opt", "refargs", "defer_subclause", - "refarg", "refact", "init_deferred_pred_opt", "conslist", - "tconscomma", "tcons", "sortlist", "eidlist", - "defer_subclause_opt", "orconf", "resolvetype", "raisetype", - "ifexists", "fullname", "selectnowith", "oneselect", - "with", "multiselect_op", "distinct", "selcollist", - "from", "where_opt", "groupby_opt", "having_opt", - "orderby_opt", "limit_opt", "values", "nexprlist", - "exprlist", "sclp", "as", "seltablist", - "stl_prefix", "joinop", "indexed_opt", "on_opt", - "using_opt", "idlist", "setlist", "insert_cmd", - "idlist_opt", "likeop", "between_op", "in_op", - "paren_exprlist", "case_operand", "case_exprlist", "case_else", - "uniqueflag", "collate", "nmnum", "trigger_decl", - "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", - "when_clause", "trigger_cmd", "trnm", "tridxby", - "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt", - "create_vtab", "vtabarglist", "vtabarg", "vtabargtoken", - "lp", "anylist", "wqlist", + /* 0 */ "$", + /* 1 */ "SEMI", + /* 2 */ "EXPLAIN", + /* 3 */ "QUERY", + /* 4 */ "PLAN", + /* 5 */ "BEGIN", + /* 6 */ "TRANSACTION", + /* 7 */ "DEFERRED", + /* 8 */ "IMMEDIATE", + /* 9 */ "EXCLUSIVE", + /* 10 */ "COMMIT", + /* 11 */ "END", + /* 12 */ "ROLLBACK", + /* 13 */ "SAVEPOINT", + /* 14 */ "RELEASE", + /* 15 */ "TO", + /* 16 */ "TABLE", + /* 17 */ "CREATE", + /* 18 */ "IF", + /* 19 */ "NOT", + /* 20 */ "EXISTS", + /* 21 */ "TEMP", + /* 22 */ "LP", + /* 23 */ "RP", + /* 24 */ "AS", + /* 25 */ "WITHOUT", + /* 26 */ "COMMA", + /* 27 */ "ABORT", + /* 28 */ "ACTION", + /* 29 */ "AFTER", + /* 30 */ "ANALYZE", + /* 31 */ "ASC", + /* 32 */ "ATTACH", + /* 33 */ "BEFORE", + /* 34 */ "BY", + /* 35 */ "CASCADE", + /* 36 */ "CAST", + /* 37 */ "CONFLICT", + /* 38 */ "DATABASE", + /* 39 */ "DESC", + /* 40 */ "DETACH", + /* 41 */ "EACH", + /* 42 */ "FAIL", + /* 43 */ "OR", + /* 44 */ "AND", + /* 45 */ "IS", + /* 46 */ "MATCH", + /* 47 */ "LIKE_KW", + /* 48 */ "BETWEEN", + /* 49 */ "IN", + /* 50 */ "ISNULL", + /* 51 */ "NOTNULL", + /* 52 */ "NE", + /* 53 */ "EQ", + /* 54 */ "GT", + /* 55 */ "LE", + /* 56 */ "LT", + /* 57 */ "GE", + /* 58 */ "ESCAPE", + /* 59 */ "ID", + /* 60 */ "COLUMNKW", + /* 61 */ "FOR", + /* 62 */ "IGNORE", + /* 63 */ "INITIALLY", + /* 64 */ "INSTEAD", + /* 65 */ "NO", + /* 66 */ "KEY", + /* 67 */ "OF", + /* 68 */ "OFFSET", + /* 69 */ "PRAGMA", + /* 70 */ "RAISE", + /* 71 */ "RECURSIVE", + /* 72 */ "REPLACE", + /* 73 */ "RESTRICT", + /* 74 */ "ROW", + /* 75 */ "TRIGGER", + /* 76 */ "VACUUM", + /* 77 */ "VIEW", + /* 78 */ "VIRTUAL", + /* 79 */ "WITH", + /* 80 */ "REINDEX", + /* 81 */ "RENAME", + /* 82 */ "CTIME_KW", + /* 83 */ "ANY", + /* 84 */ "BITAND", + /* 85 */ "BITOR", + /* 86 */ "LSHIFT", + /* 87 */ "RSHIFT", + /* 88 */ "PLUS", + /* 89 */ "MINUS", + /* 90 */ "STAR", + /* 91 */ "SLASH", + /* 92 */ "REM", + /* 93 */ "CONCAT", + /* 94 */ "COLLATE", + /* 95 */ "BITNOT", + /* 96 */ "INDEXED", + /* 97 */ "STRING", + /* 98 */ "JOIN_KW", + /* 99 */ "CONSTRAINT", + /* 100 */ "DEFAULT", + /* 101 */ "NULL", + /* 102 */ "PRIMARY", + /* 103 */ "UNIQUE", + /* 104 */ "CHECK", + /* 105 */ "REFERENCES", + /* 106 */ "AUTOINCR", + /* 107 */ "ON", + /* 108 */ "INSERT", + /* 109 */ "DELETE", + /* 110 */ "UPDATE", + /* 111 */ "SET", + /* 112 */ "DEFERRABLE", + /* 113 */ "FOREIGN", + /* 114 */ "DROP", + /* 115 */ "UNION", + /* 116 */ "ALL", + /* 117 */ "EXCEPT", + /* 118 */ "INTERSECT", + /* 119 */ "SELECT", + /* 120 */ "VALUES", + /* 121 */ "DISTINCT", + /* 122 */ "DOT", + /* 123 */ "FROM", + /* 124 */ "JOIN", + /* 125 */ "USING", + /* 126 */ "ORDER", + /* 127 */ "GROUP", + /* 128 */ "HAVING", + /* 129 */ "LIMIT", + /* 130 */ "WHERE", + /* 131 */ "INTO", + /* 132 */ "FLOAT", + /* 133 */ "BLOB", + /* 134 */ "INTEGER", + /* 135 */ "VARIABLE", + /* 136 */ "CASE", + /* 137 */ "WHEN", + /* 138 */ "THEN", + /* 139 */ "ELSE", + /* 140 */ "INDEX", + /* 141 */ "ALTER", + /* 142 */ "ADD", + /* 143 */ "error", + /* 144 */ "input", + /* 145 */ "cmdlist", + /* 146 */ "ecmd", + /* 147 */ "explain", + /* 148 */ "cmdx", + /* 149 */ "cmd", + /* 150 */ "transtype", + /* 151 */ "trans_opt", + /* 152 */ "nm", + /* 153 */ "savepoint_opt", + /* 154 */ "create_table", + /* 155 */ "create_table_args", + /* 156 */ "createkw", + /* 157 */ "temp", + /* 158 */ "ifnotexists", + /* 159 */ "dbnm", + /* 160 */ "columnlist", + /* 161 */ "conslist_opt", + /* 162 */ "table_options", + /* 163 */ "select", + /* 164 */ "columnname", + /* 165 */ "carglist", + /* 166 */ "typetoken", + /* 167 */ "typename", + /* 168 */ "signed", + /* 169 */ "plus_num", + /* 170 */ "minus_num", + /* 171 */ "scanpt", + /* 172 */ "ccons", + /* 173 */ "term", + /* 174 */ "expr", + /* 175 */ "onconf", + /* 176 */ "sortorder", + /* 177 */ "autoinc", + /* 178 */ "eidlist_opt", + /* 179 */ "refargs", + /* 180 */ "defer_subclause", + /* 181 */ "refarg", + /* 182 */ "refact", + /* 183 */ "init_deferred_pred_opt", + /* 184 */ "conslist", + /* 185 */ "tconscomma", + /* 186 */ "tcons", + /* 187 */ "sortlist", + /* 188 */ "eidlist", + /* 189 */ "defer_subclause_opt", + /* 190 */ "orconf", + /* 191 */ "resolvetype", + /* 192 */ "raisetype", + /* 193 */ "ifexists", + /* 194 */ "fullname", + /* 195 */ "selectnowith", + /* 196 */ "oneselect", + /* 197 */ "wqlist", + /* 198 */ "multiselect_op", + /* 199 */ "distinct", + /* 200 */ "selcollist", + /* 201 */ "from", + /* 202 */ "where_opt", + /* 203 */ "groupby_opt", + /* 204 */ "having_opt", + /* 205 */ "orderby_opt", + /* 206 */ "limit_opt", + /* 207 */ "values", + /* 208 */ "nexprlist", + /* 209 */ "exprlist", + /* 210 */ "sclp", + /* 211 */ "as", + /* 212 */ "seltablist", + /* 213 */ "stl_prefix", + /* 214 */ "joinop", + /* 215 */ "indexed_opt", + /* 216 */ "on_opt", + /* 217 */ "using_opt", + /* 218 */ "idlist", + /* 219 */ "with", + /* 220 */ "setlist", + /* 221 */ "insert_cmd", + /* 222 */ "idlist_opt", + /* 223 */ "likeop", + /* 224 */ "between_op", + /* 225 */ "in_op", + /* 226 */ "paren_exprlist", + /* 227 */ "case_operand", + /* 228 */ "case_exprlist", + /* 229 */ "case_else", + /* 230 */ "uniqueflag", + /* 231 */ "collate", + /* 232 */ "nmnum", + /* 233 */ "trigger_decl", + /* 234 */ "trigger_cmd_list", + /* 235 */ "trigger_time", + /* 236 */ "trigger_event", + /* 237 */ "foreach_clause", + /* 238 */ "when_clause", + /* 239 */ "trigger_cmd", + /* 240 */ "trnm", + /* 241 */ "tridxby", + /* 242 */ "database_kw_opt", + /* 243 */ "key_opt", + /* 244 */ "add_column_fullname", + /* 245 */ "kwcolumn_opt", + /* 246 */ "create_vtab", + /* 247 */ "vtabarglist", + /* 248 */ "vtabarg", + /* 249 */ "vtabargtoken", + /* 250 */ "lp", + /* 251 */ "anylist", }; -#endif /* NDEBUG */ +#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -138050,307 +141059,311 @@ static const char *const yyRuleName[] = { /* 25 */ "typetoken ::= typename LP signed RP", /* 26 */ "typetoken ::= typename LP signed COMMA signed RP", /* 27 */ "typename ::= typename ID|STRING", - /* 28 */ "ccons ::= CONSTRAINT nm", - /* 29 */ "ccons ::= DEFAULT term", - /* 30 */ "ccons ::= DEFAULT LP expr RP", - /* 31 */ "ccons ::= DEFAULT PLUS term", - /* 32 */ "ccons ::= DEFAULT MINUS term", - /* 33 */ "ccons ::= DEFAULT ID|INDEXED", - /* 34 */ "ccons ::= NOT NULL onconf", - /* 35 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", - /* 36 */ "ccons ::= UNIQUE onconf", - /* 37 */ "ccons ::= CHECK LP expr RP", - /* 38 */ "ccons ::= REFERENCES nm eidlist_opt refargs", - /* 39 */ "ccons ::= defer_subclause", - /* 40 */ "ccons ::= COLLATE ID|STRING", - /* 41 */ "autoinc ::=", - /* 42 */ "autoinc ::= AUTOINCR", - /* 43 */ "refargs ::=", - /* 44 */ "refargs ::= refargs refarg", - /* 45 */ "refarg ::= MATCH nm", - /* 46 */ "refarg ::= ON INSERT refact", - /* 47 */ "refarg ::= ON DELETE refact", - /* 48 */ "refarg ::= ON UPDATE refact", - /* 49 */ "refact ::= SET NULL", - /* 50 */ "refact ::= SET DEFAULT", - /* 51 */ "refact ::= CASCADE", - /* 52 */ "refact ::= RESTRICT", - /* 53 */ "refact ::= NO ACTION", - /* 54 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", - /* 55 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", - /* 56 */ "init_deferred_pred_opt ::=", - /* 57 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", - /* 58 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", - /* 59 */ "conslist_opt ::=", - /* 60 */ "tconscomma ::= COMMA", - /* 61 */ "tcons ::= CONSTRAINT nm", - /* 62 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf", - /* 63 */ "tcons ::= UNIQUE LP sortlist RP onconf", - /* 64 */ "tcons ::= CHECK LP expr RP onconf", - /* 65 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt", - /* 66 */ "defer_subclause_opt ::=", - /* 67 */ "onconf ::=", - /* 68 */ "onconf ::= ON CONFLICT resolvetype", - /* 69 */ "orconf ::=", - /* 70 */ "orconf ::= OR resolvetype", - /* 71 */ "resolvetype ::= IGNORE", - /* 72 */ "resolvetype ::= REPLACE", - /* 73 */ "cmd ::= DROP TABLE ifexists fullname", - /* 74 */ "ifexists ::= IF EXISTS", - /* 75 */ "ifexists ::=", - /* 76 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select", - /* 77 */ "cmd ::= DROP VIEW ifexists fullname", - /* 78 */ "cmd ::= select", - /* 79 */ "select ::= with selectnowith", - /* 80 */ "selectnowith ::= selectnowith multiselect_op oneselect", - /* 81 */ "multiselect_op ::= UNION", - /* 82 */ "multiselect_op ::= UNION ALL", - /* 83 */ "multiselect_op ::= EXCEPT|INTERSECT", - /* 84 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", - /* 85 */ "values ::= VALUES LP nexprlist RP", - /* 86 */ "values ::= values COMMA LP exprlist RP", - /* 87 */ "distinct ::= DISTINCT", - /* 88 */ "distinct ::= ALL", - /* 89 */ "distinct ::=", - /* 90 */ "sclp ::=", - /* 91 */ "selcollist ::= sclp expr as", - /* 92 */ "selcollist ::= sclp STAR", - /* 93 */ "selcollist ::= sclp nm DOT STAR", - /* 94 */ "as ::= AS nm", - /* 95 */ "as ::=", - /* 96 */ "from ::=", - /* 97 */ "from ::= FROM seltablist", - /* 98 */ "stl_prefix ::= seltablist joinop", - /* 99 */ "stl_prefix ::=", - /* 100 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", - /* 101 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt", - /* 102 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", - /* 103 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt", - /* 104 */ "dbnm ::=", - /* 105 */ "dbnm ::= DOT nm", - /* 106 */ "fullname ::= nm dbnm", - /* 107 */ "joinop ::= COMMA|JOIN", - /* 108 */ "joinop ::= JOIN_KW JOIN", - /* 109 */ "joinop ::= JOIN_KW nm JOIN", - /* 110 */ "joinop ::= JOIN_KW nm nm JOIN", - /* 111 */ "on_opt ::= ON expr", - /* 112 */ "on_opt ::=", - /* 113 */ "indexed_opt ::=", - /* 114 */ "indexed_opt ::= INDEXED BY nm", - /* 115 */ "indexed_opt ::= NOT INDEXED", - /* 116 */ "using_opt ::= USING LP idlist RP", - /* 117 */ "using_opt ::=", - /* 118 */ "orderby_opt ::=", - /* 119 */ "orderby_opt ::= ORDER BY sortlist", - /* 120 */ "sortlist ::= sortlist COMMA expr sortorder", - /* 121 */ "sortlist ::= expr sortorder", - /* 122 */ "sortorder ::= ASC", - /* 123 */ "sortorder ::= DESC", - /* 124 */ "sortorder ::=", - /* 125 */ "groupby_opt ::=", - /* 126 */ "groupby_opt ::= GROUP BY nexprlist", - /* 127 */ "having_opt ::=", - /* 128 */ "having_opt ::= HAVING expr", - /* 129 */ "limit_opt ::=", - /* 130 */ "limit_opt ::= LIMIT expr", - /* 131 */ "limit_opt ::= LIMIT expr OFFSET expr", - /* 132 */ "limit_opt ::= LIMIT expr COMMA expr", - /* 133 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt", - /* 134 */ "where_opt ::=", - /* 135 */ "where_opt ::= WHERE expr", - /* 136 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt", - /* 137 */ "setlist ::= setlist COMMA nm EQ expr", - /* 138 */ "setlist ::= setlist COMMA LP idlist RP EQ expr", - /* 139 */ "setlist ::= nm EQ expr", - /* 140 */ "setlist ::= LP idlist RP EQ expr", - /* 141 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select", - /* 142 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES", - /* 143 */ "insert_cmd ::= INSERT orconf", - /* 144 */ "insert_cmd ::= REPLACE", - /* 145 */ "idlist_opt ::=", - /* 146 */ "idlist_opt ::= LP idlist RP", - /* 147 */ "idlist ::= idlist COMMA nm", - /* 148 */ "idlist ::= nm", - /* 149 */ "expr ::= LP expr RP", - /* 150 */ "expr ::= ID|INDEXED", - /* 151 */ "expr ::= JOIN_KW", - /* 152 */ "expr ::= nm DOT nm", - /* 153 */ "expr ::= nm DOT nm DOT nm", - /* 154 */ "term ::= NULL|FLOAT|BLOB", - /* 155 */ "term ::= STRING", - /* 156 */ "term ::= INTEGER", - /* 157 */ "expr ::= VARIABLE", - /* 158 */ "expr ::= expr COLLATE ID|STRING", - /* 159 */ "expr ::= CAST LP expr AS typetoken RP", - /* 160 */ "expr ::= ID|INDEXED LP distinct exprlist RP", - /* 161 */ "expr ::= ID|INDEXED LP STAR RP", - /* 162 */ "term ::= CTIME_KW", - /* 163 */ "expr ::= LP nexprlist COMMA expr RP", - /* 164 */ "expr ::= expr AND expr", - /* 165 */ "expr ::= expr OR expr", - /* 166 */ "expr ::= expr LT|GT|GE|LE expr", - /* 167 */ "expr ::= expr EQ|NE expr", - /* 168 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", - /* 169 */ "expr ::= expr PLUS|MINUS expr", - /* 170 */ "expr ::= expr STAR|SLASH|REM expr", - /* 171 */ "expr ::= expr CONCAT expr", - /* 172 */ "likeop ::= NOT LIKE_KW|MATCH", - /* 173 */ "expr ::= expr likeop expr", - /* 174 */ "expr ::= expr likeop expr ESCAPE expr", - /* 175 */ "expr ::= expr ISNULL|NOTNULL", - /* 176 */ "expr ::= expr NOT NULL", - /* 177 */ "expr ::= expr IS expr", - /* 178 */ "expr ::= expr IS NOT expr", - /* 179 */ "expr ::= NOT expr", - /* 180 */ "expr ::= BITNOT expr", - /* 181 */ "expr ::= MINUS expr", - /* 182 */ "expr ::= PLUS expr", - /* 183 */ "between_op ::= BETWEEN", - /* 184 */ "between_op ::= NOT BETWEEN", - /* 185 */ "expr ::= expr between_op expr AND expr", - /* 186 */ "in_op ::= IN", - /* 187 */ "in_op ::= NOT IN", - /* 188 */ "expr ::= expr in_op LP exprlist RP", - /* 189 */ "expr ::= LP select RP", - /* 190 */ "expr ::= expr in_op LP select RP", - /* 191 */ "expr ::= expr in_op nm dbnm paren_exprlist", - /* 192 */ "expr ::= EXISTS LP select RP", - /* 193 */ "expr ::= CASE case_operand case_exprlist case_else END", - /* 194 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", - /* 195 */ "case_exprlist ::= WHEN expr THEN expr", - /* 196 */ "case_else ::= ELSE expr", - /* 197 */ "case_else ::=", - /* 198 */ "case_operand ::= expr", - /* 199 */ "case_operand ::=", - /* 200 */ "exprlist ::=", - /* 201 */ "nexprlist ::= nexprlist COMMA expr", - /* 202 */ "nexprlist ::= expr", - /* 203 */ "paren_exprlist ::=", - /* 204 */ "paren_exprlist ::= LP exprlist RP", - /* 205 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", - /* 206 */ "uniqueflag ::= UNIQUE", - /* 207 */ "uniqueflag ::=", - /* 208 */ "eidlist_opt ::=", - /* 209 */ "eidlist_opt ::= LP eidlist RP", - /* 210 */ "eidlist ::= eidlist COMMA nm collate sortorder", - /* 211 */ "eidlist ::= nm collate sortorder", - /* 212 */ "collate ::=", - /* 213 */ "collate ::= COLLATE ID|STRING", - /* 214 */ "cmd ::= DROP INDEX ifexists fullname", - /* 215 */ "cmd ::= VACUUM", - /* 216 */ "cmd ::= VACUUM nm", - /* 217 */ "cmd ::= PRAGMA nm dbnm", - /* 218 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", - /* 219 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", - /* 220 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", - /* 221 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", - /* 222 */ "plus_num ::= PLUS INTEGER|FLOAT", - /* 223 */ "minus_num ::= MINUS INTEGER|FLOAT", - /* 224 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", - /* 225 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", - /* 226 */ "trigger_time ::= BEFORE|AFTER", - /* 227 */ "trigger_time ::= INSTEAD OF", - /* 228 */ "trigger_time ::=", - /* 229 */ "trigger_event ::= DELETE|INSERT", - /* 230 */ "trigger_event ::= UPDATE", - /* 231 */ "trigger_event ::= UPDATE OF idlist", - /* 232 */ "when_clause ::=", - /* 233 */ "when_clause ::= WHEN expr", - /* 234 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", - /* 235 */ "trigger_cmd_list ::= trigger_cmd SEMI", - /* 236 */ "trnm ::= nm DOT nm", - /* 237 */ "tridxby ::= INDEXED BY nm", - /* 238 */ "tridxby ::= NOT INDEXED", - /* 239 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt", - /* 240 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select", - /* 241 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt", - /* 242 */ "trigger_cmd ::= select", - /* 243 */ "expr ::= RAISE LP IGNORE RP", - /* 244 */ "expr ::= RAISE LP raisetype COMMA nm RP", - /* 245 */ "raisetype ::= ROLLBACK", - /* 246 */ "raisetype ::= ABORT", - /* 247 */ "raisetype ::= FAIL", - /* 248 */ "cmd ::= DROP TRIGGER ifexists fullname", - /* 249 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", - /* 250 */ "cmd ::= DETACH database_kw_opt expr", - /* 251 */ "key_opt ::=", - /* 252 */ "key_opt ::= KEY expr", - /* 253 */ "cmd ::= REINDEX", - /* 254 */ "cmd ::= REINDEX nm dbnm", - /* 255 */ "cmd ::= ANALYZE", - /* 256 */ "cmd ::= ANALYZE nm dbnm", - /* 257 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", - /* 258 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", - /* 259 */ "add_column_fullname ::= fullname", - /* 260 */ "cmd ::= create_vtab", - /* 261 */ "cmd ::= create_vtab LP vtabarglist RP", - /* 262 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", - /* 263 */ "vtabarg ::=", - /* 264 */ "vtabargtoken ::= ANY", - /* 265 */ "vtabargtoken ::= lp anylist RP", - /* 266 */ "lp ::= LP", - /* 267 */ "with ::=", - /* 268 */ "with ::= WITH wqlist", - /* 269 */ "with ::= WITH RECURSIVE wqlist", - /* 270 */ "wqlist ::= nm eidlist_opt AS LP select RP", - /* 271 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP", - /* 272 */ "input ::= cmdlist", - /* 273 */ "cmdlist ::= cmdlist ecmd", - /* 274 */ "cmdlist ::= ecmd", - /* 275 */ "ecmd ::= SEMI", - /* 276 */ "ecmd ::= explain cmdx SEMI", - /* 277 */ "explain ::=", - /* 278 */ "trans_opt ::=", - /* 279 */ "trans_opt ::= TRANSACTION", - /* 280 */ "trans_opt ::= TRANSACTION nm", - /* 281 */ "savepoint_opt ::= SAVEPOINT", - /* 282 */ "savepoint_opt ::=", - /* 283 */ "cmd ::= create_table create_table_args", - /* 284 */ "columnlist ::= columnlist COMMA columnname carglist", - /* 285 */ "columnlist ::= columnname carglist", - /* 286 */ "nm ::= ID|INDEXED", - /* 287 */ "nm ::= STRING", - /* 288 */ "nm ::= JOIN_KW", - /* 289 */ "typetoken ::= typename", - /* 290 */ "typename ::= ID|STRING", - /* 291 */ "signed ::= plus_num", - /* 292 */ "signed ::= minus_num", - /* 293 */ "carglist ::= carglist ccons", - /* 294 */ "carglist ::=", - /* 295 */ "ccons ::= NULL onconf", - /* 296 */ "conslist_opt ::= COMMA conslist", - /* 297 */ "conslist ::= conslist tconscomma tcons", - /* 298 */ "conslist ::= tcons", - /* 299 */ "tconscomma ::=", - /* 300 */ "defer_subclause_opt ::= defer_subclause", - /* 301 */ "resolvetype ::= raisetype", - /* 302 */ "selectnowith ::= oneselect", - /* 303 */ "oneselect ::= values", - /* 304 */ "sclp ::= selcollist COMMA", - /* 305 */ "as ::= ID|STRING", - /* 306 */ "expr ::= term", - /* 307 */ "likeop ::= LIKE_KW|MATCH", - /* 308 */ "exprlist ::= nexprlist", - /* 309 */ "nmnum ::= plus_num", - /* 310 */ "nmnum ::= nm", - /* 311 */ "nmnum ::= ON", - /* 312 */ "nmnum ::= DELETE", - /* 313 */ "nmnum ::= DEFAULT", - /* 314 */ "plus_num ::= INTEGER|FLOAT", - /* 315 */ "foreach_clause ::=", - /* 316 */ "foreach_clause ::= FOR EACH ROW", - /* 317 */ "trnm ::= nm", - /* 318 */ "tridxby ::=", - /* 319 */ "database_kw_opt ::= DATABASE", - /* 320 */ "database_kw_opt ::=", - /* 321 */ "kwcolumn_opt ::=", - /* 322 */ "kwcolumn_opt ::= COLUMNKW", - /* 323 */ "vtabarglist ::= vtabarg", - /* 324 */ "vtabarglist ::= vtabarglist COMMA vtabarg", - /* 325 */ "vtabarg ::= vtabarg vtabargtoken", - /* 326 */ "anylist ::=", - /* 327 */ "anylist ::= anylist LP anylist RP", - /* 328 */ "anylist ::= anylist ANY", + /* 28 */ "scanpt ::=", + /* 29 */ "ccons ::= CONSTRAINT nm", + /* 30 */ "ccons ::= DEFAULT scanpt term scanpt", + /* 31 */ "ccons ::= DEFAULT LP expr RP", + /* 32 */ "ccons ::= DEFAULT PLUS term scanpt", + /* 33 */ "ccons ::= DEFAULT MINUS term scanpt", + /* 34 */ "ccons ::= DEFAULT scanpt ID|INDEXED", + /* 35 */ "ccons ::= NOT NULL onconf", + /* 36 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", + /* 37 */ "ccons ::= UNIQUE onconf", + /* 38 */ "ccons ::= CHECK LP expr RP", + /* 39 */ "ccons ::= REFERENCES nm eidlist_opt refargs", + /* 40 */ "ccons ::= defer_subclause", + /* 41 */ "ccons ::= COLLATE ID|STRING", + /* 42 */ "autoinc ::=", + /* 43 */ "autoinc ::= AUTOINCR", + /* 44 */ "refargs ::=", + /* 45 */ "refargs ::= refargs refarg", + /* 46 */ "refarg ::= MATCH nm", + /* 47 */ "refarg ::= ON INSERT refact", + /* 48 */ "refarg ::= ON DELETE refact", + /* 49 */ "refarg ::= ON UPDATE refact", + /* 50 */ "refact ::= SET NULL", + /* 51 */ "refact ::= SET DEFAULT", + /* 52 */ "refact ::= CASCADE", + /* 53 */ "refact ::= RESTRICT", + /* 54 */ "refact ::= NO ACTION", + /* 55 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", + /* 56 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", + /* 57 */ "init_deferred_pred_opt ::=", + /* 58 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", + /* 59 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", + /* 60 */ "conslist_opt ::=", + /* 61 */ "tconscomma ::= COMMA", + /* 62 */ "tcons ::= CONSTRAINT nm", + /* 63 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf", + /* 64 */ "tcons ::= UNIQUE LP sortlist RP onconf", + /* 65 */ "tcons ::= CHECK LP expr RP onconf", + /* 66 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt", + /* 67 */ "defer_subclause_opt ::=", + /* 68 */ "onconf ::=", + /* 69 */ "onconf ::= ON CONFLICT resolvetype", + /* 70 */ "orconf ::=", + /* 71 */ "orconf ::= OR resolvetype", + /* 72 */ "resolvetype ::= IGNORE", + /* 73 */ "resolvetype ::= REPLACE", + /* 74 */ "cmd ::= DROP TABLE ifexists fullname", + /* 75 */ "ifexists ::= IF EXISTS", + /* 76 */ "ifexists ::=", + /* 77 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select", + /* 78 */ "cmd ::= DROP VIEW ifexists fullname", + /* 79 */ "cmd ::= select", + /* 80 */ "select ::= WITH wqlist selectnowith", + /* 81 */ "select ::= WITH RECURSIVE wqlist selectnowith", + /* 82 */ "select ::= selectnowith", + /* 83 */ "selectnowith ::= selectnowith multiselect_op oneselect", + /* 84 */ "multiselect_op ::= UNION", + /* 85 */ "multiselect_op ::= UNION ALL", + /* 86 */ "multiselect_op ::= EXCEPT|INTERSECT", + /* 87 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", + /* 88 */ "values ::= VALUES LP nexprlist RP", + /* 89 */ "values ::= values COMMA LP exprlist RP", + /* 90 */ "distinct ::= DISTINCT", + /* 91 */ "distinct ::= ALL", + /* 92 */ "distinct ::=", + /* 93 */ "sclp ::=", + /* 94 */ "selcollist ::= sclp scanpt expr scanpt as", + /* 95 */ "selcollist ::= sclp scanpt STAR", + /* 96 */ "selcollist ::= sclp scanpt nm DOT STAR", + /* 97 */ "as ::= AS nm", + /* 98 */ "as ::=", + /* 99 */ "from ::=", + /* 100 */ "from ::= FROM seltablist", + /* 101 */ "stl_prefix ::= seltablist joinop", + /* 102 */ "stl_prefix ::=", + /* 103 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", + /* 104 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt", + /* 105 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", + /* 106 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt", + /* 107 */ "dbnm ::=", + /* 108 */ "dbnm ::= DOT nm", + /* 109 */ "fullname ::= nm", + /* 110 */ "fullname ::= nm DOT nm", + /* 111 */ "joinop ::= COMMA|JOIN", + /* 112 */ "joinop ::= JOIN_KW JOIN", + /* 113 */ "joinop ::= JOIN_KW nm JOIN", + /* 114 */ "joinop ::= JOIN_KW nm nm JOIN", + /* 115 */ "on_opt ::= ON expr", + /* 116 */ "on_opt ::=", + /* 117 */ "indexed_opt ::=", + /* 118 */ "indexed_opt ::= INDEXED BY nm", + /* 119 */ "indexed_opt ::= NOT INDEXED", + /* 120 */ "using_opt ::= USING LP idlist RP", + /* 121 */ "using_opt ::=", + /* 122 */ "orderby_opt ::=", + /* 123 */ "orderby_opt ::= ORDER BY sortlist", + /* 124 */ "sortlist ::= sortlist COMMA expr sortorder", + /* 125 */ "sortlist ::= expr sortorder", + /* 126 */ "sortorder ::= ASC", + /* 127 */ "sortorder ::= DESC", + /* 128 */ "sortorder ::=", + /* 129 */ "groupby_opt ::=", + /* 130 */ "groupby_opt ::= GROUP BY nexprlist", + /* 131 */ "having_opt ::=", + /* 132 */ "having_opt ::= HAVING expr", + /* 133 */ "limit_opt ::=", + /* 134 */ "limit_opt ::= LIMIT expr", + /* 135 */ "limit_opt ::= LIMIT expr OFFSET expr", + /* 136 */ "limit_opt ::= LIMIT expr COMMA expr", + /* 137 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt", + /* 138 */ "where_opt ::=", + /* 139 */ "where_opt ::= WHERE expr", + /* 140 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt", + /* 141 */ "setlist ::= setlist COMMA nm EQ expr", + /* 142 */ "setlist ::= setlist COMMA LP idlist RP EQ expr", + /* 143 */ "setlist ::= nm EQ expr", + /* 144 */ "setlist ::= LP idlist RP EQ expr", + /* 145 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select", + /* 146 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES", + /* 147 */ "insert_cmd ::= INSERT orconf", + /* 148 */ "insert_cmd ::= REPLACE", + /* 149 */ "idlist_opt ::=", + /* 150 */ "idlist_opt ::= LP idlist RP", + /* 151 */ "idlist ::= idlist COMMA nm", + /* 152 */ "idlist ::= nm", + /* 153 */ "expr ::= LP expr RP", + /* 154 */ "expr ::= ID|INDEXED", + /* 155 */ "expr ::= JOIN_KW", + /* 156 */ "expr ::= nm DOT nm", + /* 157 */ "expr ::= nm DOT nm DOT nm", + /* 158 */ "term ::= NULL|FLOAT|BLOB", + /* 159 */ "term ::= STRING", + /* 160 */ "term ::= INTEGER", + /* 161 */ "expr ::= VARIABLE", + /* 162 */ "expr ::= expr COLLATE ID|STRING", + /* 163 */ "expr ::= CAST LP expr AS typetoken RP", + /* 164 */ "expr ::= ID|INDEXED LP distinct exprlist RP", + /* 165 */ "expr ::= ID|INDEXED LP STAR RP", + /* 166 */ "term ::= CTIME_KW", + /* 167 */ "expr ::= LP nexprlist COMMA expr RP", + /* 168 */ "expr ::= expr AND expr", + /* 169 */ "expr ::= expr OR expr", + /* 170 */ "expr ::= expr LT|GT|GE|LE expr", + /* 171 */ "expr ::= expr EQ|NE expr", + /* 172 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", + /* 173 */ "expr ::= expr PLUS|MINUS expr", + /* 174 */ "expr ::= expr STAR|SLASH|REM expr", + /* 175 */ "expr ::= expr CONCAT expr", + /* 176 */ "likeop ::= NOT LIKE_KW|MATCH", + /* 177 */ "expr ::= expr likeop expr", + /* 178 */ "expr ::= expr likeop expr ESCAPE expr", + /* 179 */ "expr ::= expr ISNULL|NOTNULL", + /* 180 */ "expr ::= expr NOT NULL", + /* 181 */ "expr ::= expr IS expr", + /* 182 */ "expr ::= expr IS NOT expr", + /* 183 */ "expr ::= NOT expr", + /* 184 */ "expr ::= BITNOT expr", + /* 185 */ "expr ::= MINUS expr", + /* 186 */ "expr ::= PLUS expr", + /* 187 */ "between_op ::= BETWEEN", + /* 188 */ "between_op ::= NOT BETWEEN", + /* 189 */ "expr ::= expr between_op expr AND expr", + /* 190 */ "in_op ::= IN", + /* 191 */ "in_op ::= NOT IN", + /* 192 */ "expr ::= expr in_op LP exprlist RP", + /* 193 */ "expr ::= LP select RP", + /* 194 */ "expr ::= expr in_op LP select RP", + /* 195 */ "expr ::= expr in_op nm dbnm paren_exprlist", + /* 196 */ "expr ::= EXISTS LP select RP", + /* 197 */ "expr ::= CASE case_operand case_exprlist case_else END", + /* 198 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", + /* 199 */ "case_exprlist ::= WHEN expr THEN expr", + /* 200 */ "case_else ::= ELSE expr", + /* 201 */ "case_else ::=", + /* 202 */ "case_operand ::= expr", + /* 203 */ "case_operand ::=", + /* 204 */ "exprlist ::=", + /* 205 */ "nexprlist ::= nexprlist COMMA expr", + /* 206 */ "nexprlist ::= expr", + /* 207 */ "paren_exprlist ::=", + /* 208 */ "paren_exprlist ::= LP exprlist RP", + /* 209 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", + /* 210 */ "uniqueflag ::= UNIQUE", + /* 211 */ "uniqueflag ::=", + /* 212 */ "eidlist_opt ::=", + /* 213 */ "eidlist_opt ::= LP eidlist RP", + /* 214 */ "eidlist ::= eidlist COMMA nm collate sortorder", + /* 215 */ "eidlist ::= nm collate sortorder", + /* 216 */ "collate ::=", + /* 217 */ "collate ::= COLLATE ID|STRING", + /* 218 */ "cmd ::= DROP INDEX ifexists fullname", + /* 219 */ "cmd ::= VACUUM", + /* 220 */ "cmd ::= VACUUM nm", + /* 221 */ "cmd ::= PRAGMA nm dbnm", + /* 222 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", + /* 223 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", + /* 224 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", + /* 225 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", + /* 226 */ "plus_num ::= PLUS INTEGER|FLOAT", + /* 227 */ "minus_num ::= MINUS INTEGER|FLOAT", + /* 228 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", + /* 229 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", + /* 230 */ "trigger_time ::= BEFORE|AFTER", + /* 231 */ "trigger_time ::= INSTEAD OF", + /* 232 */ "trigger_time ::=", + /* 233 */ "trigger_event ::= DELETE|INSERT", + /* 234 */ "trigger_event ::= UPDATE", + /* 235 */ "trigger_event ::= UPDATE OF idlist", + /* 236 */ "when_clause ::=", + /* 237 */ "when_clause ::= WHEN expr", + /* 238 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", + /* 239 */ "trigger_cmd_list ::= trigger_cmd SEMI", + /* 240 */ "trnm ::= nm DOT nm", + /* 241 */ "tridxby ::= INDEXED BY nm", + /* 242 */ "tridxby ::= NOT INDEXED", + /* 243 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt", + /* 244 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt", + /* 245 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt", + /* 246 */ "trigger_cmd ::= scanpt select scanpt", + /* 247 */ "expr ::= RAISE LP IGNORE RP", + /* 248 */ "expr ::= RAISE LP raisetype COMMA nm RP", + /* 249 */ "raisetype ::= ROLLBACK", + /* 250 */ "raisetype ::= ABORT", + /* 251 */ "raisetype ::= FAIL", + /* 252 */ "cmd ::= DROP TRIGGER ifexists fullname", + /* 253 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", + /* 254 */ "cmd ::= DETACH database_kw_opt expr", + /* 255 */ "key_opt ::=", + /* 256 */ "key_opt ::= KEY expr", + /* 257 */ "cmd ::= REINDEX", + /* 258 */ "cmd ::= REINDEX nm dbnm", + /* 259 */ "cmd ::= ANALYZE", + /* 260 */ "cmd ::= ANALYZE nm dbnm", + /* 261 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", + /* 262 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", + /* 263 */ "add_column_fullname ::= fullname", + /* 264 */ "cmd ::= create_vtab", + /* 265 */ "cmd ::= create_vtab LP vtabarglist RP", + /* 266 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", + /* 267 */ "vtabarg ::=", + /* 268 */ "vtabargtoken ::= ANY", + /* 269 */ "vtabargtoken ::= lp anylist RP", + /* 270 */ "lp ::= LP", + /* 271 */ "with ::= WITH wqlist", + /* 272 */ "with ::= WITH RECURSIVE wqlist", + /* 273 */ "wqlist ::= nm eidlist_opt AS LP select RP", + /* 274 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP", + /* 275 */ "input ::= cmdlist", + /* 276 */ "cmdlist ::= cmdlist ecmd", + /* 277 */ "cmdlist ::= ecmd", + /* 278 */ "ecmd ::= SEMI", + /* 279 */ "ecmd ::= explain cmdx SEMI", + /* 280 */ "explain ::=", + /* 281 */ "trans_opt ::=", + /* 282 */ "trans_opt ::= TRANSACTION", + /* 283 */ "trans_opt ::= TRANSACTION nm", + /* 284 */ "savepoint_opt ::= SAVEPOINT", + /* 285 */ "savepoint_opt ::=", + /* 286 */ "cmd ::= create_table create_table_args", + /* 287 */ "columnlist ::= columnlist COMMA columnname carglist", + /* 288 */ "columnlist ::= columnname carglist", + /* 289 */ "nm ::= ID|INDEXED", + /* 290 */ "nm ::= STRING", + /* 291 */ "nm ::= JOIN_KW", + /* 292 */ "typetoken ::= typename", + /* 293 */ "typename ::= ID|STRING", + /* 294 */ "signed ::= plus_num", + /* 295 */ "signed ::= minus_num", + /* 296 */ "carglist ::= carglist ccons", + /* 297 */ "carglist ::=", + /* 298 */ "ccons ::= NULL onconf", + /* 299 */ "conslist_opt ::= COMMA conslist", + /* 300 */ "conslist ::= conslist tconscomma tcons", + /* 301 */ "conslist ::= tcons", + /* 302 */ "tconscomma ::=", + /* 303 */ "defer_subclause_opt ::= defer_subclause", + /* 304 */ "resolvetype ::= raisetype", + /* 305 */ "selectnowith ::= oneselect", + /* 306 */ "oneselect ::= values", + /* 307 */ "sclp ::= selcollist COMMA", + /* 308 */ "as ::= ID|STRING", + /* 309 */ "expr ::= term", + /* 310 */ "likeop ::= LIKE_KW|MATCH", + /* 311 */ "exprlist ::= nexprlist", + /* 312 */ "nmnum ::= plus_num", + /* 313 */ "nmnum ::= nm", + /* 314 */ "nmnum ::= ON", + /* 315 */ "nmnum ::= DELETE", + /* 316 */ "nmnum ::= DEFAULT", + /* 317 */ "plus_num ::= INTEGER|FLOAT", + /* 318 */ "foreach_clause ::=", + /* 319 */ "foreach_clause ::= FOR EACH ROW", + /* 320 */ "trnm ::= nm", + /* 321 */ "tridxby ::=", + /* 322 */ "database_kw_opt ::= DATABASE", + /* 323 */ "database_kw_opt ::=", + /* 324 */ "kwcolumn_opt ::=", + /* 325 */ "kwcolumn_opt ::= COLUMNKW", + /* 326 */ "vtabarglist ::= vtabarg", + /* 327 */ "vtabarglist ::= vtabarglist COMMA vtabarg", + /* 328 */ "vtabarg ::= vtabarg vtabargtoken", + /* 329 */ "anylist ::=", + /* 330 */ "anylist ::= anylist LP anylist RP", + /* 331 */ "anylist ::= anylist ANY", + /* 332 */ "with ::=", }; #endif /* NDEBUG */ @@ -138472,76 +141485,71 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ case 163: /* select */ - case 194: /* selectnowith */ - case 195: /* oneselect */ - case 206: /* values */ + case 195: /* selectnowith */ + case 196: /* oneselect */ + case 207: /* values */ { -sqlite3SelectDelete(pParse->db, (yypminor->yy243)); +sqlite3SelectDelete(pParse->db, (yypminor->yy387)); } break; - case 172: /* term */ - case 173: /* expr */ + case 173: /* term */ + case 174: /* expr */ + case 202: /* where_opt */ + case 204: /* having_opt */ + case 216: /* on_opt */ + case 227: /* case_operand */ + case 229: /* case_else */ + case 238: /* when_clause */ + case 243: /* key_opt */ { -sqlite3ExprDelete(pParse->db, (yypminor->yy190).pExpr); +sqlite3ExprDelete(pParse->db, (yypminor->yy314)); } break; - case 177: /* eidlist_opt */ - case 186: /* sortlist */ - case 187: /* eidlist */ - case 199: /* selcollist */ - case 202: /* groupby_opt */ - case 204: /* orderby_opt */ - case 207: /* nexprlist */ - case 208: /* exprlist */ - case 209: /* sclp */ - case 218: /* setlist */ - case 224: /* paren_exprlist */ - case 226: /* case_exprlist */ + case 178: /* eidlist_opt */ + case 187: /* sortlist */ + case 188: /* eidlist */ + case 200: /* selcollist */ + case 203: /* groupby_opt */ + case 205: /* orderby_opt */ + case 208: /* nexprlist */ + case 209: /* exprlist */ + case 210: /* sclp */ + case 220: /* setlist */ + case 226: /* paren_exprlist */ + case 228: /* case_exprlist */ { -sqlite3ExprListDelete(pParse->db, (yypminor->yy148)); +sqlite3ExprListDelete(pParse->db, (yypminor->yy322)); } break; - case 193: /* fullname */ - case 200: /* from */ - case 211: /* seltablist */ - case 212: /* stl_prefix */ + case 194: /* fullname */ + case 201: /* from */ + case 212: /* seltablist */ + case 213: /* stl_prefix */ { -sqlite3SrcListDelete(pParse->db, (yypminor->yy185)); +sqlite3SrcListDelete(pParse->db, (yypminor->yy259)); } break; - case 196: /* with */ - case 250: /* wqlist */ + case 197: /* wqlist */ { -sqlite3WithDelete(pParse->db, (yypminor->yy285)); +sqlite3WithDelete(pParse->db, (yypminor->yy451)); } break; - case 201: /* where_opt */ - case 203: /* having_opt */ - case 215: /* on_opt */ - case 225: /* case_operand */ - case 227: /* case_else */ - case 236: /* when_clause */ - case 241: /* key_opt */ + case 217: /* using_opt */ + case 218: /* idlist */ + case 222: /* idlist_opt */ { -sqlite3ExprDelete(pParse->db, (yypminor->yy72)); +sqlite3IdListDelete(pParse->db, (yypminor->yy384)); } break; - case 216: /* using_opt */ - case 217: /* idlist */ - case 220: /* idlist_opt */ + case 234: /* trigger_cmd_list */ + case 239: /* trigger_cmd */ { -sqlite3IdListDelete(pParse->db, (yypminor->yy254)); +sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203)); } break; - case 232: /* trigger_cmd_list */ - case 237: /* trigger_cmd */ + case 236: /* trigger_event */ { -sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy145)); -} - break; - case 234: /* trigger_event */ -{ -sqlite3IdListDelete(pParse->db, (yypminor->yy332).b); +sqlite3IdListDelete(pParse->db, (yypminor->yy90).b); } break; /********* End destructor definitions *****************************************/ @@ -138612,6 +141620,43 @@ SQLITE_PRIVATE int sqlite3ParserStackPeak(void *p){ } #endif +/* This array of booleans keeps track of the parser statement +** coverage. The element yycoverage[X][Y] is set when the parser +** is in state X and has a lookahead token Y. In a well-tested +** systems, every element of this matrix should end up being set. +*/ +#if defined(YYCOVERAGE) +static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; +#endif + +/* +** Write into out a description of every state/lookahead combination that +** +** (1) has not been used by the parser, and +** (2) is not a syntax error. +** +** Return the number of missed state/lookahead combinations. +*/ +#if defined(YYCOVERAGE) +SQLITE_PRIVATE int sqlite3ParserCoverage(FILE *out){ + int stateno, iLookAhead, i; + int nMissed = 0; + for(stateno=0; statenoyytos->stateno; - if( stateno>=YY_MIN_REDUCE ) return stateno; + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); +#if defined(YYCOVERAGE) + yycoverage[stateno][iLookAhead] = 1; +#endif do{ i = yy_shift_ofst[stateno]; + assert( i>=0 ); + assert( i+YYNTOKEN<=(int)sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); assert( iLookAhead!=YYNOCODE ); + assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ + if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ if( iLookAheadyytos->major], + fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], yyNewState); }else{ - fprintf(yyTraceFILE,"%sShift '%s'\n", - yyTracePrompt,yyTokenName[yypParser->yytos->major]); + fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], + yyNewState - YY_MIN_REDUCE); } } } #else -# define yyTraceShift(X,Y) +# define yyTraceShift(X,Y,Z) #endif /* @@ -138785,7 +141836,7 @@ static void yy_shift( yytos->stateno = (YYACTIONTYPE)yyNewState; yytos->major = (YYCODETYPE)yyMajor; yytos->minor.yy0 = yyMinor; - yyTraceShift(yypParser, yyNewState); + yyTraceShift(yypParser, yyNewState, "Shift"); } /* The following table contains information about every rule that @@ -138795,335 +141846,339 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 147, -1 }, - { 147, -3 }, - { 148, -1 }, - { 149, -3 }, - { 150, 0 }, - { 150, -1 }, - { 150, -1 }, - { 150, -1 }, - { 149, -2 }, - { 149, -2 }, - { 149, -2 }, - { 149, -3 }, - { 149, -5 }, - { 154, -6 }, - { 156, -1 }, - { 158, 0 }, - { 158, -3 }, - { 157, -1 }, - { 157, 0 }, - { 155, -5 }, - { 155, -2 }, - { 162, 0 }, - { 162, -2 }, - { 164, -2 }, - { 166, 0 }, - { 166, -4 }, - { 166, -6 }, - { 167, -2 }, - { 171, -2 }, - { 171, -2 }, - { 171, -4 }, - { 171, -3 }, - { 171, -3 }, - { 171, -2 }, - { 171, -3 }, - { 171, -5 }, - { 171, -2 }, - { 171, -4 }, - { 171, -4 }, - { 171, -1 }, - { 171, -2 }, - { 176, 0 }, - { 176, -1 }, - { 178, 0 }, - { 178, -2 }, - { 180, -2 }, - { 180, -3 }, - { 180, -3 }, - { 180, -3 }, - { 181, -2 }, - { 181, -2 }, - { 181, -1 }, - { 181, -1 }, - { 181, -2 }, - { 179, -3 }, - { 179, -2 }, - { 182, 0 }, - { 182, -2 }, - { 182, -2 }, - { 161, 0 }, - { 184, -1 }, - { 185, -2 }, - { 185, -7 }, - { 185, -5 }, - { 185, -5 }, - { 185, -10 }, - { 188, 0 }, - { 174, 0 }, - { 174, -3 }, - { 189, 0 }, - { 189, -2 }, - { 190, -1 }, - { 190, -1 }, - { 149, -4 }, - { 192, -2 }, - { 192, 0 }, - { 149, -9 }, - { 149, -4 }, - { 149, -1 }, - { 163, -2 }, - { 194, -3 }, - { 197, -1 }, - { 197, -2 }, - { 197, -1 }, - { 195, -9 }, - { 206, -4 }, - { 206, -5 }, - { 198, -1 }, - { 198, -1 }, - { 198, 0 }, - { 209, 0 }, - { 199, -3 }, - { 199, -2 }, - { 199, -4 }, - { 210, -2 }, - { 210, 0 }, - { 200, 0 }, - { 200, -2 }, - { 212, -2 }, - { 212, 0 }, - { 211, -7 }, - { 211, -9 }, - { 211, -7 }, - { 211, -7 }, - { 159, 0 }, - { 159, -2 }, - { 193, -2 }, - { 213, -1 }, - { 213, -2 }, - { 213, -3 }, - { 213, -4 }, - { 215, -2 }, - { 215, 0 }, - { 214, 0 }, - { 214, -3 }, - { 214, -2 }, - { 216, -4 }, - { 216, 0 }, - { 204, 0 }, - { 204, -3 }, - { 186, -4 }, - { 186, -2 }, - { 175, -1 }, - { 175, -1 }, - { 175, 0 }, - { 202, 0 }, - { 202, -3 }, - { 203, 0 }, - { 203, -2 }, - { 205, 0 }, - { 205, -2 }, - { 205, -4 }, - { 205, -4 }, - { 149, -6 }, - { 201, 0 }, - { 201, -2 }, - { 149, -8 }, - { 218, -5 }, - { 218, -7 }, - { 218, -3 }, - { 218, -5 }, - { 149, -6 }, - { 149, -7 }, - { 219, -2 }, - { 219, -1 }, - { 220, 0 }, - { 220, -3 }, - { 217, -3 }, - { 217, -1 }, - { 173, -3 }, - { 173, -1 }, - { 173, -1 }, - { 173, -3 }, - { 173, -5 }, - { 172, -1 }, - { 172, -1 }, - { 172, -1 }, - { 173, -1 }, - { 173, -3 }, - { 173, -6 }, - { 173, -5 }, - { 173, -4 }, - { 172, -1 }, - { 173, -5 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 173, -3 }, - { 221, -2 }, - { 173, -3 }, - { 173, -5 }, - { 173, -2 }, - { 173, -3 }, - { 173, -3 }, - { 173, -4 }, - { 173, -2 }, - { 173, -2 }, - { 173, -2 }, - { 173, -2 }, - { 222, -1 }, - { 222, -2 }, - { 173, -5 }, - { 223, -1 }, - { 223, -2 }, - { 173, -5 }, - { 173, -3 }, - { 173, -5 }, - { 173, -5 }, - { 173, -4 }, - { 173, -5 }, - { 226, -5 }, - { 226, -4 }, - { 227, -2 }, - { 227, 0 }, - { 225, -1 }, - { 225, 0 }, - { 208, 0 }, - { 207, -3 }, - { 207, -1 }, - { 224, 0 }, - { 224, -3 }, - { 149, -12 }, - { 228, -1 }, - { 228, 0 }, - { 177, 0 }, - { 177, -3 }, - { 187, -5 }, - { 187, -3 }, - { 229, 0 }, - { 229, -2 }, - { 149, -4 }, - { 149, -1 }, - { 149, -2 }, - { 149, -3 }, - { 149, -5 }, - { 149, -6 }, - { 149, -5 }, - { 149, -6 }, - { 169, -2 }, - { 170, -2 }, - { 149, -5 }, - { 231, -11 }, - { 233, -1 }, - { 233, -2 }, - { 233, 0 }, - { 234, -1 }, - { 234, -1 }, - { 234, -3 }, - { 236, 0 }, - { 236, -2 }, - { 232, -3 }, - { 232, -2 }, - { 238, -3 }, - { 239, -3 }, - { 239, -2 }, - { 237, -7 }, - { 237, -5 }, - { 237, -5 }, - { 237, -1 }, - { 173, -4 }, - { 173, -6 }, - { 191, -1 }, - { 191, -1 }, - { 191, -1 }, - { 149, -4 }, - { 149, -6 }, - { 149, -3 }, - { 241, 0 }, - { 241, -2 }, - { 149, -1 }, - { 149, -3 }, - { 149, -1 }, - { 149, -3 }, - { 149, -6 }, - { 149, -7 }, - { 242, -1 }, - { 149, -1 }, - { 149, -4 }, - { 244, -8 }, - { 246, 0 }, - { 247, -1 }, - { 247, -3 }, - { 248, -1 }, - { 196, 0 }, - { 196, -2 }, - { 196, -3 }, - { 250, -6 }, - { 250, -8 }, - { 144, -1 }, - { 145, -2 }, - { 145, -1 }, - { 146, -1 }, - { 146, -3 }, - { 147, 0 }, - { 151, 0 }, - { 151, -1 }, - { 151, -2 }, - { 153, -1 }, - { 153, 0 }, - { 149, -2 }, - { 160, -4 }, - { 160, -2 }, - { 152, -1 }, - { 152, -1 }, - { 152, -1 }, - { 166, -1 }, - { 167, -1 }, - { 168, -1 }, - { 168, -1 }, - { 165, -2 }, - { 165, 0 }, - { 171, -2 }, - { 161, -2 }, - { 183, -3 }, - { 183, -1 }, - { 184, 0 }, - { 188, -1 }, - { 190, -1 }, - { 194, -1 }, - { 195, -1 }, - { 209, -2 }, - { 210, -1 }, - { 173, -1 }, - { 221, -1 }, - { 208, -1 }, - { 230, -1 }, - { 230, -1 }, - { 230, -1 }, - { 230, -1 }, - { 230, -1 }, - { 169, -1 }, - { 235, 0 }, - { 235, -3 }, - { 238, -1 }, - { 239, 0 }, - { 240, -1 }, - { 240, 0 }, - { 243, 0 }, - { 243, -1 }, - { 245, -1 }, - { 245, -3 }, - { 246, -2 }, - { 249, 0 }, - { 249, -4 }, - { 249, -2 }, + { 147, -1 }, /* (0) explain ::= EXPLAIN */ + { 147, -3 }, /* (1) explain ::= EXPLAIN QUERY PLAN */ + { 148, -1 }, /* (2) cmdx ::= cmd */ + { 149, -3 }, /* (3) cmd ::= BEGIN transtype trans_opt */ + { 150, 0 }, /* (4) transtype ::= */ + { 150, -1 }, /* (5) transtype ::= DEFERRED */ + { 150, -1 }, /* (6) transtype ::= IMMEDIATE */ + { 150, -1 }, /* (7) transtype ::= EXCLUSIVE */ + { 149, -2 }, /* (8) cmd ::= COMMIT|END trans_opt */ + { 149, -2 }, /* (9) cmd ::= ROLLBACK trans_opt */ + { 149, -2 }, /* (10) cmd ::= SAVEPOINT nm */ + { 149, -3 }, /* (11) cmd ::= RELEASE savepoint_opt nm */ + { 149, -5 }, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */ + { 154, -6 }, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */ + { 156, -1 }, /* (14) createkw ::= CREATE */ + { 158, 0 }, /* (15) ifnotexists ::= */ + { 158, -3 }, /* (16) ifnotexists ::= IF NOT EXISTS */ + { 157, -1 }, /* (17) temp ::= TEMP */ + { 157, 0 }, /* (18) temp ::= */ + { 155, -5 }, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */ + { 155, -2 }, /* (20) create_table_args ::= AS select */ + { 162, 0 }, /* (21) table_options ::= */ + { 162, -2 }, /* (22) table_options ::= WITHOUT nm */ + { 164, -2 }, /* (23) columnname ::= nm typetoken */ + { 166, 0 }, /* (24) typetoken ::= */ + { 166, -4 }, /* (25) typetoken ::= typename LP signed RP */ + { 166, -6 }, /* (26) typetoken ::= typename LP signed COMMA signed RP */ + { 167, -2 }, /* (27) typename ::= typename ID|STRING */ + { 171, 0 }, /* (28) scanpt ::= */ + { 172, -2 }, /* (29) ccons ::= CONSTRAINT nm */ + { 172, -4 }, /* (30) ccons ::= DEFAULT scanpt term scanpt */ + { 172, -4 }, /* (31) ccons ::= DEFAULT LP expr RP */ + { 172, -4 }, /* (32) ccons ::= DEFAULT PLUS term scanpt */ + { 172, -4 }, /* (33) ccons ::= DEFAULT MINUS term scanpt */ + { 172, -3 }, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */ + { 172, -3 }, /* (35) ccons ::= NOT NULL onconf */ + { 172, -5 }, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */ + { 172, -2 }, /* (37) ccons ::= UNIQUE onconf */ + { 172, -4 }, /* (38) ccons ::= CHECK LP expr RP */ + { 172, -4 }, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */ + { 172, -1 }, /* (40) ccons ::= defer_subclause */ + { 172, -2 }, /* (41) ccons ::= COLLATE ID|STRING */ + { 177, 0 }, /* (42) autoinc ::= */ + { 177, -1 }, /* (43) autoinc ::= AUTOINCR */ + { 179, 0 }, /* (44) refargs ::= */ + { 179, -2 }, /* (45) refargs ::= refargs refarg */ + { 181, -2 }, /* (46) refarg ::= MATCH nm */ + { 181, -3 }, /* (47) refarg ::= ON INSERT refact */ + { 181, -3 }, /* (48) refarg ::= ON DELETE refact */ + { 181, -3 }, /* (49) refarg ::= ON UPDATE refact */ + { 182, -2 }, /* (50) refact ::= SET NULL */ + { 182, -2 }, /* (51) refact ::= SET DEFAULT */ + { 182, -1 }, /* (52) refact ::= CASCADE */ + { 182, -1 }, /* (53) refact ::= RESTRICT */ + { 182, -2 }, /* (54) refact ::= NO ACTION */ + { 180, -3 }, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ + { 180, -2 }, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ + { 183, 0 }, /* (57) init_deferred_pred_opt ::= */ + { 183, -2 }, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */ + { 183, -2 }, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ + { 161, 0 }, /* (60) conslist_opt ::= */ + { 185, -1 }, /* (61) tconscomma ::= COMMA */ + { 186, -2 }, /* (62) tcons ::= CONSTRAINT nm */ + { 186, -7 }, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ + { 186, -5 }, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */ + { 186, -5 }, /* (65) tcons ::= CHECK LP expr RP onconf */ + { 186, -10 }, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ + { 189, 0 }, /* (67) defer_subclause_opt ::= */ + { 175, 0 }, /* (68) onconf ::= */ + { 175, -3 }, /* (69) onconf ::= ON CONFLICT resolvetype */ + { 190, 0 }, /* (70) orconf ::= */ + { 190, -2 }, /* (71) orconf ::= OR resolvetype */ + { 191, -1 }, /* (72) resolvetype ::= IGNORE */ + { 191, -1 }, /* (73) resolvetype ::= REPLACE */ + { 149, -4 }, /* (74) cmd ::= DROP TABLE ifexists fullname */ + { 193, -2 }, /* (75) ifexists ::= IF EXISTS */ + { 193, 0 }, /* (76) ifexists ::= */ + { 149, -9 }, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ + { 149, -4 }, /* (78) cmd ::= DROP VIEW ifexists fullname */ + { 149, -1 }, /* (79) cmd ::= select */ + { 163, -3 }, /* (80) select ::= WITH wqlist selectnowith */ + { 163, -4 }, /* (81) select ::= WITH RECURSIVE wqlist selectnowith */ + { 163, -1 }, /* (82) select ::= selectnowith */ + { 195, -3 }, /* (83) selectnowith ::= selectnowith multiselect_op oneselect */ + { 198, -1 }, /* (84) multiselect_op ::= UNION */ + { 198, -2 }, /* (85) multiselect_op ::= UNION ALL */ + { 198, -1 }, /* (86) multiselect_op ::= EXCEPT|INTERSECT */ + { 196, -9 }, /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ + { 207, -4 }, /* (88) values ::= VALUES LP nexprlist RP */ + { 207, -5 }, /* (89) values ::= values COMMA LP exprlist RP */ + { 199, -1 }, /* (90) distinct ::= DISTINCT */ + { 199, -1 }, /* (91) distinct ::= ALL */ + { 199, 0 }, /* (92) distinct ::= */ + { 210, 0 }, /* (93) sclp ::= */ + { 200, -5 }, /* (94) selcollist ::= sclp scanpt expr scanpt as */ + { 200, -3 }, /* (95) selcollist ::= sclp scanpt STAR */ + { 200, -5 }, /* (96) selcollist ::= sclp scanpt nm DOT STAR */ + { 211, -2 }, /* (97) as ::= AS nm */ + { 211, 0 }, /* (98) as ::= */ + { 201, 0 }, /* (99) from ::= */ + { 201, -2 }, /* (100) from ::= FROM seltablist */ + { 213, -2 }, /* (101) stl_prefix ::= seltablist joinop */ + { 213, 0 }, /* (102) stl_prefix ::= */ + { 212, -7 }, /* (103) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ + { 212, -9 }, /* (104) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ + { 212, -7 }, /* (105) seltablist ::= stl_prefix LP select RP as on_opt using_opt */ + { 212, -7 }, /* (106) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ + { 159, 0 }, /* (107) dbnm ::= */ + { 159, -2 }, /* (108) dbnm ::= DOT nm */ + { 194, -1 }, /* (109) fullname ::= nm */ + { 194, -3 }, /* (110) fullname ::= nm DOT nm */ + { 214, -1 }, /* (111) joinop ::= COMMA|JOIN */ + { 214, -2 }, /* (112) joinop ::= JOIN_KW JOIN */ + { 214, -3 }, /* (113) joinop ::= JOIN_KW nm JOIN */ + { 214, -4 }, /* (114) joinop ::= JOIN_KW nm nm JOIN */ + { 216, -2 }, /* (115) on_opt ::= ON expr */ + { 216, 0 }, /* (116) on_opt ::= */ + { 215, 0 }, /* (117) indexed_opt ::= */ + { 215, -3 }, /* (118) indexed_opt ::= INDEXED BY nm */ + { 215, -2 }, /* (119) indexed_opt ::= NOT INDEXED */ + { 217, -4 }, /* (120) using_opt ::= USING LP idlist RP */ + { 217, 0 }, /* (121) using_opt ::= */ + { 205, 0 }, /* (122) orderby_opt ::= */ + { 205, -3 }, /* (123) orderby_opt ::= ORDER BY sortlist */ + { 187, -4 }, /* (124) sortlist ::= sortlist COMMA expr sortorder */ + { 187, -2 }, /* (125) sortlist ::= expr sortorder */ + { 176, -1 }, /* (126) sortorder ::= ASC */ + { 176, -1 }, /* (127) sortorder ::= DESC */ + { 176, 0 }, /* (128) sortorder ::= */ + { 203, 0 }, /* (129) groupby_opt ::= */ + { 203, -3 }, /* (130) groupby_opt ::= GROUP BY nexprlist */ + { 204, 0 }, /* (131) having_opt ::= */ + { 204, -2 }, /* (132) having_opt ::= HAVING expr */ + { 206, 0 }, /* (133) limit_opt ::= */ + { 206, -2 }, /* (134) limit_opt ::= LIMIT expr */ + { 206, -4 }, /* (135) limit_opt ::= LIMIT expr OFFSET expr */ + { 206, -4 }, /* (136) limit_opt ::= LIMIT expr COMMA expr */ + { 149, -6 }, /* (137) cmd ::= with DELETE FROM fullname indexed_opt where_opt */ + { 202, 0 }, /* (138) where_opt ::= */ + { 202, -2 }, /* (139) where_opt ::= WHERE expr */ + { 149, -8 }, /* (140) cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */ + { 220, -5 }, /* (141) setlist ::= setlist COMMA nm EQ expr */ + { 220, -7 }, /* (142) setlist ::= setlist COMMA LP idlist RP EQ expr */ + { 220, -3 }, /* (143) setlist ::= nm EQ expr */ + { 220, -5 }, /* (144) setlist ::= LP idlist RP EQ expr */ + { 149, -6 }, /* (145) cmd ::= with insert_cmd INTO fullname idlist_opt select */ + { 149, -7 }, /* (146) cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */ + { 221, -2 }, /* (147) insert_cmd ::= INSERT orconf */ + { 221, -1 }, /* (148) insert_cmd ::= REPLACE */ + { 222, 0 }, /* (149) idlist_opt ::= */ + { 222, -3 }, /* (150) idlist_opt ::= LP idlist RP */ + { 218, -3 }, /* (151) idlist ::= idlist COMMA nm */ + { 218, -1 }, /* (152) idlist ::= nm */ + { 174, -3 }, /* (153) expr ::= LP expr RP */ + { 174, -1 }, /* (154) expr ::= ID|INDEXED */ + { 174, -1 }, /* (155) expr ::= JOIN_KW */ + { 174, -3 }, /* (156) expr ::= nm DOT nm */ + { 174, -5 }, /* (157) expr ::= nm DOT nm DOT nm */ + { 173, -1 }, /* (158) term ::= NULL|FLOAT|BLOB */ + { 173, -1 }, /* (159) term ::= STRING */ + { 173, -1 }, /* (160) term ::= INTEGER */ + { 174, -1 }, /* (161) expr ::= VARIABLE */ + { 174, -3 }, /* (162) expr ::= expr COLLATE ID|STRING */ + { 174, -6 }, /* (163) expr ::= CAST LP expr AS typetoken RP */ + { 174, -5 }, /* (164) expr ::= ID|INDEXED LP distinct exprlist RP */ + { 174, -4 }, /* (165) expr ::= ID|INDEXED LP STAR RP */ + { 173, -1 }, /* (166) term ::= CTIME_KW */ + { 174, -5 }, /* (167) expr ::= LP nexprlist COMMA expr RP */ + { 174, -3 }, /* (168) expr ::= expr AND expr */ + { 174, -3 }, /* (169) expr ::= expr OR expr */ + { 174, -3 }, /* (170) expr ::= expr LT|GT|GE|LE expr */ + { 174, -3 }, /* (171) expr ::= expr EQ|NE expr */ + { 174, -3 }, /* (172) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ + { 174, -3 }, /* (173) expr ::= expr PLUS|MINUS expr */ + { 174, -3 }, /* (174) expr ::= expr STAR|SLASH|REM expr */ + { 174, -3 }, /* (175) expr ::= expr CONCAT expr */ + { 223, -2 }, /* (176) likeop ::= NOT LIKE_KW|MATCH */ + { 174, -3 }, /* (177) expr ::= expr likeop expr */ + { 174, -5 }, /* (178) expr ::= expr likeop expr ESCAPE expr */ + { 174, -2 }, /* (179) expr ::= expr ISNULL|NOTNULL */ + { 174, -3 }, /* (180) expr ::= expr NOT NULL */ + { 174, -3 }, /* (181) expr ::= expr IS expr */ + { 174, -4 }, /* (182) expr ::= expr IS NOT expr */ + { 174, -2 }, /* (183) expr ::= NOT expr */ + { 174, -2 }, /* (184) expr ::= BITNOT expr */ + { 174, -2 }, /* (185) expr ::= MINUS expr */ + { 174, -2 }, /* (186) expr ::= PLUS expr */ + { 224, -1 }, /* (187) between_op ::= BETWEEN */ + { 224, -2 }, /* (188) between_op ::= NOT BETWEEN */ + { 174, -5 }, /* (189) expr ::= expr between_op expr AND expr */ + { 225, -1 }, /* (190) in_op ::= IN */ + { 225, -2 }, /* (191) in_op ::= NOT IN */ + { 174, -5 }, /* (192) expr ::= expr in_op LP exprlist RP */ + { 174, -3 }, /* (193) expr ::= LP select RP */ + { 174, -5 }, /* (194) expr ::= expr in_op LP select RP */ + { 174, -5 }, /* (195) expr ::= expr in_op nm dbnm paren_exprlist */ + { 174, -4 }, /* (196) expr ::= EXISTS LP select RP */ + { 174, -5 }, /* (197) expr ::= CASE case_operand case_exprlist case_else END */ + { 228, -5 }, /* (198) case_exprlist ::= case_exprlist WHEN expr THEN expr */ + { 228, -4 }, /* (199) case_exprlist ::= WHEN expr THEN expr */ + { 229, -2 }, /* (200) case_else ::= ELSE expr */ + { 229, 0 }, /* (201) case_else ::= */ + { 227, -1 }, /* (202) case_operand ::= expr */ + { 227, 0 }, /* (203) case_operand ::= */ + { 209, 0 }, /* (204) exprlist ::= */ + { 208, -3 }, /* (205) nexprlist ::= nexprlist COMMA expr */ + { 208, -1 }, /* (206) nexprlist ::= expr */ + { 226, 0 }, /* (207) paren_exprlist ::= */ + { 226, -3 }, /* (208) paren_exprlist ::= LP exprlist RP */ + { 149, -12 }, /* (209) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ + { 230, -1 }, /* (210) uniqueflag ::= UNIQUE */ + { 230, 0 }, /* (211) uniqueflag ::= */ + { 178, 0 }, /* (212) eidlist_opt ::= */ + { 178, -3 }, /* (213) eidlist_opt ::= LP eidlist RP */ + { 188, -5 }, /* (214) eidlist ::= eidlist COMMA nm collate sortorder */ + { 188, -3 }, /* (215) eidlist ::= nm collate sortorder */ + { 231, 0 }, /* (216) collate ::= */ + { 231, -2 }, /* (217) collate ::= COLLATE ID|STRING */ + { 149, -4 }, /* (218) cmd ::= DROP INDEX ifexists fullname */ + { 149, -1 }, /* (219) cmd ::= VACUUM */ + { 149, -2 }, /* (220) cmd ::= VACUUM nm */ + { 149, -3 }, /* (221) cmd ::= PRAGMA nm dbnm */ + { 149, -5 }, /* (222) cmd ::= PRAGMA nm dbnm EQ nmnum */ + { 149, -6 }, /* (223) cmd ::= PRAGMA nm dbnm LP nmnum RP */ + { 149, -5 }, /* (224) cmd ::= PRAGMA nm dbnm EQ minus_num */ + { 149, -6 }, /* (225) cmd ::= PRAGMA nm dbnm LP minus_num RP */ + { 169, -2 }, /* (226) plus_num ::= PLUS INTEGER|FLOAT */ + { 170, -2 }, /* (227) minus_num ::= MINUS INTEGER|FLOAT */ + { 149, -5 }, /* (228) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ + { 233, -11 }, /* (229) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + { 235, -1 }, /* (230) trigger_time ::= BEFORE|AFTER */ + { 235, -2 }, /* (231) trigger_time ::= INSTEAD OF */ + { 235, 0 }, /* (232) trigger_time ::= */ + { 236, -1 }, /* (233) trigger_event ::= DELETE|INSERT */ + { 236, -1 }, /* (234) trigger_event ::= UPDATE */ + { 236, -3 }, /* (235) trigger_event ::= UPDATE OF idlist */ + { 238, 0 }, /* (236) when_clause ::= */ + { 238, -2 }, /* (237) when_clause ::= WHEN expr */ + { 234, -3 }, /* (238) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ + { 234, -2 }, /* (239) trigger_cmd_list ::= trigger_cmd SEMI */ + { 240, -3 }, /* (240) trnm ::= nm DOT nm */ + { 241, -3 }, /* (241) tridxby ::= INDEXED BY nm */ + { 241, -2 }, /* (242) tridxby ::= NOT INDEXED */ + { 239, -8 }, /* (243) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */ + { 239, -7 }, /* (244) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */ + { 239, -6 }, /* (245) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ + { 239, -3 }, /* (246) trigger_cmd ::= scanpt select scanpt */ + { 174, -4 }, /* (247) expr ::= RAISE LP IGNORE RP */ + { 174, -6 }, /* (248) expr ::= RAISE LP raisetype COMMA nm RP */ + { 192, -1 }, /* (249) raisetype ::= ROLLBACK */ + { 192, -1 }, /* (250) raisetype ::= ABORT */ + { 192, -1 }, /* (251) raisetype ::= FAIL */ + { 149, -4 }, /* (252) cmd ::= DROP TRIGGER ifexists fullname */ + { 149, -6 }, /* (253) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ + { 149, -3 }, /* (254) cmd ::= DETACH database_kw_opt expr */ + { 243, 0 }, /* (255) key_opt ::= */ + { 243, -2 }, /* (256) key_opt ::= KEY expr */ + { 149, -1 }, /* (257) cmd ::= REINDEX */ + { 149, -3 }, /* (258) cmd ::= REINDEX nm dbnm */ + { 149, -1 }, /* (259) cmd ::= ANALYZE */ + { 149, -3 }, /* (260) cmd ::= ANALYZE nm dbnm */ + { 149, -6 }, /* (261) cmd ::= ALTER TABLE fullname RENAME TO nm */ + { 149, -7 }, /* (262) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ + { 244, -1 }, /* (263) add_column_fullname ::= fullname */ + { 149, -1 }, /* (264) cmd ::= create_vtab */ + { 149, -4 }, /* (265) cmd ::= create_vtab LP vtabarglist RP */ + { 246, -8 }, /* (266) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ + { 248, 0 }, /* (267) vtabarg ::= */ + { 249, -1 }, /* (268) vtabargtoken ::= ANY */ + { 249, -3 }, /* (269) vtabargtoken ::= lp anylist RP */ + { 250, -1 }, /* (270) lp ::= LP */ + { 219, -2 }, /* (271) with ::= WITH wqlist */ + { 219, -3 }, /* (272) with ::= WITH RECURSIVE wqlist */ + { 197, -6 }, /* (273) wqlist ::= nm eidlist_opt AS LP select RP */ + { 197, -8 }, /* (274) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ + { 144, -1 }, /* (275) input ::= cmdlist */ + { 145, -2 }, /* (276) cmdlist ::= cmdlist ecmd */ + { 145, -1 }, /* (277) cmdlist ::= ecmd */ + { 146, -1 }, /* (278) ecmd ::= SEMI */ + { 146, -3 }, /* (279) ecmd ::= explain cmdx SEMI */ + { 147, 0 }, /* (280) explain ::= */ + { 151, 0 }, /* (281) trans_opt ::= */ + { 151, -1 }, /* (282) trans_opt ::= TRANSACTION */ + { 151, -2 }, /* (283) trans_opt ::= TRANSACTION nm */ + { 153, -1 }, /* (284) savepoint_opt ::= SAVEPOINT */ + { 153, 0 }, /* (285) savepoint_opt ::= */ + { 149, -2 }, /* (286) cmd ::= create_table create_table_args */ + { 160, -4 }, /* (287) columnlist ::= columnlist COMMA columnname carglist */ + { 160, -2 }, /* (288) columnlist ::= columnname carglist */ + { 152, -1 }, /* (289) nm ::= ID|INDEXED */ + { 152, -1 }, /* (290) nm ::= STRING */ + { 152, -1 }, /* (291) nm ::= JOIN_KW */ + { 166, -1 }, /* (292) typetoken ::= typename */ + { 167, -1 }, /* (293) typename ::= ID|STRING */ + { 168, -1 }, /* (294) signed ::= plus_num */ + { 168, -1 }, /* (295) signed ::= minus_num */ + { 165, -2 }, /* (296) carglist ::= carglist ccons */ + { 165, 0 }, /* (297) carglist ::= */ + { 172, -2 }, /* (298) ccons ::= NULL onconf */ + { 161, -2 }, /* (299) conslist_opt ::= COMMA conslist */ + { 184, -3 }, /* (300) conslist ::= conslist tconscomma tcons */ + { 184, -1 }, /* (301) conslist ::= tcons */ + { 185, 0 }, /* (302) tconscomma ::= */ + { 189, -1 }, /* (303) defer_subclause_opt ::= defer_subclause */ + { 191, -1 }, /* (304) resolvetype ::= raisetype */ + { 195, -1 }, /* (305) selectnowith ::= oneselect */ + { 196, -1 }, /* (306) oneselect ::= values */ + { 210, -2 }, /* (307) sclp ::= selcollist COMMA */ + { 211, -1 }, /* (308) as ::= ID|STRING */ + { 174, -1 }, /* (309) expr ::= term */ + { 223, -1 }, /* (310) likeop ::= LIKE_KW|MATCH */ + { 209, -1 }, /* (311) exprlist ::= nexprlist */ + { 232, -1 }, /* (312) nmnum ::= plus_num */ + { 232, -1 }, /* (313) nmnum ::= nm */ + { 232, -1 }, /* (314) nmnum ::= ON */ + { 232, -1 }, /* (315) nmnum ::= DELETE */ + { 232, -1 }, /* (316) nmnum ::= DEFAULT */ + { 169, -1 }, /* (317) plus_num ::= INTEGER|FLOAT */ + { 237, 0 }, /* (318) foreach_clause ::= */ + { 237, -3 }, /* (319) foreach_clause ::= FOR EACH ROW */ + { 240, -1 }, /* (320) trnm ::= nm */ + { 241, 0 }, /* (321) tridxby ::= */ + { 242, -1 }, /* (322) database_kw_opt ::= DATABASE */ + { 242, 0 }, /* (323) database_kw_opt ::= */ + { 245, 0 }, /* (324) kwcolumn_opt ::= */ + { 245, -1 }, /* (325) kwcolumn_opt ::= COLUMNKW */ + { 247, -1 }, /* (326) vtabarglist ::= vtabarg */ + { 247, -3 }, /* (327) vtabarglist ::= vtabarglist COMMA vtabarg */ + { 248, -2 }, /* (328) vtabarg ::= vtabarg vtabargtoken */ + { 251, 0 }, /* (329) anylist ::= */ + { 251, -4 }, /* (330) anylist ::= anylist LP anylist RP */ + { 251, -2 }, /* (331) anylist ::= anylist ANY */ + { 219, 0 }, /* (332) with ::= */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -139131,22 +142186,38 @@ static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. +** +** The yyLookahead and yyLookaheadToken parameters provide reduce actions +** access to the lookahead token (if any). The yyLookahead will be YYNOCODE +** if the lookahead token has already been consumed. As this procedure is +** only called from one place, optimizing compilers will in-line it, which +** means that the extra parameters have no performance impact. */ static void yy_reduce( yyParser *yypParser, /* The parser */ - unsigned int yyruleno /* Number of the rule by which to reduce */ + unsigned int yyruleno, /* Number of the rule by which to reduce */ + int yyLookahead, /* Lookahead token, or YYNOCODE if none */ + sqlite3ParserTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ sqlite3ParserARG_FETCH; + (void)yyLookahead; + (void)yyLookaheadToken; yymsp = yypParser->yytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ yysize = yyRuleInfo[yyruleno].nrhs; - fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, - yyRuleName[yyruleno], yymsp[yysize].stateno); + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + }else{ + fprintf(yyTraceFILE, "%sReduce %d [%s].\n", + yyTracePrompt, yyruleno, yyRuleName[yyruleno]); + } } #endif /* NDEBUG */ @@ -139197,15 +142268,15 @@ static void yy_reduce( { sqlite3FinishCoding(pParse); } break; case 3: /* cmd ::= BEGIN transtype trans_opt */ -{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy194);} +{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy4);} break; case 4: /* transtype ::= */ -{yymsp[1].minor.yy194 = TK_DEFERRED;} +{yymsp[1].minor.yy4 = TK_DEFERRED;} break; case 5: /* transtype ::= DEFERRED */ case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6); case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7); -{yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/} +{yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/} break; case 8: /* cmd ::= COMMIT|END trans_opt */ case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9); @@ -139228,7 +142299,7 @@ static void yy_reduce( break; case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */ { - sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy194,0,0,yymsp[-2].minor.yy194); + sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy4,0,0,yymsp[-2].minor.yy4); } break; case 14: /* createkw ::= CREATE */ @@ -139237,38 +142308,38 @@ static void yy_reduce( case 15: /* ifnotexists ::= */ case 18: /* temp ::= */ yytestcase(yyruleno==18); case 21: /* table_options ::= */ yytestcase(yyruleno==21); - case 41: /* autoinc ::= */ yytestcase(yyruleno==41); - case 56: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==56); - case 66: /* defer_subclause_opt ::= */ yytestcase(yyruleno==66); - case 75: /* ifexists ::= */ yytestcase(yyruleno==75); - case 89: /* distinct ::= */ yytestcase(yyruleno==89); - case 212: /* collate ::= */ yytestcase(yyruleno==212); -{yymsp[1].minor.yy194 = 0;} + case 42: /* autoinc ::= */ yytestcase(yyruleno==42); + case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57); + case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67); + case 76: /* ifexists ::= */ yytestcase(yyruleno==76); + case 92: /* distinct ::= */ yytestcase(yyruleno==92); + case 216: /* collate ::= */ yytestcase(yyruleno==216); +{yymsp[1].minor.yy4 = 0;} break; case 16: /* ifnotexists ::= IF NOT EXISTS */ -{yymsp[-2].minor.yy194 = 1;} +{yymsp[-2].minor.yy4 = 1;} break; case 17: /* temp ::= TEMP */ - case 42: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==42); -{yymsp[0].minor.yy194 = 1;} + case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43); +{yymsp[0].minor.yy4 = 1;} break; case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */ { - sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy194,0); + sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy4,0); } break; case 20: /* create_table_args ::= AS select */ { - sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy243); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243); + sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy387); + sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387); } break; case 22: /* table_options ::= WITHOUT nm */ { if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){ - yymsp[-1].minor.yy194 = TF_WithoutRowid | TF_NoVisibleRowid; + yymsp[-1].minor.yy4 = TF_WithoutRowid | TF_NoVisibleRowid; }else{ - yymsp[-1].minor.yy194 = 0; + yymsp[-1].minor.yy4 = 0; sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z); } } @@ -139277,8 +142348,8 @@ static void yy_reduce( {sqlite3AddColumn(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);} break; case 24: /* typetoken ::= */ - case 59: /* conslist_opt ::= */ yytestcase(yyruleno==59); - case 95: /* as ::= */ yytestcase(yyruleno==95); + case 60: /* conslist_opt ::= */ yytestcase(yyruleno==60); + case 98: /* as ::= */ yytestcase(yyruleno==98); {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = 0;} break; case 25: /* typetoken ::= typename LP signed RP */ @@ -139294,210 +142365,239 @@ static void yy_reduce( case 27: /* typename ::= typename ID|STRING */ {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);} break; - case 28: /* ccons ::= CONSTRAINT nm */ - case 61: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==61); + case 28: /* scanpt ::= */ +{ + assert( yyLookahead!=YYNOCODE ); + yymsp[1].minor.yy336 = yyLookaheadToken.z; +} + break; + case 29: /* ccons ::= CONSTRAINT nm */ + case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62); {pParse->constraintName = yymsp[0].minor.yy0;} break; - case 29: /* ccons ::= DEFAULT term */ - case 31: /* ccons ::= DEFAULT PLUS term */ yytestcase(yyruleno==31); -{sqlite3AddDefaultValue(pParse,&yymsp[0].minor.yy190);} + case 30: /* ccons ::= DEFAULT scanpt term scanpt */ +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy336,yymsp[0].minor.yy336);} break; - case 30: /* ccons ::= DEFAULT LP expr RP */ -{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);} + case 31: /* ccons ::= DEFAULT LP expr RP */ +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);} break; - case 32: /* ccons ::= DEFAULT MINUS term */ + case 32: /* ccons ::= DEFAULT PLUS term scanpt */ +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy314,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336);} + break; + case 33: /* ccons ::= DEFAULT MINUS term scanpt */ { - ExprSpan v; - v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0); - v.zStart = yymsp[-1].minor.yy0.z; - v.zEnd = yymsp[0].minor.yy190.zEnd; - sqlite3AddDefaultValue(pParse,&v); + Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy314, 0); + sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy336); } break; - case 33: /* ccons ::= DEFAULT ID|INDEXED */ + case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */ { - ExprSpan v; - spanExpr(&v, pParse, TK_STRING, yymsp[0].minor.yy0); - sqlite3AddDefaultValue(pParse,&v); + Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0); + if( p ){ + sqlite3ExprIdToTrueFalse(p); + testcase( p->op==TK_TRUEFALSE && sqlite3ExprTruthValue(p) ); + } + sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n); } break; - case 34: /* ccons ::= NOT NULL onconf */ -{sqlite3AddNotNull(pParse, yymsp[0].minor.yy194);} + case 35: /* ccons ::= NOT NULL onconf */ +{sqlite3AddNotNull(pParse, yymsp[0].minor.yy4);} break; - case 35: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ -{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy194,yymsp[0].minor.yy194,yymsp[-2].minor.yy194);} + case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ +{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy4,yymsp[0].minor.yy4,yymsp[-2].minor.yy4);} break; - case 36: /* ccons ::= UNIQUE onconf */ -{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy194,0,0,0,0, + case 37: /* ccons ::= UNIQUE onconf */ +{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy4,0,0,0,0, SQLITE_IDXTYPE_UNIQUE);} break; - case 37: /* ccons ::= CHECK LP expr RP */ -{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy190.pExpr);} + case 38: /* ccons ::= CHECK LP expr RP */ +{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy314);} break; - case 38: /* ccons ::= REFERENCES nm eidlist_opt refargs */ -{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy148,yymsp[0].minor.yy194);} + case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */ +{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy4);} break; - case 39: /* ccons ::= defer_subclause */ -{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy194);} + case 40: /* ccons ::= defer_subclause */ +{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy4);} break; - case 40: /* ccons ::= COLLATE ID|STRING */ + case 41: /* ccons ::= COLLATE ID|STRING */ {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);} break; - case 43: /* refargs ::= */ -{ yymsp[1].minor.yy194 = OE_None*0x0101; /* EV: R-19803-45884 */} + case 44: /* refargs ::= */ +{ yymsp[1].minor.yy4 = OE_None*0x0101; /* EV: R-19803-45884 */} break; - case 44: /* refargs ::= refargs refarg */ -{ yymsp[-1].minor.yy194 = (yymsp[-1].minor.yy194 & ~yymsp[0].minor.yy497.mask) | yymsp[0].minor.yy497.value; } + case 45: /* refargs ::= refargs refarg */ +{ yymsp[-1].minor.yy4 = (yymsp[-1].minor.yy4 & ~yymsp[0].minor.yy215.mask) | yymsp[0].minor.yy215.value; } break; - case 45: /* refarg ::= MATCH nm */ -{ yymsp[-1].minor.yy497.value = 0; yymsp[-1].minor.yy497.mask = 0x000000; } + case 46: /* refarg ::= MATCH nm */ +{ yymsp[-1].minor.yy215.value = 0; yymsp[-1].minor.yy215.mask = 0x000000; } break; - case 46: /* refarg ::= ON INSERT refact */ -{ yymsp[-2].minor.yy497.value = 0; yymsp[-2].minor.yy497.mask = 0x000000; } + case 47: /* refarg ::= ON INSERT refact */ +{ yymsp[-2].minor.yy215.value = 0; yymsp[-2].minor.yy215.mask = 0x000000; } break; - case 47: /* refarg ::= ON DELETE refact */ -{ yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194; yymsp[-2].minor.yy497.mask = 0x0000ff; } + case 48: /* refarg ::= ON DELETE refact */ +{ yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4; yymsp[-2].minor.yy215.mask = 0x0000ff; } break; - case 48: /* refarg ::= ON UPDATE refact */ -{ yymsp[-2].minor.yy497.value = yymsp[0].minor.yy194<<8; yymsp[-2].minor.yy497.mask = 0x00ff00; } + case 49: /* refarg ::= ON UPDATE refact */ +{ yymsp[-2].minor.yy215.value = yymsp[0].minor.yy4<<8; yymsp[-2].minor.yy215.mask = 0x00ff00; } break; - case 49: /* refact ::= SET NULL */ -{ yymsp[-1].minor.yy194 = OE_SetNull; /* EV: R-33326-45252 */} + case 50: /* refact ::= SET NULL */ +{ yymsp[-1].minor.yy4 = OE_SetNull; /* EV: R-33326-45252 */} break; - case 50: /* refact ::= SET DEFAULT */ -{ yymsp[-1].minor.yy194 = OE_SetDflt; /* EV: R-33326-45252 */} + case 51: /* refact ::= SET DEFAULT */ +{ yymsp[-1].minor.yy4 = OE_SetDflt; /* EV: R-33326-45252 */} break; - case 51: /* refact ::= CASCADE */ -{ yymsp[0].minor.yy194 = OE_Cascade; /* EV: R-33326-45252 */} + case 52: /* refact ::= CASCADE */ +{ yymsp[0].minor.yy4 = OE_Cascade; /* EV: R-33326-45252 */} break; - case 52: /* refact ::= RESTRICT */ -{ yymsp[0].minor.yy194 = OE_Restrict; /* EV: R-33326-45252 */} + case 53: /* refact ::= RESTRICT */ +{ yymsp[0].minor.yy4 = OE_Restrict; /* EV: R-33326-45252 */} break; - case 53: /* refact ::= NO ACTION */ -{ yymsp[-1].minor.yy194 = OE_None; /* EV: R-33326-45252 */} + case 54: /* refact ::= NO ACTION */ +{ yymsp[-1].minor.yy4 = OE_None; /* EV: R-33326-45252 */} break; - case 54: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ -{yymsp[-2].minor.yy194 = 0;} + case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ +{yymsp[-2].minor.yy4 = 0;} break; - case 55: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ - case 70: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==70); - case 143: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==143); -{yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;} + case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ + case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71); + case 147: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==147); +{yymsp[-1].minor.yy4 = yymsp[0].minor.yy4;} break; - case 57: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ - case 74: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==74); - case 184: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==184); - case 187: /* in_op ::= NOT IN */ yytestcase(yyruleno==187); - case 213: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==213); -{yymsp[-1].minor.yy194 = 1;} + case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ + case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75); + case 188: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==188); + case 191: /* in_op ::= NOT IN */ yytestcase(yyruleno==191); + case 217: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==217); +{yymsp[-1].minor.yy4 = 1;} break; - case 58: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ -{yymsp[-1].minor.yy194 = 0;} + case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ +{yymsp[-1].minor.yy4 = 0;} break; - case 60: /* tconscomma ::= COMMA */ + case 61: /* tconscomma ::= COMMA */ {pParse->constraintName.n = 0;} break; - case 62: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ -{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy148,yymsp[0].minor.yy194,yymsp[-2].minor.yy194,0);} + case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ +{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy4,yymsp[-2].minor.yy4,0);} break; - case 63: /* tcons ::= UNIQUE LP sortlist RP onconf */ -{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy148,yymsp[0].minor.yy194,0,0,0,0, + case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */ +{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy4,0,0,0,0, SQLITE_IDXTYPE_UNIQUE);} break; - case 64: /* tcons ::= CHECK LP expr RP onconf */ -{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy190.pExpr);} + case 65: /* tcons ::= CHECK LP expr RP onconf */ +{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy314);} break; - case 65: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ + case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ { - sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy148, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[-1].minor.yy194); - sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy194); + sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy4); + sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy4); } break; - case 67: /* onconf ::= */ - case 69: /* orconf ::= */ yytestcase(yyruleno==69); -{yymsp[1].minor.yy194 = OE_Default;} + case 68: /* onconf ::= */ + case 70: /* orconf ::= */ yytestcase(yyruleno==70); +{yymsp[1].minor.yy4 = OE_Default;} break; - case 68: /* onconf ::= ON CONFLICT resolvetype */ -{yymsp[-2].minor.yy194 = yymsp[0].minor.yy194;} + case 69: /* onconf ::= ON CONFLICT resolvetype */ +{yymsp[-2].minor.yy4 = yymsp[0].minor.yy4;} break; - case 71: /* resolvetype ::= IGNORE */ -{yymsp[0].minor.yy194 = OE_Ignore;} + case 72: /* resolvetype ::= IGNORE */ +{yymsp[0].minor.yy4 = OE_Ignore;} break; - case 72: /* resolvetype ::= REPLACE */ - case 144: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==144); -{yymsp[0].minor.yy194 = OE_Replace;} + case 73: /* resolvetype ::= REPLACE */ + case 148: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==148); +{yymsp[0].minor.yy4 = OE_Replace;} break; - case 73: /* cmd ::= DROP TABLE ifexists fullname */ + case 74: /* cmd ::= DROP TABLE ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy185, 0, yymsp[-1].minor.yy194); + sqlite3DropTable(pParse, yymsp[0].minor.yy259, 0, yymsp[-1].minor.yy4); } break; - case 76: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ + case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ { - sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy148, yymsp[0].minor.yy243, yymsp[-7].minor.yy194, yymsp[-5].minor.yy194); + sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[0].minor.yy387, yymsp[-7].minor.yy4, yymsp[-5].minor.yy4); } break; - case 77: /* cmd ::= DROP VIEW ifexists fullname */ + case 78: /* cmd ::= DROP VIEW ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy185, 1, yymsp[-1].minor.yy194); + sqlite3DropTable(pParse, yymsp[0].minor.yy259, 1, yymsp[-1].minor.yy4); } break; - case 78: /* cmd ::= select */ + case 79: /* cmd ::= select */ { SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0}; - sqlite3Select(pParse, yymsp[0].minor.yy243, &dest); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy243); + sqlite3Select(pParse, yymsp[0].minor.yy387, &dest); + sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387); } break; - case 79: /* select ::= with selectnowith */ + case 80: /* select ::= WITH wqlist selectnowith */ { - Select *p = yymsp[0].minor.yy243; + Select *p = yymsp[0].minor.yy387; if( p ){ - p->pWith = yymsp[-1].minor.yy285; + p->pWith = yymsp[-1].minor.yy451; parserDoubleLinkSelect(pParse, p); }else{ - sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy285); + sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy451); } - yymsp[-1].minor.yy243 = p; /*A-overwrites-W*/ + yymsp[-2].minor.yy387 = p; } break; - case 80: /* selectnowith ::= selectnowith multiselect_op oneselect */ + case 81: /* select ::= WITH RECURSIVE wqlist selectnowith */ { - Select *pRhs = yymsp[0].minor.yy243; - Select *pLhs = yymsp[-2].minor.yy243; + Select *p = yymsp[0].minor.yy387; + if( p ){ + p->pWith = yymsp[-1].minor.yy451; + parserDoubleLinkSelect(pParse, p); + }else{ + sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy451); + } + yymsp[-3].minor.yy387 = p; +} + break; + case 82: /* select ::= selectnowith */ +{ + Select *p = yymsp[0].minor.yy387; + if( p ){ + parserDoubleLinkSelect(pParse, p); + } + yymsp[0].minor.yy387 = p; /*A-overwrites-X*/ +} + break; + case 83: /* selectnowith ::= selectnowith multiselect_op oneselect */ +{ + Select *pRhs = yymsp[0].minor.yy387; + Select *pLhs = yymsp[-2].minor.yy387; if( pRhs && pRhs->pPrior ){ SrcList *pFrom; Token x; x.n = 0; parserDoubleLinkSelect(pParse, pRhs); pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); - pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); + pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0); } if( pRhs ){ - pRhs->op = (u8)yymsp[-1].minor.yy194; + pRhs->op = (u8)yymsp[-1].minor.yy4; pRhs->pPrior = pLhs; if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue; pRhs->selFlags &= ~SF_MultiValue; - if( yymsp[-1].minor.yy194!=TK_ALL ) pParse->hasCompound = 1; + if( yymsp[-1].minor.yy4!=TK_ALL ) pParse->hasCompound = 1; }else{ sqlite3SelectDelete(pParse->db, pLhs); } - yymsp[-2].minor.yy243 = pRhs; + yymsp[-2].minor.yy387 = pRhs; } break; - case 81: /* multiselect_op ::= UNION */ - case 83: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==83); -{yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-OP*/} + case 84: /* multiselect_op ::= UNION */ + case 86: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==86); +{yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-OP*/} break; - case 82: /* multiselect_op ::= UNION ALL */ -{yymsp[-1].minor.yy194 = TK_ALL;} + case 85: /* multiselect_op ::= UNION ALL */ +{yymsp[-1].minor.yy4 = TK_ALL;} break; - case 84: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ + case 87: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ { #if SELECTTRACE_ENABLED Token s = yymsp[-8].minor.yy0; /*A-overwrites-S*/ #endif - yymsp[-8].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy148,yymsp[-5].minor.yy185,yymsp[-4].minor.yy72,yymsp[-3].minor.yy148,yymsp[-2].minor.yy72,yymsp[-1].minor.yy148,yymsp[-7].minor.yy194,yymsp[0].minor.yy354.pLimit,yymsp[0].minor.yy354.pOffset); + yymsp[-8].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy259,yymsp[-4].minor.yy314,yymsp[-3].minor.yy322,yymsp[-2].minor.yy314,yymsp[-1].minor.yy322,yymsp[-7].minor.yy4,yymsp[0].minor.yy314); #if SELECTTRACE_ENABLED /* Populate the Select.zSelName[] string that is used to help with ** query planner debugging, to differentiate between multiple Select @@ -139508,483 +142608,466 @@ static void yy_reduce( ** comment to be the zSelName value. Otherwise, the label is #N where ** is an integer that is incremented with each SELECT statement seen. */ - if( yymsp[-8].minor.yy243!=0 ){ + if( yymsp[-8].minor.yy387!=0 ){ const char *z = s.z+6; int i; - sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "#%d", - ++pParse->nSelect); + sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName,"#%d",++pParse->nSelect); while( z[0]==' ' ) z++; if( z[0]=='/' && z[1]=='*' ){ z += 2; while( z[0]==' ' ) z++; for(i=0; sqlite3Isalnum(z[i]); i++){} - sqlite3_snprintf(sizeof(yymsp[-8].minor.yy243->zSelName), yymsp[-8].minor.yy243->zSelName, "%.*s", i, z); + sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "%.*s", i, z); } } #endif /* SELECTRACE_ENABLED */ } break; - case 85: /* values ::= VALUES LP nexprlist RP */ + case 88: /* values ::= VALUES LP nexprlist RP */ { - yymsp[-3].minor.yy243 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values,0,0); + yymsp[-3].minor.yy387 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values,0); } break; - case 86: /* values ::= values COMMA LP exprlist RP */ + case 89: /* values ::= values COMMA LP exprlist RP */ { - Select *pRight, *pLeft = yymsp[-4].minor.yy243; - pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy148,0,0,0,0,0,SF_Values|SF_MultiValue,0,0); + Select *pRight, *pLeft = yymsp[-4].minor.yy387; + pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values|SF_MultiValue,0); if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; if( pRight ){ pRight->op = TK_ALL; pRight->pPrior = pLeft; - yymsp[-4].minor.yy243 = pRight; + yymsp[-4].minor.yy387 = pRight; }else{ - yymsp[-4].minor.yy243 = pLeft; + yymsp[-4].minor.yy387 = pLeft; } } break; - case 87: /* distinct ::= DISTINCT */ -{yymsp[0].minor.yy194 = SF_Distinct;} + case 90: /* distinct ::= DISTINCT */ +{yymsp[0].minor.yy4 = SF_Distinct;} break; - case 88: /* distinct ::= ALL */ -{yymsp[0].minor.yy194 = SF_All;} + case 91: /* distinct ::= ALL */ +{yymsp[0].minor.yy4 = SF_All;} break; - case 90: /* sclp ::= */ - case 118: /* orderby_opt ::= */ yytestcase(yyruleno==118); - case 125: /* groupby_opt ::= */ yytestcase(yyruleno==125); - case 200: /* exprlist ::= */ yytestcase(yyruleno==200); - case 203: /* paren_exprlist ::= */ yytestcase(yyruleno==203); - case 208: /* eidlist_opt ::= */ yytestcase(yyruleno==208); -{yymsp[1].minor.yy148 = 0;} + case 93: /* sclp ::= */ + case 122: /* orderby_opt ::= */ yytestcase(yyruleno==122); + case 129: /* groupby_opt ::= */ yytestcase(yyruleno==129); + case 204: /* exprlist ::= */ yytestcase(yyruleno==204); + case 207: /* paren_exprlist ::= */ yytestcase(yyruleno==207); + case 212: /* eidlist_opt ::= */ yytestcase(yyruleno==212); +{yymsp[1].minor.yy322 = 0;} break; - case 91: /* selcollist ::= sclp expr as */ + case 94: /* selcollist ::= sclp scanpt expr scanpt as */ { - yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr); - if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-2].minor.yy148, &yymsp[0].minor.yy0, 1); - sqlite3ExprListSetSpan(pParse,yymsp[-2].minor.yy148,&yymsp[-1].minor.yy190); + yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy314); + if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[0].minor.yy0, 1); + sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy322,yymsp[-3].minor.yy336,yymsp[-1].minor.yy336); } break; - case 92: /* selcollist ::= sclp STAR */ + case 95: /* selcollist ::= sclp scanpt STAR */ { Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0); - yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p); + yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, p); } break; - case 93: /* selcollist ::= sclp nm DOT STAR */ + case 96: /* selcollist ::= sclp scanpt nm DOT STAR */ { Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0); Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); - yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot); + yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot); } break; - case 94: /* as ::= AS nm */ - case 105: /* dbnm ::= DOT nm */ yytestcase(yyruleno==105); - case 222: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==222); - case 223: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==223); + case 97: /* as ::= AS nm */ + case 108: /* dbnm ::= DOT nm */ yytestcase(yyruleno==108); + case 226: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==226); + case 227: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==227); {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;} break; - case 96: /* from ::= */ -{yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));} + case 99: /* from ::= */ +{yymsp[1].minor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy259));} break; - case 97: /* from ::= FROM seltablist */ + case 100: /* from ::= FROM seltablist */ { - yymsp[-1].minor.yy185 = yymsp[0].minor.yy185; - sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy185); + yymsp[-1].minor.yy259 = yymsp[0].minor.yy259; + sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy259); } break; - case 98: /* stl_prefix ::= seltablist joinop */ + case 101: /* stl_prefix ::= seltablist joinop */ { - if( ALWAYS(yymsp[-1].minor.yy185 && yymsp[-1].minor.yy185->nSrc>0) ) yymsp[-1].minor.yy185->a[yymsp[-1].minor.yy185->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy194; + if( ALWAYS(yymsp[-1].minor.yy259 && yymsp[-1].minor.yy259->nSrc>0) ) yymsp[-1].minor.yy259->a[yymsp[-1].minor.yy259->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy4; } break; - case 99: /* stl_prefix ::= */ -{yymsp[1].minor.yy185 = 0;} + case 102: /* stl_prefix ::= */ +{yymsp[1].minor.yy259 = 0;} break; - case 100: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ + case 103: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ { - yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254); - sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy185, &yymsp[-2].minor.yy0); + yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384); + sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy259, &yymsp[-2].minor.yy0); } break; - case 101: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ + case 104: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ { - yymsp[-8].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy185,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254); - sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy185, yymsp[-4].minor.yy148); + yymsp[-8].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy259,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384); + sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy259, yymsp[-4].minor.yy322); } break; - case 102: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ + case 105: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ { - yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy243,yymsp[-1].minor.yy72,yymsp[0].minor.yy254); + yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy387,yymsp[-1].minor.yy314,yymsp[0].minor.yy384); } break; - case 103: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ + case 106: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ { - if( yymsp[-6].minor.yy185==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy72==0 && yymsp[0].minor.yy254==0 ){ - yymsp[-6].minor.yy185 = yymsp[-4].minor.yy185; - }else if( yymsp[-4].minor.yy185->nSrc==1 ){ - yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy72,yymsp[0].minor.yy254); - if( yymsp[-6].minor.yy185 ){ - struct SrcList_item *pNew = &yymsp[-6].minor.yy185->a[yymsp[-6].minor.yy185->nSrc-1]; - struct SrcList_item *pOld = yymsp[-4].minor.yy185->a; + if( yymsp[-6].minor.yy259==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy314==0 && yymsp[0].minor.yy384==0 ){ + yymsp[-6].minor.yy259 = yymsp[-4].minor.yy259; + }else if( yymsp[-4].minor.yy259->nSrc==1 ){ + yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy314,yymsp[0].minor.yy384); + if( yymsp[-6].minor.yy259 ){ + struct SrcList_item *pNew = &yymsp[-6].minor.yy259->a[yymsp[-6].minor.yy259->nSrc-1]; + struct SrcList_item *pOld = yymsp[-4].minor.yy259->a; pNew->zName = pOld->zName; pNew->zDatabase = pOld->zDatabase; pNew->pSelect = pOld->pSelect; pOld->zName = pOld->zDatabase = 0; pOld->pSelect = 0; } - sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy185); + sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy259); }else{ Select *pSubquery; - sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy185); - pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy185,0,0,0,0,SF_NestedFrom,0,0); - yymsp[-6].minor.yy185 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy185,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy72,yymsp[0].minor.yy254); + sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy259); + pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy259,0,0,0,0,SF_NestedFrom,0); + yymsp[-6].minor.yy259 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy259,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy314,yymsp[0].minor.yy384); } } break; - case 104: /* dbnm ::= */ - case 113: /* indexed_opt ::= */ yytestcase(yyruleno==113); + case 107: /* dbnm ::= */ + case 117: /* indexed_opt ::= */ yytestcase(yyruleno==117); {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;} break; - case 106: /* fullname ::= nm dbnm */ -{yymsp[-1].minor.yy185 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} + case 109: /* fullname ::= nm */ +{yymsp[0].minor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/} break; - case 107: /* joinop ::= COMMA|JOIN */ -{ yymsp[0].minor.yy194 = JT_INNER; } + case 110: /* fullname ::= nm DOT nm */ +{yymsp[-2].minor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} break; - case 108: /* joinop ::= JOIN_KW JOIN */ -{yymsp[-1].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} + case 111: /* joinop ::= COMMA|JOIN */ +{ yymsp[0].minor.yy4 = JT_INNER; } break; - case 109: /* joinop ::= JOIN_KW nm JOIN */ -{yymsp[-2].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} + case 112: /* joinop ::= JOIN_KW JOIN */ +{yymsp[-1].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} break; - case 110: /* joinop ::= JOIN_KW nm nm JOIN */ -{yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} + case 113: /* joinop ::= JOIN_KW nm JOIN */ +{yymsp[-2].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} break; - case 111: /* on_opt ::= ON expr */ - case 128: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==128); - case 135: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==135); - case 196: /* case_else ::= ELSE expr */ yytestcase(yyruleno==196); -{yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;} + case 114: /* joinop ::= JOIN_KW nm nm JOIN */ +{yymsp[-3].minor.yy4 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} break; - case 112: /* on_opt ::= */ - case 127: /* having_opt ::= */ yytestcase(yyruleno==127); - case 134: /* where_opt ::= */ yytestcase(yyruleno==134); - case 197: /* case_else ::= */ yytestcase(yyruleno==197); - case 199: /* case_operand ::= */ yytestcase(yyruleno==199); -{yymsp[1].minor.yy72 = 0;} + case 115: /* on_opt ::= ON expr */ + case 132: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==132); + case 139: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==139); + case 200: /* case_else ::= ELSE expr */ yytestcase(yyruleno==200); +{yymsp[-1].minor.yy314 = yymsp[0].minor.yy314;} break; - case 114: /* indexed_opt ::= INDEXED BY nm */ + case 116: /* on_opt ::= */ + case 131: /* having_opt ::= */ yytestcase(yyruleno==131); + case 133: /* limit_opt ::= */ yytestcase(yyruleno==133); + case 138: /* where_opt ::= */ yytestcase(yyruleno==138); + case 201: /* case_else ::= */ yytestcase(yyruleno==201); + case 203: /* case_operand ::= */ yytestcase(yyruleno==203); +{yymsp[1].minor.yy314 = 0;} + break; + case 118: /* indexed_opt ::= INDEXED BY nm */ {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;} break; - case 115: /* indexed_opt ::= NOT INDEXED */ + case 119: /* indexed_opt ::= NOT INDEXED */ {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;} break; - case 116: /* using_opt ::= USING LP idlist RP */ -{yymsp[-3].minor.yy254 = yymsp[-1].minor.yy254;} + case 120: /* using_opt ::= USING LP idlist RP */ +{yymsp[-3].minor.yy384 = yymsp[-1].minor.yy384;} break; - case 117: /* using_opt ::= */ - case 145: /* idlist_opt ::= */ yytestcase(yyruleno==145); -{yymsp[1].minor.yy254 = 0;} + case 121: /* using_opt ::= */ + case 149: /* idlist_opt ::= */ yytestcase(yyruleno==149); +{yymsp[1].minor.yy384 = 0;} break; - case 119: /* orderby_opt ::= ORDER BY sortlist */ - case 126: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==126); -{yymsp[-2].minor.yy148 = yymsp[0].minor.yy148;} + case 123: /* orderby_opt ::= ORDER BY sortlist */ + case 130: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==130); +{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;} break; - case 120: /* sortlist ::= sortlist COMMA expr sortorder */ + case 124: /* sortlist ::= sortlist COMMA expr sortorder */ { - yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148,yymsp[-1].minor.yy190.pExpr); - sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy148,yymsp[0].minor.yy194); + yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322,yymsp[-1].minor.yy314); + sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy322,yymsp[0].minor.yy4); } break; - case 121: /* sortlist ::= expr sortorder */ + case 125: /* sortlist ::= expr sortorder */ { - yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy190.pExpr); /*A-overwrites-Y*/ - sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy148,yymsp[0].minor.yy194); + yymsp[-1].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy314); /*A-overwrites-Y*/ + sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy322,yymsp[0].minor.yy4); } break; - case 122: /* sortorder ::= ASC */ -{yymsp[0].minor.yy194 = SQLITE_SO_ASC;} + case 126: /* sortorder ::= ASC */ +{yymsp[0].minor.yy4 = SQLITE_SO_ASC;} break; - case 123: /* sortorder ::= DESC */ -{yymsp[0].minor.yy194 = SQLITE_SO_DESC;} + case 127: /* sortorder ::= DESC */ +{yymsp[0].minor.yy4 = SQLITE_SO_DESC;} break; - case 124: /* sortorder ::= */ -{yymsp[1].minor.yy194 = SQLITE_SO_UNDEFINED;} + case 128: /* sortorder ::= */ +{yymsp[1].minor.yy4 = SQLITE_SO_UNDEFINED;} break; - case 129: /* limit_opt ::= */ -{yymsp[1].minor.yy354.pLimit = 0; yymsp[1].minor.yy354.pOffset = 0;} + case 134: /* limit_opt ::= LIMIT expr */ +{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,0);} break; - case 130: /* limit_opt ::= LIMIT expr */ -{yymsp[-1].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr; yymsp[-1].minor.yy354.pOffset = 0;} + case 135: /* limit_opt ::= LIMIT expr OFFSET expr */ +{yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);} break; - case 131: /* limit_opt ::= LIMIT expr OFFSET expr */ -{yymsp[-3].minor.yy354.pLimit = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pOffset = yymsp[0].minor.yy190.pExpr;} + case 136: /* limit_opt ::= LIMIT expr COMMA expr */ +{yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy314,yymsp[-2].minor.yy314);} break; - case 132: /* limit_opt ::= LIMIT expr COMMA expr */ -{yymsp[-3].minor.yy354.pOffset = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr;} - break; - case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */ + case 137: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */ { - sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1); - sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0); - sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72); + sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy259, &yymsp[-1].minor.yy0); + sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy259,yymsp[0].minor.yy314,0,0); } break; - case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */ + case 140: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */ { - sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1); - sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0); - sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list"); - sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194); + sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy259, &yymsp[-3].minor.yy0); + sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy322,"set list"); + sqlite3Update(pParse,yymsp[-4].minor.yy259,yymsp[-1].minor.yy322,yymsp[0].minor.yy314,yymsp[-5].minor.yy4,0,0); } break; - case 137: /* setlist ::= setlist COMMA nm EQ expr */ + case 141: /* setlist ::= setlist COMMA nm EQ expr */ { - yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr); - sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, 1); + yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy314); + sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, 1); } break; - case 138: /* setlist ::= setlist COMMA LP idlist RP EQ expr */ + case 142: /* setlist ::= setlist COMMA LP idlist RP EQ expr */ { - yymsp[-6].minor.yy148 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy148, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr); + yymsp[-6].minor.yy322 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy322, yymsp[-3].minor.yy384, yymsp[0].minor.yy314); } break; - case 139: /* setlist ::= nm EQ expr */ + case 143: /* setlist ::= nm EQ expr */ { - yylhsminor.yy148 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy190.pExpr); - sqlite3ExprListSetName(pParse, yylhsminor.yy148, &yymsp[-2].minor.yy0, 1); + yylhsminor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy314); + sqlite3ExprListSetName(pParse, yylhsminor.yy322, &yymsp[-2].minor.yy0, 1); } - yymsp[-2].minor.yy148 = yylhsminor.yy148; + yymsp[-2].minor.yy322 = yylhsminor.yy322; break; - case 140: /* setlist ::= LP idlist RP EQ expr */ + case 144: /* setlist ::= LP idlist RP EQ expr */ { - yymsp[-4].minor.yy148 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy254, yymsp[0].minor.yy190.pExpr); + yymsp[-4].minor.yy322 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy384, yymsp[0].minor.yy314); } break; - case 141: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */ + case 145: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */ { - sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1); - sqlite3Insert(pParse, yymsp[-2].minor.yy185, yymsp[0].minor.yy243, yymsp[-1].minor.yy254, yymsp[-4].minor.yy194); + sqlite3Insert(pParse, yymsp[-2].minor.yy259, yymsp[0].minor.yy387, yymsp[-1].minor.yy384, yymsp[-4].minor.yy4); } break; - case 142: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */ + case 146: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */ { - sqlite3WithPush(pParse, yymsp[-6].minor.yy285, 1); - sqlite3Insert(pParse, yymsp[-3].minor.yy185, 0, yymsp[-2].minor.yy254, yymsp[-5].minor.yy194); + sqlite3Insert(pParse, yymsp[-3].minor.yy259, 0, yymsp[-2].minor.yy384, yymsp[-5].minor.yy4); } break; - case 146: /* idlist_opt ::= LP idlist RP */ -{yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;} + case 150: /* idlist_opt ::= LP idlist RP */ +{yymsp[-2].minor.yy384 = yymsp[-1].minor.yy384;} break; - case 147: /* idlist ::= idlist COMMA nm */ -{yymsp[-2].minor.yy254 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy254,&yymsp[0].minor.yy0);} + case 151: /* idlist ::= idlist COMMA nm */ +{yymsp[-2].minor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);} break; - case 148: /* idlist ::= nm */ -{yymsp[0].minor.yy254 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/} + case 152: /* idlist ::= nm */ +{yymsp[0].minor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/} break; - case 149: /* expr ::= LP expr RP */ -{spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ yymsp[-2].minor.yy190.pExpr = yymsp[-1].minor.yy190.pExpr;} + case 153: /* expr ::= LP expr RP */ +{yymsp[-2].minor.yy314 = yymsp[-1].minor.yy314;} break; - case 150: /* expr ::= ID|INDEXED */ - case 151: /* expr ::= JOIN_KW */ yytestcase(yyruleno==151); -{spanExpr(&yymsp[0].minor.yy190,pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} + case 154: /* expr ::= ID|INDEXED */ + case 155: /* expr ::= JOIN_KW */ yytestcase(yyruleno==155); +{yymsp[0].minor.yy314=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} break; - case 152: /* expr ::= nm DOT nm */ + case 156: /* expr ::= nm DOT nm */ { Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); - spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ - yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); + yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); } + yymsp[-2].minor.yy314 = yylhsminor.yy314; break; - case 153: /* expr ::= nm DOT nm DOT nm */ + case 157: /* expr ::= nm DOT nm DOT nm */ { Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1); Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3); - spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); + yylhsminor.yy314 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); } + yymsp[-4].minor.yy314 = yylhsminor.yy314; break; - case 154: /* term ::= NULL|FLOAT|BLOB */ - case 155: /* term ::= STRING */ yytestcase(yyruleno==155); -{spanExpr(&yymsp[0].minor.yy190,pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} + case 158: /* term ::= NULL|FLOAT|BLOB */ + case 159: /* term ::= STRING */ yytestcase(yyruleno==159); +{yymsp[0].minor.yy314=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} break; - case 156: /* term ::= INTEGER */ + case 160: /* term ::= INTEGER */ { - yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); - yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z; - yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n; + yylhsminor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); } - yymsp[0].minor.yy190 = yylhsminor.yy190; + yymsp[0].minor.yy314 = yylhsminor.yy314; break; - case 157: /* expr ::= VARIABLE */ + case 161: /* expr ::= VARIABLE */ { if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){ u32 n = yymsp[0].minor.yy0.n; - spanExpr(&yymsp[0].minor.yy190, pParse, TK_VARIABLE, yymsp[0].minor.yy0); - sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy190.pExpr, n); + yymsp[0].minor.yy314 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0); + sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy314, n); }else{ /* When doing a nested parse, one can include terms in an expression ** that look like this: #1 #2 ... These terms refer to registers ** in the virtual machine. #N is the N-th register. */ Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/ assert( t.n>=2 ); - spanSet(&yymsp[0].minor.yy190, &t, &t); if( pParse->nested==0 ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t); - yymsp[0].minor.yy190.pExpr = 0; + yymsp[0].minor.yy314 = 0; }else{ - yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0); - if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable); + yymsp[0].minor.yy314 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0); + if( yymsp[0].minor.yy314 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy314->iTable); } } } break; - case 158: /* expr ::= expr COLLATE ID|STRING */ + case 162: /* expr ::= expr COLLATE ID|STRING */ { - yymsp[-2].minor.yy190.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy190.pExpr, &yymsp[0].minor.yy0, 1); - yymsp[-2].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; + yymsp[-2].minor.yy314 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy314, &yymsp[0].minor.yy0, 1); } break; - case 159: /* expr ::= CAST LP expr AS typetoken RP */ + case 163: /* expr ::= CAST LP expr AS typetoken RP */ { - spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ - yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); - sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0); + yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); + sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy314, yymsp[-3].minor.yy314, 0); } break; - case 160: /* expr ::= ID|INDEXED LP distinct exprlist RP */ + case 164: /* expr ::= ID|INDEXED LP distinct exprlist RP */ { - if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ + if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0); } - yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy148, &yymsp[-4].minor.yy0); - spanSet(&yylhsminor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); - if( yymsp[-2].minor.yy194==SF_Distinct && yylhsminor.yy190.pExpr ){ - yylhsminor.yy190.pExpr->flags |= EP_Distinct; + yylhsminor.yy314 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0); + if( yymsp[-2].minor.yy4==SF_Distinct && yylhsminor.yy314 ){ + yylhsminor.yy314->flags |= EP_Distinct; } } - yymsp[-4].minor.yy190 = yylhsminor.yy190; + yymsp[-4].minor.yy314 = yylhsminor.yy314; break; - case 161: /* expr ::= ID|INDEXED LP STAR RP */ + case 165: /* expr ::= ID|INDEXED LP STAR RP */ { - yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); - spanSet(&yylhsminor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); } - yymsp[-3].minor.yy190 = yylhsminor.yy190; + yymsp[-3].minor.yy314 = yylhsminor.yy314; break; - case 162: /* term ::= CTIME_KW */ + case 166: /* term ::= CTIME_KW */ { - yylhsminor.yy190.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0); - spanSet(&yylhsminor.yy190, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy314 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy190 = yylhsminor.yy190; + yymsp[0].minor.yy314 = yylhsminor.yy314; break; - case 163: /* expr ::= LP nexprlist COMMA expr RP */ + case 167: /* expr ::= LP nexprlist COMMA expr RP */ { - ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr); - yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); - if( yylhsminor.yy190.pExpr ){ - yylhsminor.yy190.pExpr->x.pList = pList; - spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); + ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy322, yymsp[-1].minor.yy314); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); + if( yymsp[-4].minor.yy314 ){ + yymsp[-4].minor.yy314->x.pList = pList; }else{ sqlite3ExprListDelete(pParse->db, pList); } } - yymsp[-4].minor.yy190 = yylhsminor.yy190; break; - case 164: /* expr ::= expr AND expr */ - case 165: /* expr ::= expr OR expr */ yytestcase(yyruleno==165); - case 166: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==166); - case 167: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==167); - case 168: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==168); - case 169: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==169); - case 170: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==170); - case 171: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==171); -{spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);} + case 168: /* expr ::= expr AND expr */ + case 169: /* expr ::= expr OR expr */ yytestcase(yyruleno==169); + case 170: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==170); + case 171: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==171); + case 172: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==172); + case 173: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==173); + case 174: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==174); + case 175: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==175); +{yymsp[-2].minor.yy314=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy314,yymsp[0].minor.yy314);} break; - case 172: /* likeop ::= NOT LIKE_KW|MATCH */ + case 176: /* likeop ::= NOT LIKE_KW|MATCH */ {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/} break; - case 173: /* expr ::= expr likeop expr */ + case 177: /* expr ::= expr likeop expr */ { ExprList *pList; int bNot = yymsp[-1].minor.yy0.n & 0x80000000; yymsp[-1].minor.yy0.n &= 0x7fffffff; - pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy190.pExpr); - yymsp[-2].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0); - exprNot(pParse, bNot, &yymsp[-2].minor.yy190); - yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; - if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc; + pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy314); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy314); + yymsp[-2].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0); + if( bNot ) yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy314, 0); + if( yymsp[-2].minor.yy314 ) yymsp[-2].minor.yy314->flags |= EP_InfixFunc; } break; - case 174: /* expr ::= expr likeop expr ESCAPE expr */ + case 178: /* expr ::= expr likeop expr ESCAPE expr */ { ExprList *pList; int bNot = yymsp[-3].minor.yy0.n & 0x80000000; yymsp[-3].minor.yy0.n &= 0x7fffffff; - pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy190.pExpr); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr); - yymsp[-4].minor.yy190.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0); - exprNot(pParse, bNot, &yymsp[-4].minor.yy190); - yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; - if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc; + pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy314); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314); + yymsp[-4].minor.yy314 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0); + if( bNot ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0); + if( yymsp[-4].minor.yy314 ) yymsp[-4].minor.yy314->flags |= EP_InfixFunc; } break; - case 175: /* expr ::= expr ISNULL|NOTNULL */ -{spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);} + case 179: /* expr ::= expr ISNULL|NOTNULL */ +{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy314,0);} break; - case 176: /* expr ::= expr NOT NULL */ -{spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);} + case 180: /* expr ::= expr NOT NULL */ +{yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy314,0);} break; - case 177: /* expr ::= expr IS expr */ + case 181: /* expr ::= expr IS expr */ { - spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190); - binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL); + yymsp[-2].minor.yy314 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy314,yymsp[0].minor.yy314); + binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-2].minor.yy314, TK_ISNULL); } break; - case 178: /* expr ::= expr IS NOT expr */ + case 182: /* expr ::= expr IS NOT expr */ { - spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190); - binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL); + yymsp[-3].minor.yy314 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy314,yymsp[0].minor.yy314); + binaryToUnaryIfNull(pParse, yymsp[0].minor.yy314, yymsp[-3].minor.yy314, TK_NOTNULL); } break; - case 179: /* expr ::= NOT expr */ - case 180: /* expr ::= BITNOT expr */ yytestcase(yyruleno==180); -{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} + case 183: /* expr ::= NOT expr */ + case 184: /* expr ::= BITNOT expr */ yytestcase(yyruleno==184); +{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy314, 0);/*A-overwrites-B*/} break; - case 181: /* expr ::= MINUS expr */ -{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} + case 185: /* expr ::= MINUS expr */ +{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy314, 0);} break; - case 182: /* expr ::= PLUS expr */ -{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} + case 186: /* expr ::= PLUS expr */ +{yymsp[-1].minor.yy314 = sqlite3PExpr(pParse, TK_UPLUS, yymsp[0].minor.yy314, 0);} break; - case 183: /* between_op ::= BETWEEN */ - case 186: /* in_op ::= IN */ yytestcase(yyruleno==186); -{yymsp[0].minor.yy194 = 0;} + case 187: /* between_op ::= BETWEEN */ + case 190: /* in_op ::= IN */ yytestcase(yyruleno==190); +{yymsp[0].minor.yy4 = 0;} break; - case 185: /* expr ::= expr between_op expr AND expr */ + case 189: /* expr ::= expr between_op expr AND expr */ { - ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr); - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0); - if( yymsp[-4].minor.yy190.pExpr ){ - yymsp[-4].minor.yy190.pExpr->x.pList = pList; + ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy314); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy314, 0); + if( yymsp[-4].minor.yy314 ){ + yymsp[-4].minor.yy314->x.pList = pList; }else{ sqlite3ExprListDelete(pParse->db, pList); } - exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); - yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; + if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0); } break; - case 188: /* expr ::= expr in_op LP exprlist RP */ + case 192: /* expr ::= expr in_op LP exprlist RP */ { - if( yymsp[-1].minor.yy148==0 ){ + if( yymsp[-1].minor.yy322==0 ){ /* Expressions of the form ** ** expr1 IN () @@ -139993,9 +143076,9 @@ static void yy_reduce( ** simplify to constants 0 (false) and 1 (true), respectively, ** regardless of the value of expr1. */ - sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr); - yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1); - }else if( yymsp[-1].minor.yy148->nExpr==1 ){ + sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy314); + yymsp[-4].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy4],1); + }else if( yymsp[-1].minor.yy322->nExpr==1 ){ /* Expressions of the form: ** ** expr1 IN (?1) @@ -140012,201 +143095,195 @@ static void yy_reduce( ** affinity or the collating sequence to use for comparison. Otherwise, ** the semantics would be subtly different from IN or NOT IN. */ - Expr *pRHS = yymsp[-1].minor.yy148->a[0].pExpr; - yymsp[-1].minor.yy148->a[0].pExpr = 0; - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148); + Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr; + yymsp[-1].minor.yy322->a[0].pExpr = 0; + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); /* pRHS cannot be NULL because a malloc error would have been detected ** before now and control would have never reached this point */ if( ALWAYS(pRHS) ){ pRHS->flags &= ~EP_Collate; pRHS->flags |= EP_Generic; } - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, yymsp[-3].minor.yy4 ? TK_NE : TK_EQ, yymsp[-4].minor.yy314, pRHS); }else{ - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); - if( yymsp[-4].minor.yy190.pExpr ){ - yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148; - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0); + if( yymsp[-4].minor.yy314 ){ + yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy322; + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314); }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148); + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); } - exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); + if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0); } - yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; } break; - case 189: /* expr ::= LP select RP */ + case 193: /* expr ::= LP select RP */ { - spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ - yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); - sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243); + yymsp[-2].minor.yy314 = sqlite3PExpr(pParse, TK_SELECT, 0, 0); + sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy314, yymsp[-1].minor.yy387); } break; - case 190: /* expr ::= expr in_op LP select RP */ + case 194: /* expr ::= expr in_op LP select RP */ { - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243); - exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); - yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0); + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, yymsp[-1].minor.yy387); + if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0); } break; - case 191: /* expr ::= expr in_op nm dbnm paren_exprlist */ + case 195: /* expr ::= expr in_op nm dbnm paren_exprlist */ { SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); - Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); - if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148); - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect); - exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); - yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n]; + Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0); + if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy314, 0); + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy314, pSelect); + if( yymsp[-3].minor.yy4 ) yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy314, 0); } break; - case 192: /* expr ::= EXISTS LP select RP */ + case 196: /* expr ::= EXISTS LP select RP */ { Expr *p; - spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ - p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); - sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243); + p = yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); + sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy387); } break; - case 193: /* expr ::= CASE case_operand case_exprlist case_else END */ + case 197: /* expr ::= CASE case_operand case_exprlist case_else END */ { - spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/ - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0); - if( yymsp[-4].minor.yy190.pExpr ){ - yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148; - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr); + yymsp[-4].minor.yy314 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy314, 0); + if( yymsp[-4].minor.yy314 ){ + yymsp[-4].minor.yy314->x.pList = yymsp[-1].minor.yy314 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy314) : yymsp[-2].minor.yy322; + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy314); }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148); - sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72); + sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322); + sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy314); } } break; - case 194: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ + case 198: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ { - yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr); - yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr); + yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy314); + yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy314); } break; - case 195: /* case_exprlist ::= WHEN expr THEN expr */ + case 199: /* case_exprlist ::= WHEN expr THEN expr */ { - yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); - yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr); + yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy314); + yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy314); } break; - case 198: /* case_operand ::= expr */ -{yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/} + case 202: /* case_operand ::= expr */ +{yymsp[0].minor.yy314 = yymsp[0].minor.yy314; /*A-overwrites-X*/} break; - case 201: /* nexprlist ::= nexprlist COMMA expr */ -{yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);} + case 205: /* nexprlist ::= nexprlist COMMA expr */ +{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy314);} break; - case 202: /* nexprlist ::= expr */ -{yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/} + case 206: /* nexprlist ::= expr */ +{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy314); /*A-overwrites-Y*/} break; - case 204: /* paren_exprlist ::= LP exprlist RP */ - case 209: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==209); -{yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;} + case 208: /* paren_exprlist ::= LP exprlist RP */ + case 213: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==213); +{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;} break; - case 205: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ + case 209: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ { sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, - sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194, - &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF); + sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy4, + &yymsp[-11].minor.yy0, yymsp[0].minor.yy314, SQLITE_SO_ASC, yymsp[-8].minor.yy4, SQLITE_IDXTYPE_APPDEF); } break; - case 206: /* uniqueflag ::= UNIQUE */ - case 246: /* raisetype ::= ABORT */ yytestcase(yyruleno==246); -{yymsp[0].minor.yy194 = OE_Abort;} + case 210: /* uniqueflag ::= UNIQUE */ + case 250: /* raisetype ::= ABORT */ yytestcase(yyruleno==250); +{yymsp[0].minor.yy4 = OE_Abort;} break; - case 207: /* uniqueflag ::= */ -{yymsp[1].minor.yy194 = OE_None;} + case 211: /* uniqueflag ::= */ +{yymsp[1].minor.yy4 = OE_None;} break; - case 210: /* eidlist ::= eidlist COMMA nm collate sortorder */ + case 214: /* eidlist ::= eidlist COMMA nm collate sortorder */ { - yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); + yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4); } break; - case 211: /* eidlist ::= nm collate sortorder */ + case 215: /* eidlist ::= nm collate sortorder */ { - yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/ + yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy4, yymsp[0].minor.yy4); /*A-overwrites-Y*/ } break; - case 214: /* cmd ::= DROP INDEX ifexists fullname */ -{sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);} + case 218: /* cmd ::= DROP INDEX ifexists fullname */ +{sqlite3DropIndex(pParse, yymsp[0].minor.yy259, yymsp[-1].minor.yy4);} break; - case 215: /* cmd ::= VACUUM */ + case 219: /* cmd ::= VACUUM */ {sqlite3Vacuum(pParse,0);} break; - case 216: /* cmd ::= VACUUM nm */ + case 220: /* cmd ::= VACUUM nm */ {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);} break; - case 217: /* cmd ::= PRAGMA nm dbnm */ + case 221: /* cmd ::= PRAGMA nm dbnm */ {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} break; - case 218: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ + case 222: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} break; - case 219: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ + case 223: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} break; - case 220: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ + case 224: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);} break; - case 221: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ + case 225: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);} break; - case 224: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ + case 228: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ { Token all; all.z = yymsp[-3].minor.yy0.z; all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n; - sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all); + sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all); } break; - case 225: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + case 229: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ { - sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194); + sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy4, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy259, yymsp[0].minor.yy314, yymsp[-10].minor.yy4, yymsp[-8].minor.yy4); yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/ } break; - case 226: /* trigger_time ::= BEFORE|AFTER */ -{ yymsp[0].minor.yy194 = yymsp[0].major; /*A-overwrites-X*/ } + case 230: /* trigger_time ::= BEFORE|AFTER */ +{ yymsp[0].minor.yy4 = yymsp[0].major; /*A-overwrites-X*/ } break; - case 227: /* trigger_time ::= INSTEAD OF */ -{ yymsp[-1].minor.yy194 = TK_INSTEAD;} + case 231: /* trigger_time ::= INSTEAD OF */ +{ yymsp[-1].minor.yy4 = TK_INSTEAD;} break; - case 228: /* trigger_time ::= */ -{ yymsp[1].minor.yy194 = TK_BEFORE; } + case 232: /* trigger_time ::= */ +{ yymsp[1].minor.yy4 = TK_BEFORE; } break; - case 229: /* trigger_event ::= DELETE|INSERT */ - case 230: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==230); -{yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;} + case 233: /* trigger_event ::= DELETE|INSERT */ + case 234: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==234); +{yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;} break; - case 231: /* trigger_event ::= UPDATE OF idlist */ -{yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;} + case 235: /* trigger_event ::= UPDATE OF idlist */ +{yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy384;} break; - case 232: /* when_clause ::= */ - case 251: /* key_opt ::= */ yytestcase(yyruleno==251); -{ yymsp[1].minor.yy72 = 0; } + case 236: /* when_clause ::= */ + case 255: /* key_opt ::= */ yytestcase(yyruleno==255); +{ yymsp[1].minor.yy314 = 0; } break; - case 233: /* when_clause ::= WHEN expr */ - case 252: /* key_opt ::= KEY expr */ yytestcase(yyruleno==252); -{ yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; } + case 237: /* when_clause ::= WHEN expr */ + case 256: /* key_opt ::= KEY expr */ yytestcase(yyruleno==256); +{ yymsp[-1].minor.yy314 = yymsp[0].minor.yy314; } break; - case 234: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ + case 238: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ { - assert( yymsp[-2].minor.yy145!=0 ); - yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145; - yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145; + assert( yymsp[-2].minor.yy203!=0 ); + yymsp[-2].minor.yy203->pLast->pNext = yymsp[-1].minor.yy203; + yymsp[-2].minor.yy203->pLast = yymsp[-1].minor.yy203; } break; - case 235: /* trigger_cmd_list ::= trigger_cmd SEMI */ + case 239: /* trigger_cmd_list ::= trigger_cmd SEMI */ { - assert( yymsp[-1].minor.yy145!=0 ); - yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145; + assert( yymsp[-1].minor.yy203!=0 ); + yymsp[-1].minor.yy203->pLast = yymsp[-1].minor.yy203; } break; - case 236: /* trnm ::= nm DOT nm */ + case 240: /* trnm ::= nm DOT nm */ { yymsp[-2].minor.yy0 = yymsp[0].minor.yy0; sqlite3ErrorMsg(pParse, @@ -140214,196 +143291,194 @@ static void yy_reduce( "statements within triggers"); } break; - case 237: /* tridxby ::= INDEXED BY nm */ + case 241: /* tridxby ::= INDEXED BY nm */ { sqlite3ErrorMsg(pParse, "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " "within triggers"); } break; - case 238: /* tridxby ::= NOT INDEXED */ + case 242: /* tridxby ::= NOT INDEXED */ { sqlite3ErrorMsg(pParse, "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " "within triggers"); } break; - case 239: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ -{yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);} + case 243: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */ +{yylhsminor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy314, yymsp[-6].minor.yy4, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy336);} + yymsp[-7].minor.yy203 = yylhsminor.yy203; break; - case 240: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */ -{yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/} + case 244: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select scanpt */ +{yylhsminor.yy203 = sqlite3TriggerInsertStep(pParse->db,&yymsp[-3].minor.yy0,yymsp[-2].minor.yy384,yymsp[-1].minor.yy387,yymsp[-5].minor.yy4,yymsp[-6].minor.yy336,yymsp[0].minor.yy336);/*yylhsminor.yy203-overwrites-yymsp[-5].minor.yy4*/} + yymsp[-6].minor.yy203 = yylhsminor.yy203; break; - case 241: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ -{yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);} + case 245: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ +{yylhsminor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy314, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy336);} + yymsp[-5].minor.yy203 = yylhsminor.yy203; break; - case 242: /* trigger_cmd ::= select */ -{yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/} + case 246: /* trigger_cmd ::= scanpt select scanpt */ +{yylhsminor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy387, yymsp[-2].minor.yy336, yymsp[0].minor.yy336); /*yylhsminor.yy203-overwrites-yymsp[-1].minor.yy387*/} + yymsp[-2].minor.yy203 = yylhsminor.yy203; break; - case 243: /* expr ::= RAISE LP IGNORE RP */ + case 247: /* expr ::= RAISE LP IGNORE RP */ { - spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ - yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); - if( yymsp[-3].minor.yy190.pExpr ){ - yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore; + yymsp[-3].minor.yy314 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); + if( yymsp[-3].minor.yy314 ){ + yymsp[-3].minor.yy314->affinity = OE_Ignore; } } break; - case 244: /* expr ::= RAISE LP raisetype COMMA nm RP */ + case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */ { - spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ - yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); - if( yymsp[-5].minor.yy190.pExpr ) { - yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194; + yymsp[-5].minor.yy314 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); + if( yymsp[-5].minor.yy314 ) { + yymsp[-5].minor.yy314->affinity = (char)yymsp[-3].minor.yy4; } } break; - case 245: /* raisetype ::= ROLLBACK */ -{yymsp[0].minor.yy194 = OE_Rollback;} + case 249: /* raisetype ::= ROLLBACK */ +{yymsp[0].minor.yy4 = OE_Rollback;} break; - case 247: /* raisetype ::= FAIL */ -{yymsp[0].minor.yy194 = OE_Fail;} + case 251: /* raisetype ::= FAIL */ +{yymsp[0].minor.yy4 = OE_Fail;} break; - case 248: /* cmd ::= DROP TRIGGER ifexists fullname */ + case 252: /* cmd ::= DROP TRIGGER ifexists fullname */ { - sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194); + sqlite3DropTrigger(pParse,yymsp[0].minor.yy259,yymsp[-1].minor.yy4); } break; - case 249: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ + case 253: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ { - sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72); + sqlite3Attach(pParse, yymsp[-3].minor.yy314, yymsp[-1].minor.yy314, yymsp[0].minor.yy314); } break; - case 250: /* cmd ::= DETACH database_kw_opt expr */ + case 254: /* cmd ::= DETACH database_kw_opt expr */ { - sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr); + sqlite3Detach(pParse, yymsp[0].minor.yy314); } break; - case 253: /* cmd ::= REINDEX */ + case 257: /* cmd ::= REINDEX */ {sqlite3Reindex(pParse, 0, 0);} break; - case 254: /* cmd ::= REINDEX nm dbnm */ + case 258: /* cmd ::= REINDEX nm dbnm */ {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} break; - case 255: /* cmd ::= ANALYZE */ + case 259: /* cmd ::= ANALYZE */ {sqlite3Analyze(pParse, 0, 0);} break; - case 256: /* cmd ::= ANALYZE nm dbnm */ + case 260: /* cmd ::= ANALYZE nm dbnm */ {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} break; - case 257: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ + case 261: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ { - sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0); + sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy259,&yymsp[0].minor.yy0); } break; - case 258: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ + case 262: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ { yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n; sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0); } break; - case 259: /* add_column_fullname ::= fullname */ + case 263: /* add_column_fullname ::= fullname */ { disableLookaside(pParse); - sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185); + sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy259); } break; - case 260: /* cmd ::= create_vtab */ + case 264: /* cmd ::= create_vtab */ {sqlite3VtabFinishParse(pParse,0);} break; - case 261: /* cmd ::= create_vtab LP vtabarglist RP */ + case 265: /* cmd ::= create_vtab LP vtabarglist RP */ {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} break; - case 262: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ + case 266: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ { - sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194); + sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy4); } break; - case 263: /* vtabarg ::= */ + case 267: /* vtabarg ::= */ {sqlite3VtabArgInit(pParse);} break; - case 264: /* vtabargtoken ::= ANY */ - case 265: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==265); - case 266: /* lp ::= LP */ yytestcase(yyruleno==266); + case 268: /* vtabargtoken ::= ANY */ + case 269: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==269); + case 270: /* lp ::= LP */ yytestcase(yyruleno==270); {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} break; - case 267: /* with ::= */ -{yymsp[1].minor.yy285 = 0;} + case 271: /* with ::= WITH wqlist */ + case 272: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==272); +{ sqlite3WithPush(pParse, yymsp[0].minor.yy451, 1); } break; - case 268: /* with ::= WITH wqlist */ -{ yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; } - break; - case 269: /* with ::= WITH RECURSIVE wqlist */ -{ yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; } - break; - case 270: /* wqlist ::= nm eidlist_opt AS LP select RP */ + case 273: /* wqlist ::= nm eidlist_opt AS LP select RP */ { - yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/ + yymsp[-5].minor.yy451 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387); /*A-overwrites-X*/ } break; - case 271: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ + case 274: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ { - yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); + yymsp[-7].minor.yy451 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy451, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy387); } break; default: - /* (272) input ::= cmdlist */ yytestcase(yyruleno==272); - /* (273) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==273); - /* (274) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=274); - /* (275) ecmd ::= SEMI */ yytestcase(yyruleno==275); - /* (276) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==276); - /* (277) explain ::= */ yytestcase(yyruleno==277); - /* (278) trans_opt ::= */ yytestcase(yyruleno==278); - /* (279) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==279); - /* (280) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==280); - /* (281) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==281); - /* (282) savepoint_opt ::= */ yytestcase(yyruleno==282); - /* (283) cmd ::= create_table create_table_args */ yytestcase(yyruleno==283); - /* (284) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==284); - /* (285) columnlist ::= columnname carglist */ yytestcase(yyruleno==285); - /* (286) nm ::= ID|INDEXED */ yytestcase(yyruleno==286); - /* (287) nm ::= STRING */ yytestcase(yyruleno==287); - /* (288) nm ::= JOIN_KW */ yytestcase(yyruleno==288); - /* (289) typetoken ::= typename */ yytestcase(yyruleno==289); - /* (290) typename ::= ID|STRING */ yytestcase(yyruleno==290); - /* (291) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=291); - /* (292) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=292); - /* (293) carglist ::= carglist ccons */ yytestcase(yyruleno==293); - /* (294) carglist ::= */ yytestcase(yyruleno==294); - /* (295) ccons ::= NULL onconf */ yytestcase(yyruleno==295); - /* (296) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==296); - /* (297) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==297); - /* (298) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=298); - /* (299) tconscomma ::= */ yytestcase(yyruleno==299); - /* (300) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=300); - /* (301) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=301); - /* (302) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=302); - /* (303) oneselect ::= values */ yytestcase(yyruleno==303); - /* (304) sclp ::= selcollist COMMA */ yytestcase(yyruleno==304); - /* (305) as ::= ID|STRING */ yytestcase(yyruleno==305); - /* (306) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=306); - /* (307) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==307); - /* (308) exprlist ::= nexprlist */ yytestcase(yyruleno==308); - /* (309) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=309); - /* (310) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=310); - /* (311) nmnum ::= ON */ yytestcase(yyruleno==311); - /* (312) nmnum ::= DELETE */ yytestcase(yyruleno==312); - /* (313) nmnum ::= DEFAULT */ yytestcase(yyruleno==313); - /* (314) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==314); - /* (315) foreach_clause ::= */ yytestcase(yyruleno==315); - /* (316) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==316); - /* (317) trnm ::= nm */ yytestcase(yyruleno==317); - /* (318) tridxby ::= */ yytestcase(yyruleno==318); - /* (319) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==319); - /* (320) database_kw_opt ::= */ yytestcase(yyruleno==320); - /* (321) kwcolumn_opt ::= */ yytestcase(yyruleno==321); - /* (322) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==322); - /* (323) vtabarglist ::= vtabarg */ yytestcase(yyruleno==323); - /* (324) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==324); - /* (325) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==325); - /* (326) anylist ::= */ yytestcase(yyruleno==326); - /* (327) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==327); - /* (328) anylist ::= anylist ANY */ yytestcase(yyruleno==328); + /* (275) input ::= cmdlist */ yytestcase(yyruleno==275); + /* (276) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==276); + /* (277) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=277); + /* (278) ecmd ::= SEMI */ yytestcase(yyruleno==278); + /* (279) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==279); + /* (280) explain ::= */ yytestcase(yyruleno==280); + /* (281) trans_opt ::= */ yytestcase(yyruleno==281); + /* (282) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==282); + /* (283) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==283); + /* (284) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==284); + /* (285) savepoint_opt ::= */ yytestcase(yyruleno==285); + /* (286) cmd ::= create_table create_table_args */ yytestcase(yyruleno==286); + /* (287) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==287); + /* (288) columnlist ::= columnname carglist */ yytestcase(yyruleno==288); + /* (289) nm ::= ID|INDEXED */ yytestcase(yyruleno==289); + /* (290) nm ::= STRING */ yytestcase(yyruleno==290); + /* (291) nm ::= JOIN_KW */ yytestcase(yyruleno==291); + /* (292) typetoken ::= typename */ yytestcase(yyruleno==292); + /* (293) typename ::= ID|STRING */ yytestcase(yyruleno==293); + /* (294) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=294); + /* (295) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=295); + /* (296) carglist ::= carglist ccons */ yytestcase(yyruleno==296); + /* (297) carglist ::= */ yytestcase(yyruleno==297); + /* (298) ccons ::= NULL onconf */ yytestcase(yyruleno==298); + /* (299) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==299); + /* (300) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==300); + /* (301) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=301); + /* (302) tconscomma ::= */ yytestcase(yyruleno==302); + /* (303) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=303); + /* (304) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=304); + /* (305) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=305); + /* (306) oneselect ::= values */ yytestcase(yyruleno==306); + /* (307) sclp ::= selcollist COMMA */ yytestcase(yyruleno==307); + /* (308) as ::= ID|STRING */ yytestcase(yyruleno==308); + /* (309) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=309); + /* (310) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==310); + /* (311) exprlist ::= nexprlist */ yytestcase(yyruleno==311); + /* (312) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=312); + /* (313) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=313); + /* (314) nmnum ::= ON */ yytestcase(yyruleno==314); + /* (315) nmnum ::= DELETE */ yytestcase(yyruleno==315); + /* (316) nmnum ::= DEFAULT */ yytestcase(yyruleno==316); + /* (317) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==317); + /* (318) foreach_clause ::= */ yytestcase(yyruleno==318); + /* (319) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==319); + /* (320) trnm ::= nm */ yytestcase(yyruleno==320); + /* (321) tridxby ::= */ yytestcase(yyruleno==321); + /* (322) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==322); + /* (323) database_kw_opt ::= */ yytestcase(yyruleno==323); + /* (324) kwcolumn_opt ::= */ yytestcase(yyruleno==324); + /* (325) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==325); + /* (326) vtabarglist ::= vtabarg */ yytestcase(yyruleno==326); + /* (327) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==327); + /* (328) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==328); + /* (329) anylist ::= */ yytestcase(yyruleno==329); + /* (330) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==330); + /* (331) anylist ::= anylist ANY */ yytestcase(yyruleno==331); + /* (332) with ::= */ yytestcase(yyruleno==332); break; /********** End reduce actions ************************************************/ }; @@ -140419,16 +143494,11 @@ static void yy_reduce( /* It is not possible for a REDUCE to be followed by an error */ assert( yyact!=YY_ERROR_ACTION ); - if( yyact==YY_ACCEPT_ACTION ){ - yypParser->yytos += yysize; - yy_accept(yypParser); - }else{ - yymsp += yysize+1; - yypParser->yytos = yymsp; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yyTraceShift(yypParser, yyact); - } + yymsp += yysize+1; + yypParser->yytos = yymsp; + yymsp->stateno = (YYACTIONTYPE)yyact; + yymsp->major = (YYCODETYPE)yygoto; + yyTraceShift(yypParser, yyact, "... then shift"); } /* @@ -140466,8 +143536,11 @@ static void yy_syntax_error( /************ Begin %syntax_error code ****************************************/ UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */ - assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */ - sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); + if( TOKEN.z[0] ){ + sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); + }else{ + sqlite3ErrorMsg(pParse, "incomplete input"); + } /************ End %syntax_error code ******************************************/ sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -140539,20 +143612,31 @@ SQLITE_PRIVATE void sqlite3Parser( #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); + int stateno = yypParser->yytos->stateno; + if( stateno < YY_MIN_REDUCE ){ + fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno); + }else{ + fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + } } #endif do{ yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); - if( yyact <= YY_MAX_SHIFTREDUCE ){ + if( yyact >= YY_MIN_REDUCE ){ + yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + }else if( yyact <= YY_MAX_SHIFTREDUCE ){ yy_shift(yypParser,yyact,yymajor,yyminor); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; #endif yymajor = YYNOCODE; - }else if( yyact <= YY_MAX_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE); + }else if( yyact==YY_ACCEPT_ACTION ){ + yypParser->yytos--; + yy_accept(yypParser); + return; }else{ assert( yyact == YY_ERROR_ACTION ); yyminorunion.yy0 = yyminor; @@ -141501,7 +144585,7 @@ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzEr }else{ tokenType = TK_SEMI; } - zSql -= n; + n = 0; } if( tokenType>=TK_SPACE ){ assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); @@ -141956,6 +145040,10 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db); */ /* #include "sqlite3.h" */ +#ifdef SQLITE_OMIT_VIRTUALTABLE +# undef SQLITE_ENABLE_RTREE +#endif + #if 0 extern "C" { #endif /* __cplusplus */ @@ -141969,7 +145057,7 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); /************** End of rtree.h ***********************************************/ /************** Continuing where we left off in main.c ***********************/ #endif -#ifdef SQLITE_ENABLE_ICU +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) /************** Include sqliteicu.h in the middle of main.c ******************/ /************** Begin file sqliteicu.h ***************************************/ /* @@ -142217,6 +145305,11 @@ SQLITE_API int sqlite3_initialize(void){ sqlite3GlobalConfig.isPCacheInit = 1; rc = sqlite3OsInit(); } +#ifdef SQLITE_ENABLE_DESERIALIZE + if( rc==SQLITE_OK ){ + rc = sqlite3MemdbInit(); + } +#endif if( rc==SQLITE_OK ){ sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); @@ -142249,7 +145342,7 @@ SQLITE_API int sqlite3_initialize(void){ #ifndef NDEBUG #ifndef SQLITE_OMIT_FLOATING_POINT /* This section of code's only "output" is via assert() statements. */ - if ( rc==SQLITE_OK ){ + if( rc==SQLITE_OK ){ u64 x = (((u64)1)<<63)-1; double y; assert(sizeof(x)==8); @@ -142795,6 +145888,7 @@ SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){ { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension }, { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose }, { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG }, + { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP }, }; unsigned int i; rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ @@ -143292,9 +146386,10 @@ SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; - case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break; + case SQLITE_READONLY_CANTINIT: zName = "SQLITE_READONLY_CANTINIT"; break; case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break; case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break; + case SQLITE_READONLY_DIRECTORY: zName = "SQLITE_READONLY_DIRECTORY";break; case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break; @@ -143414,6 +146509,8 @@ SQLITE_PRIVATE const char *sqlite3ErrStr(int rc){ /* SQLITE_FORMAT */ 0, /* SQLITE_RANGE */ "column index out of range", /* SQLITE_NOTADB */ "file is not a database", + /* SQLITE_NOTICE */ "notification message", + /* SQLITE_WARNING */ "warning message", }; const char *zErr = "unknown error"; switch( rc ){ @@ -143421,6 +146518,14 @@ SQLITE_PRIVATE const char *sqlite3ErrStr(int rc){ zErr = "abort due to ROLLBACK"; break; } + case SQLITE_ROW: { + zErr = "another row available"; + break; + } + case SQLITE_DONE: { + zErr = "no more rows available"; + break; + } default: { rc &= 0xff; if( ALWAYS(rc>=0) && rcbusyTimeout; + int tmout = db->busyTimeout; int delay, prior; +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT + if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){ + if( count ){ + tmout = 0; + sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout); + return 0; + }else{ + return 1; + } + } +#else + UNUSED_PARAMETER(pFile); +#endif assert( count>=0 ); if( count < NDELAY ){ delay = delays[count]; @@ -143460,16 +146584,19 @@ static int sqliteDefaultBusyCallback( delay = delays[NDELAY-1]; prior = totals[NDELAY-1] + delay*(count-(NDELAY-1)); } - if( prior + delay > timeout ){ - delay = timeout - prior; + if( prior + delay > tmout ){ + delay = tmout - prior; if( delay<=0 ) return 0; } sqlite3OsSleep(db->pVfs, delay*1000); return 1; #else + /* This case for unix systems that lack usleep() support. Sleeping + ** must be done in increments of whole seconds */ sqlite3 *db = (sqlite3 *)ptr; - int timeout = ((sqlite3 *)ptr)->busyTimeout; - if( (count+1)*1000 > timeout ){ + int tmout = ((sqlite3 *)ptr)->busyTimeout; + UNUSED_PARAMETER(pFile); + if( (count+1)*1000 > tmout ){ return 0; } sqlite3OsSleep(db->pVfs, 1000000); @@ -143480,14 +146607,25 @@ static int sqliteDefaultBusyCallback( /* ** Invoke the given busy handler. ** -** This routine is called when an operation failed with a lock. +** This routine is called when an operation failed to acquire a +** lock on VFS file pFile. +** ** If this routine returns non-zero, the lock is retried. If it ** returns 0, the operation aborts with an SQLITE_BUSY error. */ -SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p){ +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p, sqlite3_file *pFile){ int rc; - if( NEVER(p==0) || p->xFunc==0 || p->nBusy<0 ) return 0; - rc = p->xFunc(p->pArg, p->nBusy); + if( p->xBusyHandler==0 || p->nBusy<0 ) return 0; + if( p->bExtraFileArg ){ + /* Add an extra parameter with the pFile pointer to the end of the + ** callback argument list */ + int (*xTra)(void*,int,sqlite3_file*); + xTra = (int(*)(void*,int,sqlite3_file*))p->xBusyHandler; + rc = xTra(p->pBusyArg, p->nBusy, pFile); + }else{ + /* Legacy style busy handler callback */ + rc = p->xBusyHandler(p->pBusyArg, p->nBusy); + } if( rc==0 ){ p->nBusy = -1; }else{ @@ -143509,9 +146647,10 @@ SQLITE_API int sqlite3_busy_handler( if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; #endif sqlite3_mutex_enter(db->mutex); - db->busyHandler.xFunc = xBusy; - db->busyHandler.pArg = pArg; + db->busyHandler.xBusyHandler = xBusy; + db->busyHandler.pBusyArg = pArg; db->busyHandler.nBusy = 0; + db->busyHandler.bExtraFileArg = 0; db->busyTimeout = 0; sqlite3_mutex_leave(db->mutex); return SQLITE_OK; @@ -143559,8 +146698,10 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; #endif if( ms>0 ){ - sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db); + sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback, + (void*)db); db->busyTimeout = ms; + db->busyHandler.bExtraFileArg = 1; }else{ sqlite3_busy_handler(db, 0, 0); } @@ -144800,6 +147941,7 @@ static int openDatabase( }else{ isThreadsafe = sqlite3GlobalConfig.bFullMutex; } + if( flags & SQLITE_OPEN_PRIVATECACHE ){ flags &= ~SQLITE_OPEN_SHAREDCACHE; }else if( sqlite3GlobalConfig.sharedCacheEnabled ){ @@ -144832,13 +147974,20 @@ static int openDatabase( /* Allocate the sqlite data structure */ db = sqlite3MallocZero( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; - if( isThreadsafe ){ + if( isThreadsafe +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS + || sqlite3GlobalConfig.bCoreMutex +#endif + ){ db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); if( db->mutex==0 ){ sqlite3_free(db); db = 0; goto opendb_out; } + if( isThreadsafe==0 ){ + sqlite3MutexWarnOnContention(db->mutex); + } } sqlite3_mutex_enter(db->mutex); db->errMask = 0xff; @@ -145020,7 +148169,7 @@ static int openDatabase( } #endif -#ifdef SQLITE_ENABLE_ICU +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) if( !db->mallocFailed && rc==SQLITE_OK ){ rc = sqlite3IcuInit(db); } @@ -145322,37 +148471,37 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){ ** 2. Invoke sqlite3_log() to provide the source code location where ** a low-level error is first detected. */ -static int reportError(int iErr, int lineno, const char *zType){ +SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){ sqlite3_log(iErr, "%s at line %d of [%.10s]", zType, lineno, 20+sqlite3_sourceid()); return iErr; } SQLITE_PRIVATE int sqlite3CorruptError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_CORRUPT, lineno, "database corruption"); + return sqlite3ReportError(SQLITE_CORRUPT, lineno, "database corruption"); } SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_MISUSE, lineno, "misuse"); + return sqlite3ReportError(SQLITE_MISUSE, lineno, "misuse"); } SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_CANTOPEN, lineno, "cannot open file"); + return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file"); } #ifdef SQLITE_DEBUG SQLITE_PRIVATE int sqlite3CorruptPgnoError(int lineno, Pgno pgno){ char zMsg[100]; sqlite3_snprintf(sizeof(zMsg), zMsg, "database corruption page %d", pgno); testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_CORRUPT, lineno, zMsg); + return sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); } SQLITE_PRIVATE int sqlite3NomemError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_NOMEM, lineno, "OOM"); + return sqlite3ReportError(SQLITE_NOMEM, lineno, "OOM"); } SQLITE_PRIVATE int sqlite3IoerrnomemError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); - return reportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error"); + return sqlite3ReportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error"); } #endif @@ -145545,10 +148694,8 @@ SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, vo }else if( op==SQLITE_FCNTL_JOURNAL_POINTER ){ *(sqlite3_file**)pArg = sqlite3PagerJrnlFile(pPager); rc = SQLITE_OK; - }else if( fd->pMethods ){ - rc = sqlite3OsFileControl(fd, op, pArg); }else{ - rc = SQLITE_NOTFOUND; + rc = sqlite3OsFileControl(fd, op, pArg); } sqlite3BtreeLeave(pBtree); } @@ -145880,6 +149027,22 @@ SQLITE_API int sqlite3_test_control(int op, ...){ sqlite3_mutex_leave(db->mutex); break; } + +#if defined(YYCOVERAGE) + /* sqlite3_test_control(SQLITE_TESTCTRL_PARSER_COVERAGE, FILE *out) + ** + ** This test control (only available when SQLite is compiled with + ** -DYYCOVERAGE) writes a report onto "out" that shows all + ** state/lookahead combinations in the parser state machine + ** which are never exercised. If any state is missed, make the + ** return code SQLITE_ERROR. + */ + case SQLITE_TESTCTRL_PARSER_COVERAGE: { + FILE *out = va_arg(ap, FILE*); + if( sqlite3ParserCoverage(out) ) rc = SQLITE_ERROR; + break; + } +#endif /* defined(YYCOVERAGE) */ } va_end(ap); #endif /* SQLITE_UNTESTABLE */ @@ -159383,6 +162546,7 @@ static int fts3WriteSegment( sqlite3_bind_blob(pStmt, 2, z, n, SQLITE_STATIC); sqlite3_step(pStmt); rc = sqlite3_reset(pStmt); + sqlite3_bind_null(pStmt, 2); } return rc; } @@ -159439,6 +162603,7 @@ static int fts3WriteSegdir( sqlite3_bind_blob(pStmt, 6, zRoot, nRoot, SQLITE_STATIC); sqlite3_step(pStmt); rc = sqlite3_reset(pStmt); + sqlite3_bind_null(pStmt, 6); } return rc; } @@ -160918,6 +164083,7 @@ static void fts3UpdateDocTotals( sqlite3_bind_blob(pStmt, 2, pBlob, nBlob, SQLITE_STATIC); sqlite3_step(pStmt); *pRC = sqlite3_reset(pStmt); + sqlite3_bind_null(pStmt, 2); sqlite3_free(a); } @@ -162106,6 +165272,7 @@ static int fts3TruncateSegment( sqlite3_bind_int(pChomp, 4, iIdx); sqlite3_step(pChomp); rc = sqlite3_reset(pChomp); + sqlite3_bind_null(pChomp, 2); } } @@ -162185,6 +165352,7 @@ static int fts3IncrmergeHintStore(Fts3Table *p, Blob *pHint){ sqlite3_bind_blob(pReplace, 2, pHint->a, pHint->n, SQLITE_STATIC); sqlite3_step(pReplace); rc = sqlite3_reset(pReplace); + sqlite3_bind_null(pReplace, 2); } return rc; @@ -162999,7 +166167,6 @@ SQLITE_PRIVATE int sqlite3Fts3UpdateMethod( ){ Fts3Table *p = (Fts3Table *)pVtab; int rc = SQLITE_OK; /* Return Code */ - int isRemove = 0; /* True for an UPDATE or DELETE */ u32 *aSzIns = 0; /* Sizes of inserted documents */ u32 *aSzDel = 0; /* Sizes of deleted documents */ int nChng = 0; /* Net change in number of documents */ @@ -163097,7 +166264,6 @@ SQLITE_PRIVATE int sqlite3Fts3UpdateMethod( if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER ); rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel); - isRemove = 1; } /* If this is an INSERT or UPDATE operation, insert the new record. */ @@ -163109,7 +166275,7 @@ SQLITE_PRIVATE int sqlite3Fts3UpdateMethod( rc = FTS_CORRUPT_VTAB; } } - if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){ + if( rc==SQLITE_OK ){ rc = fts3PendingTermsDocid(p, 0, iLangid, *pRowid); } if( rc==SQLITE_OK ){ @@ -165684,7 +168850,8 @@ SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ ** child page. */ -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE) +#if !defined(SQLITE_CORE) \ + || (defined(SQLITE_ENABLE_RTREE) && !defined(SQLITE_OMIT_VIRTUALTABLE)) #ifndef SQLITE_CORE /* #include "sqlite3ext.h" */ @@ -165841,7 +169008,7 @@ struct RtreeSearchPoint { ** The smallest possible node-size is (512-64)==448 bytes. And the largest ** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates). ** Therefore all non-root nodes must contain at least 3 entries. Since -** 2^40 is greater than 2^64, an r-tree structure always has a depth of +** 3^40 is greater than 2^64, an r-tree structure always has a depth of ** 40 or less. */ #define RTREE_MAX_DEPTH 40 @@ -166416,6 +169583,7 @@ static int nodeWrite(Rtree *pRtree, RtreeNode *pNode){ sqlite3_step(p); pNode->isDirty = 0; rc = sqlite3_reset(p); + sqlite3_bind_null(p, 2); if( pNode->iNode==0 && rc==SQLITE_OK ){ pNode->iNode = sqlite3_last_insert_rowid(pRtree->db); nodeHashInsert(pRtree, pNode); @@ -167653,7 +170821,7 @@ static int ChooseLeaf( ){ int rc; int ii; - RtreeNode *pNode; + RtreeNode *pNode = 0; rc = nodeAcquire(pRtree, 1, 0, &pNode); for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){ @@ -168528,7 +171696,7 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ */ if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){ int rc2; - RtreeNode *pChild; + RtreeNode *pChild = 0; i64 iChild = nodeGetRowid(pRtree, pRoot, 0); rc = nodeAcquire(pRtree, iChild, pRoot, &pChild); if( rc==SQLITE_OK ){ @@ -169240,6 +172408,463 @@ static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){ } } +/* +** Context object passed between the various routines that make up the +** implementation of integrity-check function rtreecheck(). +*/ +typedef struct RtreeCheck RtreeCheck; +struct RtreeCheck { + sqlite3 *db; /* Database handle */ + const char *zDb; /* Database containing rtree table */ + const char *zTab; /* Name of rtree table */ + int bInt; /* True for rtree_i32 table */ + int nDim; /* Number of dimensions for this rtree tbl */ + sqlite3_stmt *pGetNode; /* Statement used to retrieve nodes */ + sqlite3_stmt *aCheckMapping[2]; /* Statements to query %_parent/%_rowid */ + int nLeaf; /* Number of leaf cells in table */ + int nNonLeaf; /* Number of non-leaf cells in table */ + int rc; /* Return code */ + char *zReport; /* Message to report */ + int nErr; /* Number of lines in zReport */ +}; + +#define RTREE_CHECK_MAX_ERROR 100 + +/* +** Reset SQL statement pStmt. If the sqlite3_reset() call returns an error, +** and RtreeCheck.rc==SQLITE_OK, set RtreeCheck.rc to the error code. +*/ +static void rtreeCheckReset(RtreeCheck *pCheck, sqlite3_stmt *pStmt){ + int rc = sqlite3_reset(pStmt); + if( pCheck->rc==SQLITE_OK ) pCheck->rc = rc; +} + +/* +** The second and subsequent arguments to this function are a format string +** and printf style arguments. This function formats the string and attempts +** to compile it as an SQL statement. +** +** If successful, a pointer to the new SQL statement is returned. Otherwise, +** NULL is returned and an error code left in RtreeCheck.rc. +*/ +static sqlite3_stmt *rtreeCheckPrepare( + RtreeCheck *pCheck, /* RtreeCheck object */ + const char *zFmt, ... /* Format string and trailing args */ +){ + va_list ap; + char *z; + sqlite3_stmt *pRet = 0; + + va_start(ap, zFmt); + z = sqlite3_vmprintf(zFmt, ap); + + if( pCheck->rc==SQLITE_OK ){ + if( z==0 ){ + pCheck->rc = SQLITE_NOMEM; + }else{ + pCheck->rc = sqlite3_prepare_v2(pCheck->db, z, -1, &pRet, 0); + } + } + + sqlite3_free(z); + va_end(ap); + return pRet; +} + +/* +** The second and subsequent arguments to this function are a printf() +** style format string and arguments. This function formats the string and +** appends it to the report being accumuated in pCheck. +*/ +static void rtreeCheckAppendMsg(RtreeCheck *pCheck, const char *zFmt, ...){ + va_list ap; + va_start(ap, zFmt); + if( pCheck->rc==SQLITE_OK && pCheck->nErrrc = SQLITE_NOMEM; + }else{ + pCheck->zReport = sqlite3_mprintf("%z%s%z", + pCheck->zReport, (pCheck->zReport ? "\n" : ""), z + ); + if( pCheck->zReport==0 ){ + pCheck->rc = SQLITE_NOMEM; + } + } + pCheck->nErr++; + } + va_end(ap); +} + +/* +** This function is a no-op if there is already an error code stored +** in the RtreeCheck object indicated by the first argument. NULL is +** returned in this case. +** +** Otherwise, the contents of rtree table node iNode are loaded from +** the database and copied into a buffer obtained from sqlite3_malloc(). +** If no error occurs, a pointer to the buffer is returned and (*pnNode) +** is set to the size of the buffer in bytes. +** +** Or, if an error does occur, NULL is returned and an error code left +** in the RtreeCheck object. The final value of *pnNode is undefined in +** this case. +*/ +static u8 *rtreeCheckGetNode(RtreeCheck *pCheck, i64 iNode, int *pnNode){ + u8 *pRet = 0; /* Return value */ + + assert( pCheck->rc==SQLITE_OK ); + if( pCheck->pGetNode==0 ){ + pCheck->pGetNode = rtreeCheckPrepare(pCheck, + "SELECT data FROM %Q.'%q_node' WHERE nodeno=?", + pCheck->zDb, pCheck->zTab + ); + } + + if( pCheck->rc==SQLITE_OK ){ + sqlite3_bind_int64(pCheck->pGetNode, 1, iNode); + if( sqlite3_step(pCheck->pGetNode)==SQLITE_ROW ){ + int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0); + const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0); + pRet = sqlite3_malloc(nNode); + if( pRet==0 ){ + pCheck->rc = SQLITE_NOMEM; + }else{ + memcpy(pRet, pNode, nNode); + *pnNode = nNode; + } + } + rtreeCheckReset(pCheck, pCheck->pGetNode); + if( pCheck->rc==SQLITE_OK && pRet==0 ){ + rtreeCheckAppendMsg(pCheck, "Node %lld missing from database", iNode); + } + } + + return pRet; +} + +/* +** This function is used to check that the %_parent (if bLeaf==0) or %_rowid +** (if bLeaf==1) table contains a specified entry. The schemas of the +** two tables are: +** +** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER) +** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER) +** +** In both cases, this function checks that there exists an entry with +** IPK value iKey and the second column set to iVal. +** +*/ +static void rtreeCheckMapping( + RtreeCheck *pCheck, /* RtreeCheck object */ + int bLeaf, /* True for a leaf cell, false for interior */ + i64 iKey, /* Key for mapping */ + i64 iVal /* Expected value for mapping */ +){ + int rc; + sqlite3_stmt *pStmt; + const char *azSql[2] = { + "SELECT parentnode FROM %Q.'%q_parent' WHERE nodeno=?", + "SELECT nodeno FROM %Q.'%q_rowid' WHERE rowid=?" + }; + + assert( bLeaf==0 || bLeaf==1 ); + if( pCheck->aCheckMapping[bLeaf]==0 ){ + pCheck->aCheckMapping[bLeaf] = rtreeCheckPrepare(pCheck, + azSql[bLeaf], pCheck->zDb, pCheck->zTab + ); + } + if( pCheck->rc!=SQLITE_OK ) return; + + pStmt = pCheck->aCheckMapping[bLeaf]; + sqlite3_bind_int64(pStmt, 1, iKey); + rc = sqlite3_step(pStmt); + if( rc==SQLITE_DONE ){ + rtreeCheckAppendMsg(pCheck, "Mapping (%lld -> %lld) missing from %s table", + iKey, iVal, (bLeaf ? "%_rowid" : "%_parent") + ); + }else if( rc==SQLITE_ROW ){ + i64 ii = sqlite3_column_int64(pStmt, 0); + if( ii!=iVal ){ + rtreeCheckAppendMsg(pCheck, + "Found (%lld -> %lld) in %s table, expected (%lld -> %lld)", + iKey, ii, (bLeaf ? "%_rowid" : "%_parent"), iKey, iVal + ); + } + } + rtreeCheckReset(pCheck, pStmt); +} + +/* +** Argument pCell points to an array of coordinates stored on an rtree page. +** This function checks that the coordinates are internally consistent (no +** x1>x2 conditions) and adds an error message to the RtreeCheck object +** if they are not. +** +** Additionally, if pParent is not NULL, then it is assumed to point to +** the array of coordinates on the parent page that bound the page +** containing pCell. In this case it is also verified that the two +** sets of coordinates are mutually consistent and an error message added +** to the RtreeCheck object if they are not. +*/ +static void rtreeCheckCellCoord( + RtreeCheck *pCheck, + i64 iNode, /* Node id to use in error messages */ + int iCell, /* Cell number to use in error messages */ + u8 *pCell, /* Pointer to cell coordinates */ + u8 *pParent /* Pointer to parent coordinates */ +){ + RtreeCoord c1, c2; + RtreeCoord p1, p2; + int i; + + for(i=0; inDim; i++){ + readCoord(&pCell[4*2*i], &c1); + readCoord(&pCell[4*(2*i + 1)], &c2); + + /* printf("%e, %e\n", c1.u.f, c2.u.f); */ + if( pCheck->bInt ? c1.i>c2.i : c1.f>c2.f ){ + rtreeCheckAppendMsg(pCheck, + "Dimension %d of cell %d on node %lld is corrupt", i, iCell, iNode + ); + } + + if( pParent ){ + readCoord(&pParent[4*2*i], &p1); + readCoord(&pParent[4*(2*i + 1)], &p2); + + if( (pCheck->bInt ? c1.ibInt ? c2.i>p2.i : c2.f>p2.f) + ){ + rtreeCheckAppendMsg(pCheck, + "Dimension %d of cell %d on node %lld is corrupt relative to parent" + , i, iCell, iNode + ); + } + } + } +} + +/* +** Run rtreecheck() checks on node iNode, which is at depth iDepth within +** the r-tree structure. Argument aParent points to the array of coordinates +** that bound node iNode on the parent node. +** +** If any problems are discovered, an error message is appended to the +** report accumulated in the RtreeCheck object. +*/ +static void rtreeCheckNode( + RtreeCheck *pCheck, + int iDepth, /* Depth of iNode (0==leaf) */ + u8 *aParent, /* Buffer containing parent coords */ + i64 iNode /* Node to check */ +){ + u8 *aNode = 0; + int nNode = 0; + + assert( iNode==1 || aParent!=0 ); + assert( pCheck->nDim>0 ); + + aNode = rtreeCheckGetNode(pCheck, iNode, &nNode); + if( aNode ){ + if( nNode<4 ){ + rtreeCheckAppendMsg(pCheck, + "Node %lld is too small (%d bytes)", iNode, nNode + ); + }else{ + int nCell; /* Number of cells on page */ + int i; /* Used to iterate through cells */ + if( aParent==0 ){ + iDepth = readInt16(aNode); + if( iDepth>RTREE_MAX_DEPTH ){ + rtreeCheckAppendMsg(pCheck, "Rtree depth out of range (%d)", iDepth); + sqlite3_free(aNode); + return; + } + } + nCell = readInt16(&aNode[2]); + if( (4 + nCell*(8 + pCheck->nDim*2*4))>nNode ){ + rtreeCheckAppendMsg(pCheck, + "Node %lld is too small for cell count of %d (%d bytes)", + iNode, nCell, nNode + ); + }else{ + for(i=0; inDim*2*4)]; + i64 iVal = readInt64(pCell); + rtreeCheckCellCoord(pCheck, iNode, i, &pCell[8], aParent); + + if( iDepth>0 ){ + rtreeCheckMapping(pCheck, 0, iVal, iNode); + rtreeCheckNode(pCheck, iDepth-1, &pCell[8], iVal); + pCheck->nNonLeaf++; + }else{ + rtreeCheckMapping(pCheck, 1, iVal, iNode); + pCheck->nLeaf++; + } + } + } + } + sqlite3_free(aNode); + } +} + +/* +** The second argument to this function must be either "_rowid" or +** "_parent". This function checks that the number of entries in the +** %_rowid or %_parent table is exactly nExpect. If not, it adds +** an error message to the report in the RtreeCheck object indicated +** by the first argument. +*/ +static void rtreeCheckCount(RtreeCheck *pCheck, const char *zTbl, i64 nExpect){ + if( pCheck->rc==SQLITE_OK ){ + sqlite3_stmt *pCount; + pCount = rtreeCheckPrepare(pCheck, "SELECT count(*) FROM %Q.'%q%s'", + pCheck->zDb, pCheck->zTab, zTbl + ); + if( pCount ){ + if( sqlite3_step(pCount)==SQLITE_ROW ){ + i64 nActual = sqlite3_column_int64(pCount, 0); + if( nActual!=nExpect ){ + rtreeCheckAppendMsg(pCheck, "Wrong number of entries in %%%s table" + " - expected %lld, actual %lld" , zTbl, nExpect, nActual + ); + } + } + pCheck->rc = sqlite3_finalize(pCount); + } + } +} + +/* +** This function does the bulk of the work for the rtree integrity-check. +** It is called by rtreecheck(), which is the SQL function implementation. +*/ +static int rtreeCheckTable( + sqlite3 *db, /* Database handle to access db through */ + const char *zDb, /* Name of db ("main", "temp" etc.) */ + const char *zTab, /* Name of rtree table to check */ + char **pzReport /* OUT: sqlite3_malloc'd report text */ +){ + RtreeCheck check; /* Common context for various routines */ + sqlite3_stmt *pStmt = 0; /* Used to find column count of rtree table */ + int bEnd = 0; /* True if transaction should be closed */ + + /* Initialize the context object */ + memset(&check, 0, sizeof(check)); + check.db = db; + check.zDb = zDb; + check.zTab = zTab; + + /* If there is not already an open transaction, open one now. This is + ** to ensure that the queries run as part of this integrity-check operate + ** on a consistent snapshot. */ + if( sqlite3_get_autocommit(db) ){ + check.rc = sqlite3_exec(db, "BEGIN", 0, 0, 0); + bEnd = 1; + } + + /* Find number of dimensions in the rtree table. */ + pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.%Q", zDb, zTab); + if( pStmt ){ + int rc; + check.nDim = (sqlite3_column_count(pStmt) - 1) / 2; + if( check.nDim<1 ){ + rtreeCheckAppendMsg(&check, "Schema corrupt or not an rtree"); + }else if( SQLITE_ROW==sqlite3_step(pStmt) ){ + check.bInt = (sqlite3_column_type(pStmt, 1)==SQLITE_INTEGER); + } + rc = sqlite3_finalize(pStmt); + if( rc!=SQLITE_CORRUPT ) check.rc = rc; + } + + /* Do the actual integrity-check */ + if( check.nDim>=1 ){ + if( check.rc==SQLITE_OK ){ + rtreeCheckNode(&check, 0, 0, 1); + } + rtreeCheckCount(&check, "_rowid", check.nLeaf); + rtreeCheckCount(&check, "_parent", check.nNonLeaf); + } + + /* Finalize SQL statements used by the integrity-check */ + sqlite3_finalize(check.pGetNode); + sqlite3_finalize(check.aCheckMapping[0]); + sqlite3_finalize(check.aCheckMapping[1]); + + /* If one was opened, close the transaction */ + if( bEnd ){ + int rc = sqlite3_exec(db, "END", 0, 0, 0); + if( check.rc==SQLITE_OK ) check.rc = rc; + } + *pzReport = check.zReport; + return check.rc; +} + +/* +** Usage: +** +** rtreecheck(); +** rtreecheck(, ); +** +** Invoking this SQL function runs an integrity-check on the named rtree +** table. The integrity-check verifies the following: +** +** 1. For each cell in the r-tree structure (%_node table), that: +** +** a) for each dimension, (coord1 <= coord2). +** +** b) unless the cell is on the root node, that the cell is bounded +** by the parent cell on the parent node. +** +** c) for leaf nodes, that there is an entry in the %_rowid +** table corresponding to the cell's rowid value that +** points to the correct node. +** +** d) for cells on non-leaf nodes, that there is an entry in the +** %_parent table mapping from the cell's child node to the +** node that it resides on. +** +** 2. That there are the same number of entries in the %_rowid table +** as there are leaf cells in the r-tree structure, and that there +** is a leaf cell that corresponds to each entry in the %_rowid table. +** +** 3. That there are the same number of entries in the %_parent table +** as there are non-leaf cells in the r-tree structure, and that +** there is a non-leaf cell that corresponds to each entry in the +** %_parent table. +*/ +static void rtreecheck( + sqlite3_context *ctx, + int nArg, + sqlite3_value **apArg +){ + if( nArg!=1 && nArg!=2 ){ + sqlite3_result_error(ctx, + "wrong number of arguments to function rtreecheck()", -1 + ); + }else{ + int rc; + char *zReport = 0; + const char *zDb = (const char*)sqlite3_value_text(apArg[0]); + const char *zTab; + if( nArg==1 ){ + zTab = zDb; + zDb = "main"; + }else{ + zTab = (const char*)sqlite3_value_text(apArg[1]); + } + rc = rtreeCheckTable(sqlite3_context_db_handle(ctx), zDb, zTab, &zReport); + if( rc==SQLITE_OK ){ + sqlite3_result_text(ctx, zReport ? zReport : "ok", -1, SQLITE_TRANSIENT); + }else{ + sqlite3_result_error_code(ctx, rc); + } + sqlite3_free(zReport); + } +} + + /* ** Register the r-tree module with database handle db. This creates the ** virtual table module "rtree" and the debugging/analysis scalar @@ -169253,6 +172878,9 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){ if( rc==SQLITE_OK ){ rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0); } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0); + } if( rc==SQLITE_OK ){ #ifdef SQLITE_RTREE_INT_ONLY void *c = (void *)RTREE_COORD_INT32; @@ -169439,7 +173067,9 @@ SQLITE_API int sqlite3_rtree_init( ** provide case-independent matching. */ -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) +#if !defined(SQLITE_CORE) \ + || defined(SQLITE_ENABLE_ICU) \ + || defined(SQLITE_ENABLE_ICU_COLLATIONS) /* Include ICU headers */ #include @@ -169456,6 +173086,26 @@ SQLITE_API int sqlite3_rtree_init( /* #include "sqlite3.h" */ #endif +/* +** This function is called when an ICU function called from within +** the implementation of an SQL scalar function returns an error. +** +** The scalar function context passed as the first argument is +** loaded with an error message based on the following two args. +*/ +static void icuFunctionError( + sqlite3_context *pCtx, /* SQLite scalar function context */ + const char *zName, /* Name of ICU function that failed */ + UErrorCode e /* Error code returned by ICU function */ +){ + char zBuf[128]; + sqlite3_snprintf(128, zBuf, "ICU error: %s(): %s", zName, u_errorName(e)); + zBuf[127] = '\0'; + sqlite3_result_error(pCtx, zBuf, -1); +} + +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) + /* ** Maximum length (in bytes) of the pattern in a LIKE or GLOB ** operator. @@ -169635,24 +173285,6 @@ static void icuLikeFunc( } } -/* -** This function is called when an ICU function called from within -** the implementation of an SQL scalar function returns an error. -** -** The scalar function context passed as the first argument is -** loaded with an error message based on the following two args. -*/ -static void icuFunctionError( - sqlite3_context *pCtx, /* SQLite scalar function context */ - const char *zName, /* Name of ICU function that failed */ - UErrorCode e /* Error code returned by ICU function */ -){ - char zBuf[128]; - sqlite3_snprintf(128, zBuf, "ICU error: %s(): %s", zName, u_errorName(e)); - zBuf[127] = '\0'; - sqlite3_result_error(pCtx, zBuf, -1); -} - /* ** Function to delete compiled regexp objects. Registered as ** a destructor function with sqlite3_set_auxdata(). @@ -169818,6 +173450,8 @@ static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ assert( 0 ); /* Unreachable */ } +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */ + /* ** Collation sequence destructor function. The pCtx argument points to ** a UCollator structure previously allocated using ucol_open(). @@ -169912,6 +173546,7 @@ SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ void (*xFunc)(sqlite3_context*,int,sqlite3_value**); } scalars[] = { {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation}, +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, @@ -169923,10 +173558,10 @@ SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */ }; int rc = SQLITE_OK; int i; - for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ const struct IcuScalar *p = &scalars[i]; @@ -172636,7 +176271,7 @@ static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){ int iCid = sqlite3_column_int(pXInfo, 1); int bDesc = sqlite3_column_int(pXInfo, 3); const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4); - zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma, + zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %Q", zCols, zComma, iCid, pIter->azTblType[iCid], zCollate ); zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":""); @@ -172697,7 +176332,7 @@ static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){ ** "PRIMARY KEY" to the imposter table column declaration. */ zPk = "PRIMARY KEY "; } - zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s", + zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %Q%s", zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl, (pIter->abNotNull[iCol] ? " NOT NULL" : "") ); @@ -176131,7 +179766,7 @@ static void statSizeAndOffset(StatCursor *pCsr){ */ fd = sqlite3PagerFile(pPager); x[0] = pCsr->iPageno; - if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ + if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ pCsr->iOffset = x[0]; pCsr->szPage = (int)x[1]; } @@ -176457,17 +180092,24 @@ struct DbpageCursor { sqlite3_vtab_cursor base; /* Base class. Must be first */ int pgno; /* Current page number */ int mxPgno; /* Last page to visit on this scan */ + Pager *pPager; /* Pager being read/written */ + DbPage *pPage1; /* Page 1 of the database */ + int iDb; /* Index of database to analyze */ + int szPage; /* Size of each page in bytes */ }; struct DbpageTable { sqlite3_vtab base; /* Base class. Must be first */ sqlite3 *db; /* The database */ - Pager *pPager; /* Pager being read/written */ - int iDb; /* Index of database to analyze */ - int szPage; /* Size of each page in bytes */ - int nPage; /* Number of pages in the file */ }; +/* Columns */ +#define DBPAGE_COLUMN_PGNO 0 +#define DBPAGE_COLUMN_DATA 1 +#define DBPAGE_COLUMN_SCHEMA 2 + + + /* ** Connect to or create a dbpagevfs virtual table. */ @@ -176480,19 +180122,7 @@ static int dbpageConnect( ){ DbpageTable *pTab = 0; int rc = SQLITE_OK; - int iDb; - if( argc>=4 ){ - Token nm; - sqlite3TokenInit(&nm, (char*)argv[3]); - iDb = sqlite3FindDb(db, &nm); - if( iDb<0 ){ - *pzErr = sqlite3_mprintf("no such schema: %s", argv[3]); - return SQLITE_ERROR; - } - }else{ - iDb = 0; - } rc = sqlite3_declare_vtab(db, "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)"); if( rc==SQLITE_OK ){ @@ -176502,11 +180132,8 @@ static int dbpageConnect( assert( rc==SQLITE_OK || pTab==0 ); if( rc==SQLITE_OK ){ - Btree *pBt = db->aDb[iDb].pBt; memset(pTab, 0, sizeof(DbpageTable)); pTab->db = db; - pTab->iDb = iDb; - pTab->pPager = pBt ? sqlite3BtreePager(pBt) : 0; } *ppVtab = (sqlite3_vtab*)pTab; @@ -176524,24 +180151,55 @@ static int dbpageDisconnect(sqlite3_vtab *pVtab){ /* ** idxNum: ** -** 0 full table scan -** 1 pgno=?1 +** 0 schema=main, full table scan +** 1 schema=main, pgno=?1 +** 2 schema=?1, full table scan +** 3 schema=?1, pgno=?2 */ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ int i; - pIdxInfo->estimatedCost = 1.0e6; /* Initial cost estimate */ + int iPlan = 0; + + /* If there is a schema= constraint, it must be honored. Report a + ** ridiculously large estimated cost if the schema= constraint is + ** unavailable + */ + for(i=0; inConstraint; i++){ + struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i]; + if( p->iColumn!=DBPAGE_COLUMN_SCHEMA ) continue; + if( p->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; + if( !p->usable ){ + /* No solution. Use the default SQLITE_BIG_DBL cost */ + pIdxInfo->estimatedRows = 0x7fffffff; + return SQLITE_OK; + } + iPlan = 2; + pIdxInfo->aConstraintUsage[i].argvIndex = 1; + pIdxInfo->aConstraintUsage[i].omit = 1; + break; + } + + /* If we reach this point, it means that either there is no schema= + ** constraint (in which case we use the "main" schema) or else the + ** schema constraint was accepted. Lower the estimated cost accordingly + */ + pIdxInfo->estimatedCost = 1.0e6; + + /* Check for constraints against pgno */ for(i=0; inConstraint; i++){ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i]; if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ pIdxInfo->estimatedRows = 1; pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE; pIdxInfo->estimatedCost = 1.0; - pIdxInfo->idxNum = 1; - pIdxInfo->aConstraintUsage[i].argvIndex = 1; + pIdxInfo->aConstraintUsage[i].argvIndex = iPlan ? 2 : 1; pIdxInfo->aConstraintUsage[i].omit = 1; + iPlan |= 1; break; } } + pIdxInfo->idxNum = iPlan; + if( pIdxInfo->nOrderBy>=1 && pIdxInfo->aOrderBy[0].iColumn<=0 && pIdxInfo->aOrderBy[0].desc==0 @@ -176575,6 +180233,7 @@ static int dbpageOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ */ static int dbpageClose(sqlite3_vtab_cursor *pCursor){ DbpageCursor *pCsr = (DbpageCursor *)pCursor; + if( pCsr->pPage1 ) sqlite3PagerUnrefPageOne(pCsr->pPage1); sqlite3_free(pCsr); return SQLITE_OK; } @@ -176594,6 +180253,16 @@ static int dbpageEof(sqlite3_vtab_cursor *pCursor){ return pCsr->pgno > pCsr->mxPgno; } +/* +** idxNum: +** +** 0 schema=main, full table scan +** 1 schema=main, pgno=?1 +** 2 schema=?1, full table scan +** 3 schema=?1, pgno=?2 +** +** idxStr is not used +*/ static int dbpageFilter( sqlite3_vtab_cursor *pCursor, int idxNum, const char *idxStr, @@ -176601,23 +180270,42 @@ static int dbpageFilter( ){ DbpageCursor *pCsr = (DbpageCursor *)pCursor; DbpageTable *pTab = (DbpageTable *)pCursor->pVtab; - int rc = SQLITE_OK; - Btree *pBt = pTab->db->aDb[pTab->iDb].pBt; + int rc; + sqlite3 *db = pTab->db; + Btree *pBt; - pTab->szPage = sqlite3BtreeGetPageSize(pBt); - pTab->nPage = sqlite3BtreeLastPage(pBt); - if( idxNum==1 ){ - pCsr->pgno = sqlite3_value_int(argv[0]); - if( pCsr->pgno<1 || pCsr->pgno>pTab->nPage ){ + /* Default setting is no rows of result */ + pCsr->pgno = 1; + pCsr->mxPgno = 0; + + if( idxNum & 2 ){ + const char *zSchema; + assert( argc>=1 ); + zSchema = (const char*)sqlite3_value_text(argv[0]); + pCsr->iDb = sqlite3FindDbName(db, zSchema); + if( pCsr->iDb<0 ) return SQLITE_OK; + }else{ + pCsr->iDb = 0; + } + pBt = db->aDb[pCsr->iDb].pBt; + if( pBt==0 ) return SQLITE_OK; + pCsr->pPager = sqlite3BtreePager(pBt); + pCsr->szPage = sqlite3BtreeGetPageSize(pBt); + pCsr->mxPgno = sqlite3BtreeLastPage(pBt); + if( idxNum & 1 ){ + assert( argc>(idxNum>>1) ); + pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]); + if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){ pCsr->pgno = 1; pCsr->mxPgno = 0; }else{ pCsr->mxPgno = pCsr->pgno; } }else{ - pCsr->pgno = 1; - pCsr->mxPgno = pTab->nPage; + assert( pCsr->pgno==1 ); } + if( pCsr->pPage1 ) sqlite3PagerUnrefPageOne(pCsr->pPage1); + rc = sqlite3PagerGet(pCsr->pPager, 1, &pCsr->pPage1, 0); return rc; } @@ -176627,7 +180315,6 @@ static int dbpageColumn( int i ){ DbpageCursor *pCsr = (DbpageCursor *)pCursor; - DbpageTable *pTab = (DbpageTable *)pCursor->pVtab; int rc = SQLITE_OK; switch( i ){ case 0: { /* pgno */ @@ -176636,9 +180323,9 @@ static int dbpageColumn( } case 1: { /* data */ DbPage *pDbPage = 0; - rc = sqlite3PagerGet(pTab->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0); + rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0); if( rc==SQLITE_OK ){ - sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pTab->szPage, + sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pCsr->szPage, SQLITE_TRANSIENT); } sqlite3PagerUnref(pDbPage); @@ -176646,7 +180333,7 @@ static int dbpageColumn( } default: { /* schema */ sqlite3 *db = sqlite3_context_db_handle(ctx); - sqlite3_result_text(ctx, db->aDb[pTab->iDb].zDbSName, -1, SQLITE_STATIC); + sqlite3_result_text(ctx, db->aDb[pCsr->iDb].zDbSName, -1, SQLITE_STATIC); break; } } @@ -176666,37 +180353,51 @@ static int dbpageUpdate( sqlite_int64 *pRowid ){ DbpageTable *pTab = (DbpageTable *)pVtab; - int pgno; + Pgno pgno; DbPage *pDbPage = 0; int rc = SQLITE_OK; char *zErr = 0; + const char *zSchema; + int iDb; + Btree *pBt; + Pager *pPager; + int szPage; if( argc==1 ){ zErr = "cannot delete"; goto update_fail; } pgno = sqlite3_value_int(argv[0]); - if( pgno<1 || pgno>pTab->nPage ){ - zErr = "bad page number"; - goto update_fail; - } - if( sqlite3_value_int(argv[1])!=pgno ){ + if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){ zErr = "cannot insert"; goto update_fail; } + zSchema = (const char*)sqlite3_value_text(argv[4]); + iDb = zSchema ? sqlite3FindDbName(pTab->db, zSchema) : -1; + if( iDb<0 ){ + zErr = "no such schema"; + goto update_fail; + } + pBt = pTab->db->aDb[iDb].pBt; + if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){ + zErr = "bad page number"; + goto update_fail; + } + szPage = sqlite3BtreeGetPageSize(pBt); if( sqlite3_value_type(argv[3])!=SQLITE_BLOB - || sqlite3_value_bytes(argv[3])!=pTab->szPage + || sqlite3_value_bytes(argv[3])!=szPage ){ zErr = "bad page value"; goto update_fail; } - rc = sqlite3PagerGet(pTab->pPager, pgno, (DbPage**)&pDbPage, 0); + pPager = sqlite3BtreePager(pBt); + rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0); if( rc==SQLITE_OK ){ rc = sqlite3PagerWrite(pDbPage); if( rc==SQLITE_OK ){ memcpy(sqlite3PagerGetData(pDbPage), sqlite3_value_blob(argv[3]), - pTab->szPage); + szPage); } } sqlite3PagerUnref(pDbPage); @@ -176708,6 +180409,22 @@ update_fail: return SQLITE_ERROR; } +/* Since we do not know in advance which database files will be +** written by the sqlite_dbpage virtual table, start a write transaction +** on them all. +*/ +static int dbpageBegin(sqlite3_vtab *pVtab){ + DbpageTable *pTab = (DbpageTable *)pVtab; + sqlite3 *db = pTab->db; + int i; + for(i=0; inDb; i++){ + Btree *pBt = db->aDb[i].pBt; + if( pBt ) sqlite3BtreeBeginTrans(pBt, 1); + } + return SQLITE_OK; +} + + /* ** Invoke this routine to register the "dbpage" virtual table module */ @@ -176727,7 +180444,7 @@ SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){ dbpageColumn, /* xColumn - read data */ dbpageRowid, /* xRowid - read data */ dbpageUpdate, /* xUpdate */ - 0, /* xBegin */ + dbpageBegin, /* xBegin */ 0, /* xSync */ 0, /* xCommit */ 0, /* xRollback */ @@ -176793,6 +180510,7 @@ struct sqlite3_session { int rc; /* Non-zero if an error has occurred */ void *pFilterCtx; /* First argument to pass to xTableFilter */ int (*xTableFilter)(void *pCtx, const char *zTab); + sqlite3_value *pZeroBlob; /* Value containing X'' */ sqlite3_session *pNext; /* Next session object on same db. */ SessionTable *pTable; /* List of attached tables */ SessionHook hook; /* APIs to grab new and old data with */ @@ -176814,7 +180532,7 @@ struct SessionBuffer { ** sqlite3changeset_start_strm()). */ struct SessionInput { - int bNoDiscard; /* If true, discard no data */ + int bNoDiscard; /* If true, do not discard in InputBuffer() */ int iCurrent; /* Offset in aData[] of current change */ int iNext; /* Offset in aData[] of next change */ u8 *aData; /* Pointer to buffer containing changeset */ @@ -176860,6 +180578,7 @@ struct SessionTable { SessionTable *pNext; char *zName; /* Local name of table */ int nCol; /* Number of columns in table zName */ + int bStat1; /* True if this is sqlite_stat1 */ const char **azCol; /* Column names */ u8 *abPK; /* Array of primary key flags */ int nEntry; /* Total number of entries in hash table */ @@ -176977,8 +180696,8 @@ struct SessionTable { ** statement. ** ** For a DELETE change, all fields within the record except those associated -** with PRIMARY KEY columns are set to "undefined". The PRIMARY KEY fields -** contain the values identifying the row to delete. +** with PRIMARY KEY columns are omitted. The PRIMARY KEY fields contain the +** values identifying the row to delete. ** ** For an UPDATE change, all fields except those associated with PRIMARY KEY ** columns and columns that are modified by the UPDATE are set to "undefined". @@ -177243,6 +180962,7 @@ static int sessionPreupdateHash( h = sessionHashAppendBlob(h, n, z); }else{ assert( eType==SQLITE_NULL ); + assert( pTab->bStat1==0 || i!=1 ); *pbNullPK = 1; } } @@ -177260,7 +180980,7 @@ static int sessionPreupdateHash( static int sessionSerialLen(u8 *a){ int e = *a; int n; - if( e==0 ) return 1; + if( e==0 || e==0xFF ) return 1; if( e==SQLITE_NULL ) return 1; if( e==SQLITE_INTEGER || e==SQLITE_FLOAT ) return 9; return sessionVarintGet(&a[1], &n) + 1 + n; @@ -177340,7 +181060,7 @@ static int sessionChangeEqual( int n1 = sessionSerialLen(a1); int n2 = sessionSerialLen(a2); - if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){ + if( n1!=n2 || memcmp(a1, a2, n1) ){ return 0; } a1 += n1; @@ -177583,9 +181303,8 @@ static int sessionPreupdateEqual( }else{ z = sqlite3_value_blob(pVal); } - if( memcmp(a, z, n) ) return 0; + if( n>0 && memcmp(a, z, n) ) return 0; a += n; - break; } } } @@ -177641,9 +181360,7 @@ static int sessionGrowHash(int bPatchset, SessionTable *pTab){ /* ** This function queries the database for the names of the columns of table -** zThis, in schema zDb. It is expected that the table has nCol columns. If -** not, SQLITE_SCHEMA is returned and none of the output variables are -** populated. +** zThis, in schema zDb. ** ** Otherwise, if they are not NULL, variable *pnCol is set to the number ** of columns in the database table and variable *pzTab is set to point to a @@ -177664,9 +181381,7 @@ static int sessionGrowHash(int bPatchset, SessionTable *pTab){ ** *pabPK = {1, 0, 0, 1} ** ** All returned buffers are part of the same single allocation, which must -** be freed using sqlite3_free() by the caller. If pazCol was not NULL, then -** pointer *pazCol should be freed to release all memory. Otherwise, pointer -** *pabPK. It is illegal for both pazCol and pabPK to be NULL. +** be freed using sqlite3_free() by the caller */ static int sessionTableInfo( sqlite3 *db, /* Database connection */ @@ -177691,7 +181406,23 @@ static int sessionTableInfo( assert( pazCol && pabPK ); nThis = sqlite3Strlen30(zThis); - zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis); + if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){ + rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0); + if( rc==SQLITE_OK ){ + /* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */ + zPragma = sqlite3_mprintf( + "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL " + "SELECT 1, 'idx', '', 0, '', 2 UNION ALL " + "SELECT 2, 'stat', '', 0, '', 0" + ); + }else if( rc==SQLITE_ERROR ){ + zPragma = sqlite3_mprintf(""); + }else{ + return rc; + } + }else{ + zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis); + } if( !zPragma ) return SQLITE_NOMEM; rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0); @@ -177783,11 +181514,55 @@ static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){ break; } } + if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){ + pTab->bStat1 = 1; + } } } return (pSession->rc || pTab->abPK==0); } +/* +** Versions of the four methods in object SessionHook for use with the +** sqlite_stat1 table. The purpose of this is to substitute a zero-length +** blob each time a NULL value is read from the "idx" column of the +** sqlite_stat1 table. +*/ +typedef struct SessionStat1Ctx SessionStat1Ctx; +struct SessionStat1Ctx { + SessionHook hook; + sqlite3_session *pSession; +}; +static int sessionStat1Old(void *pCtx, int iCol, sqlite3_value **ppVal){ + SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx; + sqlite3_value *pVal = 0; + int rc = p->hook.xOld(p->hook.pCtx, iCol, &pVal); + if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){ + pVal = p->pSession->pZeroBlob; + } + *ppVal = pVal; + return rc; +} +static int sessionStat1New(void *pCtx, int iCol, sqlite3_value **ppVal){ + SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx; + sqlite3_value *pVal = 0; + int rc = p->hook.xNew(p->hook.pCtx, iCol, &pVal); + if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){ + pVal = p->pSession->pZeroBlob; + } + *ppVal = pVal; + return rc; +} +static int sessionStat1Count(void *pCtx){ + SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx; + return p->hook.xCount(p->hook.pCtx); +} +static int sessionStat1Depth(void *pCtx){ + SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx; + return p->hook.xDepth(p->hook.pCtx); +} + + /* ** This function is only called from with a pre-update-hook reporting a ** change on table pTab (attached to session pSession). The type of change @@ -177804,6 +181579,7 @@ static void sessionPreupdateOneChange( int iHash; int bNull = 0; int rc = SQLITE_OK; + SessionStat1Ctx stat1 = {0}; if( pSession->rc ) return; @@ -177823,6 +181599,25 @@ static void sessionPreupdateOneChange( return; } + if( pTab->bStat1 ){ + stat1.hook = pSession->hook; + stat1.pSession = pSession; + pSession->hook.pCtx = (void*)&stat1; + pSession->hook.xNew = sessionStat1New; + pSession->hook.xOld = sessionStat1Old; + pSession->hook.xCount = sessionStat1Count; + pSession->hook.xDepth = sessionStat1Depth; + if( pSession->pZeroBlob==0 ){ + sqlite3_value *p = sqlite3ValueNew(0); + if( p==0 ){ + rc = SQLITE_NOMEM; + goto error_out; + } + sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC); + pSession->pZeroBlob = p; + } + } + /* Calculate the hash-key for this change. If the primary key of the row ** includes a NULL value, exit early. Such changes are ignored by the ** session module. */ @@ -177912,6 +181707,9 @@ static void sessionPreupdateOneChange( /* If an error has occurred, mark the session object as failed. */ error_out: + if( pTab->bStat1 ){ + pSession->hook = stat1.hook; + } if( rc!=SQLITE_OK ){ pSession->rc = rc; } @@ -178248,7 +182046,6 @@ SQLITE_API int sqlite3session_diff( if( abPK[i] ) bHasPk = 1; } } - } sqlite3_free((char*)azCol); if( bMismatch ){ @@ -178374,6 +182171,7 @@ SQLITE_API void sqlite3session_delete(sqlite3_session *pSession){ } } sqlite3_mutex_leave(sqlite3_db_mutex(db)); + sqlite3ValueFree(pSession->pZeroBlob); /* Delete all attached table objects. And the contents of their ** associated hash-tables. */ @@ -178841,28 +182639,42 @@ static int sessionSelectStmt( sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */ ){ int rc = SQLITE_OK; - int i; - const char *zSep = ""; - SessionBuffer buf = {0, 0, 0}; + char *zSql = 0; + int nSql = -1; - sessionAppendStr(&buf, "SELECT * FROM ", &rc); - sessionAppendIdent(&buf, zDb, &rc); - sessionAppendStr(&buf, ".", &rc); - sessionAppendIdent(&buf, zTab, &rc); - sessionAppendStr(&buf, " WHERE ", &rc); - for(i=0; ibEof && pIn->xInput && pIn->iNext>=SESSIONS_STRM_CHUNK_SIZE ){ + if( pIn->xInput && pIn->iNext>=SESSIONS_STRM_CHUNK_SIZE ){ int nMove = pIn->buf.nBuf - pIn->iNext; assert( nMove>=0 ); if( nMove>0 ){ @@ -179373,13 +183185,16 @@ static int sessionReadRecord( if( abPK && abPK[i]==0 ) continue; rc = sessionInputBuffer(pIn, 9); if( rc==SQLITE_OK ){ - eType = pIn->aData[pIn->iNext++]; - } - - assert( apOut[i]==0 ); - if( eType ){ - apOut[i] = sqlite3ValueNew(0); - if( !apOut[i] ) rc = SQLITE_NOMEM; + if( pIn->iNext>=pIn->nData ){ + rc = SQLITE_CORRUPT_BKPT; + }else{ + eType = pIn->aData[pIn->iNext++]; + assert( apOut[i]==0 ); + if( eType ){ + apOut[i] = sqlite3ValueNew(0); + if( !apOut[i] ) rc = SQLITE_NOMEM; + } + } } if( rc==SQLITE_OK ){ @@ -179389,10 +183204,14 @@ static int sessionReadRecord( pIn->iNext += sessionVarintGet(aVal, &nByte); rc = sessionInputBuffer(pIn, nByte); if( rc==SQLITE_OK ){ - u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0); - rc = sessionValueSetStr(apOut[i],&pIn->aData[pIn->iNext],nByte,enc); + if( nByte<0 || nByte>pIn->nData-pIn->iNext ){ + rc = SQLITE_CORRUPT_BKPT; + }else{ + u8 enc = (eType==SQLITE_TEXT ? SQLITE_UTF8 : 0); + rc = sessionValueSetStr(apOut[i],&pIn->aData[pIn->iNext],nByte,enc); + pIn->iNext += nByte; + } } - pIn->iNext += nByte; } if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ sqlite3_int64 v = sessionGetI64(aVal); @@ -179432,8 +183251,19 @@ static int sessionChangesetBufferTblhdr(SessionInput *pIn, int *pnByte){ rc = sessionInputBuffer(pIn, 9); if( rc==SQLITE_OK ){ nRead += sessionVarintGet(&pIn->aData[pIn->iNext + nRead], &nCol); - rc = sessionInputBuffer(pIn, nRead+nCol+100); - nRead += nCol; + /* The hard upper limit for the number of columns in an SQLite + ** database table is, according to sqliteLimit.h, 32676. So + ** consider any table-header that purports to have more than 65536 + ** columns to be corrupt. This is convenient because otherwise, + ** if the (nCol>65536) condition below were omitted, a sufficiently + ** large value for nCol may cause nRead to wrap around and become + ** negative. Leading to a crash. */ + if( nCol<0 || nCol>65536 ){ + rc = SQLITE_CORRUPT_BKPT; + }else{ + rc = sessionInputBuffer(pIn, nRead+nCol+100); + nRead += nCol; + } } while( rc==SQLITE_OK ){ @@ -179510,11 +183340,15 @@ static int sessionChangesetReadTblhdr(sqlite3_changeset_iter *p){ int nByte; int nVarint; nVarint = sessionVarintGet(&p->in.aData[p->in.iNext], &p->nCol); - nCopy -= nVarint; - p->in.iNext += nVarint; - nByte = p->nCol * sizeof(sqlite3_value*) * 2 + nCopy; - p->tblhdr.nBuf = 0; - sessionBufferGrow(&p->tblhdr, nByte, &rc); + if( p->nCol>0 ){ + nCopy -= nVarint; + p->in.iNext += nVarint; + nByte = p->nCol * sizeof(sqlite3_value*) * 2 + nCopy; + p->tblhdr.nBuf = 0; + sessionBufferGrow(&p->tblhdr, nByte, &rc); + }else{ + rc = SQLITE_CORRUPT_BKPT; + } } if( rc==SQLITE_OK ){ @@ -179549,7 +183383,8 @@ static int sessionChangesetReadTblhdr(sqlite3_changeset_iter *p){ static int sessionChangesetNext( sqlite3_changeset_iter *p, /* Changeset iterator */ u8 **paRec, /* If non-NULL, store record pointer here */ - int *pnRec /* If non-NULL, store size of record here */ + int *pnRec, /* If non-NULL, store size of record here */ + int *pbNew /* If non-NULL, true if new table */ ){ int i; u8 op; @@ -179584,6 +183419,7 @@ static int sessionChangesetNext( op = p->in.aData[p->in.iNext++]; while( op=='T' || op=='P' ){ + if( pbNew ) *pbNew = 1; p->bPatchset = (op=='P'); if( sessionChangesetReadTblhdr(p) ) return p->rc; if( (p->rc = sessionInputBuffer(&p->in, 2)) ) return p->rc; @@ -179592,6 +183428,13 @@ static int sessionChangesetNext( op = p->in.aData[p->in.iNext++]; } + if( p->zTab==0 ){ + /* The first record in the changeset is not a table header. Must be a + ** corrupt changeset. */ + assert( p->in.iNext==1 ); + return (p->rc = SQLITE_CORRUPT_BKPT); + } + p->op = op; p->bIndirect = p->in.aData[p->in.iNext++]; if( p->op!=SQLITE_UPDATE && p->op!=SQLITE_DELETE && p->op!=SQLITE_INSERT ){ @@ -179634,9 +183477,9 @@ static int sessionChangesetNext( ** new.* to old.*, to accommodate the code that reads these arrays. */ for(i=0; inCol; i++){ assert( p->apValue[i]==0 ); - assert( p->abPK[i]==0 || p->apValue[i+p->nCol] ); if( p->abPK[i] ){ p->apValue[i] = p->apValue[i+p->nCol]; + if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT); p->apValue[i+p->nCol] = 0; } } @@ -179655,7 +183498,7 @@ static int sessionChangesetNext( ** callback by changeset_apply(). */ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *p){ - return sessionChangesetNext(p, 0, 0); + return sessionChangesetNext(p, 0, 0, 0); } /* @@ -180031,9 +183874,11 @@ struct SessionApplyCtx { int nCol; /* Size of azCol[] and abPK[] arrays */ const char **azCol; /* Array of column names */ u8 *abPK; /* Boolean array - true if column is in PK */ - + int bStat1; /* True if table is sqlite_stat1 */ int bDeferConstraints; /* True to defer constraints */ SessionBuffer constraints; /* Deferred constraints are stored here */ + SessionBuffer rebase; /* Rebase information (if any) here */ + int bRebaseStarted; /* If table header is already in rebase */ }; /* @@ -180201,6 +184046,7 @@ static int sessionUpdateRow( return rc; } + /* ** Formulate and prepare an SQL statement to query table zTab by primary ** key. Assuming the following table structure: @@ -180262,6 +184108,46 @@ static int sessionInsertRow( return rc; } +static int sessionPrepare(sqlite3 *db, sqlite3_stmt **pp, const char *zSql){ + return sqlite3_prepare_v2(db, zSql, -1, pp, 0); +} + +/* +** Prepare statements for applying changes to the sqlite_stat1 table. +** These are similar to those created by sessionSelectRow(), +** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for +** other tables. +*/ +static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){ + int rc = sessionSelectRow(db, "sqlite_stat1", p); + if( rc==SQLITE_OK ){ + rc = sessionPrepare(db, &p->pInsert, + "INSERT INTO main.sqlite_stat1 VALUES(?1, " + "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, " + "?3)" + ); + } + if( rc==SQLITE_OK ){ + rc = sessionPrepare(db, &p->pUpdate, + "UPDATE main.sqlite_stat1 SET " + "tbl = CASE WHEN ?2 THEN ?3 ELSE tbl END, " + "idx = CASE WHEN ?5 THEN ?6 ELSE idx END, " + "stat = CASE WHEN ?8 THEN ?9 ELSE stat END " + "WHERE tbl=?1 AND idx IS " + "CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END " + "AND (?10 OR ?8=0 OR stat IS ?7)" + ); + } + if( rc==SQLITE_OK ){ + rc = sessionPrepare(db, &p->pDelete, + "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS " + "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END " + "AND (?4 OR stat IS ?3)" + ); + } + return rc; +} + /* ** A wrapper around sqlite3_bind_value() that detects an extra problem. ** See comments in the body of this function for details. @@ -180319,7 +184205,13 @@ static int sessionBindRow( if( !abPK || abPK[i] ){ sqlite3_value *pVal; (void)xValue(pIter, i, &pVal); - rc = sessionBindValue(pStmt, i+1, pVal); + if( pVal==0 ){ + /* The value in the changeset was "undefined". This indicates a + ** corrupt changeset blob. */ + rc = SQLITE_CORRUPT_BKPT; + }else{ + rc = sessionBindValue(pStmt, i+1, pVal); + } } } return rc; @@ -180367,6 +184259,54 @@ static int sessionSeekToRow( return rc; } +/* +** This function is called from within sqlite3changset_apply_v2() when +** a conflict is encountered and resolved using conflict resolution +** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE).. +** It adds a conflict resolution record to the buffer in +** SessionApplyCtx.rebase, which will eventually be returned to the caller +** of apply_v2() as the "rebase" buffer. +** +** Return SQLITE_OK if successful, or an SQLite error code otherwise. +*/ +static int sessionRebaseAdd( + SessionApplyCtx *p, /* Apply context */ + int eType, /* Conflict resolution (OMIT or REPLACE) */ + sqlite3_changeset_iter *pIter /* Iterator pointing at current change */ +){ + int rc = SQLITE_OK; + int i; + int eOp = pIter->op; + if( p->bRebaseStarted==0 ){ + /* Append a table-header to the rebase buffer */ + const char *zTab = pIter->zTab; + sessionAppendByte(&p->rebase, 'T', &rc); + sessionAppendVarint(&p->rebase, p->nCol, &rc); + sessionAppendBlob(&p->rebase, p->abPK, p->nCol, &rc); + sessionAppendBlob(&p->rebase, (u8*)zTab, (int)strlen(zTab)+1, &rc); + p->bRebaseStarted = 1; + } + + assert( eType==SQLITE_CHANGESET_REPLACE||eType==SQLITE_CHANGESET_OMIT ); + assert( eOp==SQLITE_DELETE || eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE ); + + sessionAppendByte(&p->rebase, + (eOp==SQLITE_DELETE ? SQLITE_DELETE : SQLITE_INSERT), &rc + ); + sessionAppendByte(&p->rebase, (eType==SQLITE_CHANGESET_REPLACE), &rc); + for(i=0; inCol; i++){ + sqlite3_value *pVal = 0; + if( eOp==SQLITE_DELETE || (eOp==SQLITE_UPDATE && p->abPK[i]) ){ + sqlite3changeset_old(pIter, i, &pVal); + }else{ + sqlite3changeset_new(pIter, i, &pVal); + } + sessionAppendValue(&p->rebase, pVal, &rc); + } + + return rc; +} + /* ** Invoke the conflict handler for the change that the changeset iterator ** currently points to. @@ -180442,7 +184382,7 @@ static int sessionConflictHandler( u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent]; int nBlob = pIter->in.iNext - pIter->in.iCurrent; sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc); - res = SQLITE_CHANGESET_OMIT; + return SQLITE_OK; }else{ /* No other row with the new.* primary key. */ res = xConflict(pCtx, eType+1, pIter); @@ -180468,6 +184408,9 @@ static int sessionConflictHandler( rc = SQLITE_MISUSE; break; } + if( rc==SQLITE_OK ){ + rc = sessionRebaseAdd(p, res, pIter); + } } return rc; @@ -180592,11 +184535,25 @@ static int sessionApplyOneOp( }else{ assert( op==SQLITE_INSERT ); - rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert); - if( rc!=SQLITE_OK ) return rc; + if( p->bStat1 ){ + /* Check if there is a conflicting row. For sqlite_stat1, this needs + ** to be done using a SELECT, as there is no PRIMARY KEY in the + ** database schema to throw an exception if a duplicate is inserted. */ + rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect); + if( rc==SQLITE_ROW ){ + rc = SQLITE_CONSTRAINT; + sqlite3_reset(p->pSelect); + } + } + + if( rc==SQLITE_OK ){ + rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert); + if( rc!=SQLITE_OK ) return rc; + + sqlite3_step(p->pInsert); + rc = sqlite3_reset(p->pInsert); + } - sqlite3_step(p->pInsert); - rc = sqlite3_reset(p->pInsert); if( (rc&0xff)==SQLITE_CONSTRAINT ){ rc = sessionConflictHandler( SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace @@ -180629,42 +184586,42 @@ static int sessionApplyOneWithRetry( int rc; rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, &bReplace, &bRetry); - assert( rc==SQLITE_OK || (bRetry==0 && bReplace==0) ); - - /* If the bRetry flag is set, the change has not been applied due to an - ** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and - ** a row with the correct PK is present in the db, but one or more other - ** fields do not contain the expected values) and the conflict handler - ** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation, - ** but pass NULL as the final argument so that sessionApplyOneOp() ignores - ** the SQLITE_CHANGESET_DATA problem. */ - if( bRetry ){ - assert( pIter->op==SQLITE_UPDATE || pIter->op==SQLITE_DELETE ); - rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0); - } - - /* If the bReplace flag is set, the change is an INSERT that has not - ** been performed because the database already contains a row with the - ** specified primary key and the conflict handler returned - ** SQLITE_CHANGESET_REPLACE. In this case remove the conflicting row - ** before reattempting the INSERT. */ - else if( bReplace ){ - assert( pIter->op==SQLITE_INSERT ); - rc = sqlite3_exec(db, "SAVEPOINT replace_op", 0, 0, 0); - if( rc==SQLITE_OK ){ - rc = sessionBindRow(pIter, - sqlite3changeset_new, pApply->nCol, pApply->abPK, pApply->pDelete); - sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1); - } - if( rc==SQLITE_OK ){ - sqlite3_step(pApply->pDelete); - rc = sqlite3_reset(pApply->pDelete); - } - if( rc==SQLITE_OK ){ + if( rc==SQLITE_OK ){ + /* If the bRetry flag is set, the change has not been applied due to an + ** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and + ** a row with the correct PK is present in the db, but one or more other + ** fields do not contain the expected values) and the conflict handler + ** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation, + ** but pass NULL as the final argument so that sessionApplyOneOp() ignores + ** the SQLITE_CHANGESET_DATA problem. */ + if( bRetry ){ + assert( pIter->op==SQLITE_UPDATE || pIter->op==SQLITE_DELETE ); rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0); } - if( rc==SQLITE_OK ){ - rc = sqlite3_exec(db, "RELEASE replace_op", 0, 0, 0); + + /* If the bReplace flag is set, the change is an INSERT that has not + ** been performed because the database already contains a row with the + ** specified primary key and the conflict handler returned + ** SQLITE_CHANGESET_REPLACE. In this case remove the conflicting row + ** before reattempting the INSERT. */ + else if( bReplace ){ + assert( pIter->op==SQLITE_INSERT ); + rc = sqlite3_exec(db, "SAVEPOINT replace_op", 0, 0, 0); + if( rc==SQLITE_OK ){ + rc = sessionBindRow(pIter, + sqlite3changeset_new, pApply->nCol, pApply->abPK, pApply->pDelete); + sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1); + } + if( rc==SQLITE_OK ){ + sqlite3_step(pApply->pDelete); + rc = sqlite3_reset(pApply->pDelete); + } + if( rc==SQLITE_OK ){ + rc = sessionApplyOneOp(pIter, pApply, xConflict, pCtx, 0, 0); + } + if( rc==SQLITE_OK ){ + rc = sqlite3_exec(db, "RELEASE replace_op", 0, 0, 0); + } } } @@ -180740,10 +184697,12 @@ static int sessionChangesetApply( int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ sqlite3_changeset_iter *p /* Handle describing change and conflict */ ), - void *pCtx /* First argument passed to xConflict */ + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, /* OUT: Rebase information */ + int flags /* SESSION_APPLY_XXX flags */ ){ int schemaMismatch = 0; - int rc; /* Return code */ + int rc = SQLITE_OK; /* Return code */ const char *zTab = 0; /* Name of current table */ int nTab = 0; /* Result of sqlite3Strlen30(zTab) */ SessionApplyCtx sApply; /* changeset_apply() context object */ @@ -180754,7 +184713,9 @@ static int sessionChangesetApply( pIter->in.bNoDiscard = 1; memset(&sApply, 0, sizeof(sApply)); sqlite3_mutex_enter(sqlite3_db_mutex(db)); - rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); + if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ + rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); + } if( rc==SQLITE_OK ){ rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0); } @@ -180778,9 +184739,18 @@ static int sessionChangesetApply( sqlite3_finalize(sApply.pUpdate); sqlite3_finalize(sApply.pInsert); sqlite3_finalize(sApply.pSelect); - memset(&sApply, 0, sizeof(sApply)); sApply.db = db; + sApply.pDelete = 0; + sApply.pUpdate = 0; + sApply.pInsert = 0; + sApply.pSelect = 0; + sApply.nCol = 0; + sApply.azCol = 0; + sApply.abPK = 0; + sApply.bStat1 = 0; sApply.bDeferConstraints = 1; + sApply.bRebaseStarted = 0; + memset(&sApply.constraints, 0, sizeof(SessionBuffer)); /* If an xFilter() callback was specified, invoke it now. If the ** xFilter callback returns zero, skip this table. If it returns @@ -180829,12 +184799,20 @@ static int sessionChangesetApply( } else{ sApply.nCol = nCol; - if((rc = sessionSelectRow(db, zTab, &sApply)) - || (rc = sessionUpdateRow(db, zTab, &sApply)) - || (rc = sessionDeleteRow(db, zTab, &sApply)) - || (rc = sessionInsertRow(db, zTab, &sApply)) - ){ - break; + if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){ + if( (rc = sessionStat1Sql(db, &sApply) ) ){ + break; + } + sApply.bStat1 = 1; + }else{ + if((rc = sessionSelectRow(db, zTab, &sApply)) + || (rc = sessionUpdateRow(db, zTab, &sApply)) + || (rc = sessionDeleteRow(db, zTab, &sApply)) + || (rc = sessionInsertRow(db, zTab, &sApply)) + ){ + break; + } + sApply.bStat1 = 0; } } nTab = sqlite3Strlen30(zTab); @@ -180875,23 +184853,62 @@ static int sessionChangesetApply( } sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0); - if( rc==SQLITE_OK ){ - rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); - }else{ - sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0); - sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); + if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ + if( rc==SQLITE_OK ){ + rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); + }else{ + sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0); + sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); + } } + if( rc==SQLITE_OK && bPatchset==0 && ppRebase && pnRebase ){ + *ppRebase = (void*)sApply.rebase.aBuf; + *pnRebase = sApply.rebase.nBuf; + sApply.rebase.aBuf = 0; + } sqlite3_finalize(sApply.pInsert); sqlite3_finalize(sApply.pDelete); sqlite3_finalize(sApply.pUpdate); sqlite3_finalize(sApply.pSelect); sqlite3_free((char*)sApply.azCol); /* cast works around VC++ bug */ sqlite3_free((char*)sApply.constraints.aBuf); + sqlite3_free((char*)sApply.rebase.aBuf); sqlite3_mutex_leave(sqlite3_db_mutex(db)); return rc; } +/* +** Apply the changeset passed via pChangeset/nChangeset to the main +** database attached to handle "db". +*/ +SQLITE_API int sqlite3changeset_apply_v2( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, + int flags +){ + sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ + int rc = sqlite3changeset_start(&pIter, nChangeset, pChangeset); + if( rc==SQLITE_OK ){ + rc = sessionChangesetApply( + db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags + ); + } + return rc; +} + /* ** Apply the changeset passed via pChangeset/nChangeset to the main database ** attached to handle "db". Invoke the supplied conflict handler callback @@ -180912,12 +184929,9 @@ SQLITE_API int sqlite3changeset_apply( ), void *pCtx /* First argument passed to xConflict */ ){ - sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ - int rc = sqlite3changeset_start(&pIter, nChangeset, pChangeset); - if( rc==SQLITE_OK ){ - rc = sessionChangesetApply(db, pIter, xFilter, xConflict, pCtx); - } - return rc; + return sqlite3changeset_apply_v2( + db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0 + ); } /* @@ -180925,6 +184939,32 @@ SQLITE_API int sqlite3changeset_apply( ** attached to handle "db". Invoke the supplied conflict handler callback ** to resolve any conflicts encountered while applying the change. */ +SQLITE_API int sqlite3changeset_apply_v2_strm( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, + int flags +){ + sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ + int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn); + if( rc==SQLITE_OK ){ + rc = sessionChangesetApply( + db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags + ); + } + return rc; +} SQLITE_API int sqlite3changeset_apply_strm( sqlite3 *db, /* Apply change to "main" db of this handle */ int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ @@ -180940,12 +184980,9 @@ SQLITE_API int sqlite3changeset_apply_strm( ), void *pCtx /* First argument passed to xConflict */ ){ - sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ - int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn); - if( rc==SQLITE_OK ){ - rc = sessionChangesetApply(db, pIter, xFilter, xConflict, pCtx); - } - return rc; + return sqlite3changeset_apply_v2_strm( + db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0 + ); } /* @@ -180964,6 +185001,7 @@ struct sqlite3_changegroup { */ static int sessionChangeMerge( SessionTable *pTab, /* Table structure */ + int bRebase, /* True for a rebase hash-table */ int bPatchset, /* True for patchsets */ SessionChange *pExist, /* Existing change */ int op2, /* Second change operation */ @@ -180973,6 +185011,7 @@ static int sessionChangeMerge( SessionChange **ppNew /* OUT: Merged change */ ){ SessionChange *pNew = 0; + int rc = SQLITE_OK; if( !pExist ){ pNew = (SessionChange *)sqlite3_malloc(sizeof(SessionChange) + nRec); @@ -180982,9 +185021,66 @@ static int sessionChangeMerge( memset(pNew, 0, sizeof(SessionChange)); pNew->op = op2; pNew->bIndirect = bIndirect; - pNew->nRecord = nRec; pNew->aRecord = (u8*)&pNew[1]; - memcpy(pNew->aRecord, aRec, nRec); + if( bIndirect==0 || bRebase==0 ){ + pNew->nRecord = nRec; + memcpy(pNew->aRecord, aRec, nRec); + }else{ + int i; + u8 *pIn = aRec; + u8 *pOut = pNew->aRecord; + for(i=0; inCol; i++){ + int nIn = sessionSerialLen(pIn); + if( *pIn==0 ){ + *pOut++ = 0; + }else if( pTab->abPK[i]==0 ){ + *pOut++ = 0xFF; + }else{ + memcpy(pOut, pIn, nIn); + pOut += nIn; + } + pIn += nIn; + } + pNew->nRecord = pOut - pNew->aRecord; + } + }else if( bRebase ){ + if( pExist->op==SQLITE_DELETE && pExist->bIndirect ){ + *ppNew = pExist; + }else{ + int nByte = nRec + pExist->nRecord + sizeof(SessionChange); + pNew = (SessionChange*)sqlite3_malloc(nByte); + if( pNew==0 ){ + rc = SQLITE_NOMEM; + }else{ + int i; + u8 *a1 = pExist->aRecord; + u8 *a2 = aRec; + u8 *pOut; + + memset(pNew, 0, nByte); + pNew->bIndirect = bIndirect || pExist->bIndirect; + pNew->op = op2; + pOut = pNew->aRecord = (u8*)&pNew[1]; + + for(i=0; inCol; i++){ + int n1 = sessionSerialLen(a1); + int n2 = sessionSerialLen(a2); + if( *a1==0xFF || (pTab->abPK[i]==0 && bIndirect) ){ + *pOut++ = 0xFF; + }else if( *a2==0 ){ + memcpy(pOut, a1, n1); + pOut += n1; + }else{ + memcpy(pOut, a2, n2); + pOut += n2; + } + a1 += n1; + a2 += n2; + } + pNew->nRecord = pOut - pNew->aRecord; + } + sqlite3_free(pExist); + } }else{ int op1 = pExist->op; @@ -181078,7 +185174,7 @@ static int sessionChangeMerge( } *ppNew = pNew; - return SQLITE_OK; + return rc; } /* @@ -181087,15 +185183,15 @@ static int sessionChangeMerge( */ static int sessionChangesetToHash( sqlite3_changeset_iter *pIter, /* Iterator to read from */ - sqlite3_changegroup *pGrp /* Changegroup object to add changeset to */ + sqlite3_changegroup *pGrp, /* Changegroup object to add changeset to */ + int bRebase /* True if hash table is for rebasing */ ){ u8 *aRec; int nRec; int rc = SQLITE_OK; SessionTable *pTab = 0; - - while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec) ){ + while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, 0) ){ const char *zNew; int nCol; int op; @@ -181175,7 +185271,7 @@ static int sessionChangesetToHash( } } - rc = sessionChangeMerge(pTab, + rc = sessionChangeMerge(pTab, bRebase, pIter->bPatchset, pExist, op, bIndirect, aRec, nRec, &pChange ); if( rc ) break; @@ -181283,7 +185379,7 @@ SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup *pGrp, int nData, void rc = sqlite3changeset_start(&pIter, nData, pData); if( rc==SQLITE_OK ){ - rc = sessionChangesetToHash(pIter, pGrp); + rc = sessionChangesetToHash(pIter, pGrp, 0); } sqlite3changeset_finalize(pIter); return rc; @@ -181314,7 +185410,7 @@ SQLITE_API int sqlite3changegroup_add_strm( rc = sqlite3changeset_start_strm(&pIter, xInput, pIn); if( rc==SQLITE_OK ){ - rc = sessionChangesetToHash(pIter, pGrp); + rc = sessionChangesetToHash(pIter, pGrp, 0); } sqlite3changeset_finalize(pIter); return rc; @@ -181399,6 +185495,349 @@ SQLITE_API int sqlite3changeset_concat_strm( return rc; } +/* +** Changeset rebaser handle. +*/ +struct sqlite3_rebaser { + sqlite3_changegroup grp; /* Hash table */ +}; + +/* +** Buffers a1 and a2 must both contain a sessions module record nCol +** fields in size. This function appends an nCol sessions module +** record to buffer pBuf that is a copy of a1, except that for +** each field that is undefined in a1[], swap in the field from a2[]. +*/ +static void sessionAppendRecordMerge( + SessionBuffer *pBuf, /* Buffer to append to */ + int nCol, /* Number of columns in each record */ + u8 *a1, int n1, /* Record 1 */ + u8 *a2, int n2, /* Record 2 */ + int *pRc /* IN/OUT: error code */ +){ + sessionBufferGrow(pBuf, n1+n2, pRc); + if( *pRc==SQLITE_OK ){ + int i; + u8 *pOut = &pBuf->aBuf[pBuf->nBuf]; + for(i=0; inBuf = pOut-pBuf->aBuf; + assert( pBuf->nBuf<=pBuf->nAlloc ); + } +} + +/* +** This function is called when rebasing a local UPDATE change against one +** or more remote UPDATE changes. The aRec/nRec buffer contains the current +** old.* and new.* records for the change. The rebase buffer (a single +** record) is in aChange/nChange. The rebased change is appended to buffer +** pBuf. +** +** Rebasing the UPDATE involves: +** +** * Removing any changes to fields for which the corresponding field +** in the rebase buffer is set to "replaced" (type 0xFF). If this +** means the UPDATE change updates no fields, nothing is appended +** to the output buffer. +** +** * For each field modified by the local change for which the +** corresponding field in the rebase buffer is not "undefined" (0x00) +** or "replaced" (0xFF), the old.* value is replaced by the value +** in the rebase buffer. +*/ +static void sessionAppendPartialUpdate( + SessionBuffer *pBuf, /* Append record here */ + sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */ + u8 *aRec, int nRec, /* Local change */ + u8 *aChange, int nChange, /* Record to rebase against */ + int *pRc /* IN/OUT: Return Code */ +){ + sessionBufferGrow(pBuf, 2+nRec+nChange, pRc); + if( *pRc==SQLITE_OK ){ + int bData = 0; + u8 *pOut = &pBuf->aBuf[pBuf->nBuf]; + int i; + u8 *a1 = aRec; + u8 *a2 = aChange; + + *pOut++ = SQLITE_UPDATE; + *pOut++ = pIter->bIndirect; + for(i=0; inCol; i++){ + int n1 = sessionSerialLen(a1); + int n2 = sessionSerialLen(a2); + if( pIter->abPK[i] || a2[0]==0 ){ + if( !pIter->abPK[i] ) bData = 1; + memcpy(pOut, a1, n1); + pOut += n1; + }else if( a2[0]!=0xFF ){ + bData = 1; + memcpy(pOut, a2, n2); + pOut += n2; + }else{ + *pOut++ = '\0'; + } + a1 += n1; + a2 += n2; + } + if( bData ){ + a2 = aChange; + for(i=0; inCol; i++){ + int n1 = sessionSerialLen(a1); + int n2 = sessionSerialLen(a2); + if( pIter->abPK[i] || a2[0]!=0xFF ){ + memcpy(pOut, a1, n1); + pOut += n1; + }else{ + *pOut++ = '\0'; + } + a1 += n1; + a2 += n2; + } + pBuf->nBuf = (pOut - pBuf->aBuf); + } + } +} + +/* +** pIter is configured to iterate through a changeset. This function rebases +** that changeset according to the current configuration of the rebaser +** object passed as the first argument. If no error occurs and argument xOutput +** is not NULL, then the changeset is returned to the caller by invoking +** xOutput zero or more times and SQLITE_OK returned. Or, if xOutput is NULL, +** then (*ppOut) is set to point to a buffer containing the rebased changeset +** before this function returns. In this case (*pnOut) is set to the size of +** the buffer in bytes. It is the responsibility of the caller to eventually +** free the (*ppOut) buffer using sqlite3_free(). +** +** If an error occurs, an SQLite error code is returned. If ppOut and +** pnOut are not NULL, then the two output parameters are set to 0 before +** returning. +*/ +static int sessionRebase( + sqlite3_rebaser *p, /* Rebaser hash table */ + sqlite3_changeset_iter *pIter, /* Input data */ + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut, /* Context for xOutput callback */ + int *pnOut, /* OUT: Number of bytes in output changeset */ + void **ppOut /* OUT: Inverse of pChangeset */ +){ + int rc = SQLITE_OK; + u8 *aRec = 0; + int nRec = 0; + int bNew = 0; + SessionTable *pTab = 0; + SessionBuffer sOut = {0,0,0}; + + while( SQLITE_ROW==sessionChangesetNext(pIter, &aRec, &nRec, &bNew) ){ + SessionChange *pChange = 0; + int bDone = 0; + + if( bNew ){ + const char *zTab = pIter->zTab; + for(pTab=p->grp.pList; pTab; pTab=pTab->pNext){ + if( 0==sqlite3_stricmp(pTab->zName, zTab) ) break; + } + bNew = 0; + + /* A patchset may not be rebased */ + if( pIter->bPatchset ){ + rc = SQLITE_ERROR; + } + + /* Append a table header to the output for this new table */ + sessionAppendByte(&sOut, pIter->bPatchset ? 'P' : 'T', &rc); + sessionAppendVarint(&sOut, pIter->nCol, &rc); + sessionAppendBlob(&sOut, pIter->abPK, pIter->nCol, &rc); + sessionAppendBlob(&sOut,(u8*)pIter->zTab,(int)strlen(pIter->zTab)+1,&rc); + } + + if( pTab && rc==SQLITE_OK ){ + int iHash = sessionChangeHash(pTab, 0, aRec, pTab->nChange); + + for(pChange=pTab->apChange[iHash]; pChange; pChange=pChange->pNext){ + if( sessionChangeEqual(pTab, 0, aRec, 0, pChange->aRecord) ){ + break; + } + } + } + + if( pChange ){ + assert( pChange->op==SQLITE_DELETE || pChange->op==SQLITE_INSERT ); + switch( pIter->op ){ + case SQLITE_INSERT: + if( pChange->op==SQLITE_INSERT ){ + bDone = 1; + if( pChange->bIndirect==0 ){ + sessionAppendByte(&sOut, SQLITE_UPDATE, &rc); + sessionAppendByte(&sOut, pIter->bIndirect, &rc); + sessionAppendBlob(&sOut, pChange->aRecord, pChange->nRecord, &rc); + sessionAppendBlob(&sOut, aRec, nRec, &rc); + } + } + break; + + case SQLITE_UPDATE: + bDone = 1; + if( pChange->op==SQLITE_DELETE ){ + if( pChange->bIndirect==0 ){ + u8 *pCsr = aRec; + sessionSkipRecord(&pCsr, pIter->nCol); + sessionAppendByte(&sOut, SQLITE_INSERT, &rc); + sessionAppendByte(&sOut, pIter->bIndirect, &rc); + sessionAppendRecordMerge(&sOut, pIter->nCol, + pCsr, nRec-(pCsr-aRec), + pChange->aRecord, pChange->nRecord, &rc + ); + } + }else{ + sessionAppendPartialUpdate(&sOut, pIter, + aRec, nRec, pChange->aRecord, pChange->nRecord, &rc + ); + } + break; + + default: + assert( pIter->op==SQLITE_DELETE ); + bDone = 1; + if( pChange->op==SQLITE_INSERT ){ + sessionAppendByte(&sOut, SQLITE_DELETE, &rc); + sessionAppendByte(&sOut, pIter->bIndirect, &rc); + sessionAppendRecordMerge(&sOut, pIter->nCol, + pChange->aRecord, pChange->nRecord, aRec, nRec, &rc + ); + } + break; + } + } + + if( bDone==0 ){ + sessionAppendByte(&sOut, pIter->op, &rc); + sessionAppendByte(&sOut, pIter->bIndirect, &rc); + sessionAppendBlob(&sOut, aRec, nRec, &rc); + } + if( rc==SQLITE_OK && xOutput && sOut.nBuf>SESSIONS_STRM_CHUNK_SIZE ){ + rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); + sOut.nBuf = 0; + } + if( rc ) break; + } + + if( rc!=SQLITE_OK ){ + sqlite3_free(sOut.aBuf); + memset(&sOut, 0, sizeof(sOut)); + } + + if( rc==SQLITE_OK ){ + if( xOutput ){ + if( sOut.nBuf>0 ){ + rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); + } + }else{ + *ppOut = (void*)sOut.aBuf; + *pnOut = sOut.nBuf; + sOut.aBuf = 0; + } + } + sqlite3_free(sOut.aBuf); + return rc; +} + +/* +** Create a new rebaser object. +*/ +SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew){ + int rc = SQLITE_OK; + sqlite3_rebaser *pNew; + + pNew = sqlite3_malloc(sizeof(sqlite3_rebaser)); + if( pNew==0 ){ + rc = SQLITE_NOMEM; + }else{ + memset(pNew, 0, sizeof(sqlite3_rebaser)); + } + *ppNew = pNew; + return rc; +} + +/* +** Call this one or more times to configure a rebaser. +*/ +SQLITE_API int sqlite3rebaser_configure( + sqlite3_rebaser *p, + int nRebase, const void *pRebase +){ + sqlite3_changeset_iter *pIter = 0; /* Iterator opened on pData/nData */ + int rc; /* Return code */ + rc = sqlite3changeset_start(&pIter, nRebase, (void*)pRebase); + if( rc==SQLITE_OK ){ + rc = sessionChangesetToHash(pIter, &p->grp, 1); + } + sqlite3changeset_finalize(pIter); + return rc; +} + +/* +** Rebase a changeset according to current rebaser configuration +*/ +SQLITE_API int sqlite3rebaser_rebase( + sqlite3_rebaser *p, + int nIn, const void *pIn, + int *pnOut, void **ppOut +){ + sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */ + int rc = sqlite3changeset_start(&pIter, nIn, (void*)pIn); + + if( rc==SQLITE_OK ){ + rc = sessionRebase(p, pIter, 0, 0, pnOut, ppOut); + sqlite3changeset_finalize(pIter); + } + + return rc; +} + +/* +** Rebase a changeset according to current rebaser configuration +*/ +SQLITE_API int sqlite3rebaser_rebase_strm( + sqlite3_rebaser *p, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +){ + sqlite3_changeset_iter *pIter = 0; /* Iterator to skip through input */ + int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn); + + if( rc==SQLITE_OK ){ + rc = sessionRebase(p, pIter, xOutput, pOut, 0, 0); + sqlite3changeset_finalize(pIter); + } + + return rc; +} + +/* +** Destroy a rebaser object +*/ +SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p){ + if( p ){ + sessionDeleteTable(p->grp.pList); + sqlite3_free(p); + } +} + #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ /************** End of sqlite3session.c **************************************/ @@ -185148,6 +189587,8 @@ static Fts5ExprPhrase *sqlite3Fts5ParseTerm( int bPrefix ); +static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase*); + static Fts5ExprNearset *sqlite3Fts5ParseNearset( Fts5Parse*, Fts5ExprNearset*, @@ -185228,9 +189669,10 @@ static int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic); #define FTS5_STRING 9 #define FTS5_LP 10 #define FTS5_RP 11 -#define FTS5_COMMA 12 -#define FTS5_PLUS 13 -#define FTS5_STAR 14 +#define FTS5_CARET 12 +#define FTS5_COMMA 13 +#define FTS5_PLUS 14 +#define FTS5_STAR 15 /* ** 2000-05-29 @@ -185331,31 +189773,32 @@ static int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic); ** defined, then do no error processing. ** fts5YYNSTATE the combined number of states. ** fts5YYNRULE the number of rules in the grammar +** fts5YYNFTS5TOKEN Number of terminal symbols ** fts5YY_MAX_SHIFT Maximum value for shift actions ** fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** fts5YY_MIN_REDUCE Minimum value for reduce actions -** fts5YY_MAX_REDUCE Maximum value for reduce actions ** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error ** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept ** fts5YY_NO_ACTION The fts5yy_action[] code for no-op +** fts5YY_MIN_REDUCE Minimum value for reduce actions +** fts5YY_MAX_REDUCE Maximum value for reduce actions */ #ifndef INTERFACE # define INTERFACE 1 #endif /************* Begin control #defines *****************************************/ #define fts5YYCODETYPE unsigned char -#define fts5YYNOCODE 28 +#define fts5YYNOCODE 29 #define fts5YYACTIONTYPE unsigned char #define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token typedef union { int fts5yyinit; sqlite3Fts5ParserFTS5TOKENTYPE fts5yy0; int fts5yy4; - Fts5Colset* fts5yy11; - Fts5ExprNode* fts5yy24; - Fts5ExprNearset* fts5yy46; - Fts5ExprPhrase* fts5yy53; + Fts5ExprPhrase* fts5yy11; + Fts5ExprNearset* fts5yy14; + Fts5Colset* fts5yy43; + Fts5ExprNode* fts5yy54; } fts5YYMINORTYPE; #ifndef fts5YYSTACKDEPTH #define fts5YYSTACKDEPTH 100 @@ -185364,16 +189807,17 @@ typedef union { #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse -#define fts5YYNSTATE 33 -#define fts5YYNRULE 27 -#define fts5YY_MAX_SHIFT 32 -#define fts5YY_MIN_SHIFTREDUCE 50 -#define fts5YY_MAX_SHIFTREDUCE 76 -#define fts5YY_MIN_REDUCE 77 -#define fts5YY_MAX_REDUCE 103 -#define fts5YY_ERROR_ACTION 104 -#define fts5YY_ACCEPT_ACTION 105 -#define fts5YY_NO_ACTION 106 +#define fts5YYNSTATE 35 +#define fts5YYNRULE 28 +#define fts5YYNFTS5TOKEN 16 +#define fts5YY_MAX_SHIFT 34 +#define fts5YY_MIN_SHIFTREDUCE 52 +#define fts5YY_MAX_SHIFTREDUCE 79 +#define fts5YY_ERROR_ACTION 80 +#define fts5YY_ACCEPT_ACTION 81 +#define fts5YY_NO_ACTION 82 +#define fts5YY_MIN_REDUCE 83 +#define fts5YY_MAX_REDUCE 110 /************* End control #defines *******************************************/ /* Define the fts5yytestcase() macro to be a no-op if is not already defined @@ -185403,9 +189847,6 @@ typedef union { ** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE. ** -** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE -** and fts5YY_MAX_REDUCE -** ** N == fts5YY_ERROR_ACTION A syntax error has occurred. ** ** N == fts5YY_ACCEPT_ACTION The parser accepts its input. @@ -185413,25 +189854,22 @@ typedef union { ** N == fts5YY_NO_ACTION No such action. Denotes unused ** slots in the fts5yy_action[] table. ** +** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE +** and fts5YY_MAX_REDUCE +** ** The action table is constructed as a single large table named fts5yy_action[]. ** Given state S and lookahead X, the action is computed as either: ** ** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ] ** (B) N = fts5yy_default[S] ** -** The (A) formula is preferred. The B formula is used instead if: -** (1) The fts5yy_shift_ofst[S]+X value is out of range, or -** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or -** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT. -** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that -** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X. -** Hence only tests (1) and (2) need to be evaluated.) +** The (A) formula is preferred. The B formula is used instead if +** fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X. ** ** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of -** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of -** fts5YY_SHIFT_USE_DFLT. +** the fts5yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** @@ -185445,54 +189883,56 @@ typedef union { ** fts5yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define fts5YY_ACTTAB_COUNT (98) +#define fts5YY_ACTTAB_COUNT (105) static const fts5YYACTIONTYPE fts5yy_action[] = { - /* 0 */ 105, 19, 90, 6, 26, 93, 92, 24, 24, 17, - /* 10 */ 90, 6, 26, 16, 92, 54, 24, 18, 90, 6, - /* 20 */ 26, 10, 92, 12, 24, 75, 86, 90, 6, 26, - /* 30 */ 13, 92, 75, 24, 20, 90, 6, 26, 101, 92, - /* 40 */ 56, 24, 27, 90, 6, 26, 100, 92, 21, 24, - /* 50 */ 23, 15, 30, 11, 1, 91, 22, 25, 9, 92, - /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77, - /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12, - /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32, - /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14, + /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18, + /* 10 */ 96, 6, 28, 17, 98, 56, 26, 19, 96, 6, + /* 20 */ 28, 14, 98, 108, 26, 92, 96, 6, 28, 25, + /* 30 */ 98, 78, 26, 21, 96, 6, 28, 107, 98, 58, + /* 40 */ 26, 29, 96, 6, 28, 32, 98, 22, 26, 24, + /* 50 */ 16, 23, 11, 1, 14, 13, 24, 16, 31, 11, + /* 60 */ 3, 97, 13, 27, 8, 98, 82, 26, 7, 4, + /* 70 */ 5, 3, 4, 5, 3, 83, 4, 5, 3, 63, + /* 80 */ 33, 34, 62, 12, 2, 86, 13, 10, 12, 71, + /* 90 */ 10, 13, 78, 5, 3, 78, 9, 30, 75, 82, + /* 100 */ 54, 57, 53, 57, 15, }; static const fts5YYCODETYPE fts5yy_lookahead[] = { - /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17, - /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19, - /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20, - /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22, - /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24, - /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22, - /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0, - /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9, - /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25, - /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9, + /* 0 */ 17, 18, 19, 20, 21, 23, 23, 25, 25, 18, + /* 10 */ 19, 20, 21, 7, 23, 9, 25, 18, 19, 20, + /* 20 */ 21, 9, 23, 27, 25, 18, 19, 20, 21, 25, + /* 30 */ 23, 15, 25, 18, 19, 20, 21, 27, 23, 9, + /* 40 */ 25, 18, 19, 20, 21, 14, 23, 22, 25, 6, + /* 50 */ 7, 22, 9, 10, 9, 12, 6, 7, 13, 9, + /* 60 */ 3, 19, 12, 21, 5, 23, 28, 25, 5, 1, + /* 70 */ 2, 3, 1, 2, 3, 0, 1, 2, 3, 11, + /* 80 */ 25, 26, 11, 9, 10, 5, 12, 10, 9, 11, + /* 90 */ 10, 12, 15, 2, 3, 15, 24, 25, 9, 28, + /* 100 */ 8, 9, 8, 9, 9, 28, 28, 28, 28, 28, + /* 110 */ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + /* 120 */ 28, }; -#define fts5YY_SHIFT_USE_DFLT (98) -#define fts5YY_SHIFT_COUNT (32) +#define fts5YY_SHIFT_COUNT (34) #define fts5YY_SHIFT_MIN (0) -#define fts5YY_SHIFT_MAX (90) +#define fts5YY_SHIFT_MAX (95) static const unsigned char fts5yy_shift_ofst[] = { - /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14, - /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69, - /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87, - /* 30 */ 88, 39, 71, + /* 0 */ 43, 43, 43, 43, 43, 43, 50, 74, 79, 45, + /* 10 */ 12, 80, 77, 12, 16, 16, 30, 30, 68, 71, + /* 20 */ 75, 91, 92, 94, 6, 31, 31, 59, 63, 57, + /* 30 */ 31, 89, 95, 31, 78, }; -#define fts5YY_REDUCE_USE_DFLT (-18) -#define fts5YY_REDUCE_COUNT (16) -#define fts5YY_REDUCE_MIN (-17) -#define fts5YY_REDUCE_MAX (67) +#define fts5YY_REDUCE_COUNT (17) +#define fts5YY_REDUCE_MIN (-18) +#define fts5YY_REDUCE_MAX (72) static const signed char fts5yy_reduce_ofst[] = { - /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17, - /* 10 */ 67, 12, 12, 12, 20, 27, 35, + /* 0 */ -17, -9, -1, 7, 15, 23, 42, -18, -18, 55, + /* 10 */ 72, -4, -4, 4, -4, 10, 25, 29, }; static const fts5YYACTIONTYPE fts5yy_default[] = { - /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104, - /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104, - /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104, - /* 30 */ 104, 97, 104, + /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105, + /* 10 */ 80, 110, 110, 80, 110, 110, 80, 80, 80, 80, + /* 20 */ 80, 91, 80, 80, 80, 101, 100, 80, 80, 90, + /* 30 */ 103, 80, 80, 104, 80, }; /********** End of lemon-generated parsing tables *****************************/ @@ -185594,19 +190034,40 @@ static void sqlite3Fts5ParserTrace(FILE *TraceFILE, char *zTracePrompt){ } #endif /* NDEBUG */ -#ifndef NDEBUG +#if defined(fts5YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const fts5yyTokenName[] = { - "$", "OR", "AND", "NOT", - "TERM", "COLON", "MINUS", "LCP", - "RCP", "STRING", "LP", "RP", - "COMMA", "PLUS", "STAR", "error", - "input", "expr", "cnearset", "exprlist", - "colset", "colsetlist", "nearset", "nearphrases", - "phrase", "neardist_opt", "star_opt", + /* 0 */ "$", + /* 1 */ "OR", + /* 2 */ "AND", + /* 3 */ "NOT", + /* 4 */ "TERM", + /* 5 */ "COLON", + /* 6 */ "MINUS", + /* 7 */ "LCP", + /* 8 */ "RCP", + /* 9 */ "STRING", + /* 10 */ "LP", + /* 11 */ "RP", + /* 12 */ "CARET", + /* 13 */ "COMMA", + /* 14 */ "PLUS", + /* 15 */ "STAR", + /* 16 */ "error", + /* 17 */ "input", + /* 18 */ "expr", + /* 19 */ "cnearset", + /* 20 */ "exprlist", + /* 21 */ "colset", + /* 22 */ "colsetlist", + /* 23 */ "nearset", + /* 24 */ "nearphrases", + /* 25 */ "phrase", + /* 26 */ "neardist_opt", + /* 27 */ "star_opt", }; -#endif /* NDEBUG */ +#endif /* defined(fts5YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -185630,15 +190091,16 @@ static const char *const fts5yyRuleName[] = { /* 15 */ "cnearset ::= nearset", /* 16 */ "cnearset ::= colset COLON nearset", /* 17 */ "nearset ::= phrase", - /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP", - /* 19 */ "nearphrases ::= phrase", - /* 20 */ "nearphrases ::= nearphrases phrase", - /* 21 */ "neardist_opt ::=", - /* 22 */ "neardist_opt ::= COMMA STRING", - /* 23 */ "phrase ::= phrase PLUS STRING star_opt", - /* 24 */ "phrase ::= STRING star_opt", - /* 25 */ "star_opt ::= STAR", - /* 26 */ "star_opt ::=", + /* 18 */ "nearset ::= CARET phrase", + /* 19 */ "nearset ::= STRING LP nearphrases neardist_opt RP", + /* 20 */ "nearphrases ::= phrase", + /* 21 */ "nearphrases ::= nearphrases phrase", + /* 22 */ "neardist_opt ::=", + /* 23 */ "neardist_opt ::= COMMA STRING", + /* 24 */ "phrase ::= phrase PLUS STRING star_opt", + /* 25 */ "phrase ::= STRING star_opt", + /* 26 */ "star_opt ::= STAR", + /* 27 */ "star_opt ::=", }; #endif /* NDEBUG */ @@ -185759,33 +190221,33 @@ static void fts5yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 16: /* input */ + case 17: /* input */ { (void)pParse; } break; - case 17: /* expr */ - case 18: /* cnearset */ - case 19: /* exprlist */ + case 18: /* expr */ + case 19: /* cnearset */ + case 20: /* exprlist */ { - sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24)); + sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy54)); } break; - case 20: /* colset */ - case 21: /* colsetlist */ + case 21: /* colset */ + case 22: /* colsetlist */ { - sqlite3_free((fts5yypminor->fts5yy11)); + sqlite3_free((fts5yypminor->fts5yy43)); } break; - case 22: /* nearset */ - case 23: /* nearphrases */ + case 23: /* nearset */ + case 24: /* nearphrases */ { - sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46)); + sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy14)); } break; - case 24: /* phrase */ + case 25: /* phrase */ { - sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53)); + sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11)); } break; /********* End destructor definitions *****************************************/ @@ -185856,6 +190318,43 @@ static int sqlite3Fts5ParserStackPeak(void *p){ } #endif +/* This array of booleans keeps track of the parser statement +** coverage. The element fts5yycoverage[X][Y] is set when the parser +** is in state X and has a lookahead token Y. In a well-tested +** systems, every element of this matrix should end up being set. +*/ +#if defined(fts5YYCOVERAGE) +static unsigned char fts5yycoverage[fts5YYNSTATE][fts5YYNFTS5TOKEN]; +#endif + +/* +** Write into out a description of every state/lookahead combination that +** +** (1) has not been used by the parser, and +** (2) is not a syntax error. +** +** Return the number of missed state/lookahead combinations. +*/ +#if defined(fts5YYCOVERAGE) +static int sqlite3Fts5ParserCoverage(FILE *out){ + int stateno, iLookAhead, i; + int nMissed = 0; + for(stateno=0; statenofts5yytos->stateno; - if( stateno>=fts5YY_MIN_REDUCE ) return stateno; + if( stateno>fts5YY_MAX_SHIFT ) return stateno; assert( stateno <= fts5YY_SHIFT_COUNT ); +#if defined(fts5YYCOVERAGE) + fts5yycoverage[stateno][iLookAhead] = 1; +#endif do{ i = fts5yy_shift_ofst[stateno]; + assert( i>=0 ); + assert( i+fts5YYNFTS5TOKEN<=(int)sizeof(fts5yy_lookahead)/sizeof(fts5yy_lookahead[0]) ); assert( iLookAhead!=fts5YYNOCODE ); + assert( iLookAhead < fts5YYNFTS5TOKEN ); i += iLookAhead; - if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){ + if( fts5yy_lookahead[i]!=iLookAhead ){ #ifdef fts5YYFALLBACK fts5YYCODETYPE iFallback; /* Fallback token */ if( iLookAheadfts5yytos->major], + fprintf(fts5yyTraceFILE,"%s%s '%s', go to state %d\n", + fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major], fts5yyNewState); }else{ - fprintf(fts5yyTraceFILE,"%sShift '%s'\n", - fts5yyTracePrompt,fts5yyTokenName[fts5yypParser->fts5yytos->major]); + fprintf(fts5yyTraceFILE,"%s%s '%s', pending reduce %d\n", + fts5yyTracePrompt, zTag, fts5yyTokenName[fts5yypParser->fts5yytos->major], + fts5yyNewState - fts5YY_MIN_REDUCE); } } } #else -# define fts5yyTraceShift(X,Y) +# define fts5yyTraceShift(X,Y,Z) #endif /* @@ -186029,7 +190534,7 @@ static void fts5yy_shift( fts5yytos->stateno = (fts5YYACTIONTYPE)fts5yyNewState; fts5yytos->major = (fts5YYCODETYPE)fts5yyMajor; fts5yytos->minor.fts5yy0 = fts5yyMinor; - fts5yyTraceShift(fts5yypParser, fts5yyNewState); + fts5yyTraceShift(fts5yypParser, fts5yyNewState, "Shift"); } /* The following table contains information about every rule that @@ -186039,33 +190544,34 @@ static const struct { fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } fts5yyRuleInfo[] = { - { 16, -1 }, - { 20, -4 }, - { 20, -3 }, - { 20, -1 }, - { 20, -2 }, - { 21, -2 }, - { 21, -1 }, - { 17, -3 }, - { 17, -3 }, - { 17, -3 }, - { 17, -5 }, - { 17, -3 }, - { 17, -1 }, - { 19, -1 }, - { 19, -2 }, - { 18, -1 }, - { 18, -3 }, - { 22, -1 }, - { 22, -5 }, - { 23, -1 }, - { 23, -2 }, - { 25, 0 }, - { 25, -2 }, - { 24, -4 }, - { 24, -2 }, - { 26, -1 }, - { 26, 0 }, + { 17, -1 }, /* (0) input ::= expr */ + { 21, -4 }, /* (1) colset ::= MINUS LCP colsetlist RCP */ + { 21, -3 }, /* (2) colset ::= LCP colsetlist RCP */ + { 21, -1 }, /* (3) colset ::= STRING */ + { 21, -2 }, /* (4) colset ::= MINUS STRING */ + { 22, -2 }, /* (5) colsetlist ::= colsetlist STRING */ + { 22, -1 }, /* (6) colsetlist ::= STRING */ + { 18, -3 }, /* (7) expr ::= expr AND expr */ + { 18, -3 }, /* (8) expr ::= expr OR expr */ + { 18, -3 }, /* (9) expr ::= expr NOT expr */ + { 18, -5 }, /* (10) expr ::= colset COLON LP expr RP */ + { 18, -3 }, /* (11) expr ::= LP expr RP */ + { 18, -1 }, /* (12) expr ::= exprlist */ + { 20, -1 }, /* (13) exprlist ::= cnearset */ + { 20, -2 }, /* (14) exprlist ::= exprlist cnearset */ + { 19, -1 }, /* (15) cnearset ::= nearset */ + { 19, -3 }, /* (16) cnearset ::= colset COLON nearset */ + { 23, -1 }, /* (17) nearset ::= phrase */ + { 23, -2 }, /* (18) nearset ::= CARET phrase */ + { 23, -5 }, /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */ + { 24, -1 }, /* (20) nearphrases ::= phrase */ + { 24, -2 }, /* (21) nearphrases ::= nearphrases phrase */ + { 26, 0 }, /* (22) neardist_opt ::= */ + { 26, -2 }, /* (23) neardist_opt ::= COMMA STRING */ + { 25, -4 }, /* (24) phrase ::= phrase PLUS STRING star_opt */ + { 25, -2 }, /* (25) phrase ::= STRING star_opt */ + { 27, -1 }, /* (26) star_opt ::= STAR */ + { 27, 0 }, /* (27) star_opt ::= */ }; static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */ @@ -186073,22 +190579,38 @@ static void fts5yy_accept(fts5yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. +** +** The fts5yyLookahead and fts5yyLookaheadToken parameters provide reduce actions +** access to the lookahead token (if any). The fts5yyLookahead will be fts5YYNOCODE +** if the lookahead token has already been consumed. As this procedure is +** only called from one place, optimizing compilers will in-line it, which +** means that the extra parameters have no performance impact. */ static void fts5yy_reduce( fts5yyParser *fts5yypParser, /* The parser */ - unsigned int fts5yyruleno /* Number of the rule by which to reduce */ + unsigned int fts5yyruleno, /* Number of the rule by which to reduce */ + int fts5yyLookahead, /* Lookahead token, or fts5YYNOCODE if none */ + sqlite3Fts5ParserFTS5TOKENTYPE fts5yyLookaheadToken /* Value of the lookahead token */ ){ int fts5yygoto; /* The next state */ int fts5yyact; /* The next action */ fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */ int fts5yysize; /* Amount to pop the stack */ sqlite3Fts5ParserARG_FETCH; + (void)fts5yyLookahead; + (void)fts5yyLookaheadToken; fts5yymsp = fts5yypParser->fts5yytos; #ifndef NDEBUG if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){ fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs; - fprintf(fts5yyTraceFILE, "%sReduce [%s], go to state %d.\n", fts5yyTracePrompt, - fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno); + if( fts5yysize ){ + fprintf(fts5yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + fts5yyTracePrompt, + fts5yyruleno, fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno); + }else{ + fprintf(fts5yyTraceFILE, "%sReduce %d [%s].\n", + fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno]); + } } #endif /* NDEBUG */ @@ -186130,137 +190652,143 @@ static void fts5yy_reduce( /********** Begin reduce actions **********************************************/ fts5YYMINORTYPE fts5yylhsminor; case 0: /* input ::= expr */ -{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); } +{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy54); } break; case 1: /* colset ::= MINUS LCP colsetlist RCP */ { - fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11); + fts5yymsp[-3].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43); } break; case 2: /* colset ::= LCP colsetlist RCP */ -{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; } +{ fts5yymsp[-2].minor.fts5yy43 = fts5yymsp[-1].minor.fts5yy43; } break; case 3: /* colset ::= STRING */ { - fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); + fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); } - fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11; + fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43; break; case 4: /* colset ::= MINUS STRING */ { - fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); - fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11); + fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); + fts5yymsp[-1].minor.fts5yy43 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy43); } break; case 5: /* colsetlist ::= colsetlist STRING */ { - fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); } - fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11; + fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy43, &fts5yymsp[0].minor.fts5yy0); } + fts5yymsp[-1].minor.fts5yy43 = fts5yylhsminor.fts5yy43; break; case 6: /* colsetlist ::= STRING */ { - fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); + fts5yylhsminor.fts5yy43 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); } - fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11; + fts5yymsp[0].minor.fts5yy43 = fts5yylhsminor.fts5yy43; break; case 7: /* expr ::= expr AND expr */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0); } - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 8: /* expr ::= expr OR expr */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0); } - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 9: /* expr ::= expr NOT expr */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54, 0); } - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 10: /* expr ::= colset COLON LP expr RP */ { - sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11); - fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24; + sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[-4].minor.fts5yy43); + fts5yylhsminor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54; } - fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-4].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 11: /* expr ::= LP expr RP */ -{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;} +{fts5yymsp[-2].minor.fts5yy54 = fts5yymsp[-1].minor.fts5yy54;} break; case 12: /* expr ::= exprlist */ case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13); -{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;} - fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24; +{fts5yylhsminor.fts5yy54 = fts5yymsp[0].minor.fts5yy54;} + fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 14: /* exprlist ::= exprlist cnearset */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy54, fts5yymsp[0].minor.fts5yy54); } - fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-1].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 15: /* cnearset ::= nearset */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14); } - fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[0].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 16: /* cnearset ::= colset COLON nearset */ { - fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); - sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11); + fts5yylhsminor.fts5yy54 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy14); + sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy54, fts5yymsp[-2].minor.fts5yy43); } - fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24; + fts5yymsp[-2].minor.fts5yy54 = fts5yylhsminor.fts5yy54; break; case 17: /* nearset ::= phrase */ -{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); } - fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46; +{ fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); } + fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14; break; - case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */ + case 18: /* nearset ::= CARET phrase */ +{ + sqlite3Fts5ParseSetCaret(fts5yymsp[0].minor.fts5yy11); + fts5yymsp[-1].minor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); +} + break; + case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */ { sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0); - sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0); - fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46; + sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy14, &fts5yymsp[-1].minor.fts5yy0); + fts5yylhsminor.fts5yy14 = fts5yymsp[-2].minor.fts5yy14; } - fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46; + fts5yymsp[-4].minor.fts5yy14 = fts5yylhsminor.fts5yy14; break; - case 19: /* nearphrases ::= phrase */ + case 20: /* nearphrases ::= phrase */ { - fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); + fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); } - fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46; + fts5yymsp[0].minor.fts5yy14 = fts5yylhsminor.fts5yy14; break; - case 20: /* nearphrases ::= nearphrases phrase */ + case 21: /* nearphrases ::= nearphrases phrase */ { - fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53); + fts5yylhsminor.fts5yy14 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy14, fts5yymsp[0].minor.fts5yy11); } - fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46; + fts5yymsp[-1].minor.fts5yy14 = fts5yylhsminor.fts5yy14; break; - case 21: /* neardist_opt ::= */ + case 22: /* neardist_opt ::= */ { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; } break; - case 22: /* neardist_opt ::= COMMA STRING */ + case 23: /* neardist_opt ::= COMMA STRING */ { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; } break; - case 23: /* phrase ::= phrase PLUS STRING star_opt */ + case 24: /* phrase ::= phrase PLUS STRING star_opt */ { - fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4); + fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4); } - fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53; + fts5yymsp[-3].minor.fts5yy11 = fts5yylhsminor.fts5yy11; break; - case 24: /* phrase ::= STRING star_opt */ + case 25: /* phrase ::= STRING star_opt */ { - fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4); + fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4); } - fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53; + fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11; break; - case 25: /* star_opt ::= STAR */ + case 26: /* star_opt ::= STAR */ { fts5yymsp[0].minor.fts5yy4 = 1; } break; - case 26: /* star_opt ::= */ + case 27: /* star_opt ::= */ { fts5yymsp[1].minor.fts5yy4 = 0; } break; default: @@ -186279,16 +190807,11 @@ static void fts5yy_reduce( /* It is not possible for a REDUCE to be followed by an error */ assert( fts5yyact!=fts5YY_ERROR_ACTION ); - if( fts5yyact==fts5YY_ACCEPT_ACTION ){ - fts5yypParser->fts5yytos += fts5yysize; - fts5yy_accept(fts5yypParser); - }else{ - fts5yymsp += fts5yysize+1; - fts5yypParser->fts5yytos = fts5yymsp; - fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact; - fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto; - fts5yyTraceShift(fts5yypParser, fts5yyact); - } + fts5yymsp += fts5yysize+1; + fts5yypParser->fts5yytos = fts5yymsp; + fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact; + fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto; + fts5yyTraceShift(fts5yypParser, fts5yyact, "... then shift"); } /* @@ -186400,20 +190923,31 @@ static void sqlite3Fts5Parser( #ifndef NDEBUG if( fts5yyTraceFILE ){ - fprintf(fts5yyTraceFILE,"%sInput '%s'\n",fts5yyTracePrompt,fts5yyTokenName[fts5yymajor]); + int stateno = fts5yypParser->fts5yytos->stateno; + if( stateno < fts5YY_MIN_REDUCE ){ + fprintf(fts5yyTraceFILE,"%sInput '%s' in state %d\n", + fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno); + }else{ + fprintf(fts5yyTraceFILE,"%sInput '%s' with pending reduce %d\n", + fts5yyTracePrompt,fts5yyTokenName[fts5yymajor],stateno-fts5YY_MIN_REDUCE); + } } #endif do{ fts5yyact = fts5yy_find_shift_action(fts5yypParser,(fts5YYCODETYPE)fts5yymajor); - if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){ + if( fts5yyact >= fts5YY_MIN_REDUCE ){ + fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE,fts5yymajor,fts5yyminor); + }else if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){ fts5yy_shift(fts5yypParser,fts5yyact,fts5yymajor,fts5yyminor); #ifndef fts5YYNOERRORRECOVERY fts5yypParser->fts5yyerrcnt--; #endif fts5yymajor = fts5YYNOCODE; - }else if( fts5yyact <= fts5YY_MAX_REDUCE ){ - fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE); + }else if( fts5yyact==fts5YY_ACCEPT_ACTION ){ + fts5yypParser->fts5yytos--; + fts5yy_accept(fts5yypParser); + return; }else{ assert( fts5yyact == fts5YY_ERROR_ACTION ); fts5yyminorunion.fts5yy0 = fts5yyminor; @@ -186892,6 +191426,16 @@ static int fts5SnippetScore( return rc; } +/* +** Return the value in pVal interpreted as utf-8 text. Except, if pVal +** contains a NULL value, return a pointer to a static string zero +** bytes in length instead of a NULL pointer. +*/ +static const char *fts5ValueToText(sqlite3_value *pVal){ + const char *zRet = (const char*)sqlite3_value_text(pVal); + return zRet ? zRet : ""; +} + /* ** Implementation of snippet() function. */ @@ -186927,9 +191471,9 @@ static void fts5SnippetFunction( nCol = pApi->xColumnCount(pFts); memset(&ctx, 0, sizeof(HighlightContext)); iCol = sqlite3_value_int(apVal[0]); - ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]); - ctx.zClose = (const char*)sqlite3_value_text(apVal[2]); - zEllips = (const char*)sqlite3_value_text(apVal[3]); + ctx.zOpen = fts5ValueToText(apVal[1]); + ctx.zClose = fts5ValueToText(apVal[2]); + zEllips = fts5ValueToText(apVal[3]); nToken = sqlite3_value_int(apVal[4]); iBestCol = (iCol>=0 ? iCol : 0); @@ -188683,7 +193227,8 @@ struct Fts5ExprNode { ** or term prefix. */ struct Fts5ExprTerm { - int bPrefix; /* True for a prefix term */ + u8 bPrefix; /* True for a prefix term */ + u8 bFirst; /* True if token must be first in column */ char *zTerm; /* nul-terminated term */ Fts5IndexIter *pIter; /* Iterator for this term */ Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */ @@ -188764,6 +193309,7 @@ static int fts5ExprGetToken( case '+': tok = FTS5_PLUS; break; case '*': tok = FTS5_STAR; break; case '-': tok = FTS5_MINUS; break; + case '^': tok = FTS5_CARET; break; case '\0': tok = FTS5_EOF; break; case '"': { @@ -189023,6 +193569,7 @@ static int fts5ExprPhraseIsMatch( Fts5PoslistReader *aIter = aStatic; int i; int rc = SQLITE_OK; + int bFirst = pPhrase->aTerm[0].bFirst; fts5BufferZero(&pPhrase->poslist); @@ -189077,8 +193624,10 @@ static int fts5ExprPhraseIsMatch( }while( bMatch==0 ); /* Append position iPos to the output */ - rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos); - if( rc!=SQLITE_OK ) goto ismatch_out; + if( bFirst==0 || FTS5_POS2OFFSET(iPos)==0 ){ + rc = sqlite3Fts5PoslistWriterAppend(&pPhrase->poslist, &writer, iPos); + if( rc!=SQLITE_OK ) goto ismatch_out; + } for(i=0; inTerm; i++){ if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out; @@ -189332,7 +193881,9 @@ static int fts5ExprNearTest( ** phrase is not a match, break out of the loop early. */ for(i=0; rc==SQLITE_OK && inPhrase; i++){ Fts5ExprPhrase *pPhrase = pNear->apPhrase[i]; - if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym || pNear->pColset ){ + if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym + || pNear->pColset || pPhrase->aTerm[0].bFirst + ){ int bMatch = 0; rc = fts5ExprPhraseIsMatch(pNode, pPhrase, &bMatch); if( bMatch==0 ) break; @@ -189513,6 +194064,7 @@ static int fts5ExprNodeTest_STRING( assert( pNear->nPhrase>1 || pNear->apPhrase[0]->nTerm>1 || pNear->apPhrase[0]->aTerm[0].pSynonym + || pNear->apPhrase[0]->aTerm[0].bFirst ); /* Initialize iLast, the "lastest" rowid any iterator points to. If the @@ -190037,6 +194589,16 @@ static void fts5ExprPhraseFree(Fts5ExprPhrase *pPhrase){ } } +/* +** Set the "bFirst" flag on the first token of the phrase passed as the +** only argument. +*/ +static void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase *pPhrase){ + if( pPhrase && pPhrase->nTerm ){ + pPhrase->aTerm[0].bFirst = 1; + } +} + /* ** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated ** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is @@ -190254,7 +194816,7 @@ static Fts5ExprPhrase *sqlite3Fts5ParseTerm( ** no token characters at all. (e.g ... MATCH '""'). */ sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase)); }else if( sCtx.pPhrase->nTerm ){ - sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix; + sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix; } pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase; } @@ -190315,6 +194877,7 @@ static int sqlite3Fts5ExprClonePhrase( } if( rc==SQLITE_OK ){ sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix; + sCtx.pPhrase->aTerm[i].bFirst = pOrig->aTerm[i].bFirst; } } }else{ @@ -190333,7 +194896,10 @@ static int sqlite3Fts5ExprClonePhrase( pNew->pRoot->pNear->nPhrase = 1; sCtx.pPhrase->pNode = pNew->pRoot; - if( pOrig->nTerm==1 && pOrig->aTerm[0].pSynonym==0 ){ + if( pOrig->nTerm==1 + && pOrig->aTerm[0].pSynonym==0 + && pOrig->aTerm[0].bFirst==0 + ){ pNew->pRoot->eType = FTS5_TERM; pNew->pRoot->xNext = fts5ExprNodeNext_TERM; }else{ @@ -190607,6 +195173,7 @@ static void fts5ExprAssignXNext(Fts5ExprNode *pNode){ Fts5ExprNearset *pNear = pNode->pNear; if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 && pNear->apPhrase[0]->aTerm[0].pSynonym==0 + && pNear->apPhrase[0]->aTerm[0].bFirst==0 ){ pNode->eType = FTS5_TERM; pNode->xNext = fts5ExprNodeNext_TERM; @@ -190693,20 +195260,23 @@ static Fts5ExprNode *sqlite3Fts5ParseNode( } } - if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL - && (pNear->nPhrase!=1 || pNear->apPhrase[0]->nTerm>1) - ){ - assert( pParse->rc==SQLITE_OK ); - pParse->rc = SQLITE_ERROR; - assert( pParse->zErr==0 ); - pParse->zErr = sqlite3_mprintf( - "fts5: %s queries are not supported (detail!=full)", - pNear->nPhrase==1 ? "phrase": "NEAR" - ); - sqlite3_free(pRet); - pRet = 0; + if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL ){ + Fts5ExprPhrase *pPhrase = pNear->apPhrase[0]; + if( pNear->nPhrase!=1 + || pPhrase->nTerm>1 + || (pPhrase->nTerm>0 && pPhrase->aTerm[0].bFirst) + ){ + assert( pParse->rc==SQLITE_OK ); + pParse->rc = SQLITE_ERROR; + assert( pParse->zErr==0 ); + pParse->zErr = sqlite3_mprintf( + "fts5: %s queries are not supported (detail!=full)", + pNear->nPhrase==1 ? "phrase": "NEAR" + ); + sqlite3_free(pRet); + pRet = 0; + } } - }else{ fts5ExprAddChildren(pRet, pLeft); fts5ExprAddChildren(pRet, pRight); @@ -192709,6 +197279,7 @@ static void fts5DataWrite(Fts5Index *p, i64 iRowid, const u8 *pData, int nData){ sqlite3_bind_blob(p->pWriter, 2, pData, nData, SQLITE_STATIC); sqlite3_step(p->pWriter); p->rc = sqlite3_reset(p->pWriter); + sqlite3_bind_null(p->pWriter, 2); } /* @@ -194337,6 +198908,7 @@ static void fts5SegIterSeekInit( bDlidx = (val & 0x0001); } p->rc = sqlite3_reset(pIdxSelect); + sqlite3_bind_null(pIdxSelect, 2); if( iPgpgnoFirst ){ iPg = pSeg->pgnoFirst; @@ -195549,6 +200121,7 @@ static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){ sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC); assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW ); p->rc = sqlite3_reset(pIdxSelect); + sqlite3_bind_null(pIdxSelect, 2); } } #endif @@ -195675,6 +200248,7 @@ static void fts5WriteFlushBtree(Fts5Index *p, Fts5SegWriter *pWriter){ sqlite3_bind_int64(p->pIdxWriter, 3, bFlag + ((i64)pWriter->iBtPage<<1)); sqlite3_step(p->pIdxWriter); p->rc = sqlite3_reset(p->pIdxWriter); + sqlite3_bind_null(p->pIdxWriter, 2); } pWriter->iBtPage = 0; } @@ -196860,7 +201434,13 @@ static void fts5MergePrefixLists( Fts5Buffer out = {0, 0, 0}; Fts5Buffer tmp = {0, 0, 0}; - if( sqlite3Fts5BufferSize(&p->rc, &out, p1->n + p2->n) ) return; + /* The maximum size of the output is equal to the sum of the two + ** input sizes + 1 varint (9 bytes). The extra varint is because if the + ** first rowid in one input is a large negative number, and the first in + ** the other a non-negative number, the delta for the non-negative + ** number will be larger on disk than the literal integer value + ** was. */ + if( sqlite3Fts5BufferSize(&p->rc, &out, p1->n + p2->n + 9) ) return; fts5DoclistIterInit(p1, &i1); fts5DoclistIterInit(p2, &i2); @@ -196954,6 +201534,7 @@ static void fts5MergePrefixLists( fts5MergeAppendDocid(&out, iLastRowid, i2.iRowid); fts5BufferSafeAppendBlob(&out, i2.aPoslist, i2.aEof - i2.aPoslist); } + assert( out.n<=(p1->n+p2->n+9) ); fts5BufferSet(&p->rc, p1, out.n, out.p); fts5BufferFree(&tmp); @@ -198981,6 +203562,12 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ aColMap[1] = nCol; aColMap[2] = nCol+1; + assert( SQLITE_INDEX_CONSTRAINT_EQnConstraint; i++){ struct sqlite3_index_constraint *p = &pInfo->aConstraint[i]; @@ -198999,11 +203586,11 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ pInfo->estimatedCost = 1e50; return SQLITE_OK; } - }else{ + }else if( p->op<=SQLITE_INDEX_CONSTRAINT_MATCH ){ int j; for(j=1; jiCol] && p->op & pC->op && p->usable ){ + if( iCol==aColMap[pC->iCol] && (p->op & pC->op) && p->usable ){ pC->iConsIndex = i; idxFlags |= pC->fts5op; } @@ -201075,7 +205662,7 @@ static void fts5SourceIdFunc( ){ assert( nArg==0 ); UNUSED_PARAM2(nArg, apUnused); - sqlite3_result_text(pCtx, "fts5: 2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827", -1, SQLITE_TRANSIENT); + sqlite3_result_text(pCtx, "fts5: 2018-04-10 17:39:29 4bb2294022060e61de7da5c227a69ccd846ba330e31626ebcd59a94efd148b3b", -1, SQLITE_TRANSIENT); } static int fts5Init(sqlite3 *db){ @@ -201651,6 +206238,7 @@ static int fts5StorageInsertDocsize( sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC); sqlite3_step(pReplace); rc = sqlite3_reset(pReplace); + sqlite3_bind_null(pReplace, 2); } } return rc; @@ -202311,6 +206899,7 @@ static int sqlite3Fts5StorageConfigValue( } sqlite3_step(pReplace); rc = sqlite3_reset(pReplace); + sqlite3_bind_null(pReplace, 1); } if( rc==SQLITE_OK && pVal ){ int iNew = p->pConfig->iCookie + 1; @@ -205343,9 +209932,9 @@ SQLITE_API int sqlite3_stmt_init( #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ /************** End of stmt.c ************************************************/ -#if __LINE__!=205346 +#if __LINE__!=209935 #undef SQLITE_SOURCE_ID -#define SQLITE_SOURCE_ID "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de4alt2" +#define SQLITE_SOURCE_ID "2018-04-10 17:39:29 4bb2294022060e61de7da5c227a69ccd846ba330e31626ebcd59a94efd14alt2" #endif /* Return the source-id for this library */ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } diff --git a/external/sqlite/src/sqlite3.h b/external/sqlite/src/sqlite3.h index 5f28e036..0ba2852d 100644 --- a/external/sqlite/src/sqlite3.h +++ b/external/sqlite/src/sqlite3.h @@ -123,9 +123,9 @@ extern "C" { ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ -#define SQLITE_VERSION "3.21.0" -#define SQLITE_VERSION_NUMBER 3021000 -#define SQLITE_SOURCE_ID "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827" +#define SQLITE_VERSION "3.23.1" +#define SQLITE_VERSION_NUMBER 3023001 +#define SQLITE_SOURCE_ID "2018-04-10 17:39:29 4bb2294022060e61de7da5c227a69ccd846ba330e31626ebcd59a94efd148b3b" /* ** CAPI3REF: Run-Time Library Version Numbers @@ -470,6 +470,8 @@ SQLITE_API int sqlite3_exec( ** the most recent error can be obtained using ** [sqlite3_extended_errcode()]. */ +#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) +#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) @@ -513,6 +515,8 @@ SQLITE_API int sqlite3_exec( #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) +#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) +#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) @@ -1060,6 +1064,12 @@ struct sqlite3_io_methods { ** so that all subsequent write operations are independent. ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. +** +**
  • [[SQLITE_FCNTL_LOCK_TIMEOUT]] +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain +** a file lock using the xLock or xShmLock methods of the VFS to wait +** for up to M milliseconds before failing, where M is the single +** unsigned integer parameter. ** */ #define SQLITE_FCNTL_LOCKSTATE 1 @@ -1094,6 +1104,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 +#define SQLITE_FCNTL_LOCK_TIMEOUT 34 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE @@ -1131,12 +1142,18 @@ typedef struct sqlite3_api_routines sqlite3_api_routines; ** in the name of the object stands for "virtual file system". See ** the [VFS | VFS documentation] for further information. ** -** The value of the iVersion field is initially 1 but may be larger in -** future versions of SQLite. Additional fields may be appended to this -** object when the iVersion value is increased. Note that the structure -** of the sqlite3_vfs object changes in the transaction between -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not -** modified. +** The VFS interface is sometimes extended by adding new methods onto +** the end. Each time such an extension occurs, the iVersion field +** is incremented. The iVersion value started out as 1 in +** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 +** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased +** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields +** may be appended to the sqlite3_vfs object and the iVersion value +** may increase again in future versions of SQLite. +** Note that the structure +** of the sqlite3_vfs object changes in the transition from +** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] +** and yet the iVersion field was not modified. ** ** The szOsFile field is the size of the subclassed [sqlite3_file] ** structure used by this VFS. mxPathname is the maximum length of @@ -2044,8 +2061,9 @@ struct sqlite3_mem_methods { ** connections at all to the database. If so, it performs a checkpoint ** operation before closing the connection. This option may be used to ** override this behaviour. The first parameter passed to this operation -** is an integer - non-zero to disable checkpoints-on-close, or zero (the -** default) to enable them. The second parameter is a pointer to an integer +** is an integer - positive to disable checkpoints-on-close, or zero (the +** default) to enable them, and negative to leave the setting unchanged. +** The second parameter is a pointer to an integer ** into which is written 0 or 1 to indicate whether checkpoints-on-close ** have been disabled - 0 if they are not disabled, 1 if they are. ** @@ -2059,8 +2077,24 @@ struct sqlite3_mem_methods { ** slower. But the QPSG has the advantage of more predictable behavior. With ** the QPSG active, SQLite will always use the same query plan in the field as ** was used during testing in the lab. +** The first argument to this setting is an integer which is 0 to disable +** the QPSG, positive to enable QPSG, or negative to leave the setting +** unchanged. The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether the QPSG is disabled or enabled +** following this call. ** ** +**
    SQLITE_DBCONFIG_TRIGGER_EQP
    +**
    By default, the output of EXPLAIN QUERY PLAN commands does not +** include output for any operations performed by trigger programs. This +** option is used to set or clear (the default) a flag that governs this +** behavior. The first parameter passed to this operation is an integer - +** positive to enable output for trigger programs, or zero to disable it, +** or negative to leave the setting unchanged. +** The second parameter is a pointer to an integer into which is written +** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if +** it is not disabled, 1 if it is. +**
    ** */ #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ @@ -2071,7 +2105,8 @@ struct sqlite3_mem_methods { #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ - +#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ +#define SQLITE_DBCONFIG_MAX 1008 /* Largest DBCONFIG */ /* ** CAPI3REF: Enable Or Disable Extended Result Codes @@ -2477,16 +2512,16 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** These routines are work-alikes of the "printf()" family of functions ** from the standard C library. -** These routines understand most of the common K&R formatting options, -** plus some additional non-standard formats, detailed below. -** Note that some of the more obscure formatting options from recent -** C-library standards are omitted from this implementation. +** These routines understand most of the common formatting options from +** the standard library printf() +** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). +** See the [built-in printf()] documentation for details. ** ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their -** results into memory obtained from [sqlite3_malloc()]. +** results into memory obtained from [sqlite3_malloc64()]. ** The strings returned by these two routines should be ** released by [sqlite3_free()]. ^Both routines return a -** NULL pointer if [sqlite3_malloc()] is unable to allocate enough +** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough ** memory to hold the resulting string. ** ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from @@ -2510,71 +2545,7 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). ** -** These routines all implement some additional formatting -** options that are useful for constructing SQL statements. -** All of the usual printf() formatting options apply. In addition, there -** is are "%q", "%Q", "%w" and "%z" options. -** -** ^(The %q option works like %s in that it substitutes a nul-terminated -** string from the argument list. But %q also doubles every '\'' character. -** %q is designed for use inside a string literal.)^ By doubling each '\'' -** character it escapes that character and allows it to be inserted into -** the string. -** -** For example, assume the string variable zText contains text as follows: -** -**
    -**  char *zText = "It's a happy day!";
    -** 
    -** -** One can use this text in an SQL statement as follows: -** -**
    -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
    -**  sqlite3_exec(db, zSQL, 0, 0, 0);
    -**  sqlite3_free(zSQL);
    -** 
    -** -** Because the %q format string is used, the '\'' character in zText -** is escaped and the SQL generated is as follows: -** -**
    -**  INSERT INTO table1 VALUES('It''s a happy day!')
    -** 
    -** -** This is correct. Had we used %s instead of %q, the generated SQL -** would have looked like this: -** -**
    -**  INSERT INTO table1 VALUES('It's a happy day!');
    -** 
    -** -** This second example is an SQL syntax error. As a general rule you should -** always use %q instead of %s when inserting text into a string literal. -** -** ^(The %Q option works like %q except it also adds single quotes around -** the outside of the total string. Additionally, if the parameter in the -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without -** single quotes).)^ So, for example, one could say: -** -**
    -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
    -**  sqlite3_exec(db, zSQL, 0, 0, 0);
    -**  sqlite3_free(zSQL);
    -** 
    -** -** The code above will render a correct SQL statement in the zSQL -** variable even if the zText variable is a NULL pointer. -** -** ^(The "%w" formatting option is like "%q" except that it expects to -** be contained within double-quotes instead of single quotes, and it -** escapes the double-quote character instead of the single-quote -** character.)^ The "%w" formatting option is intended for safely inserting -** table and column names into a constructed SQL statement. -** -** ^(The "%z" formatting option works like "%s" but with the -** addition that after the string has been read and copied into -** the result, [sqlite3_free()] is called on the input string.)^ +** See also: [built-in printf()], [printf() SQL function] */ SQLITE_API char *sqlite3_mprintf(const char*,...); SQLITE_API char *sqlite3_vmprintf(const char*, va_list); @@ -2932,8 +2903,8 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, ** KEYWORDS: SQLITE_TRACE ** ** These constants identify classes of events that can be monitored -** using the [sqlite3_trace_v2()] tracing logic. The third argument -** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of +** using the [sqlite3_trace_v2()] tracing logic. The M argument +** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of ** the following constants. ^The first argument to the trace callback ** is one of the following constants. ** @@ -3640,13 +3611,13 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** or [GLOB] operator or if the parameter is compared to an indexed column ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. **
  • +** ** **

    ^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having ** the extra prepFlags parameter, which is a bit array consisting of zero or ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The ** sqlite3_prepare_v2() interface works exactly the same as ** sqlite3_prepare_v3() with a zero prepFlags parameter. -** */ SQLITE_API int sqlite3_prepare( sqlite3 *db, /* Database handle */ @@ -4779,6 +4750,9 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** datatype of the value **

    sqlite3_value_numeric_type   ** →  Best numeric datatype of the value +**
    sqlite3_value_nochange   +** →  True if the column is unchanged in an UPDATE +** against a virtual table. **
    ** ** Details: @@ -4827,6 +4801,19 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** then the conversion is performed. Otherwise no conversion occurs. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ ** +** ^Within the [xUpdate] method of a [virtual table], the +** sqlite3_value_nochange(X) interface returns true if and only if +** the column corresponding to X is unchanged by the UPDATE operation +** that the xUpdate method call was invoked to implement and if +** and the prior [xColumn] method call that was invoked to extracted +** the value for that column returned without setting a result (probably +** because it queried [sqlite3_vtab_nochange()] and found that the column +** was unchanging). ^Within an [xUpdate] method, any value for which +** sqlite3_value_nochange(X) is true will in all other respects appear +** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other +** than within an [xUpdate] method call for an UPDATE statement, then +** the return value is arbitrary and meaningless. +** ** Please pay particular attention to the fact that the pointer returned ** from [sqlite3_value_blob()], [sqlite3_value_text()], or ** [sqlite3_value_text16()] can be invalidated by a subsequent call to @@ -4849,6 +4836,7 @@ SQLITE_API int sqlite3_value_bytes(sqlite3_value*); SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); SQLITE_API int sqlite3_value_type(sqlite3_value*); SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); +SQLITE_API int sqlite3_value_nochange(sqlite3_value*); /* ** CAPI3REF: Finding The Subtype Of SQL Values @@ -6951,9 +6939,9 @@ SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); ** the xFileControl method. ^The return value of the xFileControl ** method becomes the return value of this routine. ** -** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes +** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes ** a pointer to the underlying [sqlite3_file] object to be written into -** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER +** the space pointed to by the 4th parameter. ^The [SQLITE_FCNTL_FILE_POINTER] ** case is a short-circuit path which does not actually invoke the ** underlying sqlite3_io_methods.xFileControl method. ** @@ -6965,7 +6953,7 @@ SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); ** an incorrect zDbName and an SQLITE_ERROR return from the underlying ** xFileControl method. ** -** See also: [SQLITE_FCNTL_LOCKSTATE] +** See also: [file control opcodes] */ SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); @@ -7022,7 +7010,8 @@ SQLITE_API int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_ISINIT 23 #define SQLITE_TESTCTRL_SORTER_MMAP 24 #define SQLITE_TESTCTRL_IMPOSTER 25 -#define SQLITE_TESTCTRL_LAST 25 +#define SQLITE_TESTCTRL_PARSER_COVERAGE 26 +#define SQLITE_TESTCTRL_LAST 26 /* Largest TESTCTRL */ /* ** CAPI3REF: SQLite Runtime Status @@ -7257,6 +7246,15 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. **
    ** +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(
    SQLITE_DBSTATUS_CACHE_SPILL
    +**
    This parameter returns the number of dirty cache entries that have +** been written to disk in the middle of a transaction due to the page +** cache overflowing. Transactions are more efficient if they are written +** to disk all at once. When pages spill mid-transaction, that introduces +** additional overhead. This parameter can be used help identify +** inefficiencies that can be resolve by increasing the cache size. +**
    +** ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(
    SQLITE_DBSTATUS_DEFERRED_FKS
    **
    This parameter returns zero for the current value if and only if ** all foreign key constraints (deferred or immediate) have been @@ -7276,7 +7274,8 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r #define SQLITE_DBSTATUS_CACHE_WRITE 9 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 -#define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */ +#define SQLITE_DBSTATUS_CACHE_SPILL 12 +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ /* @@ -8276,6 +8275,40 @@ SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); */ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); +/* +** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE +** +** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn] +** method of a [virtual table], then it returns true if and only if the +** column is being fetched as part of an UPDATE operation during which the +** column value will not change. Applications might use this to substitute +** a lighter-weight value to return that the corresponding [xUpdate] method +** understands as a "no-change" value. +** +** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that +** the column is not changed by the UPDATE statement, they the xColumn +** method can optionally return without setting a result, without calling +** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces]. +** In that case, [sqlite3_value_nochange(X)] will return true for the +** same column in the [xUpdate] method. +*/ +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); + +/* +** CAPI3REF: Determine The Collation For a Virtual Table Constraint +** +** This function may only be called from within a call to the [xBestIndex] +** method of a [virtual table]. +** +** The first argument must be the sqlite3_index_info object that is the +** first parameter to the xBestIndex() method. The second argument must be +** an index into the aConstraint[] array belonging to the sqlite3_index_info +** structure passed to xBestIndex. This function returns a pointer to a buffer +** containing the name of the collation sequence for the corresponding +** constraint. +*/ +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); + /* ** CAPI3REF: Conflict resolution modes ** KEYWORDS: {conflict resolution mode} @@ -8722,6 +8755,128 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( */ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); +/* +** CAPI3REF: Serialize a database +** +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory +** that is a serialization of the S database on [database connection] D. +** If P is not a NULL pointer, then the size of the database in bytes +** is written into *P. +** +** For an ordinary on-disk database file, the serialization is just a +** copy of the disk file. For an in-memory database or a "TEMP" database, +** the serialization is the same sequence of bytes which would be written +** to disk if that database where backed up to disk. +** +** The usual case is that sqlite3_serialize() copies the serialization of +** the database into memory obtained from [sqlite3_malloc64()] and returns +** a pointer to that memory. The caller is responsible for freeing the +** returned value to avoid a memory leak. However, if the F argument +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations +** are made, and the sqlite3_serialize() function will return a pointer +** to the contiguous memory representation of the database that SQLite +** is currently using for that database, or NULL if the no such contiguous +** memory representation of the database exists. A contiguous memory +** representation of the database will usually only exist if there has +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same +** values of D and S. +** The size of the database is written into *P even if the +** SQLITE_SERIALIZE_NOCOPY bit is set but no contigious copy +** of the database exists. +** +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory +** allocation error occurs. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_serialize +** +** Zero or more of the following constants can be OR-ed together for +** the F argument to [sqlite3_serialize(D,S,P,F)]. +** +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return +** a pointer to contiguous in-memory database that it is currently using, +** without making a copy of the database. If SQLite is not currently using +** a contiguous in-memory database, then this option causes +** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be +** using a contiguous in-memory database if it has been initialized by a +** prior call to [sqlite3_deserialize()]. +*/ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + +/* +** CAPI3REF: Deserialize a database +** +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the +** [database connection] D to disconnect from database S and then +** reopen S as an in-memory database based on the serialization contained +** in P. The serialized database P is N bytes in size. M is the size of +** the buffer P, which might be larger than N. If M is larger than N, and +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is +** permitted to add content to the in-memory database as long as the total +** size does not exceed M bytes. +** +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will +** invoke sqlite3_free() on the serialization buffer when the database +** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then +** SQLite will try to increase the buffer size using sqlite3_realloc64() +** if writes on the database cause it to grow larger than M bytes. +** +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the +** database is currently in a read transaction or is involved in a backup +** operation. +** +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then +** [sqlite3_free()] is invoked on argument P prior to returning. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +SQLITE_API int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_deserialize() +** +** The following are allowed values for 6th argument (the F argument) to +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. +** +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization +** in the P argument is held in memory obtained from [sqlite3_malloc64()] +** and that SQLite should take ownership of this memory and automatically +** free it when it has finished using it. Without this flag, the caller +** is resposible for freeing any dynamically allocated memory. +** +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to +** grow the size of the database using calls to [sqlite3_realloc64()]. This +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. +** Without this flag, the deserialized database cannot increase in size beyond +** the number of bytes specified by the M parameter. +** +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database +** should be treated as read-only. +*/ +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ +#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ +#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ + /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. @@ -8869,16 +9024,23 @@ extern "C" { /* ** CAPI3REF: Session Object Handle +** +** An instance of this object is a [session] that can be used to +** record changes to a database. */ typedef struct sqlite3_session sqlite3_session; /* ** CAPI3REF: Changeset Iterator Handle +** +** An instance of this object acts as a cursor for iterating +** over the elements of a [changeset] or [patchset]. */ typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; /* ** CAPI3REF: Create A New Session Object +** CONSTRUCTOR: sqlite3_session ** ** Create a new session object attached to database handle db. If successful, ** a pointer to the new object is written to *ppSession and SQLITE_OK is @@ -8915,6 +9077,7 @@ SQLITE_API int sqlite3session_create( /* ** CAPI3REF: Delete A Session Object +** DESTRUCTOR: sqlite3_session ** ** Delete a session object previously allocated using ** [sqlite3session_create()]. Once a session object has been deleted, the @@ -8930,6 +9093,7 @@ SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); /* ** CAPI3REF: Enable Or Disable A Session Object +** METHOD: sqlite3_session ** ** Enable or disable the recording of changes by a session object. When ** enabled, a session object records changes made to the database. When @@ -8949,6 +9113,7 @@ SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); /* ** CAPI3REF: Set Or Clear the Indirect Change Flag +** METHOD: sqlite3_session ** ** Each change recorded by a session object is marked as either direct or ** indirect. A change is marked as indirect if either: @@ -8978,6 +9143,7 @@ SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect) /* ** CAPI3REF: Attach A Table To A Session Object +** METHOD: sqlite3_session ** ** If argument zTab is not NULL, then it is the name of a table to attach ** to the session object passed as the first argument. All subsequent changes @@ -9003,6 +9169,35 @@ SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect) ** ** SQLITE_OK is returned if the call completes without error. Or, if an error ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned. +** +**

    Special sqlite_stat1 Handling

    +** +** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to +** some of the rules above. In SQLite, the schema of sqlite_stat1 is: +**
    +**        CREATE TABLE sqlite_stat1(tbl,idx,stat)  
    +**  
    +** +** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are +** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes +** are recorded for rows for which (idx IS NULL) is true. However, for such +** rows a zero-length blob (SQL value X'') is stored in the changeset or +** patchset instead of a NULL value. This allows such changesets to be +** manipulated by legacy implementations of sqlite3changeset_invert(), +** concat() and similar. +** +** The sqlite3changeset_apply() function automatically converts the +** zero-length blob back to a NULL value when updating the sqlite_stat1 +** table. However, if the application calls sqlite3changeset_new(), +** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset +** iterator directly (including on a changeset iterator passed to a +** conflict-handler callback) then the X'' value is returned. The application +** must translate X'' to NULL itself if required. +** +** Legacy (older than 3.22.0) versions of the sessions module cannot capture +** changes made to the sqlite_stat1 table. Legacy versions of the +** sqlite3changeset_apply() function silently ignore any modifications to the +** sqlite_stat1 table that are part of a changeset or patchset. */ SQLITE_API int sqlite3session_attach( sqlite3_session *pSession, /* Session object */ @@ -9011,6 +9206,7 @@ SQLITE_API int sqlite3session_attach( /* ** CAPI3REF: Set a table filter on a Session Object. +** METHOD: sqlite3_session ** ** The second argument (xFilter) is the "filter callback". For changes to rows ** in tables that are not attached to the Session object, the filter is called @@ -9029,6 +9225,7 @@ SQLITE_API void sqlite3session_table_filter( /* ** CAPI3REF: Generate A Changeset From A Session Object +** METHOD: sqlite3_session ** ** Obtain a changeset containing changes to the tables attached to the ** session object passed as the first argument. If successful, @@ -9138,7 +9335,8 @@ SQLITE_API int sqlite3session_changeset( ); /* -** CAPI3REF: Load The Difference Between Tables Into A Session +** CAPI3REF: Load The Difference Between Tables Into A Session +** METHOD: sqlite3_session ** ** If it is not already attached to the session object passed as the first ** argument, this function attaches table zTbl in the same manner as the @@ -9203,6 +9401,7 @@ SQLITE_API int sqlite3session_diff( /* ** CAPI3REF: Generate A Patchset From A Session Object +** METHOD: sqlite3_session ** ** The differences between a patchset and a changeset are that: ** @@ -9254,6 +9453,7 @@ SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); /* ** CAPI3REF: Create An Iterator To Traverse A Changeset +** CONSTRUCTOR: sqlite3_changeset_iter ** ** Create an iterator used to iterate through the contents of a changeset. ** If successful, *pp is set to point to the iterator handle and SQLITE_OK @@ -9294,6 +9494,7 @@ SQLITE_API int sqlite3changeset_start( /* ** CAPI3REF: Advance A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function may only be used with iterators created by function ** [sqlite3changeset_start()]. If it is called on an iterator passed to @@ -9318,6 +9519,7 @@ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); /* ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -9352,6 +9554,7 @@ SQLITE_API int sqlite3changeset_op( /* ** CAPI3REF: Obtain The Primary Key Definition Of A Table +** METHOD: sqlite3_changeset_iter ** ** For each modified table, a changeset includes the following: ** @@ -9383,6 +9586,7 @@ SQLITE_API int sqlite3changeset_pk( /* ** CAPI3REF: Obtain old.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -9413,6 +9617,7 @@ SQLITE_API int sqlite3changeset_old( /* ** CAPI3REF: Obtain new.* Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** The pIter argument passed to this function may either be an iterator ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator @@ -9446,6 +9651,7 @@ SQLITE_API int sqlite3changeset_new( /* ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function should only be used with iterator objects passed to a ** conflict-handler callback by [sqlite3changeset_apply()] with either @@ -9473,6 +9679,7 @@ SQLITE_API int sqlite3changeset_conflict( /* ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations +** METHOD: sqlite3_changeset_iter ** ** This function may only be called with an iterator passed to an ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case @@ -9489,6 +9696,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts( /* ** CAPI3REF: Finalize A Changeset Iterator +** METHOD: sqlite3_changeset_iter ** ** This function is used to finalize an iterator allocated with ** [sqlite3changeset_start()]. @@ -9505,6 +9713,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts( ** to that error is returned by this function. Otherwise, SQLITE_OK is ** returned. This is to allow the following pattern (pseudo-code): ** +**
     **   sqlite3changeset_start();
     **   while( SQLITE_ROW==sqlite3changeset_next() ){
     **     // Do something with change.
    @@ -9513,6 +9722,7 @@ SQLITE_API int sqlite3changeset_fk_conflicts(
     **   if( rc!=SQLITE_OK ){
     **     // An error has occurred 
     **   }
    +** 
    */ SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); @@ -9560,6 +9770,7 @@ SQLITE_API int sqlite3changeset_invert( ** sqlite3_changegroup object. Calling it produces similar results as the ** following code fragment: ** +**
     **   sqlite3_changegroup *pGrp;
     **   rc = sqlite3_changegroup_new(&pGrp);
     **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
    @@ -9570,6 +9781,7 @@ SQLITE_API int sqlite3changeset_invert(
     **     *ppOut = 0;
     **     *pnOut = 0;
     **   }
    +** 
    ** ** Refer to the sqlite3_changegroup documentation below for details. */ @@ -9585,11 +9797,15 @@ SQLITE_API int sqlite3changeset_concat( /* ** CAPI3REF: Changegroup Handle +** +** A changegroup is an object used to combine two or more +** [changesets] or [patchsets] */ typedef struct sqlite3_changegroup sqlite3_changegroup; /* ** CAPI3REF: Create A New Changegroup Object +** CONSTRUCTOR: sqlite3_changegroup ** ** An sqlite3_changegroup object is used to combine two or more changesets ** (or patchsets) into a single changeset (or patchset). A single changegroup @@ -9627,6 +9843,7 @@ SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); /* ** CAPI3REF: Add A Changeset To A Changegroup +** METHOD: sqlite3_changegroup ** ** Add all changes within the changeset (or patchset) in buffer pData (size ** nData bytes) to the changegroup. @@ -9704,6 +9921,7 @@ SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pDa /* ** CAPI3REF: Obtain A Composite Changeset From A Changegroup +** METHOD: sqlite3_changegroup ** ** Obtain a buffer containing a changeset (or patchset) representing the ** current contents of the changegroup. If the inputs to the changegroup @@ -9734,25 +9952,25 @@ SQLITE_API int sqlite3changegroup_output( /* ** CAPI3REF: Delete A Changegroup Object +** DESTRUCTOR: sqlite3_changegroup */ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); /* ** CAPI3REF: Apply A Changeset To A Database ** -** Apply a changeset to a database. This function attempts to update the -** "main" database attached to handle db with the changes found in the -** changeset passed via the second and third arguments. +** Apply a changeset or patchset to a database. These functions attempt to +** update the "main" database attached to handle db with the changes found in +** the changeset passed via the second and third arguments. ** -** The fourth argument (xFilter) passed to this function is the "filter +** The fourth argument (xFilter) passed to these functions is the "filter ** callback". If it is not NULL, then for each table affected by at least one ** change in the changeset, the filter callback is invoked with ** the table name as the second argument, and a copy of the context pointer -** passed as the sixth argument to this function as the first. If the "filter -** callback" returns zero, then no attempt is made to apply any changes to -** the table. Otherwise, if the return value is non-zero or the xFilter -** argument to this function is NULL, all changes related to the table are -** attempted. +** passed as the sixth argument as the first. If the "filter callback" +** returns zero, then no attempt is made to apply any changes to the table. +** Otherwise, if the return value is non-zero or the xFilter argument to +** is NULL, all changes related to the table are attempted. ** ** For each table that is not excluded by the filter callback, this function ** tests that the target database contains a compatible table. A table is @@ -9797,7 +10015,7 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** **
    **
    DELETE Changes
    -** For each DELETE change, this function checks if the target database +** For each DELETE change, the function checks if the target database ** contains a row with the same primary key value (or values) as the ** original row values stored in the changeset. If it does, and the values ** stored in all non-primary key columns also match the values stored in @@ -9842,7 +10060,7 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** [SQLITE_CHANGESET_REPLACE]. ** **
    UPDATE Changes
    -** For each UPDATE change, this function checks if the target database +** For each UPDATE change, the function checks if the target database ** contains a row with the same primary key value (or values) as the ** original row values stored in the changeset. If it does, and the values ** stored in all modified non-primary key columns also match the values @@ -9873,11 +10091,28 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** This can be used to further customize the applications conflict ** resolution strategy. ** -** All changes made by this function are enclosed in a savepoint transaction. +** All changes made by these functions are enclosed in a savepoint transaction. ** If any other error (aside from a constraint failure when attempting to ** write to the target database) occurs, then the savepoint transaction is ** rolled back, restoring the target database to its original state, and an ** SQLite error code returned. +** +** If the output parameters (ppRebase) and (pnRebase) are non-NULL and +** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2() +** may set (*ppRebase) to point to a "rebase" that may be used with the +** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase) +** is set to the size of the buffer in bytes. It is the responsibility of the +** caller to eventually free any such buffer using sqlite3_free(). The buffer +** is only allocated and populated if one or more conflicts were encountered +** while applying the patchset. See comments surrounding the sqlite3_rebaser +** APIs for further details. +** +** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent +** may be modified by passing a combination of +** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter. +** +** Note that the sqlite3changeset_apply_v2() API is still experimental +** and therefore subject to change. */ SQLITE_API int sqlite3changeset_apply( sqlite3 *db, /* Apply change to "main" db of this handle */ @@ -9894,6 +10129,41 @@ SQLITE_API int sqlite3changeset_apply( ), void *pCtx /* First argument passed to xConflict */ ); +SQLITE_API int sqlite3changeset_apply_v2( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, /* OUT: Rebase data */ + int flags /* Combination of SESSION_APPLY_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3changeset_apply_v2 +** +** The following flags may passed via the 9th parameter to +** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]: +** +**
    +**
    SQLITE_CHANGESETAPPLY_NOSAVEPOINT
    +** Usually, the sessions module encloses all operations performed by +** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The +** SAVEPOINT is committed if the changeset or patchset is successfully +** applied, or rolled back if an error occurs. Specifying this flag +** causes the sessions module to omit this savepoint. In this case, if the +** caller has an open transaction or savepoint when apply_v2() is called, +** it may revert the partially applied changeset by rolling it back. +*/ +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 /* ** CAPI3REF: Constants Passed To The Conflict Handler @@ -9991,6 +10261,161 @@ SQLITE_API int sqlite3changeset_apply( #define SQLITE_CHANGESET_REPLACE 1 #define SQLITE_CHANGESET_ABORT 2 +/* +** CAPI3REF: Rebasing changesets +** EXPERIMENTAL +** +** Suppose there is a site hosting a database in state S0. And that +** modifications are made that move that database to state S1 and a +** changeset recorded (the "local" changeset). Then, a changeset based +** on S0 is received from another site (the "remote" changeset) and +** applied to the database. The database is then in state +** (S1+"remote"), where the exact state depends on any conflict +** resolution decisions (OMIT or REPLACE) made while applying "remote". +** Rebasing a changeset is to update it to take those conflict +** resolution decisions into account, so that the same conflicts +** do not have to be resolved elsewhere in the network. +** +** For example, if both the local and remote changesets contain an +** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)": +** +** local: INSERT INTO t1 VALUES(1, 'v1'); +** remote: INSERT INTO t1 VALUES(1, 'v2'); +** +** and the conflict resolution is REPLACE, then the INSERT change is +** removed from the local changeset (it was overridden). Or, if the +** conflict resolution was "OMIT", then the local changeset is modified +** to instead contain: +** +** UPDATE t1 SET b = 'v2' WHERE a=1; +** +** Changes within the local changeset are rebased as follows: +** +**
    +**
    Local INSERT
    +** This may only conflict with a remote INSERT. If the conflict +** resolution was OMIT, then add an UPDATE change to the rebased +** changeset. Or, if the conflict resolution was REPLACE, add +** nothing to the rebased changeset. +** +**
    Local DELETE
    +** This may conflict with a remote UPDATE or DELETE. In both cases the +** only possible resolution is OMIT. If the remote operation was a +** DELETE, then add no change to the rebased changeset. If the remote +** operation was an UPDATE, then the old.* fields of change are updated +** to reflect the new.* values in the UPDATE. +** +**
    Local UPDATE
    +** This may conflict with a remote UPDATE or DELETE. If it conflicts +** with a DELETE, and the conflict resolution was OMIT, then the update +** is changed into an INSERT. Any undefined values in the new.* record +** from the update change are filled in using the old.* values from +** the conflicting DELETE. Or, if the conflict resolution was REPLACE, +** the UPDATE change is simply omitted from the rebased changeset. +** +** If conflict is with a remote UPDATE and the resolution is OMIT, then +** the old.* values are rebased using the new.* values in the remote +** change. Or, if the resolution is REPLACE, then the change is copied +** into the rebased changeset with updates to columns also updated by +** the conflicting remote UPDATE removed. If this means no columns would +** be updated, the change is omitted. +**
    +** +** A local change may be rebased against multiple remote changes +** simultaneously. If a single key is modified by multiple remote +** changesets, they are combined as follows before the local changeset +** is rebased: +** +**
      +**
    • If there has been one or more REPLACE resolutions on a +** key, it is rebased according to a REPLACE. +** +**
    • If there have been no REPLACE resolutions on a key, then +** the local changeset is rebased according to the most recent +** of the OMIT resolutions. +**
    +** +** Note that conflict resolutions from multiple remote changesets are +** combined on a per-field basis, not per-row. This means that in the +** case of multiple remote UPDATE operations, some fields of a single +** local change may be rebased for REPLACE while others are rebased for +** OMIT. +** +** In order to rebase a local changeset, the remote changeset must first +** be applied to the local database using sqlite3changeset_apply_v2() and +** the buffer of rebase information captured. Then: +** +**
      +**
    1. An sqlite3_rebaser object is created by calling +** sqlite3rebaser_create(). +**
    2. The new object is configured with the rebase buffer obtained from +** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure(). +** If the local changeset is to be rebased against multiple remote +** changesets, then sqlite3rebaser_configure() should be called +** multiple times, in the same order that the multiple +** sqlite3changeset_apply_v2() calls were made. +**
    3. Each local changeset is rebased by calling sqlite3rebaser_rebase(). +**
    4. The sqlite3_rebaser object is deleted by calling +** sqlite3rebaser_delete(). +**
    +*/ +typedef struct sqlite3_rebaser sqlite3_rebaser; + +/* +** CAPI3REF: Create a changeset rebaser object. +** EXPERIMENTAL +** +** Allocate a new changeset rebaser object. If successful, set (*ppNew) to +** point to the new object and return SQLITE_OK. Otherwise, if an error +** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) +** to NULL. +*/ +SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew); + +/* +** CAPI3REF: Configure a changeset rebaser object. +** EXPERIMENTAL +** +** Configure the changeset rebaser object to rebase changesets according +** to the conflict resolutions described by buffer pRebase (size nRebase +** bytes), which must have been obtained from a previous call to +** sqlite3changeset_apply_v2(). +*/ +SQLITE_API int sqlite3rebaser_configure( + sqlite3_rebaser*, + int nRebase, const void *pRebase +); + +/* +** CAPI3REF: Rebase a changeset +** EXPERIMENTAL +** +** Argument pIn must point to a buffer containing a changeset nIn bytes +** in size. This function allocates and populates a buffer with a copy +** of the changeset rebased rebased according to the configuration of the +** rebaser object passed as the first argument. If successful, (*ppOut) +** is set to point to the new buffer containing the rebased changset and +** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the +** responsibility of the caller to eventually free the new buffer using +** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) +** are set to zero and an SQLite error code returned. +*/ +SQLITE_API int sqlite3rebaser_rebase( + sqlite3_rebaser*, + int nIn, const void *pIn, + int *pnOut, void **ppOut +); + +/* +** CAPI3REF: Delete a changeset rebaser object. +** EXPERIMENTAL +** +** Delete the changeset rebaser object and all associated resources. There +** should be one call to this function for each successful invocation +** of sqlite3rebaser_create(). +*/ +SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); + /* ** CAPI3REF: Streaming Versions of API functions. ** @@ -10000,6 +10425,7 @@ SQLITE_API int sqlite3changeset_apply( ** ** **
    Streaming functionNon-streaming equivalent
    sqlite3changeset_apply_strm[sqlite3changeset_apply] +**
    sqlite3changeset_apply_strm_v2[sqlite3changeset_apply_v2] **
    sqlite3changeset_concat_strm[sqlite3changeset_concat] **
    sqlite3changeset_invert_strm[sqlite3changeset_invert] **
    sqlite3changeset_start_strm[sqlite3changeset_start] @@ -10095,6 +10521,23 @@ SQLITE_API int sqlite3changeset_apply_strm( ), void *pCtx /* First argument passed to xConflict */ ); +SQLITE_API int sqlite3changeset_apply_v2_strm( + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int(*xFilter)( + void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int(*xConflict)( + void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, int *pnRebase, + int flags +); SQLITE_API int sqlite3changeset_concat_strm( int (*xInputA)(void *pIn, void *pData, int *pnData), void *pInA, @@ -10132,6 +10575,13 @@ SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*, int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut ); +SQLITE_API int sqlite3rebaser_rebase_strm( + sqlite3_rebaser *pRebaser, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut +); /* diff --git a/linux/installer/common/sdk/BOMs/sdk_base.txt b/linux/installer/common/sdk/BOMs/sdk_base.txt index a8e7c53d..79557f78 100644 --- a/linux/installer/common/sdk/BOMs/sdk_base.txt +++ b/linux/installer/common/sdk/BOMs/sdk_base.txt @@ -33,6 +33,7 @@ DeliveryName InstallName FileCheckSum FileFeature FileOwner /common/inc/sgx_utils.h /package/include/./sgx_utils.h 0 main STP /common/inc/sgx_tprotected_fs.h /package/include/./sgx_tprotected_fs.h 0 main STP /common/inc/sgx_tprotected_fs.edl /package/include/./sgx_tprotected_fs.edl 0 main STP +/common/inc/sgx_pcl_guid.h /package/include/./sgx_pcl_guid.h 0 main STP /common/inc/stdc++/exception /package/include/stdc++/exception 0 main STP /common/inc/stdc++/linux/exception /package/include/stdc++/linux/exception 0 main STP /common/inc/stdc++/linux/typeinfo /package/include/stdc++/linux/typeinfo 0 main STP @@ -68,6 +69,10 @@ DeliveryName InstallName FileCheckSum FileFeature FileOwner /common/inc/tlibc/mbusafecrt.h /package/include/tlibc/mbusafecrt.h 0 main STP /common/src/se_memory.c /package/ptrace/se_memory.c 0 main STP /common/src/se_trace.c /package/ptrace/se_trace.c 0 main STP +/external/ippcp_internal/inc/ippcp.h /package/include/ipp/ippcp.h 0 main STP +/external/ippcp_internal/inc/ippcpdefs.h /package/include/ipp/ippcpdefs.h 0 main STP +/external/ippcp_internal/inc/ippversion.h /package/include/ipp/ippversion.h 0 main STP +/external/ippcp_internal/inc/sgx_ippcp.h /package/include/ipp/sgx_ippcp.h 0 main STP /linux/installer/common/sdk/install.sh /scripts/install.sh 0 main STP /linux/installer/common/sdk/Makefile /Makefile 0 main STP /SampleCode/LocalAttestation/App/App.cpp /package/SampleCode/LocalAttestation/App/App.cpp 0 main STP @@ -181,6 +186,44 @@ DeliveryName InstallName FileCheckSum FileFeature FileOwner /SampleCode/SampleEnclave/Makefile /package/SampleCode/SampleEnclave/Makefile 0 main STP /SampleCode/SampleEnclave/.project /package/SampleCode/SampleEnclave/.project 0 main STP /SampleCode/SampleEnclave/README.txt /package/SampleCode/SampleEnclave/README.txt 0 main STP +/SampleCode/SampleEnclavePCL/App/App.cpp /package/SampleCode/SampleEnclavePCL/App/App.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/App.h /package/SampleCode/SampleEnclavePCL/App/App.h 0 main STP +/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp /package/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp /package/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp /package/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp /package/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp /package/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp /package/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp 0 main STP +/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp /package/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl /package/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml /package/SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp /package/SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave.edl /package/SampleCode/SampleEnclavePCL/Enclave/Enclave.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave.h /package/SampleCode/SampleEnclavePCL/Enclave/Enclave.h 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave.lds /package/SampleCode/SampleEnclavePCL/Enclave/Enclave.lds 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem /package/SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl /package/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl 0 main STP +/SampleCode/SampleEnclavePCL/Include/user_types.h /package/SampleCode/SampleEnclavePCL/Include/user_types.h 0 main STP +/SampleCode/SampleEnclavePCL/Makefile /package/SampleCode/SampleEnclavePCL/Makefile 0 main STP +/SampleCode/SampleEnclavePCL/debug_mock_key.bin /package/SampleCode/SampleEnclavePCL/debug_mock_key.bin 0 main STP +/SampleCode/SampleEnclavePCL/README.md /package/SampleCode/SampleEnclavePCL/README.md 0 main STP +/SampleCode/SampleEnclavePCL/Seal/Seal.config.xml /package/SampleCode/SampleEnclavePCL/Seal/Seal.config.xml 0 main STP +/SampleCode/SampleEnclavePCL/Seal/Seal.cpp /package/SampleCode/SampleEnclavePCL/Seal/Seal.cpp 0 main STP +/SampleCode/SampleEnclavePCL/Seal/Seal.edl /package/SampleCode/SampleEnclavePCL/Seal/Seal.edl 0 main STP +/SampleCode/SampleEnclavePCL/Seal/Seal.lds /package/SampleCode/SampleEnclavePCL/Seal/Seal.lds 0 main STP +/SampleCode/SampleEnclavePCL/Seal/Seal_private.pem /package/SampleCode/SampleEnclavePCL/Seal/Seal_private.pem 0 main STP /SampleCode/SealedData/.cproject /package/SampleCode/SealedData/.cproject 0 main STP /SampleCode/SealedData/.settings/language.settings.xml /package/SampleCode/SealedData/.settings/language.settings.xml 0 main STP /SampleCode/SealedData/.project /package/SampleCode/SealedData/.project 0 main STP diff --git a/linux/installer/common/sdk/BOMs/sdk_x64.txt b/linux/installer/common/sdk/BOMs/sdk_x64.txt index cb4dadfe..a4622d12 100644 --- a/linux/installer/common/sdk/BOMs/sdk_x64.txt +++ b/linux/installer/common/sdk/BOMs/sdk_x64.txt @@ -22,6 +22,8 @@ DeliveryName InstallName FileCheckSum FileFeature FileOwner /build/linux/libsgx_capable.so /package/lib64/libsgx_capable.so 0 main STP /build/linux/libsgx_uprotected_fs.a /package/lib64/libsgx_uprotected_fs.a 0 main STP /build/linux/libsgx_tprotected_fs.a /package/lib64/libsgx_tprotected_fs.a 0 main STP +/build/linux/libsgx_pcl.a /package/lib64/libsgx_pcl.a 0 main STP +/build/linux/libsgx_pclsim.a /package/lib64/libsgx_pclsim.a 0 main STP /build/linux/libsgx_urts_deploy.so /package/lib64/libsgx_urts.so 0 main STP /build/linux/libsgx_urts_sim.so /package/lib64/libsgx_urts_sim.so 0 main STP /build/linux/STLport_Changes_SGX.txt /package/lib64/STLport_Changes_SGX.txt 0 main STP @@ -29,6 +31,7 @@ DeliveryName InstallName FileCheckSum FileFeature FileOwner /build/linux/sgx_config_cpusvn /package/bin/x64/sgx_config_cpusvn 0 main STP /build/linux/sgx_edger8r /package/bin/x64/sgx_edger8r 0 main STP /build/linux/sgx_sign /package/bin/x64/sgx_sign 0 main STP +/build/linux/sgx_encrypt /package/bin/x64/sgx_encrypt 0 main STP /linux/installer/common/sdk/installConfig.x64 /scripts/installConfig 0 main STP /linux/installer/common/sdk/pkgconfig/x64/libsgx_uae_service_sim.pc /package/pkgconfig/libsgx_uae_service_sim.pc 0 main STP /linux/installer/common/sdk/pkgconfig/x64/libsgx_urts_sim.pc /package/pkgconfig/libsgx_urts_sim.pc 0 main STP diff --git a/psw/ae/aesm_service/Makefile b/psw/ae/aesm_service/Makefile index 1128b458..2b537fad 100644 --- a/psw/ae/aesm_service/Makefile +++ b/psw/ae/aesm_service/Makefile @@ -32,7 +32,7 @@ TOP_DIR = ../../.. include $(TOP_DIR)/buildenv.mk -IPC_COMMON_DIR := ../common/ +IPC_COMMON_DIR := ../common IPC_COMMON_SRC_DIR := $(IPC_COMMON_DIR)/src IPC_COMMON_INC_DIR := $(IPC_COMMON_DIR)/inc IPC_COMMON_PROTO_DIR := source/protobuf @@ -75,7 +75,7 @@ INCLUDE += -I$(LINUX_PSW_DIR)/ae/inc \ INCLUDE += -I$(LINUX_PSW_DIR)/ae/pve \ -I$(LINUX_PSW_DIR)/ae/pse/pse_op -INCLUDE += -I$(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0 \ +INCLUDE += -I$(LINUX_EXTERNAL_DIR)/epid-sdk \ -I$(LINUX_EXTERNAL_DIR)/sqlite/src \ -I$(LINUX_EXTERNAL_DIR)/DALSdk/JHI/linux diff --git a/psw/ae/aesm_service/source/aesm/application/aesm_logic.cpp b/psw/ae/aesm_service/source/aesm/application/aesm_logic.cpp index 09d6d8ca..790c7f20 100644 --- a/psw/ae/aesm_service/source/aesm/application/aesm_logic.cpp +++ b/psw/ae/aesm_service/source/aesm/application/aesm_logic.cpp @@ -62,11 +62,8 @@ #include "se_wrapper.h" #include "PSDAService.h" #include "ippcp.h" -#include "ippcore.h" #include #include -#include "ippcp.h" -#include "ippcore.h" #include "prof_fun.h" #include "upse/helper.h" #include "aesm_long_lived_thread.h" @@ -215,7 +212,7 @@ ae_error_t AESMLogic::service_start() AESM_LOG_INIT(); #ifdef SGX_USE_OPT_LIB - ippInit(); + ippcpInit(); #endif AESM_DBG_INFO("aesm service is starting"); // Try to read active extended epid group id from data file diff --git a/psw/ae/aesm_service/source/aesm/extension/endpoint_select_info.cpp b/psw/ae/aesm_service/source/aesm/extension/endpoint_select_info.cpp index 8966da07..78ad72e8 100644 --- a/psw/ae/aesm_service/source/aesm/extension/endpoint_select_info.cpp +++ b/psw/ae/aesm_service/source/aesm/extension/endpoint_select_info.cpp @@ -36,8 +36,6 @@ #include "network_encoding_wrapper.h" #include "ipp_wrapper.h" #include "sgx_tcrypto.h" -#include "ippcp.h" -#include "ippcore.h" #include "aesm_xegd_blob.h" #include "peksk_pub.hh" #include "sgx_read_rand.h" diff --git a/psw/ae/aesm_service/source/le/LEClass.cpp b/psw/ae/aesm_service/source/le/LEClass.cpp index 609eb2d5..837c9b75 100644 --- a/psw/ae/aesm_service/source/le/LEClass.cpp +++ b/psw/ae/aesm_service/source/le/LEClass.cpp @@ -368,7 +368,7 @@ int CLEClass::get_launch_token( return LE_INVALID_PARAMETER; //set mrsigner based on the hash of isv pub key from enclave signature IppStatus ipperrorCode = ippStsNoErr; - ipperrorCode = ippsHashMessage(reinterpret_cast(public_key), public_key_size, reinterpret_cast(&mrsigner), IPP_ALG_HASH_SHA256); + ipperrorCode = ippsHashMessage_rmf(reinterpret_cast(public_key), public_key_size, reinterpret_cast(&mrsigner), ippsHashMethod_SHA256_TT()); if( ipperrorCode != ippStsNoErr){ return AE_FAILURE; } diff --git a/psw/ae/common/pve_qe_common.cpp b/psw/ae/common/pve_qe_common.cpp index bcfd4747..7d1bc0b6 100644 --- a/psw/ae/common/pve_qe_common.cpp +++ b/psw/ae/common/pve_qe_common.cpp @@ -29,14 +29,23 @@ * */ - #include "stdlib.h" #include "string.h" #include "pve_qe_common.h" #include "assert.h" #include "util.h" #include "sgx_trts.h" -#include "isk_pub.hh" +#ifdef __cplusplus +extern "C" { +#endif +#include "epid/common/src/memory.h" +#include "epid/member/software_member.h" +#include "epid/member/src/write_precomp.h" +#include "epid/member/src/signbasic.h" +#include "epid/member/src/nrprove.h" +#ifdef __cplusplus +} +#endif /* * Function used to get ECP context. @@ -65,7 +74,7 @@ IppStatus new_std_256_ecp(IppsECCPState **pp_new_ecp) return ipp_ret; } - ipp_ret = ippsECCPSetStd(IppECCPStd256r1, p_ctx); + ipp_ret = ippsECCPSetStd256r1(p_ctx); if(ippStsNoErr != ipp_ret) { free(p_ctx); @@ -97,7 +106,7 @@ void secure_free_std_256_ecp(IppsECCPState *p_ecp) } -int __STDCALL epid_random_func( +int IPP_STDCALL epid_random_func( unsigned int *p_random_data, int bits, void* p_user_data) @@ -111,3 +120,53 @@ int __STDCALL epid_random_func( return ippStsNoErr; } +EpidStatus epid_member_create(BitSupplier rnd_func, void* rnd_param, FpElemStr* f, MemberCtx** ctx) +{ + MemberParams params; + size_t member_size = 0; + EpidStatus epid_ret = kEpidNoErr; + + memset(¶ms, 0, sizeof(params)); + + params.rnd_func = rnd_func; + params.rnd_param = rnd_param; + params.f = f; + + epid_ret = EpidMemberGetSize(¶ms, &member_size); + if (kEpidNoErr != epid_ret) { + return epid_ret; + } + + *ctx = (MemberCtx*)SAFE_ALLOC(member_size); + if (!(*ctx)) { + return kEpidNoMemErr; + } + + epid_ret = EpidMemberInit(¶ms, *ctx); + if (kEpidNoErr != epid_ret) { + SAFE_FREE(*ctx); + *ctx = NULL; + return epid_ret; + } + + epid_ret = EpidMemberSetHashAlg(*ctx, kSha256); + if (kEpidNoErr != epid_ret) { + goto ret_point; + } + +ret_point: + if (kEpidNoErr != epid_ret) { + epid_member_delete(ctx); + } + return epid_ret; +} + +void epid_member_delete(MemberCtx** ctx) +{ + if (!ctx) { + return; + } + EpidMemberDeinit(*ctx); + SAFE_FREE(*ctx); + *ctx = NULL; +} diff --git a/psw/ae/data/prebuilt/le_prod_css.bin b/psw/ae/data/prebuilt/le_prod_css.bin index 5b48e10315cef65355fb06e9a5967e81883d4585..caae19f25463c637ebab96b40a78546747fa9f73 100644 GIT binary patch delta 1243 zcmV<11SI>A4v-Fz6apj!u@>$De{>23va*8^jjZ#Pi9`4c^p*_C)OWVF-OCuHMbh_c zVP&$A|T!-psHLHSpigg?{6vgw?P;YAPi=$TvGV@>jM6GYx!7#6tX2M+M% z+*}s954IM2cK7^}OT#fVfr>^hJ6RRJOy)1M`rxM`bF^E9{}ke@ZTb`J2Jq!=?l*do zt$L1`KKlVqUx!jENruvBfBy+E3Dku+3lEADkHae6<(Rw2`;Ts0*)>LJ(im*u>p&E{ zy@5*NoY|mn*%@wMI`5rT<~s>v!dFg;sb@>cbL%#!a0w>?q|W-^;el&cxmdPqgO70R z+)3N~l2j@I@Yy;C)Ade z6dnnJJw;l1BIk2SN-Bl%Ih3ZC%;*{+ut=_#7P^lnCAwCqZ0 z=h90`ENK>5d>E{Mh}yI;?EbaM@9M3`A5pX!D0vucd$_pSL53%&t9wrSh$VOTB^_K2 zfi*&&5?LJTIHJ2MS^-TK$~1ty??=E*YYOCjzEqNZHEh`~cyHB!Q~c)u`HqUewrlW11DZq(ptfbpKrZ-1`u% zOO`H5lADVGi{I<&Le-eQpM1;5M77|r?(GK|xrMG6aD1bwFyMlguP-LPnhLDbVsBKl z3afW>BuXWJH2d}KUqFQ90x?h8oym!C?~kpnTL*W|l+o*^-@q_lrCvdZ`Kjv%FNyO= zFMzAGc40QhIn{zokAzHiUWA5@_n73blH=NWlK4QHLGHGIE`{XOPCNoMH6(l%0mo&>x$mn>-xh3%A`7~gmJ4%} F0w3OyWBdRB delta 1243 zcmV<11SI>A4v-Fz6aokXu@>$De|V+G2RI(emcgQI+Zr;@r(`970&#O|HW7^^ZgBcq zEQ1$>wCUW{2|Mc$CQjM+5sZ?HcrE)`7UEq31WNU7)M5z0)<*)U0y1i{VK?4q7%mEi z@??+cq-duyCVgZ)x=g>{ibdbbU>%eYRhfd&dHWGjK5?UDM{L;oVWJ~be>-Fi#hi-m zH8WoO$Fj#*oX2|V%U|-hcu8yT1V+~J5H+JQWlE$0{!~q^*6U>*1QD93+k|109G&g! z?;-?H+kz;BF{staHO22S6Do!WbzZ@u-2;QAtkY@wtcw;$pfms|lu)=4*TDB92y zD9EUe_JD+HlvI_U@jHdMaY?wVwBjUY*kivi9K~4WT8bR0K`mWkjGu$rkyXlXYI&u= z*YFxWUoKgJr17216G7VI=k0*eMDnK1uN%5ok2gxB`YBu4M#Sl{3)D$300000|NsC0 zkuemLpaUQv^Aof2X89QQI<_0=_ zfzd8}EMj!jxkYa8{Eqg(e?EmbRGZ68JBn`6j!nzTb~i~(kBAVIDz;+1UD8zX#my3O zEW|>cFS+Lv_{--bWOJ(fDIHMb6Piv&{;=BLZ@%9H;*=gYcMiLwOh44NNH=L>tt7k5aA>xC>~INHj{9aSCXWZh%e zStwOxp9247F!IhIpsRxL5EBqUH5&czct0gI#kNMYf=tvjD3qY)Y zkF3m#?@IkIzH3^4x&T7(UU!eUBYN4JkR-T4`z{PwBp4*!`t#9oT&42d0FVUxmVXjv z_Wugt{vNY5SYD@ue~ngm2BwL#P%NB^&_Hl{16$1*%Y5=sq4<`w5>3NiCp-D}Rm}fK zj`;PAmQv6}m$FXISV35SxI-+w2b;4560oLgu4RT@yJ!o4E0ixOH!j_Rh;An_xW)bi zZ&=H1@TcPX4f45Irfd3M?7oLPaE)V1ZPg8#CaIiuARdk#)1yajl$LWq-9hpx-x9Vlq5NNLEd5I67Hq#>)K^3E6} zFTV|8VW2C5Pxfuh0H(CbNlZ9$wf!dpP?bdVxmhi%4bts{!_VCuP>H#ucM6$`a{nZZ zUP`a>SXbB)aKK*c~pe FtRJ^_X@dX& diff --git a/psw/ae/data/prebuilt/white_list_cert_to_be_verify.bin b/psw/ae/data/prebuilt/white_list_cert_to_be_verify.bin index b016c56b53d8c7498bcef0108ecd2459570129c0..e061a78ea439a6e094bd0faff34d84524bb4db14 100644 GIT binary patch delta 1112 zcmV-e1gHDB1Go#2lLa0C001YEnBae#2-W?3uV5}R&~-3+C(t%jupMElN}r z@|qTE=VEpNJ;XeQG04+;jTrGcnRz%r!*t~~kN>GOo@qUt5qxg4RktAo2d01DW==WK zes7l?4;{EN6D0)Q*=+=ZRk?Q=CuF5k1^0mbsJ&&guwV52^rilFLrc4>!H!CWjD&=W zdF9a_$|i8$#&4ODMF_*>sqh}`EW}|aAU5l0zeYATyA!J-tf6SZ1 z#5?cTu$Wg+21eYRtGQhfmdSssdE{yqYFwDp6T>605?RrE&gs22oj?)kSad6|QUELN z8Mc{;rm0WRJ?b(5FY_j)?s}ulmfEI6S~FZq{~Vs&r%v%Jg+jfw(%*Ci)jo(F$r2b(v?{aWTwP&}`Ki$g zXso9kN^p+8n-&`xOwdqfT1w#nta;z~@i)I`1!iPiC)Z^Oc%KH7@1#6PV9CeT&tzC{ zQA#Xs)Oex=^GRCOVw`_Fqz*2&Qe!miVWX!S>It>D-xnM^HlK%k>nbClN7a?-@KQ_b zcjc7m7VYm4Itjw8D>2hup$vzW;aJmAcwQ-5oIjreVav?#QAYpMCF>0bNd=IK%n_ub zG!=H2)FV*!>}q{gJAX=9L!GyH6iAhGmS-y|xO5tVKeKjNgMfcKd~?gW9CpIk*0MT< z-lAYt$}Ani5%}3G>GRsv*U$6~o0*)b077==lAbqL30z0MbEJzv1rib{JiEP!(d+O? z_AI3$0Ukp9`a?F3)%QtPMMrqxpQJ5*HL9i(I!rgC?fKS-fOLEwZqSE|?oI4`{DN@$ z_Hb(>Ibk<}7qx$$e3(VMa}=~kt}c>Ja00@Q3w-GBn5A~18!n1w7P&{tXO4dj`%xR` z@q`yR2RYwb-}go;;7}13EMviybt2CCSwV z>894CorOYa%O5kJ^>s~P=aroG#xT*ZWxp`C*B6~7tGs_8pIkj0v@3kc%oo`S=oharyrC((M95ive{h`nKuQ3V)ZmlMBEInBtF3XVsc{E{F4Yv zs&PSO)S^hDz_{nVFDoIs4!K}LHB~2P`;5B3a>Y$uwwYiLE&meQbFLnNkc5D}(mjn_ ek^Jm+{xS7gqhy%m>d>b8x!#xA(jV!r0UtX_${>3H delta 80 zcmV-W0I&bJ3%CQ2lLZ6-000M(nBYL$372Mv*$dBS9JL$&TZ;9cXF%K2zR0aj3-Bj^ m46RnZGv6CdN8A%cSpZN)E=u$CNZ6SHKVh&2+^Jotf>`fmAS1~D diff --git a/psw/ae/inc/internal/pve_qe_common.h b/psw/ae/inc/internal/pve_qe_common.h index 1c721687..240704a0 100644 --- a/psw/ae/inc/internal/pve_qe_common.h +++ b/psw/ae/inc/internal/pve_qe_common.h @@ -36,6 +36,7 @@ #include "se_types.h" #include "ae_ipp.h" #include "sgx_tcrypto.h" +#include "epid/member/api.h" #ifdef __cplusplus extern "C" { @@ -46,10 +47,12 @@ IppStatus new_std_256_ecp(IppsECCPState **pp_new_ecp); void secure_free_std_256_ecp(IppsECCPState *p_ecp); -int __STDCALL epid_random_func( +int IPP_STDCALL epid_random_func( unsigned int *p_random_data, int bits, void* p_user_data); +EpidStatus epid_member_create(BitSupplier rnd_func, void* rnd_param, FpElemStr* f, MemberCtx** ctx); +void epid_member_delete(MemberCtx** ctx); #ifdef __cplusplus diff --git a/psw/ae/pce/Makefile b/psw/ae/pce/Makefile index ffb4b9fe..12117435 100644 --- a/psw/ae/pce/Makefile +++ b/psw/ae/pce/Makefile @@ -37,7 +37,7 @@ CFLAGS += -Werror AENAME = pce -LINUX_EPID := $(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0/ +LINUX_EPID := $(LINUX_EXTERNAL_DIR)/epid-sdk/ INCLUDE += -I$(LINUX_PSW_DIR)/ae/data/constants/linux INCLUDE += -I$(COMMON_DIR)/inc/tlibc \ diff --git a/psw/ae/pce/config.xml b/psw/ae/pce/config.xml index 5ccfda8c..fbd28621 100644 --- a/psw/ae/pce/config.xml +++ b/psw/ae/pce/config.xml @@ -3,7 +3,7 @@ 1 0 0x1 - 5 + 6 1 0 1 diff --git a/psw/ae/pce/pce.cpp b/psw/ae/pce/pce.cpp index 51301cf3..f8966b18 100644 --- a/psw/ae/pce/pce.cpp +++ b/psw/ae/pce/pce.cpp @@ -106,8 +106,7 @@ uint32_t get_pc_info(const sgx_report_t* report, if(SGX_SUCCESS != sgx_verify_report(report)){ return PCE_INVALID_REPORT; } - if((report->body.attributes.flags & SGX_FLAGS_PROVISION_KEY) != SGX_FLAGS_PROVISION_KEY || - (report->body.attributes.flags & SGX_FLAGS_DEBUG) != 0){ + if((report->body.attributes.flags & SGX_FLAGS_PROVISION_KEY) != SGX_FLAGS_PROVISION_KEY){ return PCE_INVALID_PRIVILEGE; } uint8_t hash_buf[SGX_REPORT_DATA_SIZE];//hash value only use 32 bytes but data in report has 64 bytes size @@ -251,8 +250,7 @@ uint32_t certify_enclave(const psvn_t* cert_psvn, return PCE_INVALID_REPORT; } //only PvE could use the interface which has flag SGX_FLAGS_PROVISION_KEY - if((report->body.attributes.flags & SGX_FLAGS_PROVISION_KEY) != SGX_FLAGS_PROVISION_KEY || - (report->body.attributes.flags & SGX_FLAGS_DEBUG) != 0){ + if((report->body.attributes.flags & SGX_FLAGS_PROVISION_KEY) != SGX_FLAGS_PROVISION_KEY){ return PCE_INVALID_PRIVILEGE; } ae_ret = get_pce_priv_key(cert_psvn, &ec_prv_key); diff --git a/psw/ae/pse/pse_op/config.xml b/psw/ae/pse/pse_op/config.xml index 16969592..70b3e90a 100644 --- a/psw/ae/pse/pse_op/config.xml +++ b/psw/ae/pse/pse_op/config.xml @@ -3,7 +3,7 @@ 0 0 0x2 - 7 + 8 1 0 1 diff --git a/psw/ae/pse/pse_pr/Makefile b/psw/ae/pse/pse_pr/Makefile index 77dddd69..35bb99d8 100644 --- a/psw/ae/pse/pse_pr/Makefile +++ b/psw/ae/pse/pse_pr/Makefile @@ -35,7 +35,7 @@ include ../../buildenv.mk CFLAGS += -Werror #CXXFLAGS += -Werror -EPID_SDK_DIR := $(TOP_DIR)/external/epid-sdk-3.0.0/ +EPID_SDK_DIR := $(TOP_DIR)/external/epid-sdk/ INCLUDE += -I. \ -I./include \ @@ -50,8 +50,7 @@ INCLUDE += -I. \ EXTERNAL_LIB += -lsgx_tstdcxx -lsgx_tcrypto \ -L$(EPID_SDK_DIR)/epid/verifier -lverifier \ - -L$(EPID_SDK_DIR)/epid/common -lcommon \ - -L$(EPID_SDK_DIR)/ext/ipp/sources/ippcpepid/src -lippcpepid + -L$(EPID_SDK_DIR)/epid/common -lcommon SRC := $(wildcard *.cpp) $(wildcard ./X509_Parser/*.cpp) SRC += pse_pr_common.cpp \ diff --git a/psw/ae/pse/pse_pr/config.xml b/psw/ae/pse/pse_pr/config.xml index 2de9d6e3..2b67cef1 100644 --- a/psw/ae/pse/pse_pr/config.xml +++ b/psw/ae/pse/pse_pr/config.xml @@ -3,7 +3,7 @@ 0 0 0x2 - 7 + 8 1 0 1 diff --git a/psw/ae/pse/pse_pr/sigma_crypto_layer.cpp b/psw/ae/pse/pse_pr/sigma_crypto_layer.cpp index 9cf6c989..cc13e645 100644 --- a/psw/ae/pse/pse_pr/sigma_crypto_layer.cpp +++ b/psw/ae/pse/pse_pr/sigma_crypto_layer.cpp @@ -41,8 +41,14 @@ #include "le2be_macros.h" #include "prepare_hmac_sha256.h" #include "prepare_hash_sha256.h" +#ifdef __cplusplus +extern "C" { +#endif #include "epid/verifier/1.1/api.h" #include "epid/common/1.1/types.h" +#ifdef __cplusplus +} +#endif #include "sgx_trts.h" #include "ae_ipp.h" #include "util.h" diff --git a/psw/ae/pse/pse_pr/t_long_term_pairing.cpp b/psw/ae/pse/pse_pr/t_long_term_pairing.cpp index 61d8aa44..eba1d9c3 100644 --- a/psw/ae/pse/pse_pr/t_long_term_pairing.cpp +++ b/psw/ae/pse/pse_pr/t_long_term_pairing.cpp @@ -578,10 +578,10 @@ ae_error_t TEpidSigma11Verifier::VerifyM8 BREAK_IF_TRUE((nTotalLen_PrivRL < privRL_size), status, PSE_PR_PARAMETER_ERROR); // - // privRL_size is based on number of entries, which is basically - // an input to the enclave - // - sgx_lfence(); + // privRL_size is based on number of entries, which is basically + // an input to the enclave + // + sgx_lfence(); BREAK_IF_TRUE( (STATE_VERIFYM8 != m_nextState), status, PSE_PR_CALL_ORDER_ERROR); diff --git a/psw/ae/pve/Makefile b/psw/ae/pve/Makefile index 815ae8bc..c9ebacba 100644 --- a/psw/ae/pve/Makefile +++ b/psw/ae/pve/Makefile @@ -36,7 +36,7 @@ CXXFLAGS += -Werror CFLAGS += -Werror AENAME = provision_enclave -EPID_SDK_DIR := $(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0/ +EPID_SDK_DIR := $(LINUX_EXTERNAL_DIR)/epid-sdk/ INCLUDE += -I$(LINUX_PSW_DIR)/ae/data/constants/linux INCLUDE += -I$(COMMON_DIR)/inc/tlibc \ @@ -52,7 +52,6 @@ EPID_LIBDIR := $(EPID_SDK_DIR) EXTERNAL_LIB += -L$(EPID_LIBDIR)/epid/member -lmember \ -L$(EPID_LIBDIR)/epid/common -lcommon \ - -L$(EPID_LIBDIR)/ext/ipp/sources/ippcpepid/src -lippcpepid \ -L$(TCRYPTO_LIBDIR) -lsgx_tcrypto SRC := $(wildcard *.cpp) diff --git a/psw/ae/pve/config.xml b/psw/ae/pve/config.xml index 332eefc6..cccb6a9a 100644 --- a/psw/ae/pve/config.xml +++ b/psw/ae/pve/config.xml @@ -3,12 +3,12 @@ 1 0 0x1 - 6 + 7 1 0 1 - 0x4000 - 0x14000 - 0x14000 + 0x5000 + 0x50000 + 0x50000 1 diff --git a/psw/ae/pve/provision_msg2.cpp b/psw/ae/pve/provision_msg2.cpp index 563d570a..4338fcba 100644 --- a/psw/ae/pve/provision_msg2.cpp +++ b/psw/ae/pve/provision_msg2.cpp @@ -171,21 +171,27 @@ static pve_status_t prepare_epid_member(const proc_prov_msg2_blob_input_t *msg2_ goto ret_point; } //start preparing epid state for EPID signature generation - epid_ret = EpidMemberCreate( - &epid_cert.epid_group_cert,//group cert from old epid blob - &epid_data.epid_private_key,//group private key from old epid blob - &epid_data.member_precomp_data, - epid_prng, - NULL, - &msg3_parm->epid_member); + epid_ret = epid_member_create(epid_prng, NULL, NULL, &msg3_parm->epid_member); if(kEpidNoErr != epid_ret){ ret_status = epid_error_to_pve_error(epid_ret); goto ret_point; + } + + epid_ret = EpidProvisionKey(msg3_parm->epid_member, + &epid_cert.epid_group_cert,//group cert from old epid blob + &epid_data.epid_private_key,//group private key from old epid blob + &epid_data.member_precomp_data); + if (kEpidNoErr != epid_ret) { + ret_status = epid_error_to_pve_error(epid_ret); + goto ret_point; } - epid_ret = EpidMemberSetHashAlg(msg3_parm->epid_member, kSha256); - if(kEpidNoErr != epid_ret){ + + // start member + epid_ret = EpidMemberStartup(msg3_parm->epid_member); + if (kEpidNoErr != epid_ret) { ret_status = epid_error_to_pve_error(epid_ret); } + ret_point: (void)memset_s(&epid_data, sizeof(epid_data), 0, sizeof(epid_data));//clear secret data from stack return ret_status; diff --git a/psw/ae/pve/provision_msg3.cpp b/psw/ae/pve/provision_msg3.cpp index 86ef7242..598b4426 100644 --- a/psw/ae/pve/provision_msg3.cpp +++ b/psw/ae/pve/provision_msg3.cpp @@ -43,6 +43,16 @@ #include #include "pek_pub_key.h" #include "util.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "epid/common/src/memory.h" +#include "epid/member/software_member.h" +#include "epid/member/src/signbasic.h" +#include "epid/member/src/nrprove.h" +#ifdef __cplusplus +} +#endif /** * File: provision_msg3.cpp @@ -56,7 +66,9 @@ static pve_status_t gen_epid_signature_header(const SigRl *sigrl_header, EPIDMember *epid_member, const uint8_t *nonce_challenge, - EpidSignature *epid_header) + EpidSignature *epid_header, + BigNumStr *rnd_bsn) + { if(NULL!=sigrl_header){ memcpy(&epid_header->n2, &sigrl_header->n2, sizeof(sigrl_header->n2));//copy size into header in BigEndian @@ -69,7 +81,7 @@ static pve_status_t gen_epid_signature_header(const SigRl *sigrl_header, uint32_t msg_len = CHALLENGE_NONCE_SIZE; EpidStatus epid_ret = EpidSignBasic(epid_member, const_cast(reinterpret_cast(nonce_challenge)), - msg_len, NULL, 0, &epid_header->sigma0);//generate EpidSignature Header inside EPC memory + msg_len, NULL, 0, &epid_header->sigma0, rnd_bsn);//generate EpidSignature Header inside EPC memory if(kEpidNoErr != epid_ret){ return epid_error_to_pve_error(epid_ret); } @@ -93,7 +105,7 @@ static uint32_t pve_htonl(uint32_t x) // So that we need first copy each SigRl Entry into EPC memory, generate EPIDSigEntry inside EPC memory // and copy it out after it is generated // The function assumes the size of SigRl has been verfied and it is not checked again here. -// Finally it checks whether the hash value is valid according to ECDHA Sign in the end of SigRl to verify data is not modified +// Finally it checks whether the hash value is valid according to ECDSA Sign in the end of SigRl to verify data is not modified // A TLV Header for the EpidSignature should have been prepared in EPC memory signature_tlv_header //It is assumed that the parm->sigrl_count>0 when the function is called and the size of sigrl has been checked //EpidSignature TLV format: TLVHeader:EpidSignatureHeader:NrProof1:NrProof2:...:NrProofn @@ -117,6 +129,7 @@ static pve_status_t gen_msg3_signature(const proc_prov_msg2_blob_input_t *msg2_b NrProof temp3; uint32_t tlv_payload_size = 0; const SigRl *sigrl_header = NULL; + BigNumStr rnd_bsn = { 0 }; sgx_status_t sgx_status = SGX_SUCCESS; memset(sigrl_sign, 0, sizeof(sigrl_sign)); @@ -148,7 +161,7 @@ static pve_status_t gen_msg3_signature(const proc_prov_msg2_blob_input_t *msg2_b //overwritten the bigendian size in TLV Header. It is assumed that the size in TLV Header is always 4 bytes//Long format memcpy(signature_header_to_encrypt+EPID_SIGNATURE_TLV_SIZE_OFFSET, &tlv_payload_size, sizeof(tlv_payload_size)); - ret = gen_epid_signature_header(sigrl_header, parm->epid_member, msg2_blob_input->challenge_nonce, &parm->signature_header);//Now generate EpidSignatureHeader + ret = gen_epid_signature_header(sigrl_header, parm->epid_member, msg2_blob_input->challenge_nonce, &parm->signature_header, &rnd_bsn);//Now generate EpidSignatureHeader if( PVEC_SUCCESS != ret ) goto ret_point; //Now encrypt the TLV Header and signature header including basic signature while the parm->signature_header is kept since piece-meal processing will use it @@ -186,6 +199,8 @@ static pve_status_t gen_msg3_signature(const proc_prov_msg2_blob_input_t *msg2_b EpidStatus epid_ret = EpidNrProve(parm->epid_member, const_cast(msg2_blob_input->challenge_nonce),//msg to sign CHALLENGE_NONCE_SIZE, + &rnd_bsn, + sizeof(rnd_bsn), &parm->signature_header.sigma0, //B and K in BasicSignature &temp1, //B and K in sigrl entry &temp3); //output one NrProof @@ -271,6 +286,7 @@ static pve_status_t gen_msg3_join_proof_escrow_data(const proc_prov_msg2_blob_in JoinRequest *join_r = &join_proof.jr; EpidStatus epid_ret = kEpidNoErr; psvn_t psvn; + MemberCtx* ctx = NULL; memset(&temp_f, 0, sizeof(temp_f)); //randomly generate the private EPID key f, host to network transformation not required since server will not decode it @@ -282,11 +298,16 @@ static pve_status_t gen_msg3_join_proof_escrow_data(const proc_prov_msg2_blob_in memset(join_r, 0, sizeof(JoinRequest));//first clear to 0 //generate JoinP to fill it in field1_0_0 by EPID library - epid_ret = EpidRequestJoin( + epid_ret = epid_member_create(epid_prng, NULL, f, &ctx); + if(kEpidNoErr!=epid_ret){ + ret = epid_error_to_pve_error(epid_ret); + goto ret_point; + } + + epid_ret = EpidCreateJoinRequest(ctx, &msg2_blob_input->group_cert.key, //EPID Group Cert from ProvMsgs2 used reinterpret_cast(msg2_blob_input->challenge_nonce), - f, epid_prng, - NULL, kSha256, join_r); + join_r); if(kEpidNoErr != epid_ret){ ret = epid_error_to_pve_error(epid_ret); goto ret_point; @@ -323,6 +344,7 @@ ret_point: if(PVEC_SUCCESS != ret){ (void)memset_s(&join_proof, sizeof(join_proof), 0, sizeof(join_proof)); } + epid_member_delete(&ctx); return ret; } diff --git a/psw/ae/pve/provision_msg4.cpp b/psw/ae/pve/provision_msg4.cpp index 121f168a..caf5ea0e 100644 --- a/psw/ae/pve/provision_msg4.cpp +++ b/psw/ae/pve/provision_msg4.cpp @@ -35,6 +35,16 @@ #include "protocol.h" #include "cipher.h" #include "sgx_tcrypto.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "epid/member/software_member.h" +#include "epid/member/src/write_precomp.h" +#include "epid/member/src/signbasic.h" +#include "epid/member/src/nrprove.h" +#ifdef __cplusplus +} +#endif #include "epid/common/errors.h" #include "epid/member/api.h" #include "pve_hardcoded_tlv_data.h" @@ -118,10 +128,7 @@ static pve_status_t gen_epid_blob(const extended_epid_group_blob_t* pxegb, se_secret_epid_data_sdk_t *epid_data = NULL; se_plaintext_epid_data_sdk_t *plaintext = NULL; uint32_t tmp_buffer_size = static_cast(sizeof(se_plaintext_epid_data_sdk_t) + sizeof(se_secret_epid_data_sdk_t)); - if(!EpidIsPrivKeyInGroup(pub_key, prv_key)){ - ret = PVEC_MSG_ERROR; - goto ret_point; - } + //alloc one temp buffer to hold both plaintext and secret data before encryption //all data before encryption will be copied into the buffer inorder tmp_buffer = reinterpret_cast(malloc(tmp_buffer_size)); @@ -145,22 +152,34 @@ static pve_status_t gen_epid_blob(const extended_epid_group_blob_t* pxegb, memcpy(&plaintext->qsdk_mod, pxegb->qsdk_mod, sizeof(plaintext->qsdk_mod)); memcpy(&plaintext->epid_sk, pxegb->epid_sk, sizeof(plaintext->epid_sk)); memcpy(&epid_data->epid_private_key,prv_key,sizeof(PrivKey)); //EPID Private key is sealed in EPID_DATA_BLOB together with Member Precomputation - epid_ret = EpidMemberCreate(&(plaintext->epid_group_cert), - (PrivKey*)&(epid_data->epid_private_key), - NULL, - epid_random_func, - NULL, - &p_epid_context); + + epid_ret = epid_member_create(epid_random_func, NULL, NULL, &p_epid_context); if(kEpidNoErr!=epid_ret){ ret = epid_error_to_pve_error(epid_ret); goto ret_point; } + + epid_ret = EpidProvisionKey(p_epid_context, + &(plaintext->epid_group_cert), + (PrivKey*)&(epid_data->epid_private_key), + NULL); + if (kEpidNoErr != epid_ret) { + ret = epid_error_to_pve_error(epid_ret); + goto ret_point; + } + + // start member + epid_ret = EpidMemberStartup(p_epid_context); + if (kEpidNoErr != epid_ret) { + ret = epid_error_to_pve_error(epid_ret); + goto ret_point; + } + epid_ret = EpidMemberWritePrecomp(p_epid_context, &epid_data->member_precomp_data);//Create Member Precomputation if(kEpidNoErr!=epid_ret){ ret = epid_error_to_pve_error(epid_ret); goto ret_point; } - EpidMemberDelete(&p_epid_context); //call sgx_seal_data to generate EPID_DATA_BLOB if((sgx_status=sgx_seal_data( sizeof(se_plaintext_epid_data_sdk_t), reinterpret_cast(plaintext),//plaintext as AAD @@ -171,6 +190,7 @@ static pve_status_t gen_epid_blob(const extended_epid_group_blob_t* pxegb, goto ret_point; } ret_point: + epid_member_delete(&p_epid_context); if(tmp_buffer){ //reset memory to 0 of the temp buffer to defense in depth (void)memset_s(tmp_buffer,tmp_buffer_size, 0, tmp_buffer_size); diff --git a/psw/ae/qe/Makefile b/psw/ae/qe/Makefile index d8f87e5e..3656d805 100644 --- a/psw/ae/qe/Makefile +++ b/psw/ae/qe/Makefile @@ -35,14 +35,13 @@ include ../buildenv.mk CXXFLAGS += -Werror CFLAGS += -Werror -EPID_SDK_DIR = $(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0 +EPID_SDK_DIR = $(LINUX_EXTERNAL_DIR)/epid-sdk EXTERNAL_LIB += -L$(EPID_SDK_DIR)/epid/member -lmember \ - -L$(EPID_SDK_DIR)/epid/common -lcommon \ - -L$(EPID_SDK_DIR)/ext/ipp/sources/ippcpepid/src -lippcpepid + -L$(EPID_SDK_DIR)/epid/common -lcommon INCLUDE += -I$(LINUX_PSW_DIR)/ae/data/constants/linux \ -I$(SGX_IPP_INC)/ \ - -I$(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0 \ + -I$(LINUX_EXTERNAL_DIR)/epid-sdk \ -I$(LINUX_PSW_DIR)/ae/common \ -I$(COMMON_DIR)/inc/tlibc \ -I$(LINUX_PSW_DIR)/ae/inc/internal diff --git a/psw/ae/qe/config.xml b/psw/ae/qe/config.xml index 6cbcb20b..d83ee956 100644 --- a/psw/ae/qe/config.xml +++ b/psw/ae/qe/config.xml @@ -3,13 +3,13 @@ 0 0 0x1 - 6 + 7 1 0 1 0 0x5000 - 0x10000 - 0x10000 + 0x50000 + 0x50000 1 diff --git a/psw/ae/qe/quoting_enclave.cpp b/psw/ae/qe/quoting_enclave.cpp index f6cdf793..4afd19a0 100644 --- a/psw/ae/qe/quoting_enclave.cpp +++ b/psw/ae/qe/quoting_enclave.cpp @@ -33,11 +33,9 @@ #ifndef __linux__ #include "targetver.h" #endif -// Exclude rarely-used stuff from Windows headers -//#define WIN32_LEAN_AND_MEAN -// Windows Header Files: -//#include + +#include "ae_ipp.h" #include "se_types.h" #include "sgx_quote.h" #include "aeerror.h" @@ -46,9 +44,6 @@ #include "epid_pve_type.h" #include "sgx_utils.h" #include "ipp_wrapper.h" -#include "epid/common/errors.h" -#include "ae_ipp.h" -#include "epid/member/api.h" #include "quoting_enclave_t.c" #include "sgx_tcrypto.h" #include "se_sig_rl.h" @@ -59,6 +54,17 @@ #include "util.h" #include "qsdk_pub.hh" #include "isk_pub.hh" +#include "epid/member/api.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "epid/member/software_member.h" +#include "epid/member/src/write_precomp.h" +#include "epid/member/src/signbasic.h" +#include "epid/member/src/nrprove.h" +#ifdef __cplusplus +} +#endif #if !defined(SWAP_4BYTES) #define SWAP_4BYTES(u32) \ @@ -99,6 +105,7 @@ static ae_error_t verify_blob_internal( se_plaintext_epid_data_sdk_t& plaintext_epid_data, MemberCtx **pp_epid_context) { + ae_error_t ret = QE_UNEXPECTED_ERROR; sgx_status_t se_ret = SGX_SUCCESS; uint8_t resealed= FALSE; se_secret_epid_data_sdk_t secret_epid_data; @@ -111,177 +118,142 @@ static ae_error_t verify_blob_internal( + sizeof(secret_epid_data) + sizeof(plaintext_epid_data)] = {0}; - // We will use plaintext_old_format as buffer to hold the output of sgx_unseal_data. - // It can be se_plaintext_epid_data_sik_t or se_plaintext_epid_data_sdk_t. - // We use the static assert to reassure plaintext_old_format is big enough. - // If someone changed the definition of these 2 structures and break current assumption, - // it will report error in compile time. - se_static_assert(sizeof(plaintext_old_format)>=sizeof(plaintext_epid_data)); - if (sgx_get_encrypt_txt_len(p_epid_blob) != sizeof(se_secret_epid_data_sdk_t)&& - sgx_get_encrypt_txt_len(p_epid_blob) != sizeof(se_secret_epid_data_sik_t)){ - return QE_EPIDBLOB_ERROR; - } - plaintext_length = sgx_get_add_mac_txt_len(p_epid_blob); - if(plaintext_length != sizeof(se_plaintext_epid_data_sik_t)&& - plaintext_length != sizeof(se_plaintext_epid_data_sdk_t)) - { - return QE_EPIDBLOB_ERROR; - } + do { + // We will use plaintext_old_format as buffer to hold the output of sgx_unseal_data. + // It can be se_plaintext_epid_data_sik_t or se_plaintext_epid_data_sdk_t. + // We use the static assert to reassure plaintext_old_format is big enough. + // If someone changed the definition of these 2 structures and break current assumption, + // it will report error in compile time. + se_static_assert(sizeof(plaintext_old_format) >= sizeof(plaintext_epid_data)); - memset(&secret_epid_data, 0, sizeof(secret_epid_data)); - memset(&plaintext_epid_data, 0, sizeof(plaintext_epid_data)); - memset(&plaintext_old_format, 0, sizeof(plaintext_old_format)); - - se_ret = sgx_unseal_data(p_epid_blob, - (uint8_t *)&plaintext_old_format, // The unsealed plaintext can be old or new format, the buffer is defined as old format because it is bigger - &plaintext_length, - (uint8_t *)&secret_epid_data, - &decryptedtext_length); - if(SGX_SUCCESS != se_ret) - { - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - return QE_EPIDBLOB_ERROR; - } - - //QE will support both epid blob with/without member precomputation - //If the epid blob without member precomputation is used, QE will generate member precomputation and reseal epid blob - if((plaintext_old_format.seal_blob_type != PVE_SEAL_EPID_KEY_BLOB) - || (plaintext_old_format.epid_key_version != EPID_KEY_BLOB_VERSION_SDK&& - plaintext_old_format.epid_key_version != EPID_KEY_BLOB_VERSION_SIK )) //blob_type and key_version are always first two fields of plaintext in both format - { - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - return QE_EPIDBLOB_ERROR; - } - - // Only 2 combinations are legitimate for the tuple epid_key_version|decryptedtext_length|plaintext_length: - // EPID_KEY_BLOB_VERSION_SIK|sizeof(se_secret_epid_data_sik_t)|sizeof(se_plaintext_epid_data_sik_t) - // EPID_KEY_BLOB_VERSION_SDK|sizeof(se_secret_epid_data_sdk_t)|sizeof(se_plaintext_epid_data_sdk_t) - if((plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK && - (decryptedtext_length!=sizeof(se_secret_epid_data_sik_t)||plaintext_length!=sizeof(se_plaintext_epid_data_sik_t)))|| - (plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SDK && - (decryptedtext_length!=sizeof(se_secret_epid_data_sdk_t)||plaintext_length!=sizeof(se_plaintext_epid_data_sdk_t)))){ - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - return QE_EPIDBLOB_ERROR; - } - // If the input epid blob is in sik format, we will upgrade it to sdk version - if(plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK){ - plaintext_epid_data.seal_blob_type = PVE_SEAL_EPID_KEY_BLOB; - plaintext_epid_data.epid_key_version = EPID_KEY_BLOB_VERSION_SDK; - memcpy(&plaintext_epid_data.equiv_cpu_svn, &plaintext_old_format.equiv_cpu_svn, sizeof(plaintext_old_format.equiv_cpu_svn)); - memcpy(&plaintext_epid_data.equiv_pve_isv_svn, &plaintext_old_format.equiv_pve_isv_svn, sizeof(plaintext_old_format.equiv_pve_isv_svn)); - memcpy(&plaintext_epid_data.epid_group_cert, &plaintext_old_format.epid_group_cert, sizeof(plaintext_old_format.epid_group_cert)); - memcpy(&plaintext_epid_data.qsdk_exp, &plaintext_old_format.qsdk_exp, sizeof(plaintext_old_format.qsdk_exp)); - memcpy(&plaintext_epid_data.qsdk_mod, &plaintext_old_format.qsdk_mod, sizeof(plaintext_old_format.qsdk_mod)); - memcpy(&plaintext_epid_data.epid_sk, &plaintext_old_format.epid_sk, sizeof(plaintext_old_format.epid_sk)); - plaintext_epid_data.xeid = plaintext_old_format.xeid; - memset(&secret_epid_data.member_precomp_data, 0, sizeof(secret_epid_data.member_precomp_data)); - is_old_format = 1; - //PrivKey of secret_epid_data are both in offset 0 so that we need not move it - } - else{//SDK version format - memcpy(&plaintext_epid_data, &plaintext_old_format, sizeof(plaintext_epid_data)); - } - - /* Create report to get current cpu_svn and isv_svn. */ - sgx_report_t report; - memset(&report, 0, sizeof(report)); - se_ret = sgx_create_report(NULL, NULL, &report); - if(SGX_SUCCESS != se_ret) - { - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - return QE_UNEXPECTED_ERROR; - } - - /* Get the random function pointer. */ - BitSupplier rand_func = epid_random_func; - - /* Create EPID member context if required. PvE is responsible for verifying - the Cert signature before storing them in the EPID blob. */ - if(create_context) - { - EpidStatus epid_ret = kEpidNoErr; - epid_ret = EpidMemberCreate( - &(plaintext_epid_data.epid_group_cert), - (PrivKey*)&(secret_epid_data.epid_private_key), - is_old_format?NULL:&secret_epid_data.member_precomp_data, - rand_func, - NULL, - pp_epid_context); - if(kEpidNoErr != epid_ret) - { - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - // Make sure the pointer is not pointered to garbage. And according - // to EPID SDK 2.0 API document of EpidMemberCreate, it will not return - // error with memory allocated. So set the pointer to NULL will not - // cause memory leak here. - *pp_epid_context = NULL; - return QE_UNEXPECTED_ERROR; + if (sgx_get_encrypt_txt_len(p_epid_blob) != sizeof(se_secret_epid_data_sdk_t) && + sgx_get_encrypt_txt_len(p_epid_blob) != sizeof(se_secret_epid_data_sik_t)) { + return QE_EPIDBLOB_ERROR; } - epid_ret = EpidMemberSetHashAlg(*pp_epid_context, kSha256); - if(kEpidNoErr != epid_ret) + plaintext_length = sgx_get_add_mac_txt_len(p_epid_blob); + if (plaintext_length != sizeof(se_plaintext_epid_data_sik_t) && + plaintext_length != sizeof(se_plaintext_epid_data_sdk_t)) { - EpidMemberDelete(pp_epid_context); - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0 , - sizeof(secret_epid_data)); - *pp_epid_context = NULL; - return QE_UNEXPECTED_ERROR; + return QE_EPIDBLOB_ERROR; } - if(is_old_format) - { - epid_ret = EpidMemberWritePrecomp(*pp_epid_context, &secret_epid_data.member_precomp_data); - if(kEpidNoErr != epid_ret) - { - EpidMemberDelete(pp_epid_context); - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - *pp_epid_context = NULL; - return QE_UNEXPECTED_ERROR; - } - } - } - /* Update the Key Blob using the SEAL Key for the current TCB if the TCB is - upgraded after the Key Blob is generated. Here memcmp cpu_svns might be - different even though they're actually same, but for defense in depth we - will keep this comparison here. And we will also upgrade old format EPID - blob to new format here. */ - if((memcmp(&report.body.cpu_svn, &p_epid_blob->key_request.cpu_svn, - sizeof(report.body.cpu_svn))) - || (report.body.isv_svn != p_epid_blob->key_request.isv_svn) - || plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK) - { - se_ret = sgx_seal_data(sizeof(plaintext_epid_data), - (uint8_t *)&plaintext_epid_data, - sizeof(secret_epid_data), + memset(&secret_epid_data, 0, sizeof(secret_epid_data)); + memset(&plaintext_epid_data, 0, sizeof(plaintext_epid_data)); + memset(&plaintext_old_format, 0, sizeof(plaintext_old_format)); + + se_ret = sgx_unseal_data(p_epid_blob, + (uint8_t *)&plaintext_old_format, // The unsealed plaintext can be old or new format, the buffer is defined as old format because it is bigger + &plaintext_length, (uint8_t *)&secret_epid_data, - SGX_TRUSTED_EPID_BLOB_SIZE_SDK, - (sgx_sealed_data_t *)local_epid_blob); - if(SGX_SUCCESS != se_ret) - { - // Clear the output buffer to make sure nothing leaks. - memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - // *pp_epid_context contains pointers, so we cannot simply clear it. - if(pp_epid_context) - { - EpidMemberDelete(pp_epid_context); - *pp_epid_context = NULL; - } - return QE_UNEXPECTED_ERROR; + &decryptedtext_length); + BREAK_IF_TRUE(SGX_SUCCESS != se_ret, ret, QE_EPIDBLOB_ERROR); + + //QE will support both epid blob with/without member precomputation + //If the epid blob without member precomputation is used, QE will generate member precomputation and reseal epid blob + //blob_type and key_version are always first two fields of plaintext in both format + BREAK_IF_TRUE((plaintext_old_format.seal_blob_type != PVE_SEAL_EPID_KEY_BLOB) + || (plaintext_old_format.epid_key_version != EPID_KEY_BLOB_VERSION_SDK&& + plaintext_old_format.epid_key_version != EPID_KEY_BLOB_VERSION_SIK), + ret, QE_EPIDBLOB_ERROR); + + // Only 2 combinations are legitimate for the tuple epid_key_version|decryptedtext_length|plaintext_length: + // EPID_KEY_BLOB_VERSION_SIK|sizeof(se_secret_epid_data_sik_t)|sizeof(se_plaintext_epid_data_sik_t) + // EPID_KEY_BLOB_VERSION_SDK|sizeof(se_secret_epid_data_sdk_t)|sizeof(se_plaintext_epid_data_sdk_t) + BREAK_IF_TRUE((plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK && + (decryptedtext_length != sizeof(se_secret_epid_data_sik_t) || plaintext_length != sizeof(se_plaintext_epid_data_sik_t))) || + (plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SDK && + (decryptedtext_length != sizeof(se_secret_epid_data_sdk_t) || plaintext_length != sizeof(se_plaintext_epid_data_sdk_t))), + ret, QE_EPIDBLOB_ERROR); + + // If the input epid blob is in sik format, we will upgrade it to sdk version + if (plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK) { + plaintext_epid_data.seal_blob_type = PVE_SEAL_EPID_KEY_BLOB; + plaintext_epid_data.epid_key_version = EPID_KEY_BLOB_VERSION_SDK; + memcpy(&plaintext_epid_data.equiv_cpu_svn, &plaintext_old_format.equiv_cpu_svn, sizeof(plaintext_old_format.equiv_cpu_svn)); + memcpy(&plaintext_epid_data.equiv_pve_isv_svn, &plaintext_old_format.equiv_pve_isv_svn, sizeof(plaintext_old_format.equiv_pve_isv_svn)); + memcpy(&plaintext_epid_data.epid_group_cert, &plaintext_old_format.epid_group_cert, sizeof(plaintext_old_format.epid_group_cert)); + memcpy(&plaintext_epid_data.qsdk_exp, &plaintext_old_format.qsdk_exp, sizeof(plaintext_old_format.qsdk_exp)); + memcpy(&plaintext_epid_data.qsdk_mod, &plaintext_old_format.qsdk_mod, sizeof(plaintext_old_format.qsdk_mod)); + memcpy(&plaintext_epid_data.epid_sk, &plaintext_old_format.epid_sk, sizeof(plaintext_old_format.epid_sk)); + plaintext_epid_data.xeid = plaintext_old_format.xeid; + memset(&secret_epid_data.member_precomp_data, 0, sizeof(secret_epid_data.member_precomp_data)); + is_old_format = 1; + //PrivKey of secret_epid_data are both in offset 0 so that we need not move it } - memcpy(p_epid_blob, local_epid_blob, blob_size); - resealed = TRUE; + else {//SDK version format + memcpy(&plaintext_epid_data, &plaintext_old_format, sizeof(plaintext_epid_data)); + } + + /* Create report to get current cpu_svn and isv_svn. */ + sgx_report_t report; + memset(&report, 0, sizeof(report)); + se_ret = sgx_create_report(NULL, NULL, &report); + BREAK_IF_TRUE(SGX_SUCCESS != se_ret, ret, QE_UNEXPECTED_ERROR); + + /* Get the random function pointer. */ + BitSupplier rand_func = epid_random_func; + + /* Create EPID member context if required. PvE is responsible for verifying + the Cert signature before storing them in the EPID blob. */ + if (create_context) + { + EpidStatus epid_ret = kEpidNoErr; + epid_ret = epid_member_create(rand_func, NULL, NULL, pp_epid_context); + BREAK_IF_TRUE(kEpidNoErr != epid_ret, ret, QE_UNEXPECTED_ERROR); + + epid_ret = EpidProvisionKey(*pp_epid_context, + &(plaintext_epid_data.epid_group_cert), + (PrivKey*)&(secret_epid_data.epid_private_key), + is_old_format ? NULL : &secret_epid_data.member_precomp_data); + BREAK_IF_TRUE(kEpidNoErr != epid_ret, ret, QE_UNEXPECTED_ERROR); + + // start member + epid_ret = EpidMemberStartup(*pp_epid_context); + BREAK_IF_TRUE(kEpidNoErr != epid_ret, ret, QE_UNEXPECTED_ERROR); + + if (is_old_format) + { + epid_ret = EpidMemberWritePrecomp(*pp_epid_context, &secret_epid_data.member_precomp_data); + BREAK_IF_TRUE(kEpidNoErr != epid_ret, ret, QE_UNEXPECTED_ERROR); + } + } + + /* Update the Key Blob using the SEAL Key for the current TCB if the TCB is + upgraded after the Key Blob is generated. Here memcmp cpu_svns might be + different even though they're actually same, but for defense in depth we + will keep this comparison here. And we will also upgrade old format EPID + blob to new format here. */ + if ((memcmp(&report.body.cpu_svn, &p_epid_blob->key_request.cpu_svn, + sizeof(report.body.cpu_svn))) + || (report.body.isv_svn != p_epid_blob->key_request.isv_svn) + || plaintext_old_format.epid_key_version == EPID_KEY_BLOB_VERSION_SIK) + { + se_ret = sgx_seal_data(sizeof(plaintext_epid_data), + (uint8_t *)&plaintext_epid_data, + sizeof(secret_epid_data), + (uint8_t *)&secret_epid_data, + SGX_TRUSTED_EPID_BLOB_SIZE_SDK, + (sgx_sealed_data_t *)local_epid_blob); + BREAK_IF_TRUE(SGX_SUCCESS != se_ret, ret, QE_UNEXPECTED_ERROR); + + memcpy(p_epid_blob, local_epid_blob, blob_size); + resealed = TRUE; + } + *p_is_resealed = resealed; + ret = AE_SUCCESS; } + while (false); + + // Clear the output buffer to make sure nothing leaks. memset_s(&secret_epid_data, sizeof(secret_epid_data), 0, - sizeof(secret_epid_data)); - *p_is_resealed = resealed; - return AE_SUCCESS; + sizeof(secret_epid_data)); + if (ret != AE_SUCCESS) + { + epid_member_delete(pp_epid_context); + } + + return ret; } /* @@ -377,7 +349,7 @@ static ae_error_t qe_epid_sign( Ipp8u seeds[QE_OAEP_SEED_SIZE] = {0}; sgx_report_data_t qe_report_data = {{0}}; sgx_target_info_t report_target; - sgx_ec256_public_t ec_pub_key; + sgx_ec256_public_t ec_pub_key; // little endian se_ae_ecdsa_hash_t sig_rl_hash = {{0}}; IppECResult ec_result = ippECValid ; @@ -408,7 +380,8 @@ static ae_error_t qe_epid_sign( (uint32_t)QE_QUOTE_BODY_SIZE, (uint8_t *)const_cast(p_basename), sizeof(*p_basename), - &basic_sig); + &basic_sig, + NULL); if(kEpidNoErr != epid_ret) { ret = QE_UNEXPECTED_ERROR; @@ -693,6 +666,8 @@ static ae_error_t qe_epid_sign( epid_ret = EpidNrProve(p_epid_context, (uint8_t *)const_cast(p_quote_body), (uint32_t)QE_QUOTE_BODY_SIZE, + (uint8_t *)const_cast(p_basename), + sizeof(*p_basename), &basic_sig, // Basic signature with 'b' and 'k' in it &entry, //Single entry in SigRl composed of 'b' and 'k' &temp_nr); // The generated non-revoked proof @@ -718,7 +693,7 @@ static ae_error_t qe_epid_sign( ipp_ret = ippsAES_GCMEncrypt((Ipp8u *)&temp_nr, (Ipp8u *)&encrypted_temp_nr, - sizeof(NrProof), + sizeof(encrypted_temp_nr), aes_context); if(ipp_ret != ippStsNoErr) { @@ -865,7 +840,8 @@ CLEANUP: if(aes_context) free(aes_context); if(pub_key) - secure_free_rsa_pub_key(sizeof(g_qsdk_pub_key_n), sizeof(g_qsdk_pub_key_e), pub_key); + secure_free_rsa_pub_key(sizeof(plaintext.qsdk_mod), + sizeof(plaintext.qsdk_exp), pub_key); if(pub_key_buffer) free(pub_key_buffer); secure_free_std_256_ecp(p_ecp); @@ -1085,7 +1061,7 @@ uint32_t get_quote( } } - epid_ret = EpidRegisterBaseName(p_epid_context, (uint8_t *)&basename, + epid_ret = EpidRegisterBasename(p_epid_context, (uint8_t *)&basename, sizeof(basename)); if(kEpidNoErr != epid_ret) { @@ -1114,7 +1090,7 @@ uint32_t get_quote( quote_body.sign_type = (uint16_t)quote_type; quote_body.pce_svn = pce_isvsvn; // Both are little endian quote_body.xeid = plaintext.xeid; // Both are little endian - se_static_assert(sizeof(plaintext.epid_group_cert.gid) == sizeof(uint32_t)); + se_static_assert(sizeof(plaintext.epid_group_cert.gid) == sizeof(OctStr32)); se_static_assert(sizeof(quote_body.epid_group_id) == sizeof(uint32_t)); ((uint8_t *)("e_body.epid_group_id))[0] = plaintext.epid_group_cert.gid.data[3]; ((uint8_t *)("e_body.epid_group_id))[1] = plaintext.epid_group_cert.gid.data[2]; @@ -1170,7 +1146,7 @@ uint32_t get_quote( CLEANUP: if(p_epid_context) - EpidMemberDelete(&p_epid_context); + epid_member_delete(&p_epid_context); return ret; } diff --git a/psw/ae/ref_le/ref_le.md b/psw/ae/ref_le/ref_le.md index ac710410..7a6933bd 100644 --- a/psw/ae/ref_le/ref_le.md +++ b/psw/ae/ref_le/ref_le.md @@ -69,7 +69,8 @@ $ sudo ./sgx_linux_x64_psw_${version}.bin $ sudo cp ${top_dir}/build/linux/libsgx_ref_le.signed.so /opt/intel/sgxpsw/aesm/ $ sudo cp ${top_dir}/build/linux/ref_white_list.bin /var/opt/aesmd/data ``` -See the later topic, *Generating a White List*, for information on how to generate a white list file. +See the later topic, *Generating a White List*, for information on how to generate a white list file. + 4. Restart aesmd service with root privilege: ``` $ sudo service aesmd restart diff --git a/psw/ae/ref_le/ref_wl_gen/parse_key_file.h b/psw/ae/ref_le/ref_wl_gen/parse_key_file.h index 0ee7fc7f..ae1f0234 100644 --- a/psw/ae/ref_le/ref_wl_gen/parse_key_file.h +++ b/psw/ae/ref_le/ref_wl_gen/parse_key_file.h @@ -34,24 +34,7 @@ #ifndef _PARSE_KEY_FILE_H_ #define _PARSE_KEY_FILE_H_ - -#define N_SIZE_IN_BYTES 384 -#define E_SIZE_IN_BYTES 4 -#define D_SIZE_IN_BYTES 384 -#define P_SIZE_IN_BYTES 192 -#define Q_SIZE_IN_BYTES 192 -#define DMP1_SIZE_IN_BYTES 192 -#define DMQ1_SIZE_IN_BYTES 192 -#define IQMP_SIZE_IN_BYTES 192 - -#define N_SIZE_IN_UINT N_SIZE_IN_BYTES/sizeof(unsigned int) -#define E_SIZE_IN_UINT E_SIZE_IN_BYTES/sizeof(unsigned int) -#define D_SIZE_IN_UINT D_SIZE_IN_BYTES/sizeof(unsigned int) -#define P_SIZE_IN_UINT P_SIZE_IN_BYTES/sizeof(unsigned int) -#define Q_SIZE_IN_UINT Q_SIZE_IN_BYTES/sizeof(unsigned int) -#define DMP1_SIZE_IN_UINT DMP1_SIZE_IN_BYTES/sizeof(unsigned int) -#define DMQ1_SIZE_IN_UINT DMQ1_SIZE_IN_BYTES/sizeof(unsigned int) -#define IQMP_SIZE_IN_UINT IQMP_SIZE_IN_BYTES/sizeof(unsigned int) +#include "sgx_tcrypto.h" typedef enum _key_type_t { @@ -61,18 +44,6 @@ typedef enum _key_type_t PUBLIC_KEY } key_type_t; -typedef struct _rsa_params_t -{ - unsigned int n[N_SIZE_IN_UINT]; - unsigned int e[E_SIZE_IN_UINT]; - unsigned int d[D_SIZE_IN_UINT]; - unsigned int p[P_SIZE_IN_UINT]; - unsigned int q[Q_SIZE_IN_UINT]; - unsigned int dmp1[DMP1_SIZE_IN_UINT]; - unsigned int dmq1[DMQ1_SIZE_IN_UINT]; - unsigned int iqmp[IQMP_SIZE_IN_UINT]; -}rsa_params_t; - bool parse_key_file(const char *key_path, rsa_params_t *prsa, int *pkey_type); diff --git a/psw/uae_service/linux/Makefile b/psw/uae_service/linux/Makefile index bb0c47e7..8a662e8f 100644 --- a/psw/uae_service/linux/Makefile +++ b/psw/uae_service/linux/Makefile @@ -51,7 +51,7 @@ INCLUDE += -I$(LINUX_PSW_DIR)/ae/common \ -I$(LINUX_PSW_DIR)/ae/inc/internal \ -I$(LINUX_SDK_DIR)/tseal -INCLUDE += -I$(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0 \ +INCLUDE += -I$(LINUX_EXTERNAL_DIR)/epid-sdk \ -I$(IPC_COMMON_INC_DIR) \ -I$(UAE_INC_DIR) \ -I$(IPC_COMMON_PROTO_DIR) \ diff --git a/psw/urts/enclave.cpp b/psw/urts/enclave.cpp index 60314477..02401759 100644 --- a/psw/urts/enclave.cpp +++ b/psw/urts/enclave.cpp @@ -64,6 +64,7 @@ CEnclave::CEnclave(CLoader &ldr) , m_ocall_table(NULL) , m_pthread_is_valid(false) , m_new_thread_event(NULL) + , m_sealed_key(NULL) { memset(&m_enclave_info, 0, sizeof(debug_enclave_info_t)); se_init_rwlock(&m_rwlock); @@ -170,6 +171,16 @@ size_t CEnclave::get_dynamic_tcs_list_size() return count; } +uint8_t *CEnclave::get_sealed_key() +{ + return m_sealed_key; +} + +void CEnclave::set_sealed_key(uint8_t *sealed_key) +{ + m_sealed_key = sealed_key; +} + sgx_status_t CEnclave::error_trts2urts(unsigned int trts_error) { if(trts_error == (unsigned int)SE_ERROR_READ_LOCK_FAIL) diff --git a/psw/urts/enclave.h b/psw/urts/enclave.h index 910cadbf..3c0f9784 100644 --- a/psw/urts/enclave.h +++ b/psw/urts/enclave.h @@ -80,6 +80,8 @@ public: bool update_debug_flag(uint8_t); sgx_status_t fill_tcs_mini_pool(); sgx_status_t fill_tcs_mini_pool_fn(); + uint8_t* get_sealed_key(); + void set_sealed_key(uint8_t *sealed_key); private: CTrustThread * get_tcs(int ecall_cmd); void put_tcs(CTrustThread *trust_thread); @@ -102,6 +104,7 @@ private: pthread_t m_pthread_tid; bool m_pthread_is_valid; se_handle_t m_new_thread_event; + uint8_t *m_sealed_key; }; class CEnclavePool: private Uncopyable diff --git a/psw/urts/enclave_creator_hw.h b/psw/urts/enclave_creator_hw.h index 5c7bc687..1be7c636 100644 --- a/psw/urts/enclave_creator_hw.h +++ b/psw/urts/enclave_creator_hw.h @@ -56,7 +56,6 @@ public: int initialize(sgx_enclave_id_t enclave_id); bool use_se_hw() const; bool is_EDMM_supported(sgx_enclave_id_t enclave_id); - bool is_cpu_edmm() const; bool is_driver_compatible(); bool is_in_kernel_driver(); int get_misc_attr(sgx_misc_attribute_t *sgx_misc_attr, metadata_t *metadata, SGXLaunchToken * const lc, uint32_t flag); @@ -69,7 +68,6 @@ public: private: virtual bool open_se_device(); virtual void close_se_device(); - bool driver_support_edmm(); int try_init_enclave(sgx_enclave_id_t enclave_id, enclave_css_t *enclave_css, token_t *launch); int error_driver2urts(int driver_error); se_file_handle_t m_hdevice; diff --git a/psw/urts/enclave_creator_hw_com.cpp b/psw/urts/enclave_creator_hw_com.cpp index 359a4fd8..60f4b52e 100644 --- a/psw/urts/enclave_creator_hw_com.cpp +++ b/psw/urts/enclave_creator_hw_com.cpp @@ -61,7 +61,8 @@ int EnclaveCreatorHW::initialize(sgx_enclave_id_t enclave_id) info.cpu_features = 0; memset(info.cpuinfo_table, 0, sizeof(info.cpuinfo_table)); get_cpu_features(&info.cpu_features, (uint32_t*)info.cpuinfo_table); - info.version = (sdk_version_t)MIN((uint32_t)SDK_VERSION_2_1, enclave->get_enclave_version()); + info.version = (sdk_version_t)MIN((uint32_t)SDK_VERSION_2_2, enclave->get_enclave_version()); + info.sealed_key = enclave->get_sealed_key(); if (is_EDMM_supported(enclave_id)) info.system_feature_set[0] |= EDMM_ENABLE_BIT; diff --git a/psw/urts/linux/Makefile b/psw/urts/linux/Makefile index 8ba56a5f..43b35428 100644 --- a/psw/urts/linux/Makefile +++ b/psw/urts/linux/Makefile @@ -89,7 +89,8 @@ OBJ2 := urts.o \ get_thread_id.o \ prd_css_util.o \ urts_emodpr.o \ - urts_trim.o + urts_trim.o \ + edmm_utility.o OBJ3 := enter_enclave.o \ xsave_gnu.o diff --git a/psw/urts/linux/edmm_utility.cpp b/psw/urts/linux/edmm_utility.cpp new file mode 100644 index 00000000..effd011e --- /dev/null +++ b/psw/urts/linux/edmm_utility.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "edmm_utility.h" +#include "se_trace.h" +#include "isgx_user.h" +#include "cpuid.h" +#include +#include +#include +#include +#include +#include +#include + +#define SGX_URTS_CMD "strings /usr/lib/libsgx_urts.so 2> /dev/null | grep SGX_URTS_VERSION_2" +#define SGX_CPUID 0x12 + +/* is_urts_support_edmm() + * Parameters: + * None. + * Return Value: + * true - uRTS supports EDMM. + * false - uRTS does not support EDMM. +*/ +static bool is_urts_support_edmm() +{ + FILE* pipe = popen(SGX_URTS_CMD, "r"); + if (NULL == pipe) + { + SE_TRACE(SE_TRACE_WARNING, "Failed to open pipe.\n"); + return false; + } + + char line[1024]; + if (NULL == fgets(line, sizeof(line), pipe)) + return false; + + if (-1 == pclose(pipe)) + { + SE_TRACE(SE_TRACE_WARNING, "Failed to close pipe.\n"); + } + + return true; +} + +/* open_se_device() + * Parameters: + * hdevice [out] - The device handle as returned from the open_se_device API. + * in_kernel_driver [out] - Indicate it is in-kernel driver or not. + * Return Value: + * true - The function succeeds. + * false - The function fails. +*/ +extern "C" bool open_se_device(int *hdevice, bool *in_kernel_driver) +{ + if (NULL == hdevice) + return false; + + int hdev = open("/dev/isgx", O_RDWR); + if (-1 == hdev) + { + hdev = open("/dev/sgx", O_RDWR); + if (-1 == hdev) + { + SE_TRACE(SE_TRACE_WARNING, "Failed to open Intel SGX device.\n"); + return false; + } + + if (NULL != in_kernel_driver) + *in_kernel_driver = true; + } + + *hdevice = hdev; + + return true; +} + +/* close_se_device() + * Parameters: + * hdevice [in out] - The device handle will be set to -1 if it is closed successfully. + * Return Value: + * true - The function succeeds. + * false - The function fails. +*/ +extern "C" bool close_se_device(int *hdevice) +{ + if (NULL == hdevice) + return false; + + if (-1 != *hdevice && 0 != close(*hdevice)) + { + SE_TRACE(SE_TRACE_WARNING, "Failed to close Intel SGX device.\n"); + return false; + } + + *hdevice = -1; + + return true; +} + +/* is_cpu_support_edmm() + * Parameters: + * None. + * Return Value: + * true - CPU supports EDMM. + * false - CPU does not support EDMM. +*/ +extern "C" bool is_cpu_support_edmm() +{ + int a[4] = {0,0,0,0}; + + //Check CPU EDMM capability by CPUID + __cpuid(a, 0); + if (a[0] < SGX_CPUID) + return false; + + __cpuidex(a, SGX_CPUID, 0); + if (!(a[0] & 1)) + return false; + + return ((a[0] & 2) != 0); +} + +/* is_driver_support_edmm() + * Parameters: + * hdevice [in] - The device handle used to communicate with driver. + * Return Value: + * true - Driver supports EDMM. + * false - Driver does not support EDMM. +*/ +extern "C" bool is_driver_support_edmm(int hdevice) +{ + if (-1 == hdevice) + return false; + + sgx_modification_param param; + param.flags = 0; + param.range.start_addr = 0; + param.range.nr_pages = 0; + + int ret = ioctl(hdevice, SGX_IOC_ENCLAVE_EMODPR, ¶m); + if ((-1 == ret) && (errno == ENOTTY)) + return false; + + return true; +} + +/* is_support_edmm() + * Parameters: + * None. + * Return Value: + * true - CPU/driver/uRTS supports EDMM. + * false - Either of CPU/driver/uRTS does not support EDMM. +*/ +extern "C" bool is_support_edmm() +{ + if (false == is_cpu_support_edmm()) + return false; + + int hdevice = -1; + if (false == open_se_device(&hdevice, NULL)) + return false; + + if (false == is_driver_support_edmm(hdevice)) + { + close_se_device(&hdevice); + return false; + } + + close_se_device(&hdevice); + + if (false == is_urts_support_edmm()) + return false; + + return true; +} diff --git a/psw/urts/linux/edmm_utility.h b/psw/urts/linux/edmm_utility.h new file mode 100644 index 00000000..73ff748c --- /dev/null +++ b/psw/urts/linux/edmm_utility.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _EDMM_UTILITY_H_ +#define _EDMM_UTILITY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* open_se_device() + * Parameters: + * hdevice [out] - The device handle as returned from the open_se_device API. + * in_kernel_driver [out] - Indicate it is in-kernel driver or not. + * Return Value: + * true - The function succeeds. + * false - The function fails. +*/ +bool open_se_device(int *hdevice, bool *in_kernel_driver); + +/* close_se_device() + * Parameters: + * hdevice [in out] - The device handle will be set to -1 if it is closed successfully. + * Return Value: + * true - The function succeeds. + * false - The function fails. +*/ +bool close_se_device(int *hdevice); + +/* is_cpu_support_edmm() + * Parameters: + * None. + * Return Value: + * true - CPU supports EDMM. + * false - CPU does not support EDMM. +*/ +bool is_cpu_support_edmm(); + +/* is_driver_support_edmm() + * Parameters: + * hdevice [in] - The device handle used to communicate with driver. + * Return Value: + * true - Driver supports EDMM. + * false - Driver does not support EDMM. +*/ +bool is_driver_support_edmm(int hdevice); + +/* is_support_edmm() + * Parameters: + * None. + * Return Value: + * true - CPU/driver/uRTS supports EDMM. + * false - Either of CPU/driver/uRTS does not support EDMM. +*/ +bool is_support_edmm(); + +#ifdef __cplusplus +} +#endif + +#endif //_EDMM_UTILITY_H_ diff --git a/psw/urts/linux/enclave_creator_hw.cpp b/psw/urts/linux/enclave_creator_hw.cpp index 48482ef5..ac934f42 100644 --- a/psw/urts/linux/enclave_creator_hw.cpp +++ b/psw/urts/linux/enclave_creator_hw.cpp @@ -32,6 +32,7 @@ #include "enclave.h" #include "enclave_creator_hw.h" +#include "edmm_utility.h" #include "se_trace.h" #include "se_page_attr.h" #include "isgx_user.h" @@ -43,9 +44,6 @@ #include "cpuid.h" #include "rts.h" #include -#include -#include -#include #include #include #include @@ -53,8 +51,6 @@ #define POINTER_TO_U64(A) ((__u64)((uintptr_t)(A))) -#define SGX_CPUID 0x12 - static EnclaveCreatorHW g_enclave_creator_hw; EnclaveCreator* g_enclave_creator = &g_enclave_creator_hw; @@ -144,8 +140,9 @@ int EnclaveCreatorHW::create_enclave(secs_t *secs, sgx_enclave_id_t *enclave_id, int ret = ioctl(m_hdevice, SGX_IOC_ENCLAVE_CREATE, ¶m); if(ret) { - if(ret == -1 && errno == EINTR) { - return SGX_INTERNAL_ERROR_ENCLAVE_CREATE_INTERRUPTED; // Allow the user to retry. + if(ret == -1 && errno == EINTR) + { + return SGX_INTERNAL_ERROR_ENCLAVE_CREATE_INTERRUPTED; // Allow users to retry } SE_TRACE(SE_TRACE_WARNING, "\nSGX_IOC_ENCLAVE_CREATE failed: errno = %d\n", errno); return error_driver2urts(ret); @@ -244,42 +241,23 @@ bool EnclaveCreatorHW::get_plat_cap(sgx_misc_attribute_t *misc_attr) // need to update code to support HyperV ECO return get_plat_cap_by_cpuid(misc_attr); } - + bool EnclaveCreatorHW::open_se_device() { LockGuard lock(&m_dev_mutex); - int fd = -1; if(-1 != m_hdevice) - { return true; - } - fd = open("/dev/isgx", O_RDWR); - if (-1 == fd) { - fd = open("/dev/sgx", O_RDWR); - if (-1 == fd) { - SE_TRACE(SE_TRACE_WARNING, "Failed to open Intel SGX device\n"); - return false; - } - - m_in_kernel_driver = true; - } - - m_hdevice = fd; - - return true; + return ::open_se_device(&m_hdevice, &m_in_kernel_driver); } void EnclaveCreatorHW::close_se_device() { LockGuard lock(&m_dev_mutex); - if (m_hdevice != -1) - { - close(m_hdevice); - m_hdevice = -1; - } + ::close_se_device(&m_hdevice); + m_hdevice = -1; } int EnclaveCreatorHW::emodpr(uint64_t addr, uint64_t size, uint64_t flag) @@ -387,7 +365,7 @@ bool EnclaveCreatorHW::is_EDMM_supported(sgx_enclave_id_t enclave_id) if (enclave == NULL) return false; - cpu_edmm = is_cpu_edmm(); + cpu_edmm = is_cpu_support_edmm(); driver_supported = is_driver_compatible(); //return value of get_enclave_version() considers the version of uRTS and enclave metadata @@ -396,28 +374,10 @@ bool EnclaveCreatorHW::is_EDMM_supported(sgx_enclave_id_t enclave_id) return supported; } -bool EnclaveCreatorHW::is_cpu_edmm() const -{ - bool cpu_edmm = false; - int a[4] = {0,0,0,0}; - - //Check CPU EDMM capability by CPUID - __cpuid(a, 0); - if (a[0] < SGX_CPUID) - return false; - - __cpuidex(a, SGX_CPUID, 0); - if (!(a[0] & 1)) - return false; - - cpu_edmm = (a[0] & 2) != 0; - return cpu_edmm; -} - bool EnclaveCreatorHW::is_driver_compatible() { - static bool ret = driver_support_edmm(); - return ret; + open_se_device(); + return is_driver_support_edmm(m_hdevice); } bool EnclaveCreatorHW::is_in_kernel_driver() @@ -425,27 +385,3 @@ bool EnclaveCreatorHW::is_in_kernel_driver() open_se_device(); return m_in_kernel_driver; } - -bool EnclaveCreatorHW::driver_support_edmm() -{ - int ret; - sgx_modification_param p; - p.flags = 0; - p.range.start_addr = 0; - p.range.nr_pages = 0; - - if (false == open_se_device()) - { - return false; - } - - ret = ioctl(m_hdevice, SGX_IOC_ENCLAVE_EMODPR, &p); - if ((ret == -1) && (errno == ENOTTY)) - { - return false; - } - else - { - return true; - } -} diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp index 0137d730..f6bc3076 100644 --- a/psw/urts/linux/urts.cpp +++ b/psw/urts/linux/urts.cpp @@ -70,3 +70,59 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu return ret; } + + +extern "C" sgx_status_t +sgx_create_encrypted_enclave( + const char *file_name, + const int debug, + sgx_launch_token_t *launch_token, + int *launch_token_updated, + sgx_enclave_id_t *enclave_id, + sgx_misc_attribute_t *misc_attr, + uint8_t* sealed_key) +{ + sgx_status_t ret = SGX_SUCCESS; + + //Only true or false is valid + if(TRUE != debug && FALSE != debug) + return SGX_ERROR_INVALID_PARAMETER; + + if(NULL == sealed_key) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + int fd = open(file_name, O_RDONLY); + if(-1 == fd) + { + SE_TRACE(SE_TRACE_ERROR, "Couldn't open the enclave file, error = %d\n", errno); + return SGX_ERROR_ENCLAVE_FILE_ACCESS; + } + se_file_t file = {NULL, 0, false}; + char resolved_path[PATH_MAX]; + file.name = realpath(file_name, resolved_path); + file.name_len = (uint32_t)strlen(resolved_path); + + ret = _create_enclave( + !!debug, + fd, + file, + NULL, + launch_token, + launch_token_updated, + enclave_id, + misc_attr, + sealed_key); + if(SGX_SUCCESS != ret && misc_attr) + { + sgx_misc_attribute_t plat_cap; + memset(&plat_cap, 0, sizeof(plat_cap)); + get_enclave_creator()->get_plat_cap(&plat_cap); + memcpy_s(misc_attr, sizeof(sgx_misc_attribute_t), &plat_cap, sizeof(sgx_misc_attribute_t)); + } + + close(fd); + + return ret; +} diff --git a/psw/urts/linux/urts.lds b/psw/urts/linux/urts.lds index 6c4dd019..37679ce3 100644 --- a/psw/urts/linux/urts.lds +++ b/psw/urts/linux/urts.lds @@ -8,6 +8,7 @@ sgx_thread_setwait_untrusted_events_ocall; sgx_thread_set_multiple_untrusted_events_ocall; sgx_oc_cpuidex; + sgx_create_encrypted_enclave; local: *; }; diff --git a/psw/urts/linux/urts_internal.cpp b/psw/urts/linux/urts_internal.cpp index e27c1213..76a1ef63 100644 --- a/psw/urts/linux/urts_internal.cpp +++ b/psw/urts/linux/urts_internal.cpp @@ -42,7 +42,7 @@ #include "enclave_creator.h" -extern sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t& file, le_prd_css_file_t *prd_css_file, sgx_launch_token_t *launch, int *launch_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr); +extern sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t& file, le_prd_css_file_t *prd_css_file, sgx_launch_token_t *launch, int *launch_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, uint8_t* sealed_key = NULL); extern "C" sgx_status_t sgx_create_le(const char* file_name, const char* prd_css_file_name, const int debug, sgx_launch_token_t *launch_token, int *launch_token_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, int *production_loaded) { diff --git a/psw/urts/parser/binparser.h b/psw/urts/parser/binparser.h index 53b578bc..fde826b7 100644 --- a/psw/urts/parser/binparser.h +++ b/psw/urts/parser/binparser.h @@ -110,6 +110,7 @@ public: virtual void get_executable_sections(vector& xsec_names) const = 0; virtual bool set_memory_protection(uint64_t enclave_base_addr, bool is_after_initialization) = 0; virtual void get_pages_to_protect(uint64_t, std::vector>&) const = 0; + virtual bool has_init_section() const = 0; }; #endif diff --git a/psw/urts/parser/elfparser.cpp b/psw/urts/parser/elfparser.cpp index b6590216..3a10fa99 100644 --- a/psw/urts/parser/elfparser.cpp +++ b/psw/urts/parser/elfparser.cpp @@ -990,3 +990,19 @@ void ElfParser::get_pages_to_protect(uint64_t enclave_base_addr, std::vector& xsec_names) const; + bool is_enclave_encrypted() const; bool set_memory_protection(uint64_t enclave_base_addr, bool is_after_initialization); void get_pages_to_protect(uint64_t enclave_base_addr, std::vector>&) const; + bool has_init_section() const; + private: const uint8_t* m_start_addr; uint64_t m_len; diff --git a/psw/urts/urts_com.h b/psw/urts/urts_com.h index f11936c0..1e008858 100644 --- a/psw/urts/urts_com.h +++ b/psw/urts/urts_com.h @@ -50,6 +50,7 @@ #include "se_detect.h" #include "rts.h" #include "enclave_creator_hw.h" +#include "edmm_utility.h" #include #ifndef PARSER #include "elfparser.h" @@ -108,7 +109,7 @@ static sgx_status_t get_metadata(BinParser *parser, const int debug, metadata_t #ifndef SE_SIM EnclaveCreatorHW *enclave_creator = static_cast(get_enclave_creator()); - if (!(enclave_creator->is_cpu_edmm()) || !(enclave_creator->is_driver_compatible())) + if (!is_cpu_support_edmm() || !(enclave_creator->is_driver_compatible())) { // cannot support EDMM, adjust the possibly highest metadata version supported urts_version = META_DATA_MAKE_VERSION(SGX_1_9_MAJOR_VERSION,SGX_1_9_MINOR_VERSION); @@ -182,7 +183,7 @@ static bool is_SGX_DBG_OPTIN_variable_set() } -static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadata_t *metadata, se_file_t& file, const bool debug, SGXLaunchToken *lc, le_prd_css_file_t *prd_css_file, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr) +static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadata_t *metadata, se_file_t& file, const bool debug, SGXLaunchToken *lc, le_prd_css_file_t *prd_css_file, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, uint8_t *sealed_key) { // The "parser" will be registered into "loader" and "loader" will be registered into "enclave". // After enclave is created, "parser" and "loader" are not needed any more. @@ -203,7 +204,7 @@ static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadat if (MAJOR_VERSION_OF_METADATA(metadata->version) == MAJOR_VERSION_OF_METADATA(urts_version) && MINOR_VERSION_OF_METADATA(metadata->version) >= MINOR_VERSION_OF_METADATA(urts_version)) { - enclave_version = SDK_VERSION_2_1; + enclave_version = SDK_VERSION_2_2; } else if (MAJOR_VERSION_OF_METADATA(metadata->version) == MAJOR_VERSION_OF_METADATA(urts_version) && MINOR_VERSION_OF_METADATA(metadata->version) < MINOR_VERSION_OF_METADATA(urts_version)) @@ -227,6 +228,10 @@ static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadat return ret; } + if(sealed_key != NULL) + { + enclave->set_sealed_key(sealed_key); + } // It is accurate to get debug flag from secs enclave->set_dbg_flag(!!(loader.get_secs().attributes.flags & SGX_FLAGS_DEBUG)); @@ -291,7 +296,7 @@ static int __create_enclave(BinParser &parser, uint8_t* base_addr, const metadat uint64_t enclave_end_addr; const char* enclave_path; enclave_start_addr = (uint64_t) loader.get_start_addr(); - enclave_end_addr = enclave_start_addr + (uint64_t) metadata->enclave_size; + enclave_end_addr = enclave_start_addr + (uint64_t) metadata->enclave_size -1; SE_TRACE(SE_TRACE_DEBUG, "Invoking VTune's module mapping API __itt_module_load \n"); SE_TRACE(SE_TRACE_DEBUG, "Enclave_start_addr==0x%llx\n", enclave_start_addr); @@ -384,7 +389,7 @@ fail: } -sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t& file, le_prd_css_file_t *prd_css_file, sgx_launch_token_t *launch, int *launch_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr) +sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t& file, le_prd_css_file_t *prd_css_file, sgx_launch_token_t *launch, int *launch_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr, uint8_t* sealed_key = NULL) { unsigned int ret = SGX_SUCCESS; sgx_status_t lt_result = SGX_SUCCESS; @@ -420,6 +425,17 @@ sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t goto clean_return; } + if(NULL != sealed_key && true != parser.is_enclave_encrypted()) + { + ret = SGX_ERROR_PCL_NOT_ENCRYPTED; + goto clean_return; + } + if(NULL == sealed_key && false != parser.is_enclave_encrypted()) + { + ret = SGX_ERROR_PCL_ENCRYPTED; + goto clean_return; + } + if(SGX_SUCCESS != (ret = get_metadata(&parser, debug, &metadata, &sgx_misc_attr))) { goto clean_return; @@ -450,7 +466,7 @@ sgx_status_t _create_enclave(const bool debug, se_file_handle_t pfile, se_file_t //Need to set the whole misc_attr instead of just secs_attr. do { ret = __create_enclave(parser, mh->base_addr, metadata, file, debug, lc, prd_css_file, enclave_id, - misc_attr); + misc_attr, sealed_key); //SGX_ERROR_ENCLAVE_LOST caused by initializing enclave while power transition occurs } while(SGX_ERROR_ENCLAVE_LOST == ret); diff --git a/sdk/Makefile.opt_lib b/sdk/Makefile.opt_lib index 594aaa3f..c8a7785b 100644 --- a/sdk/Makefile.opt_lib +++ b/sdk/Makefile.opt_lib @@ -41,6 +41,7 @@ # - tkey_exchange: libsgx_tkey_exchange.a # - tprotected_fs: libsgx_tprotected_fs.a # - tcmalloc: libsgx_tcmalloc.a +# - sgx_pcl: libsgx_pcl.a # - Untrtusted libraries # - ukey_exchange: libsgx_ukey_exchange.a # - uprotected_fs: libsgx_uprotected_fs.a @@ -51,6 +52,7 @@ # - Tools # - signtool: sgx_sign # - edger8r: sgx_edger8r +# - sgx_encrypt: sgx_encrypt # - Simulation libraries and tools # - simulation: libsgx_trts_sim.a, libsgx_tservice_sim.a, libsgx_urts_sim.so, libsgx_uae_service_sim.so, sgx_config_cpusvn # @@ -62,7 +64,7 @@ LIBTCXX := $(BUILD_DIR)/libsgx_tcxx.a LIBTSE := $(BUILD_DIR)/libsgx_tservice.a .PHONY: components -components: tstdc tstdcxx tcxx tservice trts tcrypto tkey_exchange ukey_exchange tprotected_fs uprotected_fs ptrace sample_crypto libcapable simulation signtool edger8r tcmalloc +components: tstdc tstdcxx tcxx tservice trts tcrypto tkey_exchange ukey_exchange tprotected_fs uprotected_fs ptrace sample_crypto libcapable simulation signtool edger8r tcmalloc sgx_pcl sgx_encrypt # --------------------------------------------------- # tstdc @@ -216,6 +218,9 @@ tcmalloc: tprotected_fs: edger8r $(MAKE) -C protected_fs/sgx_tprotected_fs +.PHONY: sgx_pcl +sgx_pcl: + $(MAKE) -C protected_code_loader # --------------------------------------------------- # Untrusted libraries # --------------------------------------------------- @@ -260,6 +265,10 @@ signtool: edger8r: $(MAKE) -C edger8r/linux/ +.PHONY: sgx_encrypt +sgx_encrypt: tservice + $(MAKE) -C encrypt_enclave + $(BUILD_DIR): $(MKDIR) $@ @@ -289,6 +298,8 @@ clean: $(MAKE) -C simulation/ clean $(MAKE) -C sign_tool/SignTool clean $(MAKE) -C edger8r/linux clean + $(MAKE) -C protected_code_loader clean + $(MAKE) -C encrypt_enclave clean @$(RM) $(LIBTLIBC) $(LIBTLIBCXX) $(LIBTSE) @$(RM) $(BUILD_DIR)/STLport_Changes_SGX.txt @$(RM) $(BUILD_DIR)/libc++_Changes_SGX.txt diff --git a/sdk/Makefile.source b/sdk/Makefile.source index 03bf1967..22ad5825 100644 --- a/sdk/Makefile.source +++ b/sdk/Makefile.source @@ -41,6 +41,7 @@ # - tkey_exchange: libsgx_tkey_exchange.a # - tprotected_fs: libsgx_tprotected_fs.a # - tcmalloc: libsgx_tcmalloc.a +# - sgx_pcl: libsgx_pcl.a # - Untrtusted libraries # - ukey_exchange: libsgx_ukey_exchange.a # - uprotected_fs: libsgx_uprotected_fs.a @@ -51,6 +52,7 @@ # - Tools # - signtool: sgx_sign # - edger8r: sgx_edger8r +# - sgx_encrypt: sgx_encrypt # - Simulation libraries and tools # - simulation: libsgx_trts_sim.a, libsgx_tservice_sim.a, libsgx_urts_sim.so, libsgx_uae_service_sim.so, sgx_config_cpusvn # @@ -62,7 +64,7 @@ LIBTCXX := $(BUILD_DIR)/libsgx_tcxx.a LIBTSE := $(BUILD_DIR)/libsgx_tservice.a .PHONY: components -components: tstdc tstdcxx tcxx tservice trts tcrypto tkey_exchange ukey_exchange tprotected_fs uprotected_fs ptrace sample_crypto libcapable simulation signtool edger8r tcmalloc +components: tstdc tstdcxx tcxx tservice trts tcrypto tkey_exchange ukey_exchange tprotected_fs uprotected_fs ptrace sample_crypto libcapable simulation signtool edger8r tcmalloc sgx_pcl sgx_encrypt # --------------------------------------------------- # tstdc @@ -210,6 +212,9 @@ tcmalloc: tprotected_fs: edger8r $(MAKE) -C protected_fs/sgx_tprotected_fs +.PHONY: sgx_pcl +sgx_pcl: + $(MAKE) -C protected_code_loader # --------------------------------------------------- # Untrusted libraries # --------------------------------------------------- @@ -254,6 +259,10 @@ signtool: edger8r: $(MAKE) -C edger8r/linux/ +.PHONY: sgx_encrypt +sgx_encrypt: tservice + $(MAKE) -C encrypt_enclave + $(BUILD_DIR): $(MKDIR) $@ @@ -284,6 +293,8 @@ clean: $(MAKE) -C simulation/ clean $(MAKE) -C sign_tool/SignTool clean $(MAKE) -C edger8r/linux clean + $(MAKE) -C protected_code_loader clean + $(MAKE) -C encrypt_enclave clean @$(RM) $(LIBTLIBC) $(LIBTLIBCXX) $(LIBTSE) @$(RM) $(BUILD_DIR)/STLport_Changes_SGX.txt @$(RM) $(BUILD_DIR)/libc++_Changes_SGX.txt diff --git a/sdk/edger8r/linux/CodeGen.ml b/sdk/edger8r/linux/CodeGen.ml index 8424327a..b31934cc 100644 --- a/sdk/edger8r/linux/CodeGen.ml +++ b/sdk/edger8r/linux/CodeGen.ml @@ -1336,7 +1336,7 @@ let gen_func_tproxy (ufunc: Ast.untrusted_func) (idx: int) = "\t}"; ] in - List.fold_left (fun acc s -> acc ^ s ^ "\n") "" code_template + List.fold_left (fun acc s -> acc ^ "\t" ^ s ^ "\n") "" code_template else if attr.Ast.pa_iswstr then let code_template = [ sprintf "\tif (%s)" name; @@ -1349,9 +1349,9 @@ let gen_func_tproxy (ufunc: Ast.untrusted_func) (idx: int) = "\t}"; ] in - List.fold_left (fun acc s -> acc ^ s ^ "\n") "" code_template + List.fold_left (fun acc s -> acc ^ "\t" ^ s ^ "\n") "" code_template else - sprintf "\tif (%s) memcpy((void*)%s, __tmp_%s, %s);\n" name name name (mk_len_var name) + sprintf "\t\tif (%s) memcpy((void*)%s, __tmp_%s, %s);\n" name name name (mk_len_var name) | _ -> "" in List.fold_left (fun acc (pty, declr) -> @@ -1359,26 +1359,28 @@ let gen_func_tproxy (ufunc: Ast.untrusted_func) (idx: int) = Ast.PTVal _ -> acc | Ast.PTPtr(ty, attr) -> acc ^ copy_memory attr declr) "" plist in - let set_errno = if propagate_errno then "\terrno = ms->ocall_errno;" else "" in - let func_close = sprintf "%s%s\n%s%s\n" + let set_errno = if propagate_errno then "\t\terrno = ms->ocall_errno;" else "" in + let func_close = sprintf "%s%s%s\n%s%s\n" (handle_out_ptr fd.Ast.plist) set_errno + "\t}" (gen_ocfree fd.Ast.rtype fd.Ast.plist) "\treturn status;\n}" in let ocall_null = sprintf "status = sgx_ocall(%d, NULL);\n" idx in let ocall_with_ms = sprintf "status = sgx_ocall(%d, %s);\n" idx ms_struct_val in - let update_retval = sprintf "if (%s) *%s = %s;" + let update_retval = sprintf "\tif (%s) *%s = %s;" retval_name retval_name (mk_parm_accessor retval_name) in let func_body = ref [] in if (is_naked_func fd) && (propagate_errno = false) then - sprintf "%s\t%s\t%s%s" func_open local_vars ocall_null func_close + sprintf "%s\t%s\t%s%s" func_open local_vars ocall_null "\n\treturn status;\n}" else begin func_body := local_vars :: !func_body; func_body := ocalloc_ms_struct:: !func_body; List.iter (fun pd -> func_body := tproxy_fill_ms_field pd :: !func_body) fd.Ast.plist; func_body := ocall_with_ms :: !func_body; + func_body := "if (status == SGX_SUCCESS) {" :: !func_body; if fd.Ast.rtype <> Ast.Void then func_body := update_retval :: !func_body; List.fold_left (fun acc s -> acc ^ "\t" ^ s ^ "\n") func_open (List.rev !func_body) ^ func_close end diff --git a/sdk/edger8r/linux/Preprocessor.ml b/sdk/edger8r/linux/Preprocessor.ml index e225081f..2fa9530a 100644 --- a/sdk/edger8r/linux/Preprocessor.ml +++ b/sdk/edger8r/linux/Preprocessor.ml @@ -34,23 +34,20 @@ open Printf open Util -(* for compat of OCaml before version 4.02.0 *) -module Bytes = String - (* Run a command and return its results as a process_status*string. *) let read_process (command : string) : Unix.process_status * string = - let buffer_size = 2048 in + let buffer_size = 16 in let buffer = Buffer.create buffer_size in - let str = Bytes.create buffer_size in let in_channel = Unix.open_process_in command in - let chars_read = ref 1 in - while !chars_read <> 0 do - chars_read := input in_channel str 0 buffer_size; - Buffer.add_substring buffer str 0 !chars_read - done; - let status = Unix.close_process_in in_channel in - let output = Buffer.contents buffer in - ( status, output ) + let rec read_to_end() = + Buffer.add_channel buffer in_channel 1;read_to_end() in + try + read_to_end() + with + End_of_file -> ( + let status = Unix.close_process_in in_channel in + let output = Buffer.contents buffer in + ( status, output )) (*Return None if gcc not found, caller should handle it*) let processor_macro ( full_path : string) : string option= diff --git a/sdk/edger8r/linux/Util.ml b/sdk/edger8r/linux/Util.ml index b61e3742..54487634 100644 --- a/sdk/edger8r/linux/Util.ml +++ b/sdk/edger8r/linux/Util.ml @@ -189,14 +189,6 @@ let isdigit = function '0' | '1' .. '9' -> true | _ -> false let isalpha = function 'a' .. 'z' | 'A' .. 'Z' -> true | _ -> false let isalnum c = isdigit c || isalpha c -let str_map f s = - let len = String.length s in - let res = String.create len in - for i = 0 to len - 1 do - String.set res i (f (String.get s i)) - done; - res - let str_to_list s = let rec iter i lst = if i < 0 then lst else iter (i - 1) (s.[i] :: lst) @@ -223,7 +215,7 @@ let to_c_identifier (s: string) = let rest_str = String.sub s 1 (String.length s - 1) in - Char.escaped first_ch ^ str_map convert_char rest_str + Char.escaped first_ch ^ String.map convert_char rest_str (* Check whether given string is a valid C identifier. diff --git a/sdk/encrypt_enclave/Makefile b/sdk/encrypt_enclave/Makefile new file mode 100644 index 00000000..a759f0e3 --- /dev/null +++ b/sdk/encrypt_enclave/Makefile @@ -0,0 +1,71 @@ +# +# Copyright (C) 2011-2018 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + + +include ../../buildenv.mk +ifndef $(VERBOSE) + VERBOSE := @ +endif + +INC_DIR := -I$(COMMON_DIR)/inc -I$(COMMON_DIR)/inc/internal -I. +CXXFLAGS += $(INC_DIR) -Wno-attributes -g -mrdrnd -fpie +LDFLAGS := -pie $(COMMON_LDFLAGS) + +LINK_FLAGS := -lcrypto -L$(BUILD_DIR) -lsgx_tservice +CPP_FILES := encryptip.cpp +OBJS := $(CPP_FILES:.cpp=.o) +TOOL_NAME := sgx_encrypt + +.PHONY: all + +all: $(TOOL_NAME) | $(BUILD_DIR) + $(VERBOSE)$(CP) $< $| + +$(BUILD_DIR): + @$(MKDIR) $@ + +$(OBJS): $(CPP_FILES) + $(VERBOSE)$(CXX) -c $< -o $@ $(CXXFLAGS) + @echo "CXX => $@" + +$(TOOL_NAME): $(OBJS) + $(VERBOSE)$(CXX) $^ -o $@ $(LINK_FLAGS) $(LDFLAGS) + @echo "LINK => $@" + +.PHONY: clean +clean: + $(VERBOSE)$(RM) $(TOOL_NAME) $(OBJS) $(BUILD_DIR)/$(TOOL_NAME) + +.PHONY: rebuild +rebuild: + $(MAKE) clean + $(MAKE) all + diff --git a/sdk/encrypt_enclave/encryptip.cpp b/sdk/encrypt_enclave/encryptip.cpp new file mode 100644 index 00000000..70f6ed86 --- /dev/null +++ b/sdk/encrypt_enclave/encryptip.cpp @@ -0,0 +1,897 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "openssl/evp.h" +#include "openssl/ossl_typ.h" +#include "openssl/sha.h" +#include +#include +#include "pcl_common.h" +#include "encryptip.h" +#include "sgx_pcl_guid.h" + +/* + * @func main - tool entry point + * 1. Parses arguments + * 2. Read binary key file + * 3. Read enclave so file + * 4. Modify enclave binary + * 5. Save enclave to file + * @param int argc, number of command line parameters + * @param IN char *argv[], array of command line parameters' strings + * @return (int)(encip_ret_e) + * Respective error values if either parse_args, read_file, encrypt_ip or write_file fail + * ENCIP_ERROR_KEY_FILE_SIZE if size of binary key file is not 16 bytes + * ENCIP_ERROR_ENCLAVE_SIZE if enclave size is 0 + * ENCIP_SUCCESS if success + */ +int main(int argc, IN char *argv[]) +{ + char* keyfile_name = NULL; + char* enclave_in_name = NULL; + char* enclave_out_name = NULL; + bool debug = false; + uint8_t* enclave_buf = NULL; + uint8_t* key_buf = NULL; + size_t key_size = 0; + size_t enclave_size = 0; + + // Parse the arguments: + encip_ret_e ret = parse_args(argc, argv, &enclave_in_name, &enclave_out_name, &keyfile_name, &debug); + if(ENCIP_ERROR(ret)) + return (int)ret; + + // Read enclave file into buffer: + ret = read_file(enclave_in_name, &enclave_buf, &enclave_size); + if(ENCIP_ERROR(ret)) + return (int)ret; + if(0 == enclave_size) + { + ret = ENCIP_ERROR_ENCLAVE_SIZE; + goto Label_free_enclave_buffer; + } + + // Read key file into buffer: + ret = read_file(keyfile_name, &key_buf, &key_size); + if(ENCIP_ERROR(ret)) + goto Label_free_enclave_buffer; + if(SGX_AESGCM_KEY_SIZE != key_size) + { + ret = ENCIP_ERROR_KEY_FILE_SIZE; + goto Label_free_key_and_enclave_buffers; + } + + // Modify enclave for PCL: + ret = encrypt_ip(enclave_buf, enclave_size, key_buf, debug); + if(ENCIP_ERROR(ret)) + goto Label_free_key_and_enclave_buffers; + + // Write the buffer into enclave file: + ret = write_file(enclave_out_name, enclave_buf, enclave_size); + if(ENCIP_ERROR(ret)) + goto Label_free_key_and_enclave_buffers; + + // Set success: + ret = ENCIP_SUCCESS; + +Label_free_key_and_enclave_buffers: + free(key_buf); + +Label_free_enclave_buffer: + free(enclave_buf); + + return (int)ret; +} + +/* + * @func can_modify checks if section content can be modified without disrupting + * enclave signing or loading flows + * @param IN const char* const sec_name is a pointer to the section's name + * @return true iff section content can be modified without disrupting + * enclave signing or loading flows + */ +static inline bool can_modify(IN const char* const sec_name, bool debug) +{ + + /* + * non_ip_sec_names is an array of names of sections that must remain plain text + * to enable enclave signing and loading flows + */ + static char const* const non_ip_sec_names[NUM_NON_IP_OR_DEBUG_SEC_NAMES] = + { + ".shstrtab", // Sections' names string table. Pointed by e_shstrndx + ".note.sgxmeta", // SGX enclave metadata + ".bss", // Inited with zero - no IP. Section may overlap other sections + ".tbss", // Inited with zero - no IP. Section may overlap other sections + ".dynamic", // Required to construct dyn_info by function parse_dyn at elfparser.cpp + ".dynsym", // Holds content pointed by entreis with index DT_SYMTAB in dyn_info + ".dynstr", // Holds content pointed by entreis with index DT_STRTAB in dyn_info + ".rela.dyn", // Holds content pointed by entreis with index DT_REL in dyn_info + PCLTBL_SECTION_NAME, // PCL table + PCL_TEXT_SECTION_NAME, // code use by PCL flow + PCL_DATA_SECTION_NAME, // Data used by PCL flow + PCL_RODATA_SECTION_NAME, // Read only data used by PCL flow + + ".comment", // Required for debugging + ".debug_aranges", // Required for debugging + ".debug_info", // Required for debugging + ".debug_abbrev", // Required for debugging + ".debug_line", // Required for debugging + ".debug_str", // Required for debugging + ".debug_loc", // Required for debugging + ".debug_ranges", // Required for debugging + ".gnu.version_d", // Required for debugging, allocables + ".symtab", // Required for comfortable debugging + ".strtab", // Required for comfortable debugging + }; + + if(NULL == sec_name) + return false; + uint32_t num_sec_names = debug ? NUM_NON_IP_OR_DEBUG_SEC_NAMES : NUM_NON_IP_SEC_NAMES; + for(uint32_t secidx = 0; secidx < num_sec_names; secidx++) + { + if(!strcmp(non_ip_sec_names[secidx],sec_name)) + return false; + } + return true; +} + +/* + * @func parse_elf prases the ELF buffer and assigns dat astruct with: + * 1. Pointer to elf sections array + * 2. Index of sections names strings section + * 3. Number of sections + * 4. Pointer to sections names structure + * 5. Pointer to elf segments array + * 6. Number of segments + * @param IN const void* const elf_buf_in is a pointer to the ELF binary in memory + * @param size_t elf_size, ELF binary size in bytes + * @param OUT pcl_data_t* dat is a pointer to the struct holding output + * @return: + * ENCIP_ERROR_PARSE_ELF_INVALID_PARAM if input parameters are NULL + * ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE if ELF image is not valid + * ENCIP_SUCCESS if success + */ +static encip_ret_e parse_elf(const void* const elf_buf_in, size_t elf_size, pcl_data_t* dat) +{ + if(NULL == elf_buf_in || NULL == dat) + return ENCIP_ERROR_PARSE_ELF_INVALID_PARAM; + uint8_t* elf_buf = (uint8_t*)elf_buf_in; + // Elf header is at the encalve input file start address: + if(sizeof(Elf64_Ehdr) > elf_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + Elf64_Ehdr* elf_hdr = (Elf64_Ehdr*)(elf_buf); + // Verify magic: + if(ELFMAG0 != elf_hdr->e_ident[EI_MAG0] || + ELFMAG1 != elf_hdr->e_ident[EI_MAG1] || + ELFMAG2 != elf_hdr->e_ident[EI_MAG2] || + ELFMAG3 != elf_hdr->e_ident[EI_MAG3]) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + // Find the number of sections: + dat->nsections = elf_hdr->e_shnum; + + // Find the index of the section which contains the sections names strings: + uint16_t shstrndx = elf_hdr->e_shstrndx; + dat->shstrndx = shstrndx; + if(dat->nsections <= shstrndx) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + // Find the array of the sections headers: + if((elf_hdr->e_shoff >= elf_size) || + (elf_hdr->e_shoff + dat->nsections * sizeof(Elf64_Shdr) < elf_hdr->e_shoff) || + (elf_hdr->e_shoff + dat->nsections * sizeof(Elf64_Shdr) > elf_size)) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + dat->elf_sec = (Elf64_Shdr*)(elf_buf + elf_hdr->e_shoff); + + // Find the begining of the section which contains the sections names strings + if((dat->elf_sec[shstrndx].sh_offset >= elf_size) || + (dat->elf_sec[shstrndx].sh_offset + dat->elf_sec[shstrndx].sh_size < dat->elf_sec[shstrndx].sh_offset) || + (dat->elf_sec[shstrndx].sh_offset + dat->elf_sec[shstrndx].sh_size > elf_size)) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + dat->sections_names = (char*)(elf_buf + dat->elf_sec[shstrndx].sh_offset); + + // Find number of segments: + dat->nsegments = elf_hdr->e_phnum; + + if((elf_hdr->e_phoff >= elf_size) || + (elf_hdr->e_phoff + dat->nsegments * sizeof(Elf64_Phdr) < elf_hdr->e_phoff) || + (elf_hdr->e_phoff + dat->nsegments * sizeof(Elf64_Phdr) > elf_size)) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + + dat->phdr = (Elf64_Phdr*)(elf_buf + elf_hdr->e_phoff); + + return ENCIP_SUCCESS; +} + +/* + * @func get_pcl_tbl iterates over sections to find the PCL table + * @param IN const void* const elf_buf_in is a pointer to the ELF binary in memory + * @param size_t elf_size, ELF buffer size in bytes + * @param IN const pcl_data_t* const dat is a pointer to the struct holding parsed elf content + * @param OUT pcl_table_t** tbl_pp, address of pointer to table + * @return encip_ret_e: + * ENCIP_ERROR_GETTBL_INVALID_PARAM if input parameters are NULL + * ENCIP_ERROR_TBL_NOT_ALIGNED if table not aligned to PCL_TABLE_ALLIGNMENT + * ENCIP_ERROR_TBL_NOT_FOUND if table is not found in binary + * ENCIP_ERROR_ALREADY_ENCRYPTED if pcl_state in PCL table equals PCL_CIPHER + * ENCIP_ERROR_IMPROPER_STATE if pcl_state in PCL table does not equal PCL_PLAIN + * ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE if ELF image is invalid + * ENCIP_SUCCESS if success + */ +static encip_ret_e get_pcl_tbl( + IN const void* const elf_buf_in, + size_t elf_size, + IN const pcl_data_t* const dat, + OUT pcl_table_t** tbl_pp) +{ + if(NULL == elf_buf_in || NULL == dat || NULL == tbl_pp) + return ENCIP_ERROR_GETTBL_INVALID_PARAM; + + bool tbl_found = false; + + uint8_t* elf_buf = (uint8_t*)elf_buf_in; + + // Go over sections headers to find the table (skip first section): + for(uint16_t secidx = 1; secidx < dat->nsections && !tbl_found; secidx++) + { + if(dat->elf_sec[secidx].sh_name >= dat->elf_sec[dat->shstrndx].sh_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + char* sec_name = dat->sections_names + dat->elf_sec[secidx].sh_name; + /* + * Verifying string starts before end of section. Assuming (but not checking) + * that string ends before end of section. Additional check will complicate code. + * Assuming the platform this application is running on is not compromized. + */ + if((uint8_t*)sec_name >= elf_buf + elf_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + if(0 == strcmp(sec_name, PCLTBL_SECTION_NAME)) + { + *tbl_pp = (pcl_table_t *)(elf_buf + dat->elf_sec[secidx].sh_offset); + if((uint8_t*)(*tbl_pp) + sizeof(pcl_table_t) >= elf_buf + elf_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + // Verify table is aligned: + if(0 != dat->elf_sec[secidx].sh_offset % PCL_TABLE_ALLIGNMENT) + return ENCIP_ERROR_TBL_NOT_ALIGNED; + tbl_found = true; + } + } + + if(!tbl_found) + return ENCIP_ERROR_TBL_NOT_FOUND; + return ENCIP_SUCCESS; +} + +/* + * @func rdrand_supported uses CPUID to check if platform supports RDRAND + * @return true iff platform supports RDRAND + */ +bool rdrand_supported() +{ + int cpu_info[4] = {0, 0, 0, 0}; + __cpuid(cpu_info, 1); + return (!!(cpu_info[2] & SUPPORT_RDRAND)); +} + +/* + * @func init_random_iv initiates iv with a random number + * @param OUT uint8_t* iv, pointer to output random IV + * @return encip_ret_e: + * ENCIP_ERROR_RANDIV_INVALID_PARAM if iv is NULL + * ENCIP_ERROR_RDRAND_NOT_SUPPORTED if platform does not support RDRAND + * ENCIP_ERROR_RDRAND_FAILED if random number gneration fails + * ENCIP_SUCCESS if successfull + */ +static encip_ret_e init_random_iv(OUT uint8_t* iv) +{ + if(NULL == iv) + return ENCIP_ERROR_RANDIV_INVALID_PARAM; + if(rdrand_supported()) + { + uint32_t* ivp = (uint32_t*)iv; + // Get a random IV for encryption: + for(uint32_t i=0;i < SGX_AESGCM_IV_SIZE / sizeof(uint32_t);i++) + { + uint32_t randval = 0; + int rdrand32ret = _rdrand32_step(&randval); + if(RDRAND_SUCCESS != rdrand32ret) + return ENCIP_ERROR_RDRAND_FAILED; + *ivp = randval; + ivp++; + } + } + else + { + return ENCIP_ERROR_RDRAND_NOT_SUPPORTED; + } + return ENCIP_SUCCESS; +} + +/* + * @func update_flags updates the flags of sections or segments that must become writable + * @param uint16_t secidx, index of section for which the flags are currently updated + * @param INOUT pcl_data_t* dat, ELF data + * @return encip_ret_e, ENCIP_ERROR_UPDATEF_INVALID_PAR if dat is NULL, else ENCIP_SUCCESS + */ +static inline encip_ret_e update_flags(uint16_t secidx, INOUT pcl_data_t* dat) +{ + if(NULL == dat) + return ENCIP_ERROR_UPDATEF_INVALID_PAR; + + // Mark section as writable: + dat->elf_sec[secidx].sh_flags |= SHF_WRITE; + Elf64_Addr secstart = dat->elf_sec[secidx].sh_addr; + size_t secsize = dat->elf_sec[secidx].sh_size; + /* + * If section overlaps segment: + * 1. Verify segment is readable + * 2. Mark segment as writable + */ + for(uint16_t segidx=0;segidxnsegments;segidx++) + { + Elf64_Addr segstart = dat->phdr[segidx].p_vaddr; + size_t segsize = dat->phdr[segidx].p_memsz; + if(((secstart < segstart + segsize) && (secstart >= segstart )) || + ((secstart + secsize > segstart ) && (secstart + secsize <= segstart + segsize))) + { + // Segment must be readible: + if(!(dat->phdr[segidx].p_flags & (Elf64_Word)PF_R)) + { + printf("\n\nError: segment %d ", segidx); + + if(dat->elf_sec[secidx].sh_name < dat->elf_sec[dat->shstrndx].sh_size) + { + char* sec_name = dat->sections_names + dat->elf_sec[secidx].sh_name; + /* + * Verifying string starts before end of section. Assuming (but not checking) + * that string ends before end of section. Additional check will complicate code. + * Assuming the platform this application is running on is not compromized. + */ + printf("overlaps encrypted section \"%s\" and ", sec_name); + } + printf("is not readable. Exiting!!!\n\n\n"); + return ENCIP_ERROR_SEGMENT_NOT_READABLE; + } + // Mark segment as wirtable: + dat->phdr[segidx].p_flags |= (Elf64_Word)PF_W; + } + } + return ENCIP_SUCCESS; +} + +/* + * @func encrypt_or_clear_ip_sections modifies the content of some sections. + * 1. If section content cannot be modified without disrupting enclave signing or loading flows + * then section content is not modified + * 2. Allocable sections (copied to application address space at shared object's load time) + * are encrypted. + * 3. The content of sections that are not allocable is zeroed + * @param IN pcl_data_t* dat, ELF data + * @param IN uint8_t* key, the AES key for GCM encrypt + * @param INOUT uint8_t* elf_buf, base address of ELF binary buffer + * @param OUT pcl_table_t* tbl, pointer to PCL table + * @param OUT uint32_t* num_rvas_out, total number of sections that are encrypted + * @param bool debug, true iff enclave is requried to support debug + * @return encip_ret_e: + * ENCIP_ERROR_ENCSECS_INVALID_PARAM any input parameter is NULL + * PCL_MAX_NUM_ENCRYPTED_SECTIONS if out of entires in PCL table + * Respective error results in case any of the functions encrypt or update_flags fail. + * ENCIP_SUCCESS if success + */ +static encip_ret_e encrypt_or_clear_ip_sections( + IN pcl_data_t* dat, + IN uint8_t* key, + INOUT uint8_t* elf_buf, + size_t elf_size, + OUT pcl_table_t* tbl, + OUT uint32_t* num_rvas_out, + bool debug) +{ + if( + NULL == dat || + NULL == key || + NULL == elf_buf || + NULL == tbl || + NULL == num_rvas_out) + return ENCIP_ERROR_ENCSECS_INVALID_PARAM; + uint32_t num_rvas = 0; + // Go over sections headers to find sections to encrypt or clear: + char* sec_name = NULL; + for(uint16_t secidx = 1; secidx < dat->nsections; secidx++) + { + if(dat->elf_sec[secidx].sh_name >= dat->elf_sec[dat->shstrndx].sh_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + sec_name = dat->sections_names + dat->elf_sec[secidx].sh_name; + /* + * Verifying string starts before end of section. Assuming (but not checking) + * that string ends before end of section. Additional check will complicate code. + * Assuming the platform this application is running on is not compromized. + */ + if((uint8_t*)sec_name > elf_buf + elf_size) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + if(can_modify(sec_name, debug)) + { + uint8_t* va = (uint8_t *)(elf_buf + dat->elf_sec[secidx].sh_offset); + size_t size = dat->elf_sec[secidx].sh_size; + if((va >= elf_buf + elf_size) || + (va + size < va) || + (va + size > elf_buf + elf_size)) + return ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE; + // If section is allocable (mapped into process's virtual memory), decrypt it: + if(SHF_ALLOC & dat->elf_sec[secidx].sh_flags) + { + + if(PCL_MAX_NUM_ENCRYPTED_SECTIONS <= num_rvas) + { + /* + * No more empty entries in PCL table. + * To fix - redefine PCL_MAX_NUM_ENCRYPTED_SECTIONS in pcl_common.h + */ + printf("Error: No more empty entries in Intel(R) SGX PCL table\n"); + printf("To fix - redefine PCL_MAX_NUM_ENCRYPTED_SECTIONS in pcl_common.h\n"); + return ENCIP_ERROR_ENCSECS_RVAS_OVERFLOW; + } + + if(PCL_GCM_NUM_BLOCKS(size) > PCL_GCM_MAX_NUM_BLOCKS) + { + /* + * Size in 16-bytes-blocks exceeds (2^32 - 2). + * Only happen if cipher-text size is ~64GB. + */ + return ENCIP_ERROR_ENCSECS_COUNTER_OVERFLOW; + } + + uint8_t* iv = (uint8_t*)&(tbl->rvas_sizes_tags_ivs[num_rvas].iv.val); + encip_ret_e ret = init_random_iv(iv); + if(ENCIP_ERROR(ret)) + return ret; + + uint8_t* tag = (uint8_t*)&(tbl->rvas_sizes_tags_ivs[num_rvas].tag); + ret = gcm_encrypt(va, size, NULL, 0, (uint8_t *)key, iv, va, tag); + if(ENCIP_ERROR(ret)) + { + printf("Failed to gcm-encrypt section %s\n", sec_name); + return ret; + } + + // Insert entry to table: + tbl->rvas_sizes_tags_ivs[num_rvas].rva = dat->elf_sec[secidx].sh_addr; + tbl->rvas_sizes_tags_ivs[num_rvas].size = size; + + // Update flags to writable: + ret = update_flags(secidx, dat); + if(ENCIP_ERROR(ret)) + return ret; + + // Increment num_rvas: + num_rvas++; + } + // Else (section is not allocable), zero it: + else + { + memset(va, 0, size); + } + } + } + *num_rvas_out = num_rvas; + return ENCIP_SUCCESS; +} + +/* + * @func encrypt_ip modifies the content of some sections. + * @param INOUT uint8_t* elf_buf, buffer of ELF binary + * @param size_t elf_size, size of ELF binary in bytes + * @param IN uint8_t* key, AES-GCM-128 key + * @param bool debug, true iff enclave is requried to support debug + * @return encip_ret_e: + * ENCIP_ERROR_ENCRYPTIP_INVALID_PARAM if any input parameter is NULL + * Respective error results in case any of the following functions fail: + * parse_elf, get_pcl_tbl init_random_iv, encrypt_or_clear_ip_sections or sha256 + * ENCIP_ERROR_MEM_ALLOC if memory allocation fails + * ENCIP_ERROR_SEALED_BUF_SIZE if sealed buf size exceeds the size allocated for it in PCL table + * ENCIP_SUCCESS if success + */ +encip_ret_e encrypt_ip(INOUT uint8_t* elf_buf, size_t elf_size, IN uint8_t* key, bool debug) +{ + if(NULL == elf_buf || NULL == key) + return ENCIP_ERROR_ENCRYPTIP_INVALID_PARAM; + encip_ret_e ret = ENCIP_ERROR_FAIL; + pcl_data_t dat = { + .elf_sec = 0, + .shstrndx = 0, + .sections_names = NULL, + .phdr = NULL, + .nsections = 0, + .nsegments = 0, + }; + pcl_table_t* tbl = NULL; + + ret = parse_elf(elf_buf, elf_size, &dat); + if(ENCIP_ERROR(ret)) + return ret; + + ret = get_pcl_tbl(elf_buf, elf_size, &dat, &tbl); + if(ENCIP_ERROR(ret)) + return ret; + + // Verify state of binary: + if(PCL_CIPHER == tbl->pcl_state) + return ENCIP_ERROR_ALREADY_ENCRYPTED; + if(PCL_PLAIN != tbl->pcl_state) + return ENCIP_ERROR_IMPROPER_STATE; + + // Encrypt or clear IP sections: + uint32_t num_rvas = 0; + ret = encrypt_or_clear_ip_sections(&dat, key, elf_buf, elf_size, tbl, &num_rvas, debug); + if(ENCIP_ERROR(ret)) + return ret; + + // Set GUID: + memcpy(tbl->pcl_guid, g_pcl_guid, sizeof(tbl->pcl_guid)); + + // Set sealed blob size: + tbl->sealed_blob_size = (size_t)sgx_calc_sealed_data_size(SGX_PCL_GUID_SIZE, SGX_AESGCM_KEY_SIZE); + // Verify calculated size equals hard coded size of buffer in PCL table: + if(PCL_SEALED_BLOB_SIZE != tbl->sealed_blob_size) + return ENCIP_ERROR_SEALED_BUF_SIZE; + + // Set num RVAs: + tbl->num_rvas = num_rvas; + + // Set decryption key sha256 hash result: + ret = sha256(key, SGX_AESGCM_KEY_SIZE, tbl->decryption_key_hash); + if(ENCIP_ERROR(ret)) + return ret; + + // Set PCL state + tbl->pcl_state = PCL_CIPHER; + + return ENCIP_SUCCESS; +} + +/* + * @func print_usage prints sgx_encrypt usage instructions + * @param IN char* encip_name is the name of the application + */ +void print_usage(IN char* encip_name) +{ + printf("\n"); + printf("\tUsage: \n"); + printf("\t %s -i -o -k [-d]\n", + encip_name); + printf("\t -d (optional) prevents the tool from disabling the debug capabilities\n"); + printf("\n"); +} + +/* + * @func parse_args parses the application's input argument. + * @param int argc is the number of arguments + * @param IN char* argv[] is the array of input arguments + * @param OUT char** ifname points to the name of the original input enclave binary file + * @param OUT char** ofname points to the name of the modified output enclave binary file + * @param OUT char** kfname points to the name of the input key file + * @param OUT bool* debug, true if enclave needs to support debug + * the encrypted enclave binary. + * @return encip_ret_e: + * ENCIP_ERROR_PARSE_INVALID_PARAM if any of the input parameters is NULL + * ENCIP_ERROR_PARSE_ARGS if input arguments are not supported + * ENCIP_SUCCESS if success + */ +encip_ret_e parse_args( + int argc, + IN char* argv[], + OUT char** ifname, + OUT char** ofname, + OUT char** kfname, + OUT bool* debug) +{ + if(NULL == argv) + return ENCIP_ERROR_PARSE_INVALID_PARAM; + + char* encip_name = argv[0]; + + if((argc != 7 && argc != 8) || + NULL == ifname || + NULL == ofname || + NULL == kfname) + { + print_usage(encip_name); + return ENCIP_ERROR_PARSE_INVALID_PARAM; + } + encip_ret_e ret = ENCIP_SUCCESS; + + for(int argidx = 1; argidx < argc; argidx++) + { + if(!strcmp(argv[argidx],"-d")) + { + *debug = true; + } + else if(!strcmp(argv[argidx],"-i") && argidx + 1 < argc) + { + argidx++; + *ifname = argv[argidx]; + } + else if(!strcmp(argv[argidx],"-o") && argidx + 1 < argc) + { + argidx++; + *ofname = argv[argidx]; } + else if(!strcmp(argv[argidx],"-k") && argidx + 1 < argc) + { + argidx++; + *kfname = argv[argidx]; + } + else + { + ret = ENCIP_ERROR_PARSE_ARGS; + } + } + + if((ENCIP_SUCCESS != ret) || + (NULL == *ifname) || + (NULL == *ofname) || + (NULL == *kfname)) + { + print_usage(encip_name); + ret = ENCIP_ERROR_PARSE_ARGS; + } + return ret; +} + +/* + * @func read_file reads file into buffer. + * @param IN const char* const ifname is the input file name + * @param OUT uint8_t** buf_pp points to the output buffer + * @param OUT size_t* size_out points to the output data size + * @return encip_ret_e: + * ENCIP_ERROR_READF_INVALID_PARAM if any of the input parameters is NULL + * ENCIP_ERROR_READF_OPEN if unable to open input file + * ENCIP_ERROR_READF_ALLOC if unable to allocate output buffer + * ENCIP_ERROR_READF_READ if unable to read file to buffer + * ENCIP_SUCCESS if success + */ +static encip_ret_e read_file(IN const char* const ifname, OUT uint8_t** buf_pp, OUT size_t* size_out) +{ + if(NULL == ifname || NULL == buf_pp || NULL == size_out) + return ENCIP_ERROR_READF_INVALID_PARAM; + + FILE* fin = fopen(ifname, "rb"); + if(NULL == fin) + return ENCIP_ERROR_READF_OPEN; + + fseek(fin,0,SEEK_END); + size_t const size = ftell(fin); + fseek(fin, 0, SEEK_SET); + + *buf_pp = (uint8_t*)malloc(size); + if(NULL == *buf_pp) + { + fclose(fin); + return ENCIP_ERROR_MEM_ALLOC; + } + + size_t const num_bytes = fread(*buf_pp, 1, size, fin); + if(num_bytes != size) + { + fclose(fin); + free (*buf_pp); + return ENCIP_ERROR_READF_READ; + } + fclose(fin); + *size_out = size; + return ENCIP_SUCCESS; +} + +/* + * @func write_file writes buffer into file + * @param IN char* ofname is the output file name + * @param IN uint8_t* buf is the input buffer + * @param size_t size is the size of the buffer + * @return encip_ret_e: + * ENCIP_ERROR_WRITEF_INVALID_PARAM if any of the input parameters is NULL + * ENCIP_ERROR_WRITEF_OPEN if unable to open output file + * ENCIP_ERROR_WRITEF_WRITE if unable to write buf to file + * ENCIP_SUCCESS if success + */ +static encip_ret_e write_file(IN const char* const ofname, IN uint8_t* buf, size_t size) +{ + if(NULL == ofname || NULL == buf) + return ENCIP_ERROR_WRITEF_INVALID_PARAM; + FILE* fout = fopen(ofname, "wb"); + if(NULL == fout) + return ENCIP_ERROR_WRITEF_OPEN; + + size_t num_bytes = fwrite(buf, 1, size, fout); + if(num_bytes != size) + { + fclose(fout); + return ENCIP_ERROR_WRITEF_WRITE; + } + + fclose(fout); + return ENCIP_SUCCESS; +} + +/* + * @func sha256 calculates SHA256 + * @param IN const void* const buf is the input payload + * @param size_t buflen is the payload length in bytes + * @param OUT uint8_t* hash is the resulting output hash + * @return encip_ret_e: + * ENCIP_ERROR_SHA_INVALID_PARAM if any of the input parameters is NULL + * ENCIP_ERROR_SHA_ALLOC if EVP_MD_CTX_create is unable to allocate buffer + * ENCIP_ERROR_SHA_INIT is EVP_DigestInit_ex fails + * ENCIP_ERROR_SHA_UPDATE if EVP_DigestUpdate fails + * ENCIP_ERROR_SHA_FINAL if EVP_DigestFinal_ex fails + * ENCIP_SUCCESS if success + */ +encip_ret_e sha256(IN const void* const buf, size_t buflen, OUT uint8_t* hash) +{ + encip_ret_e ret = ENCIP_ERROR_FAIL; + unsigned int digest_len = 0; + + if(NULL== buf || NULL== hash) + return ENCIP_ERROR_SHA_INVALID_PARAM; + + EVP_MD_CTX *mdctx = EVP_MD_CTX_create(); + if(NULL == mdctx) + return ENCIP_ERROR_SHA_ALLOC; + + if(EVP_SUCCESS != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)){ + ret = ENCIP_ERROR_SHA_INIT; + goto Label_free_context; + } + + if(EVP_SUCCESS != EVP_DigestUpdate(mdctx, buf, buflen)){ + ret = ENCIP_ERROR_SHA_UPDATE; + goto Label_free_context; + } + + if((EVP_SUCCESS != EVP_DigestFinal_ex(mdctx, hash, &digest_len)) || + (SGX_SHA256_HASH_SIZE != digest_len)){ + ret = ENCIP_ERROR_SHA_FINAL; + goto Label_free_context; + } + + ret = ENCIP_SUCCESS; + +Label_free_context: + EVP_MD_CTX_destroy(mdctx); + + return ret; +} + +/* + * @func gcm_encrypt calculates AES-GCM-128 + * @param IN unsigned char *plaintext, input plain text + * @param int plaintext_len, size of plain text in bytes + * @param IN unsigned char *aad, AAD + * @param int aad_len, size of AAD in bytes + * @param IN unsigned char *key, key + * @param IN unsigned char *iv, iv + * @param OUT unsigned char *ciphertext, output cipher text + * @param OUT unsigned char *tag, GCM TAG result + * @return encip_ret_e: + * ENCIP_ERROR_GCM_ENCRYPT_INVALID_PARAM if any of the input parameters is NULL + * ENCIP_ERROR_ENCRYPT_ALLOC if EVP_CIPHER_CTX_new is unable to allocate the requried buffer + * ENCIP_ERROR_ENCRYPT_INIT_EX if initializing encryption function with EVP_EncryptInit_ex fails + * ENCIP_ERROR_ENCRYPT_IV_LEN if setting IV length with EVP_CIPHER_CTX_ctrl fails + * ENCIP_ERROR_ENCRYPT_INIT_KEY if setting key with EVP_EncryptInit_ex fails + * ENCIP_ERROR_ENCRYPT_AAD if initializing AAD using EVP_EncryptUpdate fails + * ENCIP_ERROR_ENCRYPT_UPDATE if encryption using EVP_EncryptUpdate fails + * ENCIP_ERROR_ENCRYPT_FINAL if call to EVP_EncryptFinal_ex fails + * ENCIP_ERROR_ENCRYPT_TAG if calculating TAG result using EVP_CIPHER_CTX_ctrl fails + * ENCIP_SUCCESS if success + */ +encip_ret_e gcm_encrypt( + IN unsigned char *plaintext, + size_t plaintext_len, + IN unsigned char *aad, + size_t aad_len, + IN unsigned char *key, + IN unsigned char *iv, + OUT unsigned char *ciphertext, + OUT unsigned char *tag) +{ + EVP_CIPHER_CTX *ctx; + int len; + encip_ret_e ret = ENCIP_ERROR_GCM_ENCRYPT_INVALID_PARAM; + if( NULL == plaintext || + NULL == key || + NULL == iv || + NULL == ciphertext || + NULL == tag) + return ENCIP_ERROR_GCM_ENCRYPT_INVALID_PARAM; + // Create and init context + if(NULL == (ctx = EVP_CIPHER_CTX_new())) + return ENCIP_ERROR_ENCRYPT_ALLOC; + // Init the encryption function + if(EVP_SUCCESS != EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL)) + { + ret = ENCIP_ERROR_ENCRYPT_INIT_EX; + goto Label_gcm_cleanup; + } + // Set IV length to SGX_AESGCM_IV_SIZE + if(EVP_SUCCESS != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, SGX_AESGCM_IV_SIZE, NULL)) + { + ret = ENCIP_ERROR_ENCRYPT_IV_LEN; + goto Label_gcm_cleanup; + } + // Init key and IV: + if(EVP_SUCCESS != EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) + { + ret = ENCIP_ERROR_ENCRYPT_INIT_KEY; + goto Label_gcm_cleanup; + } + // Init AAD: + if(NULL != aad) + { + if(EVP_SUCCESS != EVP_EncryptUpdate(ctx, NULL, &len, aad, (int)aad_len)) + { + ret = ENCIP_ERROR_ENCRYPT_AAD; + goto Label_gcm_cleanup; + } + } + // Encrypt: + if(EVP_SUCCESS != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, (int)plaintext_len)) + { + ret = ENCIP_ERROR_ENCRYPT_UPDATE; + goto Label_gcm_cleanup; + } + // Final: + if(EVP_SUCCESS != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) + { + ret = ENCIP_ERROR_ENCRYPT_FINAL; + goto Label_gcm_cleanup; + } + // Get Tag: + if(EVP_SUCCESS != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, SGX_CMAC_MAC_SIZE, tag)) + { + ret = ENCIP_ERROR_ENCRYPT_TAG; + goto Label_gcm_cleanup; + } + + ret = ENCIP_SUCCESS; + + // Cleanup: +Label_gcm_cleanup: + EVP_CIPHER_CTX_free(ctx); + return ret; +} diff --git a/sdk/encrypt_enclave/encryptip.h b/sdk/encrypt_enclave/encryptip.h new file mode 100644 index 00000000..fd2c778f --- /dev/null +++ b/sdk/encrypt_enclave/encryptip.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ENCRYPTIP_H +#define ENCRYPTIP_H + +// PCL table must be alligned to PCL_TABLE_ALLIGNMENT bytes +#define PCL_TABLE_ALLIGNMENT (16) + +#define PCL_TEXT_SECTION_NAME ".nipx" +#define PCL_DATA_SECTION_NAME ".nipd" +#define PCL_RODATA_SECTION_NAME ".niprod" + +#define NUM_NON_IP_OR_DEBUG_SEC_NAMES (23) +#define NUM_NON_IP_SEC_NAMES (12) + +/* + * When running CPUID with leaf 0, bit 30 of the output ECX + * indicates if platform supports RDRAND + */ +#define SUPPORT_RDRAND (1<<30) + +// GCM can encrypt up to (2^32 - 2) blocks per single IV +#define PCL_GCM_MAX_NUM_BLOCKS \ + ((size_t)((uint32_t)(-2))) + +#define PCL_GCM_NUM_BLOCKS(size) \ + ((size + PCL_AES_BLOCK_LEN - 1)/ PCL_AES_BLOCK_LEN) + +#define EVP_SUCCESS (1) +#define RDRAND_SUCCESS (1) +#define ENCIP_ERROR(r) (ENCIP_SUCCESS != (r)) + +typedef enum encip_ret_e_ +{ + ENCIP_SUCCESS = 0x0, + ENCIP_ERROR_FAIL = 0x80, + ENCIP_ERROR_INVALID_PARAM = 0x82, + ENCIP_ERROR_KEY_FILE_SIZE = 0x84, + ENCIP_ERROR_ENCLAVE_SIZE = 0x86, + ENCIP_ERROR_MEM_ALLOC = 0x88, + ENCIP_ERROR_PARSE_ARGS = 0x8a, + ENCIP_ERROR_PARSE_INVALID_PARAM = 0x8c, + ENCIP_ERROR_READF_INVALID_PARAM = 0x8e, + ENCIP_ERROR_READF_OPEN = 0x90, + ENCIP_ERROR_READF_ALLOC = 0x92, + ENCIP_ERROR_READF_READ = 0x94, + ENCIP_ERROR_WRITEF_INVALID_PARAM = 0x96, + ENCIP_ERROR_WRITEF_OPEN = 0x98, + ENCIP_ERROR_WRITEF_WRITE = 0x9a, + ENCIP_ERROR_SEALED_BUF_SIZE = 0x9c, + ENCIP_ERROR_GETTBL_INVALID_PARAM = 0x9e, + ENCIP_ERROR_TBL_NOT_FOUND = 0xa0, + ENCIP_ERROR_TBL_NOT_ALIGNED = 0xa2, + ENCIP_ERROR_ALREADY_ENCRYPTED = 0xa4, + ENCIP_ERROR_IMPROPER_STATE = 0xa6, + ENCIP_ERROR_RANDIV_INVALID_PARAM = 0xa8, + ENCIP_ERROR_RDRAND_NOT_SUPPORTED = 0xa9, + ENCIP_ERROR_RDRAND_FAILED = 0xaa, + ENCIP_ERROR_GCM_ENCRYPT_INVALID_PARAM = 0xac, + ENCIP_ERROR_ENCRYPT_ALLOC = 0xae, + ENCIP_ERROR_ENCRYPT_INIT_EX = 0xb0, + ENCIP_ERROR_ENCRYPT_IV_LEN = 0xb2, + ENCIP_ERROR_ENCRYPT_INIT_KEY = 0xb4, + ENCIP_ERROR_ENCRYPT_AAD = 0xb6, + ENCIP_ERROR_ENCRYPT_UPDATE = 0xb8, + ENCIP_ERROR_ENCRYPT_FINAL = 0xba, + ENCIP_ERROR_ENCRYPT_TAG = 0xbc, + ENCIP_ERROR_INCIV_INVALID_PARAM = 0xbe, + ENCIP_ERROR_IV_OVERFLOW = 0xc0, + ENCIP_ERROR_SHA_INVALID_PARAM = 0xc2, + ENCIP_ERROR_SHA_ALLOC = 0xc4, + ENCIP_ERROR_SHA_INIT = 0xc6, + ENCIP_ERROR_SHA_UPDATE = 0xc8, + ENCIP_ERROR_SHA_FINAL = 0xca, + ENCIP_ERROR_ENCSECS_INVALID_PARAM = 0xcc, + ENCIP_ERROR_ENCSECS_COUNTER_OVERFLOW = 0xce, + ENCIP_ERROR_ENCSECS_RVAS_OVERFLOW = 0xd0, + ENCIP_ERROR_UPDATEF_INVALID_PAR = 0xd2, + ENCIP_ERROR_ENCRYPTIP_INVALID_PARAM = 0xd4, + ENCIP_ERROR_PARSE_ELF_INVALID_PARAM = 0xd6, + ENCIP_ERROR_PARSE_ELF_INVALID_IMAGE = 0xd8, + ENCIP_ERROR_SEGMENT_NOT_READABLE = 0xda, +}encip_ret_e; + +typedef struct pcl_data_t_ +{ + + Elf64_Shdr* elf_sec; + Elf64_Half shstrndx; + char* sections_names; + Elf64_Phdr* phdr; + uint16_t nsections; + uint16_t nsegments; +}pcl_data_t; + +encip_ret_e parse_args( + int argc, + IN char* argv[], + OUT char** ifname, + OUT char** ofname, + OUT char** kfname, + OUT bool* debug); +static encip_ret_e read_file(IN const char* const name,OUT uint8_t** data,OUT size_t* size_out); +static encip_ret_e write_file(const char* const name, uint8_t* data, size_t size); +encip_ret_e gcm_encrypt( + unsigned char *plaintext, + size_t plaintext_len, + unsigned char *aad, + size_t aad_len, + unsigned char *key, + unsigned char *iv, + unsigned char *ciphertext, + unsigned char *tag); +encip_ret_e sha256(const void* const buf, size_t buflen, uint8_t* hash); +encip_ret_e encrypt_ip(uint8_t* elf_buf, size_t elf_size, uint8_t* key, bool debug); +encip_ret_e write_tbl_strs(pcl_table_t* tbl); + +#endif // #ifndef ENCRYPTIP_H + diff --git a/sdk/protected_code_loader/Makefile b/sdk/protected_code_loader/Makefile new file mode 100644 index 00000000..5b2bc835 --- /dev/null +++ b/sdk/protected_code_loader/Makefile @@ -0,0 +1,184 @@ +# +# Copyright (C) 2011-2018 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +# PCL library makefile + +include ../../buildenv.mk + +ifndef $(VERBOSE) + VERBOSE := @ +endif + + +ifeq ($(ARCH), x86) + $(error x86 build is not supported, only x64!!) +endif + +# output dir for simulation build objects +SIM_DIR := simulation/ +SIM_OBJ_DIR := $(SIM_DIR) + + +PCL_SIM_LIB := libsgx_pclsim.a +PCL_LIB := libsgx_pcl.a + +# source files +PCL_ASM_FILES := crypto/pcl_vpaes-x86_64.s \ + crypto/pcl_ghash-x86_64.s + +PCL_CPP_FILES := pcl_entry.cpp \ + pcl_mem.cpp \ + crypto/pcl_crypto.cpp \ + unseal/pcl_tSeal.cpp \ + unseal/pcl_sgx_get_key.cpp \ + unseal/pcl_tSeal_util.cpp \ + unseal/pcl_tSeal_internal.cpp + +PCL_C_FILES := crypto/pcl_sha256.c \ + crypto/pcl_gcm128.c + +# files for simulation mode +PCL_SIM_C_FILES := $(PCL_C_FILES) crypto/pcl_cmac.c +PCL_SIM_CPP_FILES := $(PCL_CPP_FILES) unseal/sim/pcl_deriv.cpp unseal/sim/pcl_t_instructions.cpp + +# object files +PCL_CPP_OBJECTS := $(PCL_CPP_FILES:%.cpp=%.o) +PCL_C_OBJECTS := $(PCL_C_FILES:%.c=%.o) +PCL_ASM_OBJECTS := $(PCL_ASM_FILES:%.s=%.o) + +# simulation objects +PCL_SIM_CPP_OBJECTS := $(PCL_SIM_CPP_FILES:%.cpp=$(SIM_OBJ_DIR)%.o) +PCL_SIM_C_OBJECTS := $(PCL_SIM_C_FILES:%.c=$(SIM_OBJ_DIR)%.o) + +# build flags +PCL_INCLUDE_PATH := -I$(COMMON_DIR)/inc \ + -I$(COMMON_DIR)/inc/tlibc \ + -I$(COMMON_DIR)/inc/internal \ + -I./crypto \ + -I./unseal \ + -I/usr/include/x86_64-linux-gnu \ + -I/usr/include \ + -I./ + +TCFLAGS := $(filter-out -ffunction-sections -fdata-sections, $(CFLAGS)) +TCXXFLAGS := $(filter-out -ffunction-sections -fdata-sections, $(CXXFLAGS)) +PCL_LIB_C_FLAGS := $(TCFLAGS) $(ENCLAVE_CFLAGS) $(PCL_INCLUDE_PATH) +PCL_LIB_CPP_FLAGS := $(TCXXFLAGS) $(ENCLAVE_CXXFLAGS) $(PCL_INCLUDE_PATH) + + +PCL_SIM_LIB_C_FLAGS := $(TCFLAGS) $(ENCLAVE_CFLAGS) -DSE_SIM=1 $(PCL_INCLUDE_PATH) -I$(LINUX_SDK_DIR)/simulation/tinst +PCL_SIM_LIB_CPP_FLAGS := $(TCXXFLAGS) $(ENCLAVE_CXXFLAGS) -DSE_SIM=1 $(PCL_INCLUDE_PATH) -I$(LINUX_SDK_DIR)/simulation/tinst + + +# targets +.PHONY: all + +all: | $(BUILD_DIR) + $(VERBOSE)$(MAKE) $(PCL_LIB) + $(VERBOSE)$(MAKE) $(PCL_SIM_LIB) + $(VERBOSE)$(CP) $(PCL_LIB) $| + $(VERBOSE)$(CP) $(PCL_SIM_LIB) $| + +$(BUILD_DIR): + $(VERBOSE)$(MKDIR) $@ + +.PHONY: $(PCL_LIB) +$(PCL_LIB):$(PCL_CPP_OBJECTS) $(PCL_ASM_OBJECTS) $(PCL_C_OBJECTS) + @echo "library build with DEBUG =" $(DEBUG) + $(VERBOSE)$(AR) -rc $@ $^ + @echo "AR <= $@" + + +.PHONY: $(PCL_SIM_LIB) +$(PCL_SIM_LIB):$(PCL_SIM_CPP_OBJECTS) $(PCL_ASM_OBJECTS) $(PCL_SIM_C_OBJECTS) + @echo "library build with DEBUG =" $(DEBUG) + $(VERBOSE)$(AR) -rc $@ $^ + @echo "AR <= $@" + + +%.o: %.s + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_LIB_C_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +%.o: %.c + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_LIB_C_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +%.o: %.cpp + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_LIB_CPP_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +# Simulation objects +$(SIM_OBJ_DIR)%.o: %.s + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_SIM_LIB_C_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +$(SIM_OBJ_DIR)%.o: %.c + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_SIM_LIB_C_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +$(SIM_OBJ_DIR)%.o: %.cpp + $(VERBOSE)mkdir -p $(@D) + $(VERBOSE)$(CXX) $(PCL_SIM_LIB_CPP_FLAGS) -c $< -o $@ + $(VERBOSE)$(OBJCOPY) $@ --rename-section .text=$(NIPX) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .data=$(NIPD) + $(VERBOSE)$(OBJCOPY) $@ --rename-section .rodata=$(NIPRODT) + @echo "CXX <= $<" + +.PHONY: clean +clean: + $(VERBOSE)$(RM) $(PCL_LIB) $(PCL_SIM_LIB) $(PCL_CPP_OBJECTS) $(PCL_ASM_OBJECTS) $(PCL_C_OBJECTS) $(PCL_SIM_CPP_OBJECTS) $(PCL_SIM_C_OBJECTS) + $(VERBOSE)rm -rf $(SIM_DIR) $(BUILD_DIR)/$(PCL_LIB) $(BUILD_DIR)/$(PCL_SIM_LIB) + +.PHONY: rebuild +rebuild: + $(MAKE) clean + $(MAKE) all diff --git a/sdk/protected_code_loader/crypto/pcl_cmac.c b/sdk/protected_code_loader/crypto/pcl_cmac.c new file mode 100644 index 00000000..e69d7831 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_cmac.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Content from openssl-1.1.0e/crypto/cmac/cmac.c */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef SE_SIM + +void make_kn( + unsigned char *k1, + const unsigned char *l, + int bl) +{ + int i; + unsigned char c = l[0], carry = c >> 7, cnext; + + /* Shift block to left, including carry */ + for (i = 0; i < bl - 1; i++, c = cnext) + k1[i] = (c << 1) | ((cnext = l[i + 1]) >> 7); + + /* If MSB set fixup with R */ + k1[i] = (c << 1) ^ ((0 - carry) & (bl == 16 ? 0x87 : 0x1b)); +} + +#endif // #ifdef SE_SIM + diff --git a/sdk/protected_code_loader/crypto/pcl_crypto.cpp b/sdk/protected_code_loader/crypto/pcl_crypto.cpp new file mode 100644 index 00000000..577ffd55 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_crypto.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * @func pcl_gcm_decrypt applies AES-GCM-128 + * @param OUT uint8_t* plaintext, input plain text buffer + * @param IN uint8_t* ciphertext, output cipher text buffer + * @param size_t textlen, size of buffer in bytes + * @param IN uint8_t* aad, aditional authenticated data + * @param size_t aad_len, size of aditional authenticated data + * @param IN uint8_t* key, 16 bytes decryption key + * @param IN uint8_t* iv, 12 bytes IV + * @param IN uint8_t* tag, 16 bytes TAG result + * @return sgx_status_t + * SGX_ERROR_INVALID_PARAMETER if any pointer is NULL except for aad + * SGX_ERROR_UNEXPECTED if any of the following functions fail: + * pcl_vpaes_set_encrypt_key, pcl_CRYPTO_gcm128_aad or pcl_CRYPTO_gcm128_decrypt + * SGX_ERROR_PCL_MAC_MISMATCH if MAC mismatch when calling pcl_CRYPTO_gcm128_finish + * SGX_SUCCESS if successfull + */ +sgx_status_t pcl_gcm_decrypt( + OUT uint8_t* plaintext, + IN uint8_t* ciphertext, + size_t textlen, + IN uint8_t* aad, + size_t aad_len, + IN uint8_t* key, + IN uint8_t* iv, + IN uint8_t* tag) +{ + sgx_status_t ret_status = SGX_ERROR_INVALID_PARAMETER; + + if( NULL == plaintext || + NULL == ciphertext || + NULL == key || + NULL == iv || + NULL == tag) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + AES_KEY wide_key = { 0 }; + GCM128_CONTEXT gcm_ctx; + + int ret = pcl_vpaes_set_encrypt_key(key, PCL_AES_BLOCK_LEN_BITS, &wide_key); + if(0 != ret) + { + ret_status = SGX_ERROR_UNEXPECTED; + goto Label_zero_wide_key; + } + + pcl_CRYPTO_gcm128_init(&gcm_ctx, &wide_key, (block128_f)pcl_vpaes_encrypt); + + pcl_CRYPTO_gcm128_setiv(&gcm_ctx, iv, SGX_AESGCM_IV_SIZE); + + if(NULL != aad) + { + ret = pcl_CRYPTO_gcm128_aad(&gcm_ctx, aad, aad_len); + if(0 != ret) + { + ret_status = SGX_ERROR_UNEXPECTED; + goto Label_zero_buffers; + } + } + + ret = pcl_CRYPTO_gcm128_decrypt( + &gcm_ctx, + ciphertext, + plaintext, + textlen); + if(0 != ret) + { + ret_status = SGX_ERROR_UNEXPECTED; + goto Label_zero_buffers; + } + + ret = pcl_CRYPTO_gcm128_finish(&gcm_ctx, tag, SGX_CMAC_MAC_SIZE); + if(0 != ret) + { + ret_status = SGX_ERROR_PCL_MAC_MISMATCH; + goto Label_zero_buffers; + } + + ret_status = SGX_SUCCESS; + + // Scrab secrets from stack: +Label_zero_buffers: + pcl_volatile_memset((volatile void*)(&gcm_ctx), 0, sizeof(gcm_ctx)); +Label_zero_wide_key: + pcl_volatile_memset((volatile void*)(&wide_key), 0, sizeof(wide_key)); + + return ret_status; +} + +/* + * @func pcl_sha256 calculates the payload SHA256 + * @param IN uint8_t* buf, payload buffer + * @param size_t buflen, buffer size in bytes + * @param OUT uint8_t* hash, SHA256 result + */ +sgx_status_t pcl_sha256(IN uint8_t* buf, size_t buflen, OUT uint8_t* hash) +{ + if(NULL == buf || NULL == hash) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + SHA256_CTX sha256; + + pcl_SHA256_Init(&sha256); + + pcl_SHA256_Update(&sha256, buf, buflen); + + pcl_SHA256_Final(hash, &sha256); + + pcl_volatile_memset((volatile void*)(&sha256), 0, sizeof(SHA256_CTX)); + + return SGX_SUCCESS; +} + +#ifdef SE_SIM + +/* + * @func pcl_cmac calcualtes CMAC-128 on payload + * @param IN const sgx_cmac_128bit_key_t *p_key, CMAC key + * @param IN const uint8_t *p_src, input buffer + * @param uint32_t src_len, buffer size in bytes + * @param OUT sgx_cmac_128bit_tag_t *p_mac, 16 bytes resulting MAC + * @return int, -1 if p_key, p_src or p_mac are NULL, 0 if success + */ +int pcl_cmac( + const sgx_cmac_128bit_key_t *p_key, + const uint8_t *p_src, + uint32_t src_len, + sgx_cmac_128bit_tag_t *p_mac) +{ + if(NULL == p_key || NULL == p_src || NULL == p_mac) + { + return -1; + } + unsigned char iv[PCL_COUNTER_SIZE] = { 0 }; + unsigned char aux[PCL_AES_BLOCK_LEN] = { 0 }; + unsigned char k1[PCL_AES_BLOCK_LEN] = { 0 }; + + AES_KEY wide_key; + pcl_vpaes_set_encrypt_key((const unsigned char *)p_key, PCL_AES_BLOCK_LEN_BITS, &wide_key); + + // Apply AES-CBC encrypt on input = 0^16 and IV = 0^16: + pcl_vpaes_cbc_encrypt(iv, aux, PCL_AES_BLOCK_LEN, &wide_key, iv, 1); + + // Use result to generate K1: + make_kn(k1, aux, PCL_AES_BLOCK_LEN); + + // Digest message except for last block: + pcl_memset(iv, 0, PCL_COUNTER_SIZE); + while(src_len > PCL_AES_BLOCK_LEN) + { + pcl_vpaes_cbc_encrypt((uint8_t *)p_src, aux, PCL_AES_BLOCK_LEN, &wide_key, iv, 1); + src_len -= PCL_AES_BLOCK_LEN; + p_src += PCL_AES_BLOCK_LEN; + } + + + // XOR K1 with last block of message: + for (int i = 0; i < PCL_AES_BLOCK_LEN; i++)aux[i] = p_src[i] ^ k1[i]; + + // Apply AES-CBC encrypt on result and IV + pcl_vpaes_cbc_encrypt(aux, (uint8_t*)p_mac, PCL_AES_BLOCK_LEN, &wide_key, iv, 1); + return 0; +} + +#endif // #ifdef SE_SIM + diff --git a/sdk/protected_code_loader/crypto/pcl_crypto_internal.h b/sdk/protected_code_loader/crypto/pcl_crypto_internal.h new file mode 100644 index 00000000..fbe39db3 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_crypto_internal.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef SGX_PCL_CRYPTO_INTERNAL_H +#define SGX_PCL_CRYPTO_INTERNAL_H + +extern "C" +{ + +int pcl_SHA256_Update(SHA256_CTX *c, void *data_, size_t len); +int pcl_SHA256_Final(unsigned char *md, SHA256_CTX *c); +int pcl_SHA256_Init(SHA256_CTX *c); + +typedef uint64_t u64; +typedef uint32_t u32; +typedef uint8_t u8; +typedef struct { + u64 hi, lo; +} u128; + +int pcl_vpaes_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); + +struct gcm128_context { + /* Following 6 names follow names in GCM specification */ + union { + u64 u[2]; + u32 d[4]; + u8 c[16]; + size_t t[16 / sizeof(size_t)]; + } Yi, EKi, EK0, len, Xi, H; + /* + * Relative position of Xi, H and pre-computed Htable is used in some + * assembler modules, i.e. don't change the order! + */ + u128 Htable[16]; + void (*gmult) (u64 Xi[2], const u128 Htable[16]); + void (*ghash) (u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); + unsigned int mres, ares; + block128_f block; + void *key; +}; + +void pcl_CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block); +void pcl_CRYPTO_gcm128_setiv( + GCM128_CONTEXT *ctx, + const unsigned char *iv, + size_t len); +int pcl_CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len); +int pcl_CRYPTO_gcm128_aad( + GCM128_CONTEXT *ctx, + const unsigned char *aad, + size_t len); +int pcl_CRYPTO_gcm128_finish( + GCM128_CONTEXT *ctx, + const unsigned char *tag, + size_t len); +void pcl_vpaes_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); + +#ifdef SE_SIM + +void make_kn( + unsigned char *k1, + const unsigned char *l, + int bl); +void pcl_vpaes_cbc_encrypt( + uint8_t* in, + uint8_t* out, + size_t len, + AES_KEY* wide_key_p, + uint8_t* iv, + bool encrypt); + +#endif // #ifdef SE_SIM + +}; // extern "C" + +#endif // #ifndef SGX_PCL_CRYPTO_INTERNAL_H + diff --git a/sdk/protected_code_loader/crypto/pcl_gcm128.c b/sdk/protected_code_loader/crypto/pcl_gcm128.c new file mode 100644 index 00000000..97addfd0 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_gcm128.c @@ -0,0 +1,2477 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Content from openssl-1.1.0e/crypto/modes/gcm128.c */ + + #include +#include +#include +#include +#include +#include +#include +#include +/* PCL UNUSED START * +#if defined(BSWAP4) && defined(STRICT_ALIGNMENT) +/* redefine, because alignment is ensured * / +# undef GETU32 +# define GETU32(p) BSWAP4(*(const u32 *)(p)) +# undef PUTU32 +# define PUTU32(p,v) *(u32 *)(p) = BSWAP4(v) +#endif + +#define PACK(s) ((size_t)(s)<<(sizeof(size_t)*8-16)) +#define REDUCE1BIT(V) do { \ + if (sizeof(size_t)==8) { \ + u64 T = U64(0xe100000000000000) & (0-(V.lo&1)); \ + V.lo = (V.hi<<63)|(V.lo>>1); \ + V.hi = (V.hi>>1 )^T; \ + } \ + else { \ + u32 T = 0xe1000000U & (0-(u32)(V.lo&1)); \ + V.lo = (V.hi<<63)|(V.lo>>1); \ + V.hi = (V.hi>>1 )^((u64)T<<32); \ + } \ +} while(0) + +/*- + * Even though permitted values for TABLE_BITS are 8, 4 and 1, it should + * never be set to 8. 8 is effectively reserved for testing purposes. + * TABLE_BITS>1 are lookup-table-driven implementations referred to as + * "Shoup's" in GCM specification. In other words OpenSSL does not cover + * whole spectrum of possible table driven implementations. Why? In + * non-"Shoup's" case memory access pattern is segmented in such manner, + * that it's trivial to see that cache timing information can reveal + * fair portion of intermediate hash value. Given that ciphertext is + * always available to attacker, it's possible for him to attempt to + * deduce secret parameter H and if successful, tamper with messages + * [which is nothing but trivial in CTR mode]. In "Shoup's" case it's + * not as trivial, but there is no reason to believe that it's resistant + * to cache-timing attack. And the thing about "8-bit" implementation is + * that it consumes 16 (sixteen) times more memory, 4KB per individual + * key + 1KB shared. Well, on pros side it should be twice as fast as + * "4-bit" version. And for gcc-generated x86[_64] code, "8-bit" version + * was observed to run ~75% faster, closer to 100% for commercial + * compilers... Yet "4-bit" procedure is preferred, because it's + * believed to provide better security-performance balance and adequate + * all-round performance. "All-round" refers to things like: + * + * - shorter setup time effectively improves overall timing for + * handling short messages; + * - larger table allocation can become unbearable because of VM + * subsystem penalties (for example on Windows large enough free + * results in VM working set trimming, meaning that consequent + * malloc would immediately incur working set expansion); + * - larger table has larger cache footprint, which can affect + * performance of other code paths (not necessarily even from same + * thread in Hyper-Threading world); + * + * Value of 1 is not appropriate for performance reasons. + * / +#if TABLE_BITS==8 + +static void gcm_init_8bit(u128 Htable[256], u64 H[2]) +{ + int i, j; + u128 V; + + Htable[0].hi = 0; + Htable[0].lo = 0; + V.hi = H[0]; + V.lo = H[1]; + + for (Htable[128] = V, i = 64; i > 0; i >>= 1) { + REDUCE1BIT(V); + Htable[i] = V; + } + + for (i = 2; i < 256; i <<= 1) { + u128 *Hi = Htable + i, H0 = *Hi; + for (j = 1; j < i; ++j) { + Hi[j].hi = H0.hi ^ Htable[j].hi; + Hi[j].lo = H0.lo ^ Htable[j].lo; + } + } +} + +static void gcm_gmult_8bit(u64 Xi[2], const u128 Htable[256]) +{ + u128 Z = { 0, 0 }; + const u8 *xi = (const u8 *)Xi + 15; + size_t rem, n = *xi; + const union { + long one; + char little; + } is_endian = { 1 }; + static const size_t rem_8bit[256] = { + PACK(0x0000), PACK(0x01C2), PACK(0x0384), PACK(0x0246), + PACK(0x0708), PACK(0x06CA), PACK(0x048C), PACK(0x054E), + PACK(0x0E10), PACK(0x0FD2), PACK(0x0D94), PACK(0x0C56), + PACK(0x0918), PACK(0x08DA), PACK(0x0A9C), PACK(0x0B5E), + PACK(0x1C20), PACK(0x1DE2), PACK(0x1FA4), PACK(0x1E66), + PACK(0x1B28), PACK(0x1AEA), PACK(0x18AC), PACK(0x196E), + PACK(0x1230), PACK(0x13F2), PACK(0x11B4), PACK(0x1076), + PACK(0x1538), PACK(0x14FA), PACK(0x16BC), PACK(0x177E), + PACK(0x3840), PACK(0x3982), PACK(0x3BC4), PACK(0x3A06), + PACK(0x3F48), PACK(0x3E8A), PACK(0x3CCC), PACK(0x3D0E), + PACK(0x3650), PACK(0x3792), PACK(0x35D4), PACK(0x3416), + PACK(0x3158), PACK(0x309A), PACK(0x32DC), PACK(0x331E), + PACK(0x2460), PACK(0x25A2), PACK(0x27E4), PACK(0x2626), + PACK(0x2368), PACK(0x22AA), PACK(0x20EC), PACK(0x212E), + PACK(0x2A70), PACK(0x2BB2), PACK(0x29F4), PACK(0x2836), + PACK(0x2D78), PACK(0x2CBA), PACK(0x2EFC), PACK(0x2F3E), + PACK(0x7080), PACK(0x7142), PACK(0x7304), PACK(0x72C6), + PACK(0x7788), PACK(0x764A), PACK(0x740C), PACK(0x75CE), + PACK(0x7E90), PACK(0x7F52), PACK(0x7D14), PACK(0x7CD6), + PACK(0x7998), PACK(0x785A), PACK(0x7A1C), PACK(0x7BDE), + PACK(0x6CA0), PACK(0x6D62), PACK(0x6F24), PACK(0x6EE6), + PACK(0x6BA8), PACK(0x6A6A), PACK(0x682C), PACK(0x69EE), + PACK(0x62B0), PACK(0x6372), PACK(0x6134), PACK(0x60F6), + PACK(0x65B8), PACK(0x647A), PACK(0x663C), PACK(0x67FE), + PACK(0x48C0), PACK(0x4902), PACK(0x4B44), PACK(0x4A86), + PACK(0x4FC8), PACK(0x4E0A), PACK(0x4C4C), PACK(0x4D8E), + PACK(0x46D0), PACK(0x4712), PACK(0x4554), PACK(0x4496), + PACK(0x41D8), PACK(0x401A), PACK(0x425C), PACK(0x439E), + PACK(0x54E0), PACK(0x5522), PACK(0x5764), PACK(0x56A6), + PACK(0x53E8), PACK(0x522A), PACK(0x506C), PACK(0x51AE), + PACK(0x5AF0), PACK(0x5B32), PACK(0x5974), PACK(0x58B6), + PACK(0x5DF8), PACK(0x5C3A), PACK(0x5E7C), PACK(0x5FBE), + PACK(0xE100), PACK(0xE0C2), PACK(0xE284), PACK(0xE346), + PACK(0xE608), PACK(0xE7CA), PACK(0xE58C), PACK(0xE44E), + PACK(0xEF10), PACK(0xEED2), PACK(0xEC94), PACK(0xED56), + PACK(0xE818), PACK(0xE9DA), PACK(0xEB9C), PACK(0xEA5E), + PACK(0xFD20), PACK(0xFCE2), PACK(0xFEA4), PACK(0xFF66), + PACK(0xFA28), PACK(0xFBEA), PACK(0xF9AC), PACK(0xF86E), + PACK(0xF330), PACK(0xF2F2), PACK(0xF0B4), PACK(0xF176), + PACK(0xF438), PACK(0xF5FA), PACK(0xF7BC), PACK(0xF67E), + PACK(0xD940), PACK(0xD882), PACK(0xDAC4), PACK(0xDB06), + PACK(0xDE48), PACK(0xDF8A), PACK(0xDDCC), PACK(0xDC0E), + PACK(0xD750), PACK(0xD692), PACK(0xD4D4), PACK(0xD516), + PACK(0xD058), PACK(0xD19A), PACK(0xD3DC), PACK(0xD21E), + PACK(0xC560), PACK(0xC4A2), PACK(0xC6E4), PACK(0xC726), + PACK(0xC268), PACK(0xC3AA), PACK(0xC1EC), PACK(0xC02E), + PACK(0xCB70), PACK(0xCAB2), PACK(0xC8F4), PACK(0xC936), + PACK(0xCC78), PACK(0xCDBA), PACK(0xCFFC), PACK(0xCE3E), + PACK(0x9180), PACK(0x9042), PACK(0x9204), PACK(0x93C6), + PACK(0x9688), PACK(0x974A), PACK(0x950C), PACK(0x94CE), + PACK(0x9F90), PACK(0x9E52), PACK(0x9C14), PACK(0x9DD6), + PACK(0x9898), PACK(0x995A), PACK(0x9B1C), PACK(0x9ADE), + PACK(0x8DA0), PACK(0x8C62), PACK(0x8E24), PACK(0x8FE6), + PACK(0x8AA8), PACK(0x8B6A), PACK(0x892C), PACK(0x88EE), + PACK(0x83B0), PACK(0x8272), PACK(0x8034), PACK(0x81F6), + PACK(0x84B8), PACK(0x857A), PACK(0x873C), PACK(0x86FE), + PACK(0xA9C0), PACK(0xA802), PACK(0xAA44), PACK(0xAB86), + PACK(0xAEC8), PACK(0xAF0A), PACK(0xAD4C), PACK(0xAC8E), + PACK(0xA7D0), PACK(0xA612), PACK(0xA454), PACK(0xA596), + PACK(0xA0D8), PACK(0xA11A), PACK(0xA35C), PACK(0xA29E), + PACK(0xB5E0), PACK(0xB422), PACK(0xB664), PACK(0xB7A6), + PACK(0xB2E8), PACK(0xB32A), PACK(0xB16C), PACK(0xB0AE), + PACK(0xBBF0), PACK(0xBA32), PACK(0xB874), PACK(0xB9B6), + PACK(0xBCF8), PACK(0xBD3A), PACK(0xBF7C), PACK(0xBEBE) + }; + + while (1) { + Z.hi ^= Htable[n].hi; + Z.lo ^= Htable[n].lo; + + if ((u8 *)Xi == xi) + break; + + n = *(--xi); + + rem = (size_t)Z.lo & 0xff; + Z.lo = (Z.hi << 56) | (Z.lo >> 8); + Z.hi = (Z.hi >> 8); + if (sizeof(size_t) == 8) + Z.hi ^= rem_8bit[rem]; + else + Z.hi ^= (u64)rem_8bit[rem] << 32; + } + + if (is_endian.little) { +# ifdef BSWAP8 + Xi[0] = BSWAP8(Z.hi); + Xi[1] = BSWAP8(Z.lo); +# else + u8 *p = (u8 *)Xi; + u32 v; + v = (u32)(Z.hi >> 32); + PUTU32(p, v); + v = (u32)(Z.hi); + PUTU32(p + 4, v); + v = (u32)(Z.lo >> 32); + PUTU32(p + 8, v); + v = (u32)(Z.lo); + PUTU32(p + 12, v); +# endif + } else { + Xi[0] = Z.hi; + Xi[1] = Z.lo; + } +} + +# define GCM_MUL(ctx,Xi) gcm_gmult_8bit(ctx->Xi.u,ctx->Htable) + +#elif TABLE_BITS==4 + +static void pcl_gcm_init_4bit(u128 Htable[16], u64 H[2]) +{ + u128 V; +# if defined(OPENSSL_SMALL_FOOTPRINT) + int i; +# endif + Htable[0].hi = 0; + Htable[0].lo = 0; + V.hi = H[0]; + V.lo = H[1]; + # if defined(OPENSSL_SMALL_FOOTPRINT) + for (Htable[8] = V, i = 4; i > 0; i >>= 1) { + REDUCE1BIT(V); + Htable[i] = V; + } + + for (i = 2; i < 16; i <<= 1) { + u128 *Hi = Htable + i; + int j; + for (V = *Hi, j = 1; j < i; ++j) { + Hi[j].hi = V.hi ^ Htable[j].hi; + Hi[j].lo = V.lo ^ Htable[j].lo; + } + } + # else + Htable[8] = V; + REDUCE1BIT(V); + Htable[4] = V; + REDUCE1BIT(V); + Htable[2] = V; + REDUCE1BIT(V); + Htable[1] = V; + Htable[3].hi = V.hi ^ Htable[2].hi, Htable[3].lo = V.lo ^ Htable[2].lo; + V = Htable[4]; + Htable[5].hi = V.hi ^ Htable[1].hi, Htable[5].lo = V.lo ^ Htable[1].lo; + Htable[6].hi = V.hi ^ Htable[2].hi, Htable[6].lo = V.lo ^ Htable[2].lo; + Htable[7].hi = V.hi ^ Htable[3].hi, Htable[7].lo = V.lo ^ Htable[3].lo; + V = Htable[8]; + Htable[9].hi = V.hi ^ Htable[1].hi, Htable[9].lo = V.lo ^ Htable[1].lo; + Htable[10].hi = V.hi ^ Htable[2].hi, Htable[10].lo = V.lo ^ Htable[2].lo; + Htable[11].hi = V.hi ^ Htable[3].hi, Htable[11].lo = V.lo ^ Htable[3].lo; + Htable[12].hi = V.hi ^ Htable[4].hi, Htable[12].lo = V.lo ^ Htable[4].lo; + Htable[13].hi = V.hi ^ Htable[5].hi, Htable[13].lo = V.lo ^ Htable[5].lo; + Htable[14].hi = V.hi ^ Htable[6].hi, Htable[14].lo = V.lo ^ Htable[6].lo; + Htable[15].hi = V.hi ^ Htable[7].hi, Htable[15].lo = V.lo ^ Htable[7].lo; + # endif + # if defined(GHASH_ASM) && (defined(__arm__) || defined(__arm)) + /* + * ARM assembler expects specific dword order in Htable. + * / + { + int j; + const union { + long one; + char little; + } is_endian = { 1 }; + + if (is_endian.little) + for (j = 0; j < 16; ++j) { + V = Htable[j]; + Htable[j].hi = V.lo; + Htable[j].lo = V.hi; + } else + for (j = 0; j < 16; ++j) { + V = Htable[j]; + Htable[j].hi = V.lo << 32 | V.lo >> 32; + Htable[j].lo = V.hi << 32 | V.hi >> 32; + } + } + # endif +} + + +static const size_t rem_4bit[16] = { + PACK(0x0000), PACK(0x1C20), PACK(0x3840), PACK(0x2460), + PACK(0x7080), PACK(0x6CA0), PACK(0x48C0), PACK(0x54E0), + PACK(0xE100), PACK(0xFD20), PACK(0xD940), PACK(0xC560), + PACK(0x9180), PACK(0x8DA0), PACK(0xA9C0), PACK(0xB5E0) +}; + +static void pcl_gcm_gmult_4bit(u64 Xi[2], const u128 Htable[16]) +{ + u128 Z; + int cnt = 15; + size_t rem, nlo, nhi; + const union { + long one; + char little; + } is_endian = { 1 }; + + nlo = ((const u8 *)Xi)[15]; + nhi = nlo >> 4; + nlo &= 0xf; + + Z.hi = Htable[nlo].hi; + Z.lo = Htable[nlo].lo; + + while (1) { + rem = (size_t)Z.lo & 0xf; + Z.lo = (Z.hi << 60) | (Z.lo >> 4); + Z.hi = (Z.hi >> 4); + if (sizeof(size_t) == 8) + Z.hi ^= rem_4bit[rem]; + else + Z.hi ^= (u64)rem_4bit[rem] << 32; + + Z.hi ^= Htable[nhi].hi; + Z.lo ^= Htable[nhi].lo; + + if (--cnt < 0) + break; + + nlo = ((const u8 *)Xi)[cnt]; + nhi = nlo >> 4; + nlo &= 0xf; + + rem = (size_t)Z.lo & 0xf; + Z.lo = (Z.hi << 60) | (Z.lo >> 4); + Z.hi = (Z.hi >> 4); + if (sizeof(size_t) == 8) + Z.hi ^= rem_4bit[rem]; + else + Z.hi ^= (u64)rem_4bit[rem] << 32; + + Z.hi ^= Htable[nlo].hi; + Z.lo ^= Htable[nlo].lo; + } + + if (is_endian.little) { + # ifdef BSWAP8 + Xi[0] = BSWAP8(Z.hi); + Xi[1] = BSWAP8(Z.lo); + # else + u8 *p = (u8 *)Xi; + u32 v; + v = (u32)(Z.hi >> 32); + PUTU32(p, v); + v = (u32)(Z.hi); + PUTU32(p + 4, v); + v = (u32)(Z.lo >> 32); + PUTU32(p + 8, v); + v = (u32)(Z.lo); + PUTU32(p + 12, v); + # endif + } else { + Xi[0] = Z.hi; + Xi[1] = Z.lo; + } +} + +# if !defined(OPENSSL_SMALL_FOOTPRINT) +/* + * Streamed gcm_mult_4bit, see CRYPTO_gcm128_[en|de]crypt for + * details... Compiler-generated code doesn't seem to give any + * performance improvement, at least not on x86[_64]. It's here + * mostly as reference and a placeholder for possible future + * non-trivial optimization[s]... + * / +static void gcm_ghash_4bit(u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) +{ + u128 Z; + int cnt; + size_t rem, nlo, nhi; + const union { + long one; + char little; + } is_endian = { 1 }; + +# if 1 + do { + cnt = 15; + nlo = ((const u8 *)Xi)[15]; + nlo ^= inp[15]; + nhi = nlo >> 4; + nlo &= 0xf; + + Z.hi = Htable[nlo].hi; + Z.lo = Htable[nlo].lo; + + while (1) { + rem = (size_t)Z.lo & 0xf; + Z.lo = (Z.hi << 60) | (Z.lo >> 4); + Z.hi = (Z.hi >> 4); + if (sizeof(size_t) == 8) + Z.hi ^= rem_4bit[rem]; + else + Z.hi ^= (u64)rem_4bit[rem] << 32; + + Z.hi ^= Htable[nhi].hi; + Z.lo ^= Htable[nhi].lo; + + if (--cnt < 0) + break; + + nlo = ((const u8 *)Xi)[cnt]; + nlo ^= inp[cnt]; + nhi = nlo >> 4; + nlo &= 0xf; + + rem = (size_t)Z.lo & 0xf; + Z.lo = (Z.hi << 60) | (Z.lo >> 4); + Z.hi = (Z.hi >> 4); + if (sizeof(size_t) == 8) + Z.hi ^= rem_4bit[rem]; + else + Z.hi ^= (u64)rem_4bit[rem] << 32; + + Z.hi ^= Htable[nlo].hi; + Z.lo ^= Htable[nlo].lo; + } + # else + /* + * Extra 256+16 bytes per-key plus 512 bytes shared tables + * [should] give ~50% improvement... One could have PACK()-ed + * the rem_8bit even here, but the priority is to minimize + * cache footprint... + * / + u128 Hshr4[16]; /* Htable shifted right by 4 bits * / + u8 Hshl4[16]; /* Htable shifted left by 4 bits * / + static const unsigned short rem_8bit[256] = { + 0x0000, 0x01C2, 0x0384, 0x0246, 0x0708, 0x06CA, 0x048C, 0x054E, + 0x0E10, 0x0FD2, 0x0D94, 0x0C56, 0x0918, 0x08DA, 0x0A9C, 0x0B5E, + 0x1C20, 0x1DE2, 0x1FA4, 0x1E66, 0x1B28, 0x1AEA, 0x18AC, 0x196E, + 0x1230, 0x13F2, 0x11B4, 0x1076, 0x1538, 0x14FA, 0x16BC, 0x177E, + 0x3840, 0x3982, 0x3BC4, 0x3A06, 0x3F48, 0x3E8A, 0x3CCC, 0x3D0E, + 0x3650, 0x3792, 0x35D4, 0x3416, 0x3158, 0x309A, 0x32DC, 0x331E, + 0x2460, 0x25A2, 0x27E4, 0x2626, 0x2368, 0x22AA, 0x20EC, 0x212E, + 0x2A70, 0x2BB2, 0x29F4, 0x2836, 0x2D78, 0x2CBA, 0x2EFC, 0x2F3E, + 0x7080, 0x7142, 0x7304, 0x72C6, 0x7788, 0x764A, 0x740C, 0x75CE, + 0x7E90, 0x7F52, 0x7D14, 0x7CD6, 0x7998, 0x785A, 0x7A1C, 0x7BDE, + 0x6CA0, 0x6D62, 0x6F24, 0x6EE6, 0x6BA8, 0x6A6A, 0x682C, 0x69EE, + 0x62B0, 0x6372, 0x6134, 0x60F6, 0x65B8, 0x647A, 0x663C, 0x67FE, + 0x48C0, 0x4902, 0x4B44, 0x4A86, 0x4FC8, 0x4E0A, 0x4C4C, 0x4D8E, + 0x46D0, 0x4712, 0x4554, 0x4496, 0x41D8, 0x401A, 0x425C, 0x439E, + 0x54E0, 0x5522, 0x5764, 0x56A6, 0x53E8, 0x522A, 0x506C, 0x51AE, + 0x5AF0, 0x5B32, 0x5974, 0x58B6, 0x5DF8, 0x5C3A, 0x5E7C, 0x5FBE, + 0xE100, 0xE0C2, 0xE284, 0xE346, 0xE608, 0xE7CA, 0xE58C, 0xE44E, + 0xEF10, 0xEED2, 0xEC94, 0xED56, 0xE818, 0xE9DA, 0xEB9C, 0xEA5E, + 0xFD20, 0xFCE2, 0xFEA4, 0xFF66, 0xFA28, 0xFBEA, 0xF9AC, 0xF86E, + 0xF330, 0xF2F2, 0xF0B4, 0xF176, 0xF438, 0xF5FA, 0xF7BC, 0xF67E, + 0xD940, 0xD882, 0xDAC4, 0xDB06, 0xDE48, 0xDF8A, 0xDDCC, 0xDC0E, + 0xD750, 0xD692, 0xD4D4, 0xD516, 0xD058, 0xD19A, 0xD3DC, 0xD21E, + 0xC560, 0xC4A2, 0xC6E4, 0xC726, 0xC268, 0xC3AA, 0xC1EC, 0xC02E, + 0xCB70, 0xCAB2, 0xC8F4, 0xC936, 0xCC78, 0xCDBA, 0xCFFC, 0xCE3E, + 0x9180, 0x9042, 0x9204, 0x93C6, 0x9688, 0x974A, 0x950C, 0x94CE, + 0x9F90, 0x9E52, 0x9C14, 0x9DD6, 0x9898, 0x995A, 0x9B1C, 0x9ADE, + 0x8DA0, 0x8C62, 0x8E24, 0x8FE6, 0x8AA8, 0x8B6A, 0x892C, 0x88EE, + 0x83B0, 0x8272, 0x8034, 0x81F6, 0x84B8, 0x857A, 0x873C, 0x86FE, + 0xA9C0, 0xA802, 0xAA44, 0xAB86, 0xAEC8, 0xAF0A, 0xAD4C, 0xAC8E, + 0xA7D0, 0xA612, 0xA454, 0xA596, 0xA0D8, 0xA11A, 0xA35C, 0xA29E, + 0xB5E0, 0xB422, 0xB664, 0xB7A6, 0xB2E8, 0xB32A, 0xB16C, 0xB0AE, + 0xBBF0, 0xBA32, 0xB874, 0xB9B6, 0xBCF8, 0xBD3A, 0xBF7C, 0xBEBE + }; + /* + * This pre-processing phase slows down procedure by approximately + * same time as it makes each loop spin faster. In other words + * single block performance is approximately same as straightforward + * "4-bit" implementation, and then it goes only faster... + * / + for (cnt = 0; cnt < 16; ++cnt) { + Z.hi = Htable[cnt].hi; + Z.lo = Htable[cnt].lo; + Hshr4[cnt].lo = (Z.hi << 60) | (Z.lo >> 4); + Hshr4[cnt].hi = (Z.hi >> 4); + Hshl4[cnt] = (u8)(Z.lo << 4); + } + + do { + for (Z.lo = 0, Z.hi = 0, cnt = 15; cnt; --cnt) { + nlo = ((const u8 *)Xi)[cnt]; + nlo ^= inp[cnt]; + nhi = nlo >> 4; + nlo &= 0xf; + + Z.hi ^= Htable[nlo].hi; + Z.lo ^= Htable[nlo].lo; + + rem = (size_t)Z.lo & 0xff; + + Z.lo = (Z.hi << 56) | (Z.lo >> 8); + Z.hi = (Z.hi >> 8); + + Z.hi ^= Hshr4[nhi].hi; + Z.lo ^= Hshr4[nhi].lo; + Z.hi ^= (u64)rem_8bit[rem ^ Hshl4[nhi]] << 48; + } + + nlo = ((const u8 *)Xi)[0]; + nlo ^= inp[0]; + nhi = nlo >> 4; + nlo &= 0xf; + + Z.hi ^= Htable[nlo].hi; + Z.lo ^= Htable[nlo].lo; + + rem = (size_t)Z.lo & 0xf; + + Z.lo = (Z.hi << 60) | (Z.lo >> 4); + Z.hi = (Z.hi >> 4); + + Z.hi ^= Htable[nhi].hi; + Z.lo ^= Htable[nhi].lo; + Z.hi ^= ((u64)rem_8bit[rem << 4]) << 48; + # endif + + if (is_endian.little) { + # ifdef BSWAP8 + Xi[0] = BSWAP8(Z.hi); + Xi[1] = BSWAP8(Z.lo); + # else + u8 *p = (u8 *)Xi; + u32 v; + v = (u32)(Z.hi >> 32); + PUTU32(p, v); + v = (u32)(Z.hi); + PUTU32(p + 4, v); + v = (u32)(Z.lo >> 32); + PUTU32(p + 8, v); + v = (u32)(Z.lo); + PUTU32(p + 12, v); + # endif + } else { + Xi[0] = Z.hi; + Xi[1] = Z.lo; + } + } while (inp += 16, len -= 16); +} +# endif +# else +void gcm_gmult_4bit(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_4bit(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# endif + +# define GCM_MUL(ctx,Xi) gcm_gmult_4bit(ctx->Xi.u,ctx->Htable) +# if defined(GHASH_ASM) || !defined(OPENSSL_SMALL_FOOTPRINT) +# define GHASH(ctx,in,len) gcm_ghash_4bit((ctx)->Xi.u,(ctx)->Htable,in,len) +/* PCL UNUSED END */ +/* + * GHASH_CHUNK is "stride parameter" missioned to mitigate cache trashing + * effect. In other words idea is to hash data while it's still in L1 cache + * after encryption pass... + */ +# define GHASH_CHUNK (3*1024) +/* PCL UNUSED START * +# endif + +#else /* TABLE_BITS * / + +static void gcm_gmult_1bit(u64 Xi[2], const u64 H[2]) +{ + u128 V, Z = { 0, 0 }; + long X; + int i, j; + const long *xi = (const long *)Xi; + const union { + long one; + char little; + } is_endian = { 1 }; + + V.hi = H[0]; /* H is in host byte order, no byte swapping * / + V.lo = H[1]; + + for (j = 0; j < 16 / sizeof(long); ++j) { + if (is_endian.little) { + if (sizeof(long) == 8) { +# ifdef BSWAP8 + X = (long)(BSWAP8(xi[j])); +# else + const u8 *p = (const u8 *)(xi + j); + X = (long)((u64)GETU32(p) << 32 | GETU32(p + 4)); +# endif + } else { + const u8 *p = (const u8 *)(xi + j); + X = (long)GETU32(p); + } + } else + X = xi[j]; + + for (i = 0; i < 8 * sizeof(long); ++i, X <<= 1) { + u64 M = (u64)(X >> (8 * sizeof(long) - 1)); + Z.hi ^= V.hi & M; + Z.lo ^= V.lo & M; + + REDUCE1BIT(V); + } + } + + if (is_endian.little) { +# ifdef BSWAP8 + Xi[0] = BSWAP8(Z.hi); + Xi[1] = BSWAP8(Z.lo); +# else + u8 *p = (u8 *)Xi; + u32 v; + v = (u32)(Z.hi >> 32); + PUTU32(p, v); + v = (u32)(Z.hi); + PUTU32(p + 4, v); + v = (u32)(Z.lo >> 32); + PUTU32(p + 8, v); + v = (u32)(Z.lo); + PUTU32(p + 12, v); +# endif + } else { + Xi[0] = Z.hi; + Xi[1] = Z.lo; + } +} + +# define GCM_MUL(ctx,Xi) gcm_gmult_1bit(ctx->Xi.u,ctx->H.u) + +#endif + +#if TABLE_BITS==4 && (defined(GHASH_ASM) || defined(OPENSSL_CPUID_OBJ)) +# if !defined(I386_ONLY) && \ + (defined(__i386) || defined(__i386__) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) +# define GHASH_ASM_X86_OR_64 +# define GCM_FUNCREF_4BIT +extern unsigned int OPENSSL_ia32cap_P[]; + +void gcm_init_clmul(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_clmul(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_clmul(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); + +# if defined(__i386) || defined(__i386__) || defined(_M_IX86) +# define gcm_init_avx gcm_init_clmul +# define gcm_gmult_avx gcm_gmult_clmul +# define gcm_ghash_avx gcm_ghash_clmul +# else +void gcm_init_avx(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_avx(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_avx(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# endif + +# if defined(__i386) || defined(__i386__) || defined(_M_IX86) +# define GHASH_ASM_X86 +void gcm_gmult_4bit_mmx(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_4bit_mmx(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); + +void gcm_gmult_4bit_x86(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_4bit_x86(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# endif +# elif defined(__arm__) || defined(__arm) || defined(__aarch64__) +# include "arm_arch.h" +# if __ARM_MAX_ARCH__>=7 +# define GHASH_ASM_ARM +# define GCM_FUNCREF_4BIT +# define PMULL_CAPABLE (OPENSSL_armcap_P & ARMV8_PMULL) +# if defined(__arm__) || defined(__arm) +# define NEON_CAPABLE (OPENSSL_armcap_P & ARMV7_NEON) +# endif +void gcm_init_neon(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_neon(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_neon(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +void gcm_init_v8(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_v8(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_v8(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# endif +# elif defined(__sparc__) || defined(__sparc) +# include "sparc_arch.h" +# define GHASH_ASM_SPARC +# define GCM_FUNCREF_4BIT +extern unsigned int OPENSSL_sparcv9cap_P[]; +void gcm_init_vis3(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_vis3(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_vis3(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# elif defined(OPENSSL_CPUID_OBJ) && (defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC)) +# include "ppc_arch.h" +# define GHASH_ASM_PPC +# define GCM_FUNCREF_4BIT +void gcm_init_p8(u128 Htable[16], const u64 Xi[2]); +void gcm_gmult_p8(u64 Xi[2], const u128 Htable[16]); +void gcm_ghash_p8(u64 Xi[2], const u128 Htable[16], const u8 *inp, + size_t len); +# endif +#endif + +#ifdef GCM_FUNCREF_4BIT +# undef GCM_MUL +# define GCM_MUL(ctx,Xi) (*gcm_gmult_p)(ctx->Xi.u,ctx->Htable) +# ifdef GHASH +# undef GHASH +/* PCL UNUSED END */ +extern "C" void pcl_gcm_init_clmul(u128 Htable[16], u64 H[2]); +extern "C" void pcl_gcm_gmult_clmul(u64 Xi[2], const u128 Htable[16]); +extern "C" void pcl_gcm_ghash_clmul(u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len); +# define GCM_MUL(ctx,Xi) pcl_gcm_gmult_clmul(ctx->Xi.u,ctx->Htable) +# define GHASH(ctx,in,len) (*gcm_ghash_p)(ctx->Xi.u,ctx->Htable,in,len) +/* PCL UNUSED START * +# endif +#endif +/* PCL UNUSED END */ +void pcl_CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block) +{ +/* PCL UNUSED START * + const union { + long one; + char little; + } is_endian = { 1 }; +/* PCL UNUSED END */ + + pcl_memset(ctx, 0, sizeof(*ctx)); + ctx->block = block; + ctx->key = key; + + (*block) (ctx->H.c, ctx->H.c, key); +/* PCL UNUSED START * + if (is_endian.little) { + /* H is stored in host byte order * + #ifdef BSWAP8 +/* PCL UNUSED END */ + ctx->H.u[0] = BSWAP8(ctx->H.u[0]); + ctx->H.u[1] = BSWAP8(ctx->H.u[1]); +/* PCL UNUSED START * + #else + u8 *p = ctx->H.c; + u64 hi, lo; + hi = (u64)GETU32(p) << 32 | GETU32(p + 4); + lo = (u64)GETU32(p + 8) << 32 | GETU32(p + 12); + ctx->H.u[0] = hi; + ctx->H.u[1] = lo; + #endif + } + #if TABLE_BITS==8 + gcm_init_8bit(ctx->Htable, ctx->H.u); + #elif TABLE_BITS==4 + # if defined(GHASH) + # define CTX__GHASH(f) (ctx->ghash = (f)) + # else + # define CTX__GHASH(f) (ctx->ghash = NULL) + # endif + # if defined(GHASH_ASM_X86_OR_64) + # if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2) + if (OPENSSL_ia32cap_P[0] & (1 << 24) && // check FXSR bit + OPENSSL_ia32cap_P[1] & (1 << 1)) { // check PCLMULQDQ bit + if (((OPENSSL_ia32cap_P[1] >> 22) & 0x41) == 0x41) { // AVX+MOVBE + + gcm_init_avx(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_avx; + CTX__GHASH(gcm_ghash_avx); + } else { +/* PCL UNUSED END */ + pcl_gcm_init_clmul(ctx->Htable, ctx->H.u); + ctx->gmult = pcl_gcm_gmult_clmul; + ctx->ghash = pcl_gcm_ghash_clmul; +/* PCL UNUSED START * + CTX__GHASH(gcm_ghash_clmul); + } +/* PCL UNUSED END */ + return; +/* PCL UNUSED START * + } + # endif + pcl_gcm_init_4bit(ctx->Htable, ctx->H.u); + # if defined(GHASH_ASM_X86) // x86 only + # if defined(OPENSSL_IA32_SSE2) + if (OPENSSL_ia32cap_P[0] & (1 << 25)) { // check SSE bit + # else + if (OPENSSL_ia32cap_P[0] & (1 << 23)) { // check MMX bit + # endif + ctx->gmult = gcm_gmult_4bit_mmx; + CTX__GHASH(gcm_ghash_4bit_mmx); + } else { + ctx->gmult = gcm_gmult_4bit_x86; + CTX__GHASH(gcm_ghash_4bit_x86); + } + # else + ctx->gmult = pcl_gcm_gmult_4bit; + CTX__GHASH(pcl_gcm_ghash_4bit); + ctx->ghash = pcl_gcm_ghash_4bit; + # endif + # elif defined(GHASH_ASM_ARM) + # ifdef PMULL_CAPABLE + if (PMULL_CAPABLE) { + gcm_init_v8(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_v8; + CTX__GHASH(gcm_ghash_v8); + } else + # endif + # ifdef NEON_CAPABLE + if (NEON_CAPABLE) { + gcm_init_neon(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_neon; + CTX__GHASH(gcm_ghash_neon); + } else + # endif + { + gcm_init_4bit(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_4bit; + CTX__GHASH(gcm_ghash_4bit); + } + # elif defined(GHASH_ASM_SPARC) + if (OPENSSL_sparcv9cap_P[0] & SPARCV9_VIS3) { + gcm_init_vis3(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_vis3; + CTX__GHASH(gcm_ghash_vis3); + } else { + gcm_init_4bit(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_4bit; + CTX__GHASH(gcm_ghash_4bit); + } + # elif defined(GHASH_ASM_PPC) + if (OPENSSL_ppccap_P & PPC_CRYPTO207) { + gcm_init_p8(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_p8; + CTX__GHASH(gcm_ghash_p8); + } else { + gcm_init_4bit(ctx->Htable, ctx->H.u); + ctx->gmult = gcm_gmult_4bit; + CTX__GHASH(gcm_ghash_4bit); + } + # else + gcm_init_4bit(ctx->Htable, ctx->H.u); + # endif + # undef CTX__GHASH + #endif +/* PCL UNUSED END */ +} + +void pcl_CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv, + size_t len) +{ +/* PCL UNUSED START * + const union { + long one; + char little; + } is_endian = { 1 }; +/* PCL UNUSED END */ + unsigned int ctr; +/* PCL UNUSED START * + #ifdef GCM_FUNCREF_4BIT +/* PCL UNUSED END */ + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +/* PCL UNUSED START * + #endif +/* PCL UNUSED END */ + + ctx->Yi.u[0] = 0; + ctx->Yi.u[1] = 0; + ctx->Xi.u[0] = 0; + ctx->Xi.u[1] = 0; + ctx->len.u[0] = 0; /* AAD length */ + ctx->len.u[1] = 0; /* message length */ + ctx->ares = 0; + ctx->mres = 0; +/* PCL UNUSED START * + if (len == 12) { +/* PCL UNUSED END */ + pcl_memcpy(ctx->Yi.c, (void*)iv, 12); + ctx->Yi.c[15] = 1; + ctr = 1; +/* PCL UNUSED START * + } else { + size_t i; + u64 len0 = len; + + while (len >= 16) { + for (i = 0; i < 16; ++i) + ctx->Yi.c[i] ^= iv[i]; + GCM_MUL(ctx, Yi); + iv += 16; + len -= 16; + } + if (len) { + for (i = 0; i < len; ++i) + ctx->Yi.c[i] ^= iv[i]; + GCM_MUL(ctx, Yi); + } + len0 <<= 3; + if (is_endian.little) { + #ifdef BSWAP8 + ctx->Yi.u[1] ^= BSWAP8(len0); + #else + ctx->Yi.c[8] ^= (u8)(len0 >> 56); + ctx->Yi.c[9] ^= (u8)(len0 >> 48); + ctx->Yi.c[10] ^= (u8)(len0 >> 40); + ctx->Yi.c[11] ^= (u8)(len0 >> 32); + ctx->Yi.c[12] ^= (u8)(len0 >> 24); + ctx->Yi.c[13] ^= (u8)(len0 >> 16); + ctx->Yi.c[14] ^= (u8)(len0 >> 8); + ctx->Yi.c[15] ^= (u8)(len0); + #endif + } else + ctx->Yi.u[1] ^= len0; + + GCM_MUL(ctx, Yi); + + if (is_endian.little) + #ifdef BSWAP4 + ctr = BSWAP4(ctx->Yi.d[3]); + #else + ctr = GETU32(ctx->Yi.c + 12); + #endif + else + ctr = ctx->Yi.d[3]; + } +/* PCL UNUSED END */ + + (*ctx->block) (ctx->Yi.c, ctx->EK0.c, ctx->key); + ++ctr; +/* PCL UNUSED START * + if (is_endian.little) + #ifdef BSWAP4 +/* PCL UNUSED END */ + ctx->Yi.d[3] = pcl_bswap32(ctr); +/* PCL UNUSED START * + #else + PUTU32(ctx->Yi.c + 12, ctr); + #endif + else + ctx->Yi.d[3] = ctr; +/* PCL UNUSED END */ +} + +int pcl_CRYPTO_gcm128_aad( + GCM128_CONTEXT *ctx, + const unsigned char *aad, + size_t len) +{ + size_t i; + unsigned int n; + u64 alen = ctx->len.u[0]; +/* PCL UNUSED START * + #ifdef GCM_FUNCREF_4BIT +/* PCL UNUSED END */ + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +/* PCL UNUSED START * + # ifdef GHASH +/* PCL UNUSED END */ + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx->ghash; +/* PCL UNUSED START * + # endif + #endif +/* PCL UNUSED END */ + + if (ctx->len.u[1]) + return -2; + + alen += len; + if (alen > (U64(1) << 61) || (sizeof(len) == 8 && alen < len)) + return -1; + ctx->len.u[0] = alen; + + n = ctx->ares; + if (n) { + while (n && len) { + ctx->Xi.c[n] ^= *(aad++); + --len; + n = (n + 1) % 16; + } + if (n == 0) + GCM_MUL(ctx, Xi); + else { + ctx->ares = n; + return 0; + } + } +/* PCL UNUSED START * + #ifdef GHASH +/* PCL UNUSED END */ + if ((i = (len & (size_t)-16))) { + GHASH(ctx, aad, i); + aad += i; + len -= i; + } +/* PCL UNUSED START * + #else + while (len >= 16) { + for (i = 0; i < 16; ++i) + ctx->Xi.c[i] ^= aad[i]; + GCM_MUL(ctx, Xi); + aad += 16; + len -= 16; + } + #endif +/* PCL UNUSED END */ + if (len) { + n = (unsigned int)len; + for (i = 0; i < len; ++i) + ctx->Xi.c[i] ^= aad[i]; + } + + ctx->ares = n; + return 0; +} + +/* PCL UNUSED START * +int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len) +{ + const union { + long one; + char little; + } is_endian = { 1 }; + unsigned int n, ctr; + size_t i; + u64 mlen = ctx->len.u[1]; + block128_f block = ctx->block; + void *key = ctx->key; +#ifdef GCM_FUNCREF_4BIT + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +# if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT) + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx->ghash; +# endif +#endif + + mlen += len; + if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) + return -1; + ctx->len.u[1] = mlen; + + if (ctx->ares) { + /* First call to encrypt finalizes GHASH(AAD) * / + GCM_MUL(ctx, Xi); + ctx->ares = 0; + } + + if (is_endian.little) +#ifdef BSWAP4 + ctr = BSWAP4(ctx->Yi.d[3]); +#else + ctr = GETU32(ctx->Yi.c + 12); +#endif + else + ctr = ctx->Yi.d[3]; + + n = ctx->mres; +#if !defined(OPENSSL_SMALL_FOOTPRINT) + if (16 % sizeof(size_t) == 0) { /* always true actually * / + do { + if (n) { + while (n && len) { + ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n]; + --len; + n = (n + 1) % 16; + } + if (n == 0) + GCM_MUL(ctx, Xi); + else { + ctx->mres = n; + return 0; + } + } +# if defined(STRICT_ALIGNMENT) + if (((size_t)in | (size_t)out) % sizeof(size_t) != 0) + break; +# endif +# if defined(GHASH) +# if defined(GHASH_CHUNK) + while (len >= GHASH_CHUNK) { + size_t j = GHASH_CHUNK; + + while (j) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + for (i = 0; i < 16 / sizeof(size_t); ++i) + out_t[i] = in_t[i] ^ ctx->EKi.t[i]; + out += 16; + in += 16; + j -= 16; + } + GHASH(ctx, out - GHASH_CHUNK, GHASH_CHUNK); + len -= GHASH_CHUNK; + } +# endif + if ((i = (len & (size_t)-16))) { + size_t j = i; + + while (len >= 16) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + for (i = 0; i < 16 / sizeof(size_t); ++i) + out_t[i] = in_t[i] ^ ctx->EKi.t[i]; + out += 16; + in += 16; + len -= 16; + } + GHASH(ctx, out - j, j); + } +# else + while (len >= 16) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + for (i = 0; i < 16 / sizeof(size_t); ++i) + ctx->Xi.t[i] ^= out_t[i] = in_t[i] ^ ctx->EKi.t[i]; + GCM_MUL(ctx, Xi); + out += 16; + in += 16; + len -= 16; + } +# endif + if (len) { + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + while (len--) { + ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n]; + ++n; + } + } + + ctx->mres = n; + return 0; + } while (0); + } +#endif + for (i = 0; i < len; ++i) { + if (n == 0) { + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +#ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +#else + PUTU32(ctx->Yi.c + 12, ctr); +#endif + else + ctx->Yi.d[3] = ctr; + } + ctx->Xi.c[n] ^= out[i] = in[i] ^ ctx->EKi.c[n]; + n = (n + 1) % 16; + if (n == 0) + GCM_MUL(ctx, Xi); + } + + ctx->mres = n; + return 0; +} +/* PCL UNUSED END */ + +int pcl_CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len) +{ +/* PCL UNUSED START * + const union { + long one; + char little; + } is_endian = { 1 }; +/* PCL UNUSED END */ + unsigned int n, ctr; + size_t i; + u64 mlen = ctx->len.u[1]; + block128_f block = ctx->block; + void *key = ctx->key; +/* PCL UNUSED START * +#ifdef GCM_FUNCREF_4BIT +/* PCL UNUSED END */ + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +/* PCL UNUSED START * +# if defined(GHASH) && !defined(OPENSSL_SMALL_FOOTPRINT) +/* PCL UNUSED END */ + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx->ghash; +/* PCL UNUSED START * +# endif +#endif +/* PCL UNUSED END */ + mlen += len; + if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) + return -1; + ctx->len.u[1] = mlen; + + if (ctx->ares) { + /* First call to decrypt finalizes GHASH(AAD) */ + GCM_MUL(ctx, Xi); + ctx->ares = 0; + } +/* PCL UNUSED START * + if (is_endian.little) +#ifdef BSWAP4 +/* PCL UNUSED END */ + ctr = pcl_bswap32(ctx->Yi.d[3]); +/* PCL UNUSED START * +#else + ctr = GETU32(ctx->Yi.c + 12); +#endif + else + ctr = ctx->Yi.d[3]; +/* PCL UNUSED END */ + n = ctx->mres; +/* PCL UNUSED START * +#if !defined(OPENSSL_SMALL_FOOTPRINT) + if (16 % sizeof(size_t) == 0) { /* always true actually * / + do { +/* PCL UNUSED END */ + if (n) { + while (n && len) { + u8 c = *(in++); + *(out++) = c ^ ctx->EKi.c[n]; + ctx->Xi.c[n] ^= c; + --len; + n = (n + 1) % 16; + } + if (n == 0) + GCM_MUL(ctx, Xi); + else { + ctx->mres = n; + return 0; + } + } +/* PCL UNUSED START * +# if defined(STRICT_ALIGNMENT) + if (((size_t)in | (size_t)out) % sizeof(size_t) != 0) + break; +# endif + +# if defined(GHASH) +# if defined(GHASH_CHUNK) +/* PCL UNUSED END */ + while (len >= GHASH_CHUNK) { + size_t j = GHASH_CHUNK; + + GHASH(ctx, in, GHASH_CHUNK); + while (j) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; +/* PCL UNUSED START * + if (is_endian.little) + +# ifdef BSWAP4 +/* PCL UNUSED END */ + ctx->Yi.d[3] = pcl_bswap32(ctr); +/* PCL UNUSED START * +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; +/* PCL UNUSED END */ + for (i = 0; i < 16 / sizeof(size_t); ++i) + out_t[i] = in_t[i] ^ ctx->EKi.t[i]; + out += 16; + in += 16; + j -= 16; + } + len -= GHASH_CHUNK; + } +/* PCL UNUSED START * +# endif +/* PCL UNUSED END */ + if ((i = (len & (size_t)-16))) { + GHASH(ctx, in, i); + while (len >= 16) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; +/* PCL UNUSED START * + if (is_endian.little) +# ifdef BSWAP4 +/* PCL UNUSED END */ + ctx->Yi.d[3] = pcl_bswap32(ctr); +/* PCL UNUSED START * +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; +/* PCL UNUSED END */ + for (i = 0; i < 16 / sizeof(size_t); ++i) + out_t[i] = in_t[i] ^ ctx->EKi.t[i]; + out += 16; + in += 16; + len -= 16; + } + } +/* PCL UNUSED START * +# else + while (len >= 16) { + size_t *out_t = (size_t *)out; + const size_t *in_t = (const size_t *)in; + + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + for (i = 0; i < 16 / sizeof(size_t); ++i) { + size_t c = in[i]; + out[i] = c ^ ctx->EKi.t[i]; + ctx->Xi.t[i] ^= c; + } + GCM_MUL(ctx, Xi); + out += 16; + in += 16; + len -= 16; + } +# endif +/* PCL UNUSED END */ + if (len) { + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; +/* PCL UNUSED START * + if (is_endian.little) +# ifdef BSWAP4 +/* PCL UNUSED END */ + ctx->Yi.d[3] = pcl_bswap32(ctr); +/* PCL UNUSED START * +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; +/* PCL UNUSED END */ + while (len--) { + u8 c = in[n]; + ctx->Xi.c[n] ^= c; + out[n] = c ^ ctx->EKi.c[n]; + ++n; + } + } + + ctx->mres = n; + return 0; +/* PCL UNUSED START * + } while (0); + } +#endif + for (i = 0; i < len; ++i) { + u8 c; + if (n == 0) { + (*block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +#ifdef BSWAP4 + ctx->Yi.d[3] = pcl_bswap32(ctr); +#else + PUTU32(ctx->Yi.c + 12, ctr); +#endif + else + ctx->Yi.d[3] = ctr; + } + c = in[i]; + out[i] = c ^ ctx->EKi.c[n]; + ctx->Xi.c[n] ^= c; + n = (n + 1) % 16; + if (n == 0) + GCM_MUL(ctx, Xi); + } + + ctx->mres = n; + return 0; +/* PCL UNUSED END */ +} + +/* PCL UNUSED START * +int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream) +{ +#if defined(OPENSSL_SMALL_FOOTPRINT) + return CRYPTO_gcm128_encrypt(ctx, in, out, len); +#else + const union { + long one; + char little; + } is_endian = { 1 }; + unsigned int n, ctr; + size_t i; + u64 mlen = ctx->len.u[1]; + void *key = ctx->key; +# ifdef GCM_FUNCREF_4BIT + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +# ifdef GHASH + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx->ghash; +# endif +# endif + + mlen += len; + if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) + return -1; + ctx->len.u[1] = mlen; + + if (ctx->ares) { + /* First call to encrypt finalizes GHASH(AAD) * / + GCM_MUL(ctx, Xi); + ctx->ares = 0; + } + + if (is_endian.little) +# ifdef BSWAP4 + ctr = BSWAP4(ctx->Yi.d[3]); +# else + ctr = GETU32(ctx->Yi.c + 12); +# endif + else + ctr = ctx->Yi.d[3]; + + n = ctx->mres; + if (n) { + while (n && len) { + ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n]; + --len; + n = (n + 1) % 16; + } + if (n == 0) + GCM_MUL(ctx, Xi); + else { + ctx->mres = n; + return 0; + } + } +# if defined(GHASH) && defined(GHASH_CHUNK) + while (len >= GHASH_CHUNK) { + (*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c); + ctr += GHASH_CHUNK / 16; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + GHASH(ctx, out, GHASH_CHUNK); + out += GHASH_CHUNK; + in += GHASH_CHUNK; + len -= GHASH_CHUNK; + } +# endif + if ((i = (len & (size_t)-16))) { + size_t j = i / 16; + + (*stream) (in, out, j, key, ctx->Yi.c); + ctr += (unsigned int)j; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + in += i; + len -= i; +# if defined(GHASH) + GHASH(ctx, out, i); + out += i; +# else + while (j--) { + for (i = 0; i < 16; ++i) + ctx->Xi.c[i] ^= out[i]; + GCM_MUL(ctx, Xi); + out += 16; + } +# endif + } + if (len) { + (*ctx->block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + while (len--) { + ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n]; + ++n; + } + } + + ctx->mres = n; + return 0; +#endif +} + +int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream) +{ +#if defined(OPENSSL_SMALL_FOOTPRINT) + return CRYPTO_gcm128_decrypt(ctx, in, out, len); +#else + const union { + long one; + char little; + } is_endian = { 1 }; + unsigned int n, ctr; + size_t i; + u64 mlen = ctx->len.u[1]; + void *key = ctx->key; +# ifdef GCM_FUNCREF_4BIT + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +# ifdef GHASH + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx->ghash; +# endif +# endif + + mlen += len; + if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) + return -1; + ctx->len.u[1] = mlen; + + if (ctx->ares) { + /* First call to decrypt finalizes GHASH(AAD) * / + GCM_MUL(ctx, Xi); + ctx->ares = 0; + } + + if (is_endian.little) +# ifdef BSWAP4 + ctr = BSWAP4(ctx->Yi.d[3]); +# else + ctr = GETU32(ctx->Yi.c + 12); +# endif + else + ctr = ctx->Yi.d[3]; + + n = ctx->mres; + if (n) { + while (n && len) { + u8 c = *(in++); + *(out++) = c ^ ctx->EKi.c[n]; + ctx->Xi.c[n] ^= c; + --len; + n = (n + 1) % 16; + } + if (n == 0) + GCM_MUL(ctx, Xi); + else { + ctx->mres = n; + return 0; + } + } +# if defined(GHASH) && defined(GHASH_CHUNK) + while (len >= GHASH_CHUNK) { + GHASH(ctx, in, GHASH_CHUNK); + (*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c); + ctr += GHASH_CHUNK / 16; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + out += GHASH_CHUNK; + in += GHASH_CHUNK; + len -= GHASH_CHUNK; + } +# endif + if ((i = (len & (size_t)-16))) { + size_t j = i / 16; + +# if defined(GHASH) + GHASH(ctx, in, i); +# else + while (j--) { + size_t k; + for (k = 0; k < 16; ++k) + ctx->Xi.c[k] ^= in[k]; + GCM_MUL(ctx, Xi); + in += 16; + } + j = i / 16; + in -= i; +# endif + (*stream) (in, out, j, key, ctx->Yi.c); + ctr += (unsigned int)j; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + out += i; + in += i; + len -= i; + } + if (len) { + (*ctx->block) (ctx->Yi.c, ctx->EKi.c, key); + ++ctr; + if (is_endian.little) +# ifdef BSWAP4 + ctx->Yi.d[3] = BSWAP4(ctr); +# else + PUTU32(ctx->Yi.c + 12, ctr); +# endif + else + ctx->Yi.d[3] = ctr; + while (len--) { + u8 c = in[n]; + ctx->Xi.c[n] ^= c; + out[n] = c ^ ctx->EKi.c[n]; + ++n; + } + } + + ctx->mres = n; + return 0; +#endif +} +/* PCL UNUSED END */ + +int pcl_CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag, + size_t len) +{ +/* PCL UNUSED START * + const union { + long one; + char little; + } is_endian = { 1 }; +/* PCL UNUSED END */ + u64 alen = ctx->len.u[0] << 3; + u64 clen = ctx->len.u[1] << 3; +/* PCL UNUSED START * + #ifdef GCM_FUNCREF_4BIT +/* PCL UNUSED END */ + void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult; +/* PCL UNUSED START * + #endif +/* PCL UNUSED END */ + + if (ctx->mres || ctx->ares) + GCM_MUL(ctx, Xi); +/* PCL UNUSED START * + if (is_endian.little) { + #ifdef BSWAP8 +/* PCL UNUSED END */ + alen = BSWAP8(alen); + clen = BSWAP8(clen); +/* PCL UNUSED START * + #else + u8 *p = ctx->len.c; + + ctx->len.u[0] = alen; + ctx->len.u[1] = clen; + + alen = (u64)GETU32(p) << 32 | GETU32(p + 4); + clen = (u64)GETU32(p + 8) << 32 | GETU32(p + 12); + #endif + } +/* PCL UNUSED END */ + + ctx->Xi.u[0] ^= alen; + ctx->Xi.u[1] ^= clen; + GCM_MUL(ctx, Xi); + + ctx->Xi.u[0] ^= ctx->EK0.u[0]; + ctx->Xi.u[1] ^= ctx->EK0.u[1]; + + if (tag && len <= sizeof(ctx->Xi)) + return !pcl_consttime_memequal(ctx->Xi.c, (void*)tag, len); + else + return -1; +} + +/* PCL UNUSED START * +void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len) +{ + CRYPTO_gcm128_finish(ctx, NULL, 0); + memcpy(tag, ctx->Xi.c, + len <= sizeof(ctx->Xi.c) ? len : sizeof(ctx->Xi.c)); +} + +GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block) +{ + GCM128_CONTEXT *ret; + + if ((ret = OPENSSL_malloc(sizeof(*ret))) != NULL) + CRYPTO_gcm128_init(ret, key, block); + + return ret; +} + +void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx) +{ + OPENSSL_clear_free(ctx, sizeof(*ctx)); +} + +#if defined(SELFTEST) +# include +# include + +/* Test Case 1 * / +static const u8 K1[16], *P1 = NULL, *A1 = NULL, IV1[12], *C1 = NULL; +static const u8 T1[] = { + 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, + 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a +}; + +/* Test Case 2 * / +# define K2 K1 +# define A2 A1 +# define IV2 IV1 +static const u8 P2[16]; +static const u8 C2[] = { + 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, + 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 +}; + +static const u8 T2[] = { + 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd, + 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf +}; + +/* Test Case 3 * / +# define A3 A2 +static const u8 K3[] = { + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 +}; + +static const u8 P3[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 +}; + +static const u8 IV3[] = { + 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, + 0xde, 0xca, 0xf8, 0x88 +}; + +static const u8 C3[] = { + 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, + 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, + 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, + 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, + 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, + 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, + 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, + 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85 +}; + +static const u8 T3[] = { + 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, + 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 +}; + +/* Test Case 4 * / +# define K4 K3 +# define IV4 IV3 +static const u8 P4[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39 +}; + +static const u8 A4[] = { + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xab, 0xad, 0xda, 0xd2 +}; + +static const u8 C4[] = { + 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, + 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, + 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, + 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, + 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, + 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, + 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, + 0x3d, 0x58, 0xe0, 0x91 +}; + +static const u8 T4[] = { + 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, + 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 +}; + +/* Test Case 5 * / +# define K5 K4 +# define P5 P4 +# define A5 A4 +static const u8 IV5[] = { + 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad +}; + +static const u8 C5[] = { + 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, + 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, + 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, + 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, + 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, + 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, + 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, + 0xc2, 0x3f, 0x45, 0x98 +}; + +static const u8 T5[] = { + 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, + 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb +}; + +/* Test Case 6 * / +# define K6 K5 +# define P6 P5 +# define A6 A5 +static const u8 IV6[] = { + 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, + 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, + 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, + 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, + 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, + 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, + 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, + 0xa6, 0x37, 0xb3, 0x9b +}; + +static const u8 C6[] = { + 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, + 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, + 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, + 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, + 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, + 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, + 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, + 0x4c, 0x34, 0xae, 0xe5 +}; + +static const u8 T6[] = { + 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, + 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 +}; + +/* Test Case 7 * / +static const u8 K7[24], *P7 = NULL, *A7 = NULL, IV7[12], *C7 = NULL; +static const u8 T7[] = { + 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b, + 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 +}; + +/* Test Case 8 * / +# define K8 K7 +# define IV8 IV7 +# define A8 A7 +static const u8 P8[16]; +static const u8 C8[] = { + 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, + 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 +}; + +static const u8 T8[] = { + 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab, + 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb +}; + +/* Test Case 9 * / +# define A9 A8 +static const u8 K9[] = { + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c +}; + +static const u8 P9[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 +}; + +static const u8 IV9[] = { + 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, + 0xde, 0xca, 0xf8, 0x88 +}; + +static const u8 C9[] = { + 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, + 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, + 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, + 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, + 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, + 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, + 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, + 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56 +}; + +static const u8 T9[] = { + 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf, + 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 +}; + +/* Test Case 10 * / +# define K10 K9 +# define IV10 IV9 +static const u8 P10[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39 +}; + +static const u8 A10[] = { + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xab, 0xad, 0xda, 0xd2 +}; + +static const u8 C10[] = { + 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, + 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, + 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, + 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, + 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, + 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, + 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, + 0xcc, 0xda, 0x27, 0x10 +}; + +static const u8 T10[] = { + 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f, + 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c +}; + +/* Test Case 11 * / +# define K11 K10 +# define P11 P10 +# define A11 A10 +static const u8 IV11[] = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad }; + +static const u8 C11[] = { + 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54, + 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8, + 0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f, + 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57, + 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75, + 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9, + 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f, + 0xa0, 0xf0, 0x62, 0xf7 +}; + +static const u8 T11[] = { + 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24, + 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8 +}; + +/* Test Case 12 * / +# define K12 K11 +# define P12 P11 +# define A12 A11 +static const u8 IV12[] = { + 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, + 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, + 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, + 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, + 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, + 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, + 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, + 0xa6, 0x37, 0xb3, 0x9b +}; + +static const u8 C12[] = { + 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c, + 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff, + 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef, + 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45, + 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9, + 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3, + 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7, + 0xe9, 0xb7, 0x37, 0x3b +}; + +static const u8 T12[] = { + 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb, + 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9 +}; + +/* Test Case 13 * / +static const u8 K13[32], *P13 = NULL, *A13 = NULL, IV13[12], *C13 = NULL; +static const u8 T13[] = { + 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9, + 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b +}; + +/* Test Case 14 * / +# define K14 K13 +# define A14 A13 +static const u8 P14[16], IV14[12]; +static const u8 C14[] = { + 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, + 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18 +}; + +static const u8 T14[] = { + 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, + 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 +}; + +/* Test Case 15 * / +# define A15 A14 +static const u8 K15[] = { + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 +}; + +static const u8 P15[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 +}; + +static const u8 IV15[] = { + 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, + 0xde, 0xca, 0xf8, 0x88 +}; + +static const u8 C15[] = { + 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, + 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, + 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, + 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, + 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, + 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, + 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, + 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad +}; + +static const u8 T15[] = { + 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd, + 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c +}; + +/* Test Case 16 * / +# define K16 K15 +# define IV16 IV15 +static const u8 P16[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39 +}; + +static const u8 A16[] = { + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, + 0xab, 0xad, 0xda, 0xd2 +}; + +static const u8 C16[] = { + 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, + 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, + 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, + 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, + 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, + 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, + 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, + 0xbc, 0xc9, 0xf6, 0x62 +}; + +static const u8 T16[] = { + 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, + 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b +}; + +/* Test Case 17 * / +# define K17 K16 +# define P17 P16 +# define A17 A16 +static const u8 IV17[] = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad }; + +static const u8 C17[] = { + 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, + 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb, + 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa, + 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, + 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0, + 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78, + 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, + 0xf4, 0x7c, 0x9b, 0x1f +}; + +static const u8 T17[] = { + 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, + 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 +}; + +/* Test Case 18 * / +# define K18 K17 +# define P18 P17 +# define A18 A17 +static const u8 IV18[] = { + 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, + 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, + 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, + 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, + 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, + 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, + 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, + 0xa6, 0x37, 0xb3, 0x9b +}; + +static const u8 C18[] = { + 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1, + 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20, + 0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19, + 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4, + 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45, + 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde, + 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e, + 0x44, 0xae, 0x7e, 0x3f +}; + +static const u8 T18[] = { + 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0, + 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a +}; + +/* Test Case 19 * / +# define K19 K1 +# define P19 P1 +# define IV19 IV1 +# define C19 C1 +static const u8 A19[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, + 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, + 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, + 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, + 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, + 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, + 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, + 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, + 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad +}; + +static const u8 T19[] = { + 0x5f, 0xea, 0x79, 0x3a, 0x2d, 0x6f, 0x97, 0x4d, + 0x37, 0xe6, 0x8e, 0x0c, 0xb8, 0xff, 0x94, 0x92 +}; + +/* Test Case 20 * / +# define K20 K1 +# define A20 A1 +/* this results in 0xff in counter LSB * / +static const u8 IV20[64] = { 0xff, 0xff, 0xff, 0xff }; + +static const u8 P20[288]; +static const u8 C20[] = { + 0x56, 0xb3, 0x37, 0x3c, 0xa9, 0xef, 0x6e, 0x4a, + 0x2b, 0x64, 0xfe, 0x1e, 0x9a, 0x17, 0xb6, 0x14, + 0x25, 0xf1, 0x0d, 0x47, 0xa7, 0x5a, 0x5f, 0xce, + 0x13, 0xef, 0xc6, 0xbc, 0x78, 0x4a, 0xf2, 0x4f, + 0x41, 0x41, 0xbd, 0xd4, 0x8c, 0xf7, 0xc7, 0x70, + 0x88, 0x7a, 0xfd, 0x57, 0x3c, 0xca, 0x54, 0x18, + 0xa9, 0xae, 0xff, 0xcd, 0x7c, 0x5c, 0xed, 0xdf, + 0xc6, 0xa7, 0x83, 0x97, 0xb9, 0xa8, 0x5b, 0x49, + 0x9d, 0xa5, 0x58, 0x25, 0x72, 0x67, 0xca, 0xab, + 0x2a, 0xd0, 0xb2, 0x3c, 0xa4, 0x76, 0xa5, 0x3c, + 0xb1, 0x7f, 0xb4, 0x1c, 0x4b, 0x8b, 0x47, 0x5c, + 0xb4, 0xf3, 0xf7, 0x16, 0x50, 0x94, 0xc2, 0x29, + 0xc9, 0xe8, 0xc4, 0xdc, 0x0a, 0x2a, 0x5f, 0xf1, + 0x90, 0x3e, 0x50, 0x15, 0x11, 0x22, 0x13, 0x76, + 0xa1, 0xcd, 0xb8, 0x36, 0x4c, 0x50, 0x61, 0xa2, + 0x0c, 0xae, 0x74, 0xbc, 0x4a, 0xcd, 0x76, 0xce, + 0xb0, 0xab, 0xc9, 0xfd, 0x32, 0x17, 0xef, 0x9f, + 0x8c, 0x90, 0xbe, 0x40, 0x2d, 0xdf, 0x6d, 0x86, + 0x97, 0xf4, 0xf8, 0x80, 0xdf, 0xf1, 0x5b, 0xfb, + 0x7a, 0x6b, 0x28, 0x24, 0x1e, 0xc8, 0xfe, 0x18, + 0x3c, 0x2d, 0x59, 0xe3, 0xf9, 0xdf, 0xff, 0x65, + 0x3c, 0x71, 0x26, 0xf0, 0xac, 0xb9, 0xe6, 0x42, + 0x11, 0xf4, 0x2b, 0xae, 0x12, 0xaf, 0x46, 0x2b, + 0x10, 0x70, 0xbe, 0xf1, 0xab, 0x5e, 0x36, 0x06, + 0x87, 0x2c, 0xa1, 0x0d, 0xee, 0x15, 0xb3, 0x24, + 0x9b, 0x1a, 0x1b, 0x95, 0x8f, 0x23, 0x13, 0x4c, + 0x4b, 0xcc, 0xb7, 0xd0, 0x32, 0x00, 0xbc, 0xe4, + 0x20, 0xa2, 0xf8, 0xeb, 0x66, 0xdc, 0xf3, 0x64, + 0x4d, 0x14, 0x23, 0xc1, 0xb5, 0x69, 0x90, 0x03, + 0xc1, 0x3e, 0xce, 0xf4, 0xbf, 0x38, 0xa3, 0xb6, + 0x0e, 0xed, 0xc3, 0x40, 0x33, 0xba, 0xc1, 0x90, + 0x27, 0x83, 0xdc, 0x6d, 0x89, 0xe2, 0xe7, 0x74, + 0x18, 0x8a, 0x43, 0x9c, 0x7e, 0xbc, 0xc0, 0x67, + 0x2d, 0xbd, 0xa4, 0xdd, 0xcf, 0xb2, 0x79, 0x46, + 0x13, 0xb0, 0xbe, 0x41, 0x31, 0x5e, 0xf7, 0x78, + 0x70, 0x8a, 0x70, 0xee, 0x7d, 0x75, 0x16, 0x5c +}; + +static const u8 T20[] = { + 0x8b, 0x30, 0x7f, 0x6b, 0x33, 0x28, 0x6d, 0x0a, + 0xb0, 0x26, 0xa9, 0xed, 0x3f, 0xe1, 0xe8, 0x5f +}; + +# define TEST_CASE(n) do { \ + u8 out[sizeof(P##n)]; \ + AES_set_encrypt_key(K##n,sizeof(K##n)*8,&key); \ + CRYPTO_gcm128_init(&ctx,&key,(block128_f)AES_encrypt); \ + CRYPTO_gcm128_setiv(&ctx,IV##n,sizeof(IV##n)); \ + memset(out,0,sizeof(out)); \ + if (A##n) CRYPTO_gcm128_aad(&ctx,A##n,sizeof(A##n)); \ + if (P##n) CRYPTO_gcm128_encrypt(&ctx,P##n,out,sizeof(out)); \ + if (CRYPTO_gcm128_finish(&ctx,T##n,16) || \ + (C##n && memcmp(out,C##n,sizeof(out)))) \ + ret++, printf ("encrypt test#%d failed.\n",n); \ + CRYPTO_gcm128_setiv(&ctx,IV##n,sizeof(IV##n)); \ + memset(out,0,sizeof(out)); \ + if (A##n) CRYPTO_gcm128_aad(&ctx,A##n,sizeof(A##n)); \ + if (C##n) CRYPTO_gcm128_decrypt(&ctx,C##n,out,sizeof(out)); \ + if (CRYPTO_gcm128_finish(&ctx,T##n,16) || \ + (P##n && memcmp(out,P##n,sizeof(out)))) \ + ret++, printf ("decrypt test#%d failed.\n",n); \ + } while(0) + +int main() +{ + GCM128_CONTEXT ctx; + AES_KEY key; + int ret = 0; + + TEST_CASE(1); + TEST_CASE(2); + TEST_CASE(3); + TEST_CASE(4); + TEST_CASE(5); + TEST_CASE(6); + TEST_CASE(7); + TEST_CASE(8); + TEST_CASE(9); + TEST_CASE(10); + TEST_CASE(11); + TEST_CASE(12); + TEST_CASE(13); + TEST_CASE(14); + TEST_CASE(15); + TEST_CASE(16); + TEST_CASE(17); + TEST_CASE(18); + TEST_CASE(19); + TEST_CASE(20); + +# ifdef OPENSSL_CPUID_OBJ + { + size_t start, stop, gcm_t, ctr_t, OPENSSL_rdtsc(); + union { + u64 u; + u8 c[1024]; + } buf; + int i; + + AES_set_encrypt_key(K1, sizeof(K1) * 8, &key); + CRYPTO_gcm128_init(&ctx, &key, (block128_f) AES_encrypt); + CRYPTO_gcm128_setiv(&ctx, IV1, sizeof(IV1)); + + CRYPTO_gcm128_encrypt(&ctx, buf.c, buf.c, sizeof(buf)); + start = OPENSSL_rdtsc(); + CRYPTO_gcm128_encrypt(&ctx, buf.c, buf.c, sizeof(buf)); + gcm_t = OPENSSL_rdtsc() - start; + + CRYPTO_ctr128_encrypt(buf.c, buf.c, sizeof(buf), + &key, ctx.Yi.c, ctx.EKi.c, &ctx.mres, + (block128_f) AES_encrypt); + start = OPENSSL_rdtsc(); + CRYPTO_ctr128_encrypt(buf.c, buf.c, sizeof(buf), + &key, ctx.Yi.c, ctx.EKi.c, &ctx.mres, + (block128_f) AES_encrypt); + ctr_t = OPENSSL_rdtsc() - start; + + printf("%.2f-%.2f=%.2f\n", + gcm_t / (double)sizeof(buf), + ctr_t / (double)sizeof(buf), + (gcm_t - ctr_t) / (double)sizeof(buf)); +# ifdef GHASH + { + void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16], + const u8 *inp, size_t len) = ctx.ghash; + + GHASH((&ctx), buf.c, sizeof(buf)); + start = OPENSSL_rdtsc(); + for (i = 0; i < 100; ++i) + GHASH((&ctx), buf.c, sizeof(buf)); + gcm_t = OPENSSL_rdtsc() - start; + printf("%.2f\n", gcm_t / (double)sizeof(buf) / (double)i); + } +# endif + } +# endif + + return ret; +} +#endif +/* PCL UNUSED END */ diff --git a/sdk/protected_code_loader/crypto/pcl_ghash-x86_64.s b/sdk/protected_code_loader/crypto/pcl_ghash-x86_64.s new file mode 100644 index 00000000..634abcfe --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_ghash-x86_64.s @@ -0,0 +1,691 @@ +/* + * Copyright (C) 2011-2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * Content from openssl-1.1.0e/crypto/modes/ghash-x86_64.s + * which is auto-generated by openssl-1.1.0e/crypto/modes/asm/ghash-x86_64.pl + */ + +.text + +.globl pcl_gcm_init_clmul +.type pcl_gcm_init_clmul,@function +.align 16 +pcl_gcm_init_clmul: +.L_init_clmul: + movdqu (%rsi),%xmm2 + pshufd $78,%xmm2,%xmm2 + + + pshufd $255,%xmm2,%xmm4 + movdqa %xmm2,%xmm3 + psllq $1,%xmm2 + pxor %xmm5,%xmm5 + psrlq $63,%xmm3 + pcmpgtd %xmm4,%xmm5 + pslldq $8,%xmm3 + por %xmm3,%xmm2 + + + pand .L0x1c2_polynomial(%rip),%xmm5 + pxor %xmm5,%xmm2 + + + pshufd $78,%xmm2,%xmm6 + movdqa %xmm2,%xmm0 + pxor %xmm2,%xmm6 + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm3 + pxor %xmm0,%xmm3 +.byte 102,15,58,68,194,0 +.byte 102,15,58,68,202,17 +.byte 102,15,58,68,222,0 + pxor %xmm0,%xmm3 + pxor %xmm1,%xmm3 + + movdqa %xmm3,%xmm4 + psrldq $8,%xmm3 + pslldq $8,%xmm4 + pxor %xmm3,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + pshufd $78,%xmm2,%xmm3 + pshufd $78,%xmm0,%xmm4 + pxor %xmm2,%xmm3 + movdqu %xmm2,0(%rdi) + pxor %xmm0,%xmm4 + movdqu %xmm0,16(%rdi) +.byte 102,15,58,15,227,8 + movdqu %xmm4,32(%rdi) + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm3 + pxor %xmm0,%xmm3 +.byte 102,15,58,68,194,0 +.byte 102,15,58,68,202,17 +.byte 102,15,58,68,222,0 + pxor %xmm0,%xmm3 + pxor %xmm1,%xmm3 + + movdqa %xmm3,%xmm4 + psrldq $8,%xmm3 + pslldq $8,%xmm4 + pxor %xmm3,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + movdqa %xmm0,%xmm5 + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm3 + pxor %xmm0,%xmm3 +.byte 102,15,58,68,194,0 +.byte 102,15,58,68,202,17 +.byte 102,15,58,68,222,0 + pxor %xmm0,%xmm3 + pxor %xmm1,%xmm3 + + movdqa %xmm3,%xmm4 + psrldq $8,%xmm3 + pslldq $8,%xmm4 + pxor %xmm3,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + pshufd $78,%xmm5,%xmm3 + pshufd $78,%xmm0,%xmm4 + pxor %xmm5,%xmm3 + movdqu %xmm5,48(%rdi) + pxor %xmm0,%xmm4 + movdqu %xmm0,64(%rdi) +.byte 102,15,58,15,227,8 + movdqu %xmm4,80(%rdi) + .byte 0xf3,0xc3 +.size pcl_gcm_init_clmul,.-pcl_gcm_init_clmul + +.globl pcl_gcm_gmult_clmul +.type pcl_gcm_gmult_clmul,@function +.align 16 +pcl_gcm_gmult_clmul: +.L_gmult_clmul: + movdqu (%rdi),%xmm0 + movdqa .Lbswap_mask(%rip),%xmm5 + movdqu (%rsi),%xmm2 + movdqu 32(%rsi),%xmm4 +.byte 102,15,56,0,197 + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm3 + pxor %xmm0,%xmm3 +.byte 102,15,58,68,194,0 +.byte 102,15,58,68,202,17 +.byte 102,15,58,68,220,0 + pxor %xmm0,%xmm3 + pxor %xmm1,%xmm3 + + movdqa %xmm3,%xmm4 + psrldq $8,%xmm3 + pslldq $8,%xmm4 + pxor %xmm3,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 +.byte 102,15,56,0,197 + movdqu %xmm0,(%rdi) + .byte 0xf3,0xc3 +.size pcl_gcm_gmult_clmul,.-pcl_gcm_gmult_clmul + +.globl pcl_gcm_ghash_clmul +.type pcl_gcm_ghash_clmul,@function +.align 32 +pcl_gcm_ghash_clmul: +.L_ghash_clmul: + movdqa .Lbswap_mask(%rip),%xmm10 + + movdqu (%rdi),%xmm0 + movdqu (%rsi),%xmm2 + movdqu 32(%rsi),%xmm7 +.byte 102,65,15,56,0,194 + + subq $0x10,%rcx + jz .Lodd_tail + + movdqu 16(%rsi),%xmm6 + # Commenting out Silvermont optimizations: movl OPENSSL_ia32cap_P+4(%rip),%eax + cmpq $0x30,%rcx + jb .Lskip4x + + # Commenting out Silvermont optimizations: andl $71303168,%eax + # Commenting out Silvermont optimizations: cmpl $4194304,%eax + # Commenting out Silvermont optimizations: je .Lskip4x + + subq $0x30,%rcx + movq $0xA040608020C0E000,%rax + movdqu 48(%rsi),%xmm14 + movdqu 64(%rsi),%xmm15 + + + + + movdqu 48(%rdx),%xmm3 + movdqu 32(%rdx),%xmm11 +.byte 102,65,15,56,0,218 +.byte 102,69,15,56,0,218 + movdqa %xmm3,%xmm5 + pshufd $78,%xmm3,%xmm4 + pxor %xmm3,%xmm4 +.byte 102,15,58,68,218,0 +.byte 102,15,58,68,234,17 +.byte 102,15,58,68,231,0 + + movdqa %xmm11,%xmm13 + pshufd $78,%xmm11,%xmm12 + pxor %xmm11,%xmm12 +.byte 102,68,15,58,68,222,0 +.byte 102,68,15,58,68,238,17 +.byte 102,68,15,58,68,231,16 + xorps %xmm11,%xmm3 + xorps %xmm13,%xmm5 + movups 80(%rsi),%xmm7 + xorps %xmm12,%xmm4 + + movdqu 16(%rdx),%xmm11 + movdqu 0(%rdx),%xmm8 +.byte 102,69,15,56,0,218 +.byte 102,69,15,56,0,194 + movdqa %xmm11,%xmm13 + pshufd $78,%xmm11,%xmm12 + pxor %xmm8,%xmm0 + pxor %xmm11,%xmm12 +.byte 102,69,15,58,68,222,0 + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm8 + pxor %xmm0,%xmm8 +.byte 102,69,15,58,68,238,17 +.byte 102,68,15,58,68,231,0 + xorps %xmm11,%xmm3 + xorps %xmm13,%xmm5 + + leaq 64(%rdx),%rdx + subq $0x40,%rcx + jc .Ltail4x + + jmp .Lmod4_loop +.align 32 +.Lmod4_loop: +.byte 102,65,15,58,68,199,0 + xorps %xmm12,%xmm4 + movdqu 48(%rdx),%xmm11 +.byte 102,69,15,56,0,218 +.byte 102,65,15,58,68,207,17 + xorps %xmm3,%xmm0 + movdqu 32(%rdx),%xmm3 + movdqa %xmm11,%xmm13 +.byte 102,68,15,58,68,199,16 + pshufd $78,%xmm11,%xmm12 + xorps %xmm5,%xmm1 + pxor %xmm11,%xmm12 +.byte 102,65,15,56,0,218 + movups 32(%rsi),%xmm7 + xorps %xmm4,%xmm8 +.byte 102,68,15,58,68,218,0 + pshufd $78,%xmm3,%xmm4 + + pxor %xmm0,%xmm8 + movdqa %xmm3,%xmm5 + pxor %xmm1,%xmm8 + pxor %xmm3,%xmm4 + movdqa %xmm8,%xmm9 +.byte 102,68,15,58,68,234,17 + pslldq $8,%xmm8 + psrldq $8,%xmm9 + pxor %xmm8,%xmm0 + movdqa .L7_mask(%rip),%xmm8 + pxor %xmm9,%xmm1 +.byte 102,76,15,110,200 + + pand %xmm0,%xmm8 +.byte 102,69,15,56,0,200 + pxor %xmm0,%xmm9 +.byte 102,68,15,58,68,231,0 + psllq $57,%xmm9 + movdqa %xmm9,%xmm8 + pslldq $8,%xmm9 +.byte 102,15,58,68,222,0 + psrldq $8,%xmm8 + pxor %xmm9,%xmm0 + pxor %xmm8,%xmm1 + movdqu 0(%rdx),%xmm8 + + movdqa %xmm0,%xmm9 + psrlq $1,%xmm0 +.byte 102,15,58,68,238,17 + xorps %xmm11,%xmm3 + movdqu 16(%rdx),%xmm11 +.byte 102,69,15,56,0,218 +.byte 102,15,58,68,231,16 + xorps %xmm13,%xmm5 + movups 80(%rsi),%xmm7 +.byte 102,69,15,56,0,194 + pxor %xmm9,%xmm1 + pxor %xmm0,%xmm9 + psrlq $5,%xmm0 + + movdqa %xmm11,%xmm13 + pxor %xmm12,%xmm4 + pshufd $78,%xmm11,%xmm12 + pxor %xmm9,%xmm0 + pxor %xmm8,%xmm1 + pxor %xmm11,%xmm12 +.byte 102,69,15,58,68,222,0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + movdqa %xmm0,%xmm1 +.byte 102,69,15,58,68,238,17 + xorps %xmm11,%xmm3 + pshufd $78,%xmm0,%xmm8 + pxor %xmm0,%xmm8 + +.byte 102,68,15,58,68,231,0 + xorps %xmm13,%xmm5 + + leaq 64(%rdx),%rdx + subq $0x40,%rcx + jnc .Lmod4_loop + +.Ltail4x: +.byte 102,65,15,58,68,199,0 +.byte 102,65,15,58,68,207,17 +.byte 102,68,15,58,68,199,16 + xorps %xmm12,%xmm4 + xorps %xmm3,%xmm0 + xorps %xmm5,%xmm1 + pxor %xmm0,%xmm1 + pxor %xmm4,%xmm8 + + pxor %xmm1,%xmm8 + pxor %xmm0,%xmm1 + + movdqa %xmm8,%xmm9 + psrldq $8,%xmm8 + pslldq $8,%xmm9 + pxor %xmm8,%xmm1 + pxor %xmm9,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + addq $0x40,%rcx + jz .Ldone + movdqu 32(%rsi),%xmm7 + subq $0x10,%rcx + jz .Lodd_tail +.Lskip4x: + + movdqu (%rdx),%xmm8 + movdqu 16(%rdx),%xmm3 +.byte 102,69,15,56,0,194 +.byte 102,65,15,56,0,218 + pxor %xmm8,%xmm0 + + movdqa %xmm3,%xmm5 + pshufd $78,%xmm3,%xmm4 + pxor %xmm3,%xmm4 +.byte 102,15,58,68,218,0 +.byte 102,15,58,68,234,17 +.byte 102,15,58,68,231,0 + + leaq 32(%rdx),%rdx + nop + subq $0x20,%rcx + jbe .Leven_tail + nop + jmp .Lmod_loop + +.align 32 +.Lmod_loop: + movdqa %xmm0,%xmm1 + movdqa %xmm4,%xmm8 + pshufd $78,%xmm0,%xmm4 + pxor %xmm0,%xmm4 + +.byte 102,15,58,68,198,0 +.byte 102,15,58,68,206,17 +.byte 102,15,58,68,231,16 + + pxor %xmm3,%xmm0 + pxor %xmm5,%xmm1 + movdqu (%rdx),%xmm9 + pxor %xmm0,%xmm8 +.byte 102,69,15,56,0,202 + movdqu 16(%rdx),%xmm3 + + pxor %xmm1,%xmm8 + pxor %xmm9,%xmm1 + pxor %xmm8,%xmm4 +.byte 102,65,15,56,0,218 + movdqa %xmm4,%xmm8 + psrldq $8,%xmm8 + pslldq $8,%xmm4 + pxor %xmm8,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm3,%xmm5 + + movdqa %xmm0,%xmm9 + movdqa %xmm0,%xmm8 + psllq $5,%xmm0 + pxor %xmm0,%xmm8 +.byte 102,15,58,68,218,0 + psllq $1,%xmm0 + pxor %xmm8,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm8 + pslldq $8,%xmm0 + psrldq $8,%xmm8 + pxor %xmm9,%xmm0 + pshufd $78,%xmm5,%xmm4 + pxor %xmm8,%xmm1 + pxor %xmm5,%xmm4 + + movdqa %xmm0,%xmm9 + psrlq $1,%xmm0 +.byte 102,15,58,68,234,17 + pxor %xmm9,%xmm1 + pxor %xmm0,%xmm9 + psrlq $5,%xmm0 + pxor %xmm9,%xmm0 + leaq 32(%rdx),%rdx + psrlq $1,%xmm0 +.byte 102,15,58,68,231,0 + pxor %xmm1,%xmm0 + + subq $0x20,%rcx + ja .Lmod_loop + +.Leven_tail: + movdqa %xmm0,%xmm1 + movdqa %xmm4,%xmm8 + pshufd $78,%xmm0,%xmm4 + pxor %xmm0,%xmm4 + +.byte 102,15,58,68,198,0 +.byte 102,15,58,68,206,17 +.byte 102,15,58,68,231,16 + + pxor %xmm3,%xmm0 + pxor %xmm5,%xmm1 + pxor %xmm0,%xmm8 + pxor %xmm1,%xmm8 + pxor %xmm8,%xmm4 + movdqa %xmm4,%xmm8 + psrldq $8,%xmm8 + pslldq $8,%xmm4 + pxor %xmm8,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 + testq %rcx,%rcx + jnz .Ldone + +.Lodd_tail: + movdqu (%rdx),%xmm8 +.byte 102,69,15,56,0,194 + pxor %xmm8,%xmm0 + movdqa %xmm0,%xmm1 + pshufd $78,%xmm0,%xmm3 + pxor %xmm0,%xmm3 +.byte 102,15,58,68,194,0 +.byte 102,15,58,68,202,17 +.byte 102,15,58,68,223,0 + pxor %xmm0,%xmm3 + pxor %xmm1,%xmm3 + + movdqa %xmm3,%xmm4 + psrldq $8,%xmm3 + pslldq $8,%xmm4 + pxor %xmm3,%xmm1 + pxor %xmm4,%xmm0 + + movdqa %xmm0,%xmm4 + movdqa %xmm0,%xmm3 + psllq $5,%xmm0 + pxor %xmm0,%xmm3 + psllq $1,%xmm0 + pxor %xmm3,%xmm0 + psllq $57,%xmm0 + movdqa %xmm0,%xmm3 + pslldq $8,%xmm0 + psrldq $8,%xmm3 + pxor %xmm4,%xmm0 + pxor %xmm3,%xmm1 + + + movdqa %xmm0,%xmm4 + psrlq $1,%xmm0 + pxor %xmm4,%xmm1 + pxor %xmm0,%xmm4 + psrlq $5,%xmm0 + pxor %xmm4,%xmm0 + psrlq $1,%xmm0 + pxor %xmm1,%xmm0 +.Ldone: +.byte 102,65,15,56,0,194 + movdqu %xmm0,(%rdi) + .byte 0xf3,0xc3 +.size pcl_gcm_ghash_clmul,.-pcl_gcm_ghash_clmul + +.align 64 +.Lbswap_mask: +.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 +.L0x1c2_polynomial: +.byte 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2 +.L7_mask: +.long 7,0,7,0 +.L7_mask_poly: +.long 7,0,450,0 + diff --git a/sdk/protected_code_loader/crypto/pcl_md32_common.h b/sdk/protected_code_loader/crypto/pcl_md32_common.h new file mode 100644 index 00000000..b9c63e38 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_md32_common.h @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Content from openssl-1.1.0e/crypto/include/internal/md32_common.h */ + +#ifndef SGX_PCL_MD32_COMMON_H +#define SGX_PCL_MD32_COMMON_H + +# define ROTATE(a,n) ({ register unsigned int ret; \ + asm ( \ + "roll %1,%0" \ + : "=r"(ret) \ + : "I"(n), "0"((unsigned int)(a)) \ + : "cc"); \ + ret; \ + }) + +# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ + asm ("bswapl %0":"=r"(r):"0"(r)); \ + (c)+=4; (l)=r; }) +# define HOST_l2c(l,c) ({ unsigned int r=(l); \ + asm ("bswapl %0":"=r"(r):"0"(r)); \ + *((unsigned int *)(c))=r; (c)+=4; r; }) + +int pcl_SHA256_Update(SHA256_CTX *c, void *data_, size_t len) +{ + unsigned char *data = (unsigned char *)data_; + unsigned char *p; + SHA_LONG l; + size_t n; + + if (len == 0) + return 1; + + l = (c->Nl + (((SHA_LONG) len) << 3)) & 0xffffffffUL; + /* + * 95-05-24 eay Fixed a bug with the overflow handling, thanks to Wei Dai + * for pointing it out. + */ + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh += (SHA_LONG) (len >> 29); /* might cause compiler warning on + * 16-bit */ + c->Nl = l; +/* PCL UNUSED START * + n = c->num; + if (n != 0) { + p = (unsigned char *)c->data; + + if (len >= SHA_CBLOCK || len + n >= SHA_CBLOCK) { + pcl_memcpy(p + n, data, SHA_CBLOCK - n); + pcl_sha256_block_data_order(c, p, 1); + n = SHA_CBLOCK - n; + data += n; + len -= n; + c->num = 0; + /* + * We use memset rather than OPENSSL_cleanse() here deliberately. + * Using OPENSSL_cleanse() here could be a performance issue. It + * will get properly cleansed on finalisation so this isn't a + * security problem. + * / + pcl_memset(p, 0, SHA_CBLOCK); /* keep it zeroed * / + } else { + pcl_memcpy(p + n, data, len); + c->num += (unsigned int)len; + return 1; + } + } +/* PCL UNUSED END */ + n = len / SHA_CBLOCK; + if (n > 0) { + pcl_sha256_block_data_order(c, data, n); + n *= SHA_CBLOCK; + data += n; + len -= n; + } + + if (len != 0) { + p = (unsigned char *)c->data; + c->num = (unsigned int)len; + pcl_memcpy(p, data, len); + } + return 1; +} + +int pcl_SHA256_Final(unsigned char *md, SHA256_CTX *c) +{ + unsigned char *p = (unsigned char *)c->data; + size_t n = c->num; + + p[n] = 0x80; /* there is always room for one */ + n++; + + if (n > (SHA_CBLOCK - 8)) { + pcl_memset(p + n, 0, SHA_CBLOCK - n); + n = 0; + pcl_sha256_block_data_order(c, p, 1); + } + pcl_memset(p + n, 0, SHA_CBLOCK - 8 - n); + + p += SHA_CBLOCK - 8; +/* PCL UNUSED START * +#if defined(DATA_ORDER_IS_BIG_ENDIAN) +/* PCL UNUSED END */ + (void)HOST_l2c(c->Nh, p); + (void)HOST_l2c(c->Nl, p); +/* PCL UNUSED START * +#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) + (void)HOST_l2c(c->Nl, p); + (void)HOST_l2c(c->Nh, p); +#endif +/* PCL UNUSED END */ + p -= SHA_CBLOCK; + pcl_sha256_block_data_order(c, p, 1); + c->num = 0; + pcl_memset(p, 0, SHA_CBLOCK); +/* PCL UNUSED START * +#ifndef HASH_MAKE_STRING +# error "HASH_MAKE_STRING must be defined!" +#else +/* PCL UNUSED END */ + HASH_MAKE_STRING(c, md); +/* PCL UNUSED START * +#endif +/* PCL UNUSED END */ + + return 1; +} + +#define MD32_REG_T int + +#endif // #ifndef SGX_PCL_MD32_COMMON_H + diff --git a/sdk/protected_code_loader/crypto/pcl_modes_lcl.h b/sdk/protected_code_loader/crypto/pcl_modes_lcl.h new file mode 100644 index 00000000..e8b97439 --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_modes_lcl.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Content from openssl-1.1.0e/crypto/modes/modes_lcl.h */ + +#ifndef SGX_PCL_MODES_LCL_H +#define SGX_PCL_MODES_LCL_H + +# define BSWAP8(x) ({ u64 ret_=(x); \ + asm ("bswapq %0" \ + : "+r"(ret_)); ret_; }) + +#endif // #ifndef SGX_PCL_MODES_LCL_H + diff --git a/sdk/protected_code_loader/crypto/pcl_sha256.c b/sdk/protected_code_loader/crypto/pcl_sha256.c new file mode 100644 index 00000000..7736003e --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_sha256.c @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* Content from openssl-1.1.0e/crypto/sha/sha256.c */ + +#include +#include +#include +#include +#include +#include +#include + +int pcl_SHA256_Init(SHA256_CTX *c) +{ + pcl_memset(c, 0, sizeof(*c)); + c->h[0] = 0x6a09e667UL; + c->h[1] = 0xbb67ae85UL; + c->h[2] = 0x3c6ef372UL; + c->h[3] = 0xa54ff53aUL; + c->h[4] = 0x510e527fUL; + c->h[5] = 0x9b05688cUL; + c->h[6] = 0x1f83d9abUL; + c->h[7] = 0x5be0cd19UL; + c->md_len = SHA256_DIGEST_LENGTH; + return 1; +} +#define HASH_MAKE_STRING(c,s) do { \ + unsigned long ll; \ + unsigned int nn; \ + for (nn=0;nnh[nn]; (void)HOST_l2c(ll,(s)); } \ + } while (0) + +static void pcl_sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num); +#include +static const SHA_LONG pcl_K256[64] = { + 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, + 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, + 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, + 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, + 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, + 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, + 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, + 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, + 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, + 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, + 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, + 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, + 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, + 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, + 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, + 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL +}; + +/* + * FIPS specification refers to right rotations, while our ROTATE macro + * is left one. This is why you might notice that rotation coefficients + * differ from those observed in FIPS document by 32-N... + */ +# define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10)) +# define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7)) +# define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3)) +# define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10)) + +# define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) +# define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +static void pcl_sha256_block_data_order(SHA256_CTX *ctx, const void *in, + size_t num) +{ + unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1, T2; + SHA_LONG X[16], l; + int i; + const unsigned char *data = (const unsigned char *) in; + + while (num--) { + + a = ctx->h[0]; + b = ctx->h[1]; + c = ctx->h[2]; + d = ctx->h[3]; + e = ctx->h[4]; + f = ctx->h[5]; + g = ctx->h[6]; + h = ctx->h[7]; + + for (i = 0; i < 16; i++) { + (void)HOST_c2l(data, l); + T1 = X[i] = l; + T1 += h + Sigma1(e) + Ch(e, f, g) + pcl_K256[i]; + T2 = Sigma0(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } + + for (; i < 64; i++) { + s0 = X[(i + 1) & 0x0f]; + s0 = sigma0(s0); + s1 = X[(i + 14) & 0x0f]; + s1 = sigma1(s1); + + T1 = X[i & 0xf] += s0 + s1 + X[(i + 9) & 0xf]; + T1 += h + Sigma1(e) + Ch(e, f, g) + pcl_K256[i]; + T2 = Sigma0(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + T1; + d = c; + c = b; + b = a; + a = T1 + T2; + } + + ctx->h[0] += a; + ctx->h[1] += b; + ctx->h[2] += c; + ctx->h[3] += d; + ctx->h[4] += e; + ctx->h[5] += f; + ctx->h[6] += g; + ctx->h[7] += h; + + } +} + diff --git a/sdk/protected_code_loader/crypto/pcl_vpaes-x86_64.s b/sdk/protected_code_loader/crypto/pcl_vpaes-x86_64.s new file mode 100644 index 00000000..b64146eb --- /dev/null +++ b/sdk/protected_code_loader/crypto/pcl_vpaes-x86_64.s @@ -0,0 +1,770 @@ +/* + * Copyright (C) 2011-2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ==================================================================== + * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * Content from openssl-1.1.0e/crypto/aes/vpaes-x86_64.s + * which is auto-generated by openssl-1.1.0e/crypto/aes/asm/vpaes-x86_64.pl + */ + +.text + +.type _pcl_vpaes_encrypt_core,@function +.align 16 +_pcl_vpaes_encrypt_core: + movq %rdx,%r9 + movq $16,%r11 + movl 240(%rdx),%eax + movdqa %xmm9,%xmm1 + movdqa .Lk_ipt(%rip),%xmm2 + pandn %xmm0,%xmm1 + movdqu (%r9),%xmm5 + psrld $4,%xmm1 + pand %xmm9,%xmm0 +.byte 102,15,56,0,208 + movdqa .Lk_ipt+16(%rip),%xmm0 +.byte 102,15,56,0,193 + pxor %xmm5,%xmm2 + addq $16,%r9 + pxor %xmm2,%xmm0 + leaq .Lk_mc_backward(%rip),%r10 + jmp .Lenc_entry + + +.align 16 +.Lenc_loop: + + movdqa %xmm13,%xmm4 + movdqa %xmm12,%xmm0 +.byte 102,15,56,0,226 +.byte 102,15,56,0,195 + pxor %xmm5,%xmm4 + movdqa %xmm15,%xmm5 + pxor %xmm4,%xmm0 + movdqa -64(%r11,%r10,1),%xmm1 +.byte 102,15,56,0,234 + movdqa (%r11,%r10,1),%xmm4 + movdqa %xmm14,%xmm2 +.byte 102,15,56,0,211 + movdqa %xmm0,%xmm3 + pxor %xmm5,%xmm2 +.byte 102,15,56,0,193 + addq $16,%r9 + pxor %xmm2,%xmm0 +.byte 102,15,56,0,220 + addq $16,%r11 + pxor %xmm0,%xmm3 +.byte 102,15,56,0,193 + andq $0x30,%r11 + subq $1,%rax + pxor %xmm3,%xmm0 + +.Lenc_entry: + + movdqa %xmm9,%xmm1 + movdqa %xmm11,%xmm5 + pandn %xmm0,%xmm1 + psrld $4,%xmm1 + pand %xmm9,%xmm0 +.byte 102,15,56,0,232 + movdqa %xmm10,%xmm3 + pxor %xmm1,%xmm0 +.byte 102,15,56,0,217 + movdqa %xmm10,%xmm4 + pxor %xmm5,%xmm3 +.byte 102,15,56,0,224 + movdqa %xmm10,%xmm2 + pxor %xmm5,%xmm4 +.byte 102,15,56,0,211 + movdqa %xmm10,%xmm3 + pxor %xmm0,%xmm2 +.byte 102,15,56,0,220 + movdqu (%r9),%xmm5 + pxor %xmm1,%xmm3 + jnz .Lenc_loop + + + movdqa -96(%r10),%xmm4 + movdqa -80(%r10),%xmm0 +.byte 102,15,56,0,226 + pxor %xmm5,%xmm4 +.byte 102,15,56,0,195 + movdqa 64(%r11,%r10,1),%xmm1 + pxor %xmm4,%xmm0 +.byte 102,15,56,0,193 + .byte 0xf3,0xc3 +.size _pcl_vpaes_encrypt_core,.-_pcl_vpaes_encrypt_core + + +.type _pcl_vpaes_decrypt_core,@function +.align 16 +_pcl_vpaes_decrypt_core: + movq %rdx,%r9 + movl 240(%rdx),%eax + movdqa %xmm9,%xmm1 + movdqa .Lk_dipt(%rip),%xmm2 + pandn %xmm0,%xmm1 + movq %rax,%r11 + psrld $4,%xmm1 + movdqu (%r9),%xmm5 + shlq $4,%r11 + pand %xmm9,%xmm0 +.byte 102,15,56,0,208 + movdqa .Lk_dipt+16(%rip),%xmm0 + xorq $0x30,%r11 + leaq .Lk_dsbd(%rip),%r10 +.byte 102,15,56,0,193 + andq $0x30,%r11 + pxor %xmm5,%xmm2 + movdqa .Lk_mc_forward+48(%rip),%xmm5 + pxor %xmm2,%xmm0 + addq $16,%r9 + addq %r10,%r11 + jmp .Ldec_entry + + +.align 16 +.Ldec_loop: + + movdqa -32(%r10),%xmm4 + movdqa -16(%r10),%xmm1 +.byte 102,15,56,0,226 +.byte 102,15,56,0,203 + pxor %xmm4,%xmm0 + movdqa 0(%r10),%xmm4 + pxor %xmm1,%xmm0 + movdqa 16(%r10),%xmm1 + +.byte 102,15,56,0,226 +.byte 102,15,56,0,197 +.byte 102,15,56,0,203 + pxor %xmm4,%xmm0 + movdqa 32(%r10),%xmm4 + pxor %xmm1,%xmm0 + movdqa 48(%r10),%xmm1 + +.byte 102,15,56,0,226 +.byte 102,15,56,0,197 +.byte 102,15,56,0,203 + pxor %xmm4,%xmm0 + movdqa 64(%r10),%xmm4 + pxor %xmm1,%xmm0 + movdqa 80(%r10),%xmm1 + +.byte 102,15,56,0,226 +.byte 102,15,56,0,197 +.byte 102,15,56,0,203 + pxor %xmm4,%xmm0 + addq $16,%r9 +.byte 102,15,58,15,237,12 + pxor %xmm1,%xmm0 + subq $1,%rax + +.Ldec_entry: + + movdqa %xmm9,%xmm1 + pandn %xmm0,%xmm1 + movdqa %xmm11,%xmm2 + psrld $4,%xmm1 + pand %xmm9,%xmm0 +.byte 102,15,56,0,208 + movdqa %xmm10,%xmm3 + pxor %xmm1,%xmm0 +.byte 102,15,56,0,217 + movdqa %xmm10,%xmm4 + pxor %xmm2,%xmm3 +.byte 102,15,56,0,224 + pxor %xmm2,%xmm4 + movdqa %xmm10,%xmm2 +.byte 102,15,56,0,211 + movdqa %xmm10,%xmm3 + pxor %xmm0,%xmm2 +.byte 102,15,56,0,220 + movdqu (%r9),%xmm0 + pxor %xmm1,%xmm3 + jnz .Ldec_loop + + movdqa 96(%r10),%xmm4 +.byte 102,15,56,0,226 + pxor %xmm0,%xmm4 + movdqa 112(%r10),%xmm0 + movdqa -352(%r11),%xmm2 +.byte 102,15,56,0,195 + pxor %xmm4,%xmm0 +.byte 102,15,56,0,194 + .byte 0xf3,0xc3 +.size _pcl_vpaes_decrypt_core,.-_pcl_vpaes_decrypt_core + + +.type _pcl_vpaes_schedule_core,@function +.align 16 +_pcl_vpaes_schedule_core: + + call _pcl_vpaes_preheat + movdqa .Lk_rcon(%rip),%xmm8 + movdqu (%rdi),%xmm0 + + + movdqa %xmm0,%xmm3 + leaq .Lk_ipt(%rip),%r11 + call _pcl_vpaes_schedule_transform + movdqa %xmm0,%xmm7 + + leaq .Lk_sr(%rip),%r10 + testq %rcx,%rcx + jnz .Lschedule_am_decrypting + + movdqu %xmm0,(%rdx) + jmp .Lschedule_go + +.Lschedule_am_decrypting: + + movdqa (%r8,%r10,1),%xmm1 +.byte 102,15,56,0,217 + movdqu %xmm3,(%rdx) + xorq $0x30,%r8 + +.Lschedule_go: + cmpl $192,%esi + ja .Lschedule_256 + je .Lschedule_192 + +.Lschedule_128: + movl $10,%esi + +.Loop_schedule_128: + call _pcl_vpaes_schedule_round + decq %rsi + jz .Lschedule_mangle_last + call _pcl_vpaes_schedule_mangle + jmp .Loop_schedule_128 + + +.align 16 +.Lschedule_192: + movdqu 8(%rdi),%xmm0 + call _pcl_vpaes_schedule_transform + movdqa %xmm0,%xmm6 + pxor %xmm4,%xmm4 + movhlps %xmm4,%xmm6 + movl $4,%esi + +.Loop_schedule_192: + call _pcl_vpaes_schedule_round +.byte 102,15,58,15,198,8 + call _pcl_vpaes_schedule_mangle + call _pcl_vpaes_schedule_192_smear + call _pcl_vpaes_schedule_mangle + call _pcl_vpaes_schedule_round + decq %rsi + jz .Lschedule_mangle_last + call _pcl_vpaes_schedule_mangle + call _pcl_vpaes_schedule_192_smear + jmp .Loop_schedule_192 + + +.align 16 +.Lschedule_256: + movdqu 16(%rdi),%xmm0 + call _pcl_vpaes_schedule_transform + movl $7,%esi + +.Loop_schedule_256: + call _pcl_vpaes_schedule_mangle + movdqa %xmm0,%xmm6 + + + call _pcl_vpaes_schedule_round + decq %rsi + jz .Lschedule_mangle_last + call _pcl_vpaes_schedule_mangle + + + pshufd $0xFF,%xmm0,%xmm0 + movdqa %xmm7,%xmm5 + movdqa %xmm6,%xmm7 + call _pcl_vpaes_schedule_low_round + movdqa %xmm5,%xmm7 + + jmp .Loop_schedule_256 + + +.align 16 +.Lschedule_mangle_last: + + leaq .Lk_deskew(%rip),%r11 + testq %rcx,%rcx + jnz .Lschedule_mangle_last_dec + + + movdqa (%r8,%r10,1),%xmm1 +.byte 102,15,56,0,193 + leaq .Lk_opt(%rip),%r11 + addq $32,%rdx + +.Lschedule_mangle_last_dec: + addq $-16,%rdx + pxor .Lk_s63(%rip),%xmm0 + call _pcl_vpaes_schedule_transform + movdqu %xmm0,(%rdx) + + + pxor %xmm0,%xmm0 + pxor %xmm1,%xmm1 + pxor %xmm2,%xmm2 + pxor %xmm3,%xmm3 + pxor %xmm4,%xmm4 + pxor %xmm5,%xmm5 + pxor %xmm6,%xmm6 + pxor %xmm7,%xmm7 + .byte 0xf3,0xc3 +.size _pcl_vpaes_schedule_core,.-_pcl_vpaes_schedule_core + + +.type _pcl_vpaes_schedule_192_smear,@function +.align 16 +_pcl_vpaes_schedule_192_smear: + pshufd $0x80,%xmm6,%xmm1 + pshufd $0xFE,%xmm7,%xmm0 + pxor %xmm1,%xmm6 + pxor %xmm1,%xmm1 + pxor %xmm0,%xmm6 + movdqa %xmm6,%xmm0 + movhlps %xmm1,%xmm6 + .byte 0xf3,0xc3 +.size _pcl_vpaes_schedule_192_smear,.-_pcl_vpaes_schedule_192_smear + + +.type _pcl_vpaes_schedule_round,@function +.align 16 +_pcl_vpaes_schedule_round: + + pxor %xmm1,%xmm1 +.byte 102,65,15,58,15,200,15 +.byte 102,69,15,58,15,192,15 + pxor %xmm1,%xmm7 + + + pshufd $0xFF,%xmm0,%xmm0 +.byte 102,15,58,15,192,1 + + +_pcl_vpaes_schedule_low_round: + + movdqa %xmm7,%xmm1 + pslldq $4,%xmm7 + pxor %xmm1,%xmm7 + movdqa %xmm7,%xmm1 + pslldq $8,%xmm7 + pxor %xmm1,%xmm7 + pxor .Lk_s63(%rip),%xmm7 + + + movdqa %xmm9,%xmm1 + pandn %xmm0,%xmm1 + psrld $4,%xmm1 + pand %xmm9,%xmm0 + movdqa %xmm11,%xmm2 +.byte 102,15,56,0,208 + pxor %xmm1,%xmm0 + movdqa %xmm10,%xmm3 +.byte 102,15,56,0,217 + pxor %xmm2,%xmm3 + movdqa %xmm10,%xmm4 +.byte 102,15,56,0,224 + pxor %xmm2,%xmm4 + movdqa %xmm10,%xmm2 +.byte 102,15,56,0,211 + pxor %xmm0,%xmm2 + movdqa %xmm10,%xmm3 +.byte 102,15,56,0,220 + pxor %xmm1,%xmm3 + movdqa %xmm13,%xmm4 +.byte 102,15,56,0,226 + movdqa %xmm12,%xmm0 +.byte 102,15,56,0,195 + pxor %xmm4,%xmm0 + + + pxor %xmm7,%xmm0 + movdqa %xmm0,%xmm7 + .byte 0xf3,0xc3 +.size _pcl_vpaes_schedule_round,.-_pcl_vpaes_schedule_round + + +.type _pcl_vpaes_schedule_transform,@function +.align 16 +_pcl_vpaes_schedule_transform: + movdqa %xmm9,%xmm1 + pandn %xmm0,%xmm1 + psrld $4,%xmm1 + pand %xmm9,%xmm0 + movdqa (%r11),%xmm2 +.byte 102,15,56,0,208 + movdqa 16(%r11),%xmm0 +.byte 102,15,56,0,193 + pxor %xmm2,%xmm0 + .byte 0xf3,0xc3 +.size _pcl_vpaes_schedule_transform,.-_pcl_vpaes_schedule_transform + + +.type _pcl_vpaes_schedule_mangle,@function +.align 16 +_pcl_vpaes_schedule_mangle: + movdqa %xmm0,%xmm4 + movdqa .Lk_mc_forward(%rip),%xmm5 + testq %rcx,%rcx + jnz .Lschedule_mangle_dec + + + addq $16,%rdx + pxor .Lk_s63(%rip),%xmm4 +.byte 102,15,56,0,229 + movdqa %xmm4,%xmm3 +.byte 102,15,56,0,229 + pxor %xmm4,%xmm3 +.byte 102,15,56,0,229 + pxor %xmm4,%xmm3 + + jmp .Lschedule_mangle_both +.align 16 +.Lschedule_mangle_dec: + + leaq .Lk_dksd(%rip),%r11 + movdqa %xmm9,%xmm1 + pandn %xmm4,%xmm1 + psrld $4,%xmm1 + pand %xmm9,%xmm4 + + movdqa 0(%r11),%xmm2 +.byte 102,15,56,0,212 + movdqa 16(%r11),%xmm3 +.byte 102,15,56,0,217 + pxor %xmm2,%xmm3 +.byte 102,15,56,0,221 + + movdqa 32(%r11),%xmm2 +.byte 102,15,56,0,212 + pxor %xmm3,%xmm2 + movdqa 48(%r11),%xmm3 +.byte 102,15,56,0,217 + pxor %xmm2,%xmm3 +.byte 102,15,56,0,221 + + movdqa 64(%r11),%xmm2 +.byte 102,15,56,0,212 + pxor %xmm3,%xmm2 + movdqa 80(%r11),%xmm3 +.byte 102,15,56,0,217 + pxor %xmm2,%xmm3 +.byte 102,15,56,0,221 + + movdqa 96(%r11),%xmm2 +.byte 102,15,56,0,212 + pxor %xmm3,%xmm2 + movdqa 112(%r11),%xmm3 +.byte 102,15,56,0,217 + pxor %xmm2,%xmm3 + + addq $-16,%rdx + +.Lschedule_mangle_both: + movdqa (%r8,%r10,1),%xmm1 +.byte 102,15,56,0,217 + addq $-16,%r8 + andq $0x30,%r8 + movdqu %xmm3,(%rdx) + .byte 0xf3,0xc3 +.size _pcl_vpaes_schedule_mangle,.-_pcl_vpaes_schedule_mangle + + +.globl pcl_vpaes_set_encrypt_key +.type pcl_vpaes_set_encrypt_key,@function +.align 16 +pcl_vpaes_set_encrypt_key: + movl %esi,%eax + shrl $5,%eax + addl $5,%eax + movl %eax,240(%rdx) + + movl $0,%ecx + movl $0x30,%r8d + call _pcl_vpaes_schedule_core + xorl %eax,%eax + .byte 0xf3,0xc3 +.size pcl_vpaes_set_encrypt_key,.-pcl_vpaes_set_encrypt_key + +.globl pcl_vpaes_set_decrypt_key +.type pcl_vpaes_set_decrypt_key,@function +.align 16 +pcl_vpaes_set_decrypt_key: + movl %esi,%eax + shrl $5,%eax + addl $5,%eax + movl %eax,240(%rdx) + shll $4,%eax + leaq 16(%rdx,%rax,1),%rdx + + movl $1,%ecx + movl %esi,%r8d + shrl $1,%r8d + andl $32,%r8d + xorl $32,%r8d + call _pcl_vpaes_schedule_core + xorl %eax,%eax + .byte 0xf3,0xc3 +.size pcl_vpaes_set_decrypt_key,.-pcl_vpaes_set_decrypt_key + +.globl pcl_vpaes_encrypt +.type pcl_vpaes_encrypt,@function +.align 16 +pcl_vpaes_encrypt: + movdqu (%rdi),%xmm0 + call _pcl_vpaes_preheat + call _pcl_vpaes_encrypt_core + movdqu %xmm0,(%rsi) + .byte 0xf3,0xc3 +.size pcl_vpaes_encrypt,.-pcl_vpaes_encrypt + +.globl pcl_vpaes_decrypt +.type pcl_vpaes_decrypt,@function +.align 16 +pcl_vpaes_decrypt: + movdqu (%rdi),%xmm0 + call _pcl_vpaes_preheat + call _pcl_vpaes_decrypt_core + movdqu %xmm0,(%rsi) + .byte 0xf3,0xc3 +.size pcl_vpaes_decrypt,.-pcl_vpaes_decrypt +.globl pcl_vpaes_cbc_encrypt +.type pcl_vpaes_cbc_encrypt,@function +.align 16 +pcl_vpaes_cbc_encrypt: + xchgq %rcx,%rdx + subq $16,%rcx + jc .Lcbc_abort + movdqu (%r8),%xmm6 + subq %rdi,%rsi + call _pcl_vpaes_preheat + cmpl $0,%r9d + je .Lcbc_dec_loop + jmp .Lcbc_enc_loop +.align 16 +.Lcbc_enc_loop: + movdqu (%rdi),%xmm0 + pxor %xmm6,%xmm0 + call _pcl_vpaes_encrypt_core + movdqa %xmm0,%xmm6 + movdqu %xmm0,(%rsi,%rdi,1) + leaq 16(%rdi),%rdi + subq $16,%rcx + jnc .Lcbc_enc_loop + jmp .Lcbc_done +.align 16 +.Lcbc_dec_loop: + movdqu (%rdi),%xmm0 + movdqa %xmm0,%xmm7 + call _pcl_vpaes_decrypt_core + pxor %xmm6,%xmm0 + movdqa %xmm7,%xmm6 + movdqu %xmm0,(%rsi,%rdi,1) + leaq 16(%rdi),%rdi + subq $16,%rcx + jnc .Lcbc_dec_loop +.Lcbc_done: + movdqu %xmm6,(%r8) +.Lcbc_abort: + .byte 0xf3,0xc3 +.size pcl_vpaes_cbc_encrypt,.-pcl_vpaes_cbc_encrypt + + +.type _pcl_vpaes_preheat,@function +.align 16 +_pcl_vpaes_preheat: + leaq .Lk_s0F(%rip),%r10 + movdqa -32(%r10),%xmm10 + movdqa -16(%r10),%xmm11 + movdqa 0(%r10),%xmm9 + movdqa 48(%r10),%xmm13 + movdqa 64(%r10),%xmm12 + movdqa 80(%r10),%xmm15 + movdqa 96(%r10),%xmm14 + .byte 0xf3,0xc3 +.size _pcl_vpaes_preheat,.-_pcl_vpaes_preheat + + +.type _pcl_vpaes_consts,@object +.align 64 +_pcl_vpaes_consts: +.Lk_inv: +.quad 0x0E05060F0D080180, 0x040703090A0B0C02 +.quad 0x01040A060F0B0780, 0x030D0E0C02050809 + +.Lk_s0F: +.quad 0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F + +.Lk_ipt: +.quad 0xC2B2E8985A2A7000, 0xCABAE09052227808 +.quad 0x4C01307D317C4D00, 0xCD80B1FCB0FDCC81 + +.Lk_sb1: +.quad 0xB19BE18FCB503E00, 0xA5DF7A6E142AF544 +.quad 0x3618D415FAE22300, 0x3BF7CCC10D2ED9EF +.Lk_sb2: +.quad 0xE27A93C60B712400, 0x5EB7E955BC982FCD +.quad 0x69EB88400AE12900, 0xC2A163C8AB82234A +.Lk_sbo: +.quad 0xD0D26D176FBDC700, 0x15AABF7AC502A878 +.quad 0xCFE474A55FBB6A00, 0x8E1E90D1412B35FA + +.Lk_mc_forward: +.quad 0x0407060500030201, 0x0C0F0E0D080B0A09 +.quad 0x080B0A0904070605, 0x000302010C0F0E0D +.quad 0x0C0F0E0D080B0A09, 0x0407060500030201 +.quad 0x000302010C0F0E0D, 0x080B0A0904070605 + +.Lk_mc_backward: +.quad 0x0605040702010003, 0x0E0D0C0F0A09080B +.quad 0x020100030E0D0C0F, 0x0A09080B06050407 +.quad 0x0E0D0C0F0A09080B, 0x0605040702010003 +.quad 0x0A09080B06050407, 0x020100030E0D0C0F + +.Lk_sr: +.quad 0x0706050403020100, 0x0F0E0D0C0B0A0908 +.quad 0x030E09040F0A0500, 0x0B06010C07020D08 +.quad 0x0F060D040B020900, 0x070E050C030A0108 +.quad 0x0B0E0104070A0D00, 0x0306090C0F020508 + +.Lk_rcon: +.quad 0x1F8391B9AF9DEEB6, 0x702A98084D7C7D81 + +.Lk_s63: +.quad 0x5B5B5B5B5B5B5B5B, 0x5B5B5B5B5B5B5B5B + +.Lk_opt: +.quad 0xFF9F4929D6B66000, 0xF7974121DEBE6808 +.quad 0x01EDBD5150BCEC00, 0xE10D5DB1B05C0CE0 + +.Lk_deskew: +.quad 0x07E4A34047A4E300, 0x1DFEB95A5DBEF91A +.quad 0x5F36B5DC83EA6900, 0x2841C2ABF49D1E77 + + +.Lk_dksd: +.quad 0xFEB91A5DA3E44700, 0x0740E3A45A1DBEF9 +.quad 0x41C277F4B5368300, 0x5FDC69EAAB289D1E +.Lk_dksb: +.quad 0x9A4FCA1F8550D500, 0x03D653861CC94C99 +.quad 0x115BEDA7B6FC4A00, 0xD993256F7E3482C8 +.Lk_dkse: +.quad 0xD5031CCA1FC9D600, 0x53859A4C994F5086 +.quad 0xA23196054FDC7BE8, 0xCD5EF96A20B31487 +.Lk_dks9: +.quad 0xB6116FC87ED9A700, 0x4AED933482255BFC +.quad 0x4576516227143300, 0x8BB89FACE9DAFDCE + + +.Lk_dipt: +.quad 0x0F505B040B545F00, 0x154A411E114E451A +.quad 0x86E383E660056500, 0x12771772F491F194 + +.Lk_dsb9: +.quad 0x851C03539A86D600, 0xCAD51F504F994CC9 +.quad 0xC03B1789ECD74900, 0x725E2C9EB2FBA565 +.Lk_dsbd: +.quad 0x7D57CCDFE6B1A200, 0xF56E9B13882A4439 +.quad 0x3CE2FAF724C6CB00, 0x2931180D15DEEFD3 +.Lk_dsbb: +.quad 0xD022649296B44200, 0x602646F6B0F2D404 +.quad 0xC19498A6CD596700, 0xF3FF0C3E3255AA6B +.Lk_dsbe: +.quad 0x46F2929626D4D000, 0x2242600464B4F6B0 +.quad 0x0C55A6CDFFAAC100, 0x9467F36B98593E32 +.Lk_dsbo: +.quad 0x1387EA537EF94000, 0xC7AA6DB9D4943E2D +.quad 0x12D7560F93441D00, 0xCA4B8159D8C58E9C +.byte 86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105,111,110,32,65,69,83,32,102,111,114,32,120,56,54,95,54,52,47,83,83,83,69,51,44,32,77,105,107,101,32,72,97,109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32,85,110,105,118,101,114,115,105,116,121,41,0 +.align 64 +.size _pcl_vpaes_consts,.-_pcl_vpaes_consts + diff --git a/sdk/protected_code_loader/pcl_entry.cpp b/sdk/protected_code_loader/pcl_entry.cpp new file mode 100644 index 00000000..f42c0308 --- /dev/null +++ b/sdk/protected_code_loader/pcl_entry.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include + +/* + * g_tbl holds the PCL table. Its content is set by enclave encryption tool at build time + * It is located in its own section (PCLTBL_SECTION_NAME) so that + * enclave encryption tool can find it. + */ +pcl_table_t g_tbl __attribute__((section(PCLTBL_SECTION_NAME))) = {PCL_PLAIN}; + +/* + * g_pcl_imagebase is set at runtime to ELF base address. + * It is used by functions pcl_is_outside_enclave and pcl_is_within_enclave + */ +uintptr_t g_pcl_imagebase = 0; + +/* + * @func pcl_entry is the PCL entry point. It is called from init_enclave in + * trusted runtime entry point. It extracts the decryption key from the sealed blob + * and use it to decrypt the encrypted portions of the enclave binary. + * @param INOUT void* elf_base, base address of enclave + * @param IN void* sealed_blob, the sealed blob + * @return sgx_status_t + * SGX_ERROR_UNEXPECTED if + * 1. Table inconsistencies: + * a. PCL state in PCL table is not PCL_CIPHER + * b. PCL_SEALED_BLOB_MAX_SIZE < tbl->sealed_blob_size + * 2. pcl_unseal_data returns incorrect values for either guid size or key size + * Respective error returned from pcl_unseal_data, pcl_sha256, pcl_gcm_decrypt or pcl_increment_iv + * SGX_SUCCESS if successfull + */ +sgx_status_t pcl_entry(void* elf_base, void* sealed_blob) +{ + sgx_status_t ret = SGX_SUCCESS; + pcl_table_t* tbl = &g_tbl; + unsigned char* iv = NULL; + int memcmpret = 0; + sgx_sha256_hash_t hash = {0}; + sgx_aes_gcm_128bit_key_t key = {0}; + + // Verify PCL state: + if(PCL_CIPHER != tbl->pcl_state) + { + return SGX_ERROR_UNEXPECTED; + } + tbl->pcl_state = PCL_RUNNING; + + // ELF base address used by pcl_is_outside_enclave and pcl_is_within_enclave + g_pcl_imagebase = (uintptr_t)elf_base; + + // Get key from sealed blob: + uint32_t guid_size = SGX_PCL_GUID_SIZE; + uint32_t key_size = SGX_AESGCM_KEY_SIZE; + + // Verify the buffer size: + if(PCL_SEALED_BLOB_SIZE != tbl->sealed_blob_size) + { + return SGX_ERROR_UNEXPECTED; + } + if(!(pcl_is_outside_enclave(sealed_blob, PCL_SEALED_BLOB_SIZE))) + { + return SGX_ERROR_UNEXPECTED; + } + + // LFENCE after boundary check + sgx_lfence(); + + // Copy sealed blob into enclave binary. + pcl_memcpy(tbl->sealed_blob, sealed_blob, PCL_SEALED_BLOB_SIZE); + + // Unseal the sealed blob: + ret = pcl_unseal_data( + (const sgx_sealed_data_t*)tbl->sealed_blob, // Sealed data + tbl->pcl_guid, // AAD buffer + &guid_size, // pointer to AAD buffer length + key, // Resulting key + &key_size); // Size of resulting key + if(SGX_SUCCESS != ret) + { + goto Label_erase_key; + } + if((sizeof(tbl->pcl_guid) != guid_size) || + (sizeof(key) != key_size )) + { + ret = SGX_ERROR_UNEXPECTED; + goto Label_erase_key; + } + + // Verify key hash matches: + ret = pcl_sha256(key, SGX_AESGCM_KEY_SIZE, hash); + if(SGX_SUCCESS != ret) + { + goto Label_erase_key; + } + memcmpret = pcl_consttime_memequal(hash, tbl->decryption_key_hash, sizeof(sgx_sha256_hash_t)); + pcl_volatile_memset((volatile void*)hash, 0, sizeof(sgx_sha256_hash_t)); // Scrub hash + if(1 != memcmpret) + { + ret = SGX_ERROR_PCL_SHA_MISMATCH; + goto Label_erase_key; + } + + for(uint32_t i = 0;i< tbl->num_rvas;i++) + { + size_t size = tbl->rvas_sizes_tags_ivs[i].size; + unsigned char* ciphertext = (unsigned char *)((uint64_t)elf_base + tbl->rvas_sizes_tags_ivs[i].rva); + unsigned char* plaintext = ciphertext; // decrypt in place + unsigned char* tag = (unsigned char *)&(tbl->rvas_sizes_tags_ivs[i].tag); + unsigned char* iv = (unsigned char *)&(tbl->rvas_sizes_tags_ivs[i].iv.val); + // Verify ciphertext is inside the enclave: + if(!(pcl_is_within_enclave(ciphertext, size))) + { + ret = SGX_ERROR_UNEXPECTED; + goto Label_erase_key; + } + ret = pcl_gcm_decrypt(plaintext, ciphertext, size, NULL, 0, key, iv, tag); + if(SGX_SUCCESS != ret) + { + goto Label_erase_key; + } + } + + // Return success: + ret = SGX_SUCCESS; + +Label_erase_key: + // Erase key: + pcl_volatile_memset((volatile void*)key, 0, sizeof(sgx_aes_gcm_128bit_key_t)); + tbl->pcl_state = PCL_DONE; + return ret; +} + +/* + * @func pcl_bswap32 swaps a 32bit value endianity + * @param uint32_t val, input value + * @return uint32_t, val in opposite endianity + */ +uint32_t pcl_bswap32(uint32_t val) +{ + uint32_t ret=(val); + asm ("bswap %0":"+r"(ret)); + return ret; +} + diff --git a/sdk/protected_code_loader/pcl_internal.h b/sdk/protected_code_loader/pcl_internal.h new file mode 100644 index 00000000..33bc4c04 --- /dev/null +++ b/sdk/protected_code_loader/pcl_internal.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef SGX_PCL_INTERNAL_H +#define SGX_PCL_INTERNAL_H + +#define ALIGN_X2Y_AUX(x,y) \ + (x % y ? x + y - (x % y) : x) +#define ALIGN_X2Y(x,y) ALIGN_X2Y_AUX((x),(y)) +#define CASTU8P(x) ((uint8_t*)(x)) +#define CAST_VOLATILE_U8P(x) ((volatile uint8_t*)(x)) +#define CASTU64(x) ((uint64_t)(x)) +#define ROUND_TO(x,y) ALIGN_X2Y(x,y) +#define MAX(x,y) ((x)>(y)?(x):(y)) +#define assert(x) + + + +#ifdef __cplusplus +extern "C" { +#endif // #ifdef __cplusplus + +void pcl_memcpy(OUT void* dst, IN void* src, size_t size); +void pcl_memset(OUT void* dst, uint8_t val, size_t size); +void pcl_volatile_memset(OUT volatile void* dst, uint8_t val, size_t size); +// code taken from consttime_memequal +uint32_t pcl_consttime_memequal(IN const void *b1, IN const void *b2, size_t len); + +int pcl_decrypt( + IN unsigned char *ciphertext, + size_t ciphertext_len, + IN unsigned char *aad, + size_t aad_len, + IN unsigned char *tag, + IN unsigned char *key, + IN unsigned char *iv, + OUT unsigned char *plaintext); + +sgx_status_t pcl_sha256(IN uint8_t* buf, size_t buflen, OUT uint8_t* hash); +sgx_status_t pcl_unseal_data( + IN const sgx_sealed_data_t *p_sealed_data, + IN uint8_t *p_additional_MACtext, + INOUT uint32_t *p_additional_MACtext_length, + OUT uint8_t *p_decrypted_text, + INOUT uint32_t *p_decrypted_text_length); +sgx_status_t pcl_gcm_decrypt( + IN uint8_t* plaintext, + OUT uint8_t* ciphertext, + size_t textlen, + IN uint8_t* aad, + size_t aad_len, + IN uint8_t* key, + IN uint8_t* iv, + IN uint8_t* tag); + +uint32_t pcl_bswap32(uint32_t val); +uint64_t pcl_bswap64(uint64_t val); + +sgx_status_t pcl_increment_iv(INOUT uint8_t* iv); + +void abort(void) __attribute__((__noreturn__)); + +int pcl_is_outside_enclave(const void *addr, size_t size); +int pcl_is_within_enclave(const void *addr, size_t size); +#ifdef __cplusplus +}; // extern "C" +#endif // #ifdef __cplusplus + +#endif // #ifndef SGX_PCL_INTERNAL_H + diff --git a/sdk/protected_code_loader/pcl_mem.cpp b/sdk/protected_code_loader/pcl_mem.cpp new file mode 100644 index 00000000..8c2fb76a --- /dev/null +++ b/sdk/protected_code_loader/pcl_mem.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * @func pcl_memcpy implements memcpy that can run before runtime initiazliation + * @param OUT void* dst, output destination buffer + * @param IN void* src, input source buffer + * @param size_t size, buffer size in bytes + */ +void pcl_memcpy(OUT void* dst, IN void* src, size_t size) +{ + if(NULL == dst || NULL == src)abort(); + for(size_t i=0;i> 8)); +} + +/* + * g_pcl_imagebase is set by PCL at runtime to ELF base address. + * It is used by functions pcl_is_outside_enclave and pcl_is_within_enclave + */ +extern uintptr_t g_pcl_imagebase; + +/* + * @func pcl_is_outside_enclave checks if buffer is completely outside the enclave + * @par IN const void* addr - the start address of the buffer + * @par size_t size - buffer size in bytes + * @return int + * 1 - the buffer is strictly outside the enclave + * 0 - the whole buffer or part of the buffer is not outside the enclave, + * or the buffer is wrap around + */ +int pcl_is_outside_enclave(IN const void *addr, size_t size) +{ + size_t start = (size_t)addr; + size_t end = 0; + size_t enclave_start = (size_t)g_pcl_imagebase; + size_t enclave_end = enclave_start + g_global_data.enclave_size - 1; + // g_global_data.enclave_end = enclave_base + enclave_size - 1; + // so the enclave range is [enclave_start, enclave_end] inclusively + + if(size > 0) + { + end = start + size - 1; + } + else + { + end = start; + } + + if( (start <= end) && ((end < enclave_start) || (start > enclave_end)) ) + { + return 1; + } + return 0; +} + +/* + * @func pcl_is_outside_enclave checks if buffer is completely inside the enclave + * @par IN const void* addr - the start address of the buffer + * @par size_t size - buffer size in bytes + * @return int + * 1 - the buffer is strictly within the enclave + * 0 - the whole buffer or part of the buffer is not within the enclave, + * or the buffer is wrap around + */ +int pcl_is_within_enclave(const void *addr, size_t size) +{ + size_t start = (size_t)addr; + size_t end = 0; + size_t enclave_start = (size_t)g_pcl_imagebase; + size_t enclave_end = enclave_start + g_global_data.enclave_size - 1; + // g_global_data.enclave_end = enclave_base + enclave_size - 1; + // so the enclave range is [enclave_start, enclave_end] inclusively + + if(size > 0) + { + end = start + size - 1; + } + else + { + end = start; + } + if( (start <= end) && (start >= enclave_start) && (end <= enclave_end) ) + { + return 1; + } + return 0; +} + diff --git a/sdk/protected_code_loader/unseal/pcl_sgx_get_key.cpp b/sdk/protected_code_loader/unseal/pcl_sgx_get_key.cpp new file mode 100644 index 00000000..067778da --- /dev/null +++ b/sdk/protected_code_loader/unseal/pcl_sgx_get_key.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/selib/sgx_get_key.cpp */ + +#include +#include +#include +#ifdef SE_SIM +#include +#endif // #ifdef SE_SIM +#include +#include +#include + +PCL_COMPILE_TIME_ASSERT(KEY_ALIGN_SIZE == SGX_AESGCM_KEY_SIZE) ; +PCL_COMPILE_TIME_ASSERT(sizeof(sgx_key_128bit_t) == SGX_AESGCM_KEY_SIZE) ; +PCL_COMPILE_TIME_ASSERT(KEY_REQUEST_ALIGN_SIZE == KEY_REQUEST_SIZE); +PCL_COMPILE_TIME_ASSERT(sizeof(sgx_key_request_t) == KEY_REQUEST_SIZE); +uint8_t ip1_buf[PCL_EGETKEY_BUFFER_SIZE]; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_sgx_get_key() +// Intel(R) SGX PCL version of sgx_get_key. +// It is requried because the Intel(R) SGX SDK is unavailable at +// this point +// Parameters: +// [IN] key_request - pointer to key_request structure +// [OUT] key - resulting key +// Return Value: +// SGX_SUCCESS or error codes +sgx_status_t pcl_sgx_get_key(IN const sgx_key_request_t *key_request, OUT sgx_key_128bit_t *key) +{ + sgx_status_t err = SGX_ERROR_UNEXPECTED; + void *buffer = NULL; + size_t size = 0, buf_ptr =0; + sgx_key_request_t *tmp_key_request = NULL; + sgx_key_128bit_t *tmp_key = NULL; + egetkey_status_t egetkey_status = EGETKEY_SUCCESS; + int i = 0; + + // check parameters + // + // key_request must be within the enclave + if(!key_request || !pcl_is_within_enclave(key_request, sizeof(*key_request))) + { + err = SGX_ERROR_INVALID_PARAMETER; + goto CLEANUP; + } + + if (key_request->reserved1 != 0) + { + err = SGX_ERROR_INVALID_PARAMETER; + goto CLEANUP; + } + + for (i=0; ireserved2[i] != 0) + { + err = SGX_ERROR_INVALID_PARAMETER; + goto CLEANUP; + } + } + + // key must be within the enclave + if(!key || !pcl_is_within_enclave(key, sizeof(*key))) + { + err = SGX_ERROR_INVALID_PARAMETER; + goto CLEANUP; + } + // check key_request->key_policy reserved bits + if(key_request->key_policy & ~(SGX_KEYPOLICY_MRENCLAVE | SGX_KEYPOLICY_MRSIGNER)) + { + err = SGX_ERROR_INVALID_PARAMETER; + goto CLEANUP; + } + + // allocate memory + // + // To minimize the effort of memory management, the two elements allocation + // are combined in a single malloc. The calculation for the required size has + // an assumption, that + // the elements should be allocated in descending order of the alignment size. + // + // If the alignment requirements are changed, the allocation order needs to + // change accordingly. + // + // Current allocation order is: + // key_request -> key + // + // key_request: 512-byte aligned, 512-byte length + // key: 16-byte aligned, 16-byte length + size = ROUND_TO(sizeof(*key_request), KEY_REQUEST_ALIGN_SIZE) + ROUND_TO(sizeof(*key), KEY_ALIGN_SIZE); + size += MAX(KEY_REQUEST_ALIGN_SIZE, KEY_ALIGN_SIZE) - 1; + + // There is no heap during Intel(R) SGX PCL execution. + // Must use global memory + buffer = &ip1_buf[0]; + pcl_memset(buffer, 0, size); + buf_ptr = reinterpret_cast(buffer); + + buf_ptr = ROUND_TO(buf_ptr, KEY_REQUEST_ALIGN_SIZE); + tmp_key_request = reinterpret_cast(buf_ptr); + buf_ptr += sizeof(*tmp_key_request); + + buf_ptr = ROUND_TO(buf_ptr, KEY_ALIGN_SIZE); + tmp_key = reinterpret_cast(buf_ptr); + + // Copy data from user buffer to the aligned memory + pcl_memcpy(tmp_key_request, (void*)key_request, sizeof(*tmp_key_request)); + + // Do EGETKEY +#ifndef SE_SIM + egetkey_status = (egetkey_status_t) do_egetkey(tmp_key_request, tmp_key); +#else + egetkey_status = (egetkey_status_t)pcl_egetkey(tmp_key_request,(uint8_t *)tmp_key); +#endif + switch(egetkey_status) + { + case EGETKEY_SUCCESS: + err = SGX_SUCCESS; + break; + case EGETKEY_INVALID_ATTRIBUTE: + err = SGX_ERROR_INVALID_ATTRIBUTE; + break; + case EGETKEY_INVALID_CPUSVN: + err = SGX_ERROR_INVALID_CPUSVN; + break; + case EGETKEY_INVALID_ISVSVN: + err = SGX_ERROR_INVALID_ISVSVN; + break; + case EGETKEY_INVALID_KEYNAME: + err = SGX_ERROR_INVALID_KEYNAME; + break; + default: + err = SGX_ERROR_UNEXPECTED; + break; + } + + +CLEANUP: + /* + * - If success, copy resulting key into key buffer. + * - In case of failure, leave the key buffer untouched becuase + * Intel(R) SGX PCL does not call sgx_read_rand. + */ + if((SGX_SUCCESS == err) && (NULL != key)) + { + // Copy data to the user buffer + pcl_memcpy(key, tmp_key, sizeof(*key)); + } + + // cleanup + if(buffer) + { + pcl_volatile_memset((volatile void*)buffer, 0, size); + } + + return err; +} diff --git a/sdk/protected_code_loader/unseal/pcl_tSeal.cpp b/sdk/protected_code_loader/unseal/pcl_tSeal.cpp new file mode 100644 index 00000000..667b2641 --- /dev/null +++ b/sdk/protected_code_loader/unseal/pcl_tSeal.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/tseal/tSeal.cpp */ + +#include +#include +#include +#ifdef SE_SIM +#include +#endif // #ifdef SE_SIM +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_unseal_data() +// PCL version of sgx_unseal_data (needed since the SGX SDK is unavailable at this point) +// Parameters: +// [IN] p_sealed_data - pointer to sealed key blob +// [OUT] p_additional_MACtext - additional text to MAC +// [IN] additional_MACtext_length - length of additional text +// [OUT] p_decrypted_text - buffer to fill with decrypted data +// [IN] decrypted_text_length - length of p_decrypted_text buffer +// Return Value: +// SGX_SUCCESS or error codes +sgx_status_t pcl_unseal_data(const sgx_sealed_data_t *p_sealed_data, uint8_t *p_additional_MACtext, + uint32_t *p_additional_MACtext_length, uint8_t *p_decrypted_text, uint32_t *p_decrypted_text_length) +{ + sgx_status_t err = SGX_ERROR_UNEXPECTED; + // Ensure the the sgx_sealed_data_t members are all inside enclave before using them. + if ((p_sealed_data == NULL) || (!pcl_is_within_enclave(p_sealed_data,sizeof(sgx_sealed_data_t)))) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + uint32_t encrypt_text_length = pcl_get_encrypt_txt_len(p_sealed_data); + if (encrypt_text_length == UINT32_MAX) + { + return SGX_ERROR_MAC_MISMATCH; // Return error indicating the blob is corrupted + } + uint32_t aad_text_length = pcl_get_aad_mac_txt_len(p_sealed_data); + if (aad_text_length == UINT32_MAX) + { + return SGX_ERROR_MAC_MISMATCH; // Return error indicating the blob is corrupted + } + uint32_t sealedDataSize = pcl_calc_sealed_data_size(aad_text_length, encrypt_text_length); + if (sealedDataSize == UINT32_MAX) + { + return SGX_ERROR_MAC_MISMATCH; // Return error indicating the blob is corrupted + } + + // + // Check parameters + // + // Ensure sealed data blob is within an enclave during the sealing process + if (!pcl_is_within_enclave(p_sealed_data,sealedDataSize)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + if ((aad_text_length > 0) && ((p_additional_MACtext == NULL) || (p_additional_MACtext_length == NULL))) + { + return SGX_ERROR_INVALID_PARAMETER; + } + if ((encrypt_text_length < 1) || (p_decrypted_text == NULL) || (p_decrypted_text_length == NULL)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + if (!pcl_is_within_enclave(p_decrypted_text,encrypt_text_length)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + if (!pcl_is_within_enclave(p_decrypted_text_length,sizeof(p_decrypted_text_length))) + { + return SGX_ERROR_INVALID_PARAMETER; + } + // Ensure aad data does not cross enclave boundary + if ((aad_text_length > 0) && + (!(pcl_is_within_enclave(p_additional_MACtext,aad_text_length) || pcl_is_outside_enclave(p_additional_MACtext, aad_text_length)))) + { + return SGX_ERROR_INVALID_PARAMETER; + } + if ((*p_decrypted_text_length) < encrypt_text_length) + { + return SGX_ERROR_INVALID_PARAMETER; + } + uint32_t additional_MACtext_length = (NULL != p_additional_MACtext_length) ? *p_additional_MACtext_length : 0; + if (additional_MACtext_length != aad_text_length) { + return SGX_ERROR_INVALID_PARAMETER; + } + + err = pcl_unseal_data_helper(p_sealed_data, p_additional_MACtext, aad_text_length, + p_decrypted_text, encrypt_text_length); + if (err == SGX_SUCCESS) + { + *p_decrypted_text_length = encrypt_text_length; + if (p_additional_MACtext_length != NULL) + *p_additional_MACtext_length = aad_text_length; + } + else + { + // Scrub p_decrypted_text + pcl_volatile_memset((volatile void*)p_decrypted_text, 0, encrypt_text_length); + } + return err; +} + diff --git a/sdk/protected_code_loader/unseal/pcl_tSeal_internal.cpp b/sdk/protected_code_loader/unseal/pcl_tSeal_internal.cpp new file mode 100644 index 00000000..1ff2b983 --- /dev/null +++ b/sdk/protected_code_loader/unseal/pcl_tSeal_internal.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/tseal/tSeal_internal.cpp */ + +#include +#include +#include +#ifdef SE_SIM +#include +#endif // #ifdef SE_SIM +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_unseal_data_helper() +// helper function for pcl_unseal_data, does the actual decryption and MAC compare +// Parameters: +// [IN] p_sealed_data - pointer to sealed key blob +// [OUT] p_additional_MACtext - additional text to MAC +// [IN] additional_MACtext_length - length of additional text +// [OUT] p_decrypted_text - buffer to fill with decrypted data +// [IN] decrypted_text_length - length of p_decrypted_text buffer +// Return Value: +// SGX_SUCCESS or error codes +sgx_status_t pcl_unseal_data_helper(const sgx_sealed_data_t *p_sealed_data, uint8_t *p_additional_MACtext, + uint32_t additional_MACtext_length, uint8_t *p_decrypted_text, uint32_t decrypted_text_length) +{ + // code based on tSeal_internal.cpp in tseal library + + sgx_status_t err = SGX_ERROR_UNEXPECTED; + sgx_key_128bit_t seal_key; + pcl_memset(&seal_key, 0, sizeof(sgx_key_128bit_t)); + uint8_t payload_iv[SGX_SEAL_IV_SIZE]; + pcl_memset(&payload_iv, 0, SGX_SEAL_IV_SIZE); + const uint8_t* p_aad = NULL; + uint32_t res = 0; + sgx_aes_gcm_128bit_tag_t mac; + //uint8_t mac[16]; + + if (decrypted_text_length > 0) + pcl_memset(p_decrypted_text, 0, decrypted_text_length); + + if (additional_MACtext_length > 0) + { + // Verify GUID in sealed blob matches GUID in PCL table: + p_aad = const_cast(&(p_sealed_data->aes_data.payload[decrypted_text_length])); + if (pcl_consttime_memequal(p_aad, p_additional_MACtext, additional_MACtext_length) == 0) + { + return SGX_ERROR_PCL_GUID_MISMATCH; + } + pcl_memset(p_additional_MACtext, 0, additional_MACtext_length); + } + + // Get the seal key + err = pcl_sgx_get_key(&p_sealed_data->key_request, &seal_key); + if (err != SGX_SUCCESS) + { + // Provide only error codes that the calling code could act on + if ((err != SGX_ERROR_INVALID_CPUSVN) && (err != SGX_ERROR_INVALID_ISVSVN)) + err = SGX_ERROR_MAC_MISMATCH; + goto out; + } + err = pcl_gcm_decrypt( + (uint8_t*)p_decrypted_text, + (uint8_t*)p_sealed_data->aes_data.payload, + decrypted_text_length, + (uint8_t*)p_aad, + additional_MACtext_length, + (uint8_t*)(&seal_key), + (uint8_t*)(&payload_iv[0]), + (uint8_t*)(p_sealed_data->aes_data.payload_tag)); + + if (SGX_SUCCESS != err) + { + // Scrub p_decrypted_text + pcl_volatile_memset((volatile void*)p_decrypted_text, 0, decrypted_text_length); + goto out; + } + + err = SGX_SUCCESS; +out: + // Scrub seal_key + pcl_volatile_memset((volatile void*)(&seal_key), 0, sizeof(sgx_key_128bit_t)); + return err; +} + diff --git a/sdk/protected_code_loader/unseal/pcl_tSeal_util.cpp b/sdk/protected_code_loader/unseal/pcl_tSeal_util.cpp new file mode 100644 index 00000000..573065d2 --- /dev/null +++ b/sdk/protected_code_loader/unseal/pcl_tSeal_util.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/tseal/tSeal_util.cpp */ + +#include +#include +#include +#ifdef SE_SIM +#include +#endif // #ifdef SE_SIM +#include +#include +#include + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_calc_sealed_data_size() +// computes sealedDataSize = payload size + sizeof(sgx_sealed_data_t) +// Parameters: +// [IN] aad_mac_txt_size - optional additional data size +// [IN] txt_encrypt_size - the actual encrypted data (payload) +// Return Value: +// sealedDataSize +uint32_t pcl_calc_sealed_data_size(const uint32_t aad_mac_txt_size, const uint32_t txt_encrypt_size) +{ + // code copied from tseal_util.cpp from the tseal library + if (aad_mac_txt_size > UINT32_MAX - txt_encrypt_size) + return UINT32_MAX; + uint32_t payload_size = aad_mac_txt_size + txt_encrypt_size; //Calculate the payload size + + if (payload_size > UINT32_MAX - sizeof(sgx_sealed_data_t)) + return UINT32_MAX; + return (uint32_t)(sizeof(sgx_sealed_data_t) + payload_size); +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_get_aad_mac_txt_len() +// computes optional additional data size +// Parameters: +// [IN] p_sealed_data - pointer to the sealed blob +// Return Value: +// additional data size +uint32_t pcl_get_aad_mac_txt_len(const sgx_sealed_data_t* p_sealed_data) +{ + if (p_sealed_data == NULL) + return UINT32_MAX; + + uint32_t data_size = p_sealed_data->aes_data.payload_size - p_sealed_data->plain_text_offset; + if (data_size > p_sealed_data->aes_data.payload_size) + return UINT32_MAX; + return data_size; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// pcl_get_encrypt_txt_len() +// computes encrypted data size +// Parameters: +// [IN] p_sealed_data - pointer to the sealed blob +// Return Value: +// encrypted data size +uint32_t pcl_get_encrypt_txt_len(const sgx_sealed_data_t* p_sealed_data) +{ + return ((p_sealed_data == NULL) ? UINT32_MAX : p_sealed_data->plain_text_offset); +} + diff --git a/sdk/protected_code_loader/unseal/pcl_unseal_internal.h b/sdk/protected_code_loader/unseal/pcl_unseal_internal.h new file mode 100644 index 00000000..e1ca9914 --- /dev/null +++ b/sdk/protected_code_loader/unseal/pcl_unseal_internal.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Includes common to PCL unsealing files*/ + +#ifndef SGX_PCL_UNSEAL_INTERNAL_H +#define SGX_PCL_UNSEAL_INTERNAL_H + +#define BIT_ERROR(x) (1 << (x)) + + +// Key request defines: +#define KEY_ALIGN_SIZE (16) +#define KEY_REQUEST_SIZE (512) +#define KEY_REQUEST_ALIGN_SIZE (512) +#define PCL_EGETKEY_BUFFER_SIZE (2 * KEY_REQUEST_ALIGN_SIZE + KEY_ALIGN_SIZE - 1) +PCL_COMPILE_TIME_ASSERT(KEY_REQUEST_ALIGN_SIZE >= KEY_ALIGN_SIZE); + +extern "C" +{ + +extern uint8_t ip1_buf[]; + +int do_egetkey(const sgx_key_request_t *key_request, sgx_key_128bit_t *key); + +sgx_status_t pcl_unseal_data_helper(const sgx_sealed_data_t *p_sealed_data, uint8_t *p_additional_MACtext, + uint32_t additional_MACtext_length, uint8_t *p_decrypted_text, uint32_t decrypted_text_length); +sgx_status_t pcl_sgx_get_key(const sgx_key_request_t *key_request, sgx_key_128bit_t *key); +// Typedefs: +typedef enum _egetkey_status_t +{ + EGETKEY_SUCCESS = 0, + EGETKEY_INVALID_ATTRIBUTE = BIT_ERROR(1), + EGETKEY_INVALID_CPUSVN = BIT_ERROR(5), + EGETKEY_INVALID_ISVSVN = BIT_ERROR(6), + EGETKEY_INVALID_KEYNAME = BIT_ERROR(8), +} egetkey_status_t; + +uint32_t pcl_calc_sealed_data_size(const uint32_t aad_mac_txt_size, const uint32_t txt_encrypt_size); +uint32_t pcl_get_aad_mac_txt_len(const sgx_sealed_data_t* p_sealed_data); +uint32_t pcl_get_encrypt_txt_len(const sgx_sealed_data_t* p_sealed_data); + +#ifdef SE_SIM + +egetkey_status_t pcl_egetkey(sgx_key_request_t* kr, sgx_key_128bit_t okey); +void pcl_derive_key(const derivation_data_t* dd, sgx_key_128bit_t okey); + +#endif // #ifdef SE_SIM + +}; // extern "C" + +#endif // #ifndef SGX_PCL_UNSEAL_INTERNAL_H + diff --git a/sdk/protected_code_loader/unseal/sim/pcl_deriv.cpp b/sdk/protected_code_loader/unseal/sim/pcl_deriv.cpp new file mode 100644 index 00000000..bf7fc020 --- /dev/null +++ b/sdk/protected_code_loader/unseal/sim/pcl_deriv.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/simulation/tinst/deriv.cpp */ + +#include "t_instructions.h" /* for `g_global_data_sim' */ +#include "deriv.h" +#include +#include +#include + +extern global_data_sim_t g_global_data_sim; + +int pcl_cmac(const sgx_cmac_128bit_key_t *p_key, const uint8_t *p_src, + uint32_t src_len, sgx_cmac_128bit_tag_t *p_mac); + +// The built-in seal key in simulation mode +static const uint8_t PCL_BASE_SEAL_KEY[] = { + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, +}; + +static const uint8_t* pcl_get_base_key(uint16_t key_name) +{ + // Shouldn't use switch else requires relocation +/* PCL UNUSED START * + switch (key_name) { + case SGX_KEYSELECT_SEAL: + return BASE_SEAL_KEY; + case SGX_KEYSELECT_REPORT: + return BASE_REPORT_KEY; + case SGX_KEYSELECT_EINITTOKEN: + return BASE_EINITTOKEN_KEY; + case SGX_KEYSELECT_PROVISION: + return BASE_PROVISION_KEY; + case SGX_KEYSELECT_PROVISION_SEAL: + return BASE_PROV_SEAL_KEY; + } +/* PCL UNUSED END */ + if (key_name == SGX_KEYSELECT_SEAL) return PCL_BASE_SEAL_KEY; + + // Should not come here - error should have been reported + // when the key name is not supported in the caller. + return (uint8_t*)0; +} + +// Compute the CMAC of derivation data with corresponding base key +// and save it to `okey'. +void pcl_derive_key(const derivation_data_t* dd, sgx_key_128bit_t okey) +{ + const uint8_t* base_key = pcl_get_base_key(dd->key_name); + pcl_cmac((const sgx_cmac_128bit_key_t*)base_key,dd->ddbuf, dd->size, (sgx_cmac_128bit_tag_t*)okey); +} + diff --git a/sdk/protected_code_loader/unseal/sim/pcl_t_instructions.cpp b/sdk/protected_code_loader/unseal/sim/pcl_t_instructions.cpp new file mode 100644 index 00000000..0696b668 --- /dev/null +++ b/sdk/protected_code_loader/unseal/sim/pcl_t_instructions.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Content from sdk/simulation/tinst/t_instructions.cpp */ + +#include "t_instructions.h" /* for `g_global_data_sim' */ +#include "deriv.h" +#include +#include "pcl_common.h" +#include "pcl_internal.h" +#include "pcl_unseal_internal.h" + +//////////////////////////////////////////////////////////////////////// +// Simulation for EGETKEY +//////////////////////////////////////////////////////////////////////// + +// The hard-coded OwnerEpoch. +static const se_owner_epoch_t SIMU_OWNER_EPOCH_MSR = { + 0x54, 0x48, 0x49, 0x53, 0x49, 0x53, 0x4f, 0x57, + 0x4e, 0x45, 0x52, 0x45, 0x50, 0x4f, 0x43, 0x48, +}; + +static const sgx_cpu_svn_t PCL_DEFAULT_CPUSVN = { + { + 0x48, 0x20, 0xf3, 0x37, 0x6a, 0xe6, 0xb2, 0xf2, + 0x03, 0x4d, 0x3b, 0x7a, 0x4b, 0x48, 0xa7, 0x78 + } +}; + +static const sgx_cpu_svn_t PCL_UPGRADED_CPUSVN = { + { + 0x53, 0x39, 0xae, 0x8c, 0x93, 0xae, 0x8f, 0x3c, + 0xe4, 0x32, 0xdb, 0x92, 0x4d, 0x0f, 0x07, 0x33 + } +}; + +static const sgx_cpu_svn_t PCL_DOWNGRADED_CPUSVN = { + { + 0x64, 0xea, 0x4f, 0x3f, 0xa0, 0x03, 0x0c, 0x36, + 0x38, 0x3c, 0x32, 0x2d, 0x4f, 0x3a, 0x8d, 0x4f + } +}; + +egetkey_status_t pcl_check_cpu_svn(sgx_key_request_t* kr) +{ + if(!pcl_consttime_memequal(&kr->cpu_svn, (void*)&PCL_UPGRADED_CPUSVN, sizeof(PCL_UPGRADED_CPUSVN)) && + !pcl_consttime_memequal(&kr->cpu_svn, (void*)&PCL_DEFAULT_CPUSVN, sizeof(PCL_DEFAULT_CPUSVN)) && + !pcl_consttime_memequal(&kr->cpu_svn, (void*)&PCL_DOWNGRADED_CPUSVN, sizeof(PCL_DOWNGRADED_CPUSVN))){ + return EGETKEY_INVALID_CPUSVN; + } + if ( (pcl_consttime_memequal(&g_global_data_sim.cpusvn_sim, (void*)&PCL_DEFAULT_CPUSVN, sizeof(PCL_DEFAULT_CPUSVN)) && + pcl_consttime_memequal(&kr->cpu_svn, (void*)&PCL_UPGRADED_CPUSVN, sizeof(PCL_UPGRADED_CPUSVN))) || + (pcl_consttime_memequal(&g_global_data_sim.cpusvn_sim, (void*)&PCL_DOWNGRADED_CPUSVN, sizeof(PCL_DOWNGRADED_CPUSVN)) && + !pcl_consttime_memequal(&kr->cpu_svn, (void*)&PCL_DOWNGRADED_CPUSVN, sizeof(PCL_DOWNGRADED_CPUSVN)))){ + return EGETKEY_INVALID_CPUSVN; + } + return EGETKEY_SUCCESS; +} + + +#define check_attr_flag(secs, flag) do { \ + if ((secs->attributes.flags & flag) == 0) { \ + return EGETKEY_INVALID_ATTRIBUTE; \ + } \ +} while(0) + + +// The hardware EGETKEY instruction will set ZF on failure. +// +// In simulation mode, we can not guarentee that the ZF is always set +// between _EGETKEY ending its life and tRTS testing ZF. Since there +// are additional assembly code in between. +// +// In simulation mode, we check return code instead of ZF. +// c.f. do_egetkey() in trts/linux/trts_pic.S +# define GP() return ((egetkey_status_t)-1) +#define GP_ON(cond) do { if (unlikely(cond)) GP(); } while (0) + +egetkey_status_t pcl_check_isv_svn(sgx_key_request_t* kr, secs_t* secs) +{ + if (kr->isv_svn > secs->isv_svn) { + return EGETKEY_INVALID_ISVSVN; + } + return EGETKEY_SUCCESS; +} + +egetkey_status_t pcl_egetkey(sgx_key_request_t* kr, sgx_key_128bit_t okey) +{ + // check alignment of KEYREQUEST + GP_ON(((size_t)kr & (KEY_REQUEST_ALIGN_SIZE - 1)) != 0); + + // check to see if KEYREQEUST is inside the current enclave + ////GP_ON(!sgx_is_within_enclave(kr, sizeof(sgx_key_request_t))); + + // check alignment of OUTPUTDATA + GP_ON(((size_t)okey & (KEY_ALIGN_SIZE - 1)) != 0); + + // check to see if OUTPUTDATA is inside the current enclave + ////GP_ON(!sgx_is_within_enclave(okey, sizeof(sgx_key_128bit_t))); + + // check reserved bits are not set + GP_ON((kr->key_policy & ~(SGX_KEYPOLICY_MRENCLAVE | SGX_KEYPOLICY_MRSIGNER)) != 0); + + // check to see if reserved space in KEYREQUEST are valid + const uint8_t* u8ptr = (uint8_t *)(&(kr->reserved1)); + for (unsigned i = 0; i < sizeof(kr->reserved1); ++i) + GP_ON(u8ptr[i] != (uint8_t)0); + + u8ptr = (uint8_t *)(&(kr->reserved2)); + for (unsigned i = 0; i < sizeof(kr->reserved2); ++i) + GP_ON(u8ptr[i] != (uint8_t)0); + + secs_t* cur_secs = g_global_data_sim.secs_ptr; + sgx_attributes_t tmp_attr; + derivation_data_t dd; + + pcl_memset(&dd, 0, sizeof(dd)); + dd.key_name = kr->key_name; + + // Determine which enclave attributes that must be included in the key. + // Attributes that must always be included INIT & DEBUG. + pcl_memset(&tmp_attr, 0, sizeof(tmp_attr)); + tmp_attr.flags = kr->attribute_mask.flags | SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG; + tmp_attr.flags &= cur_secs->attributes.flags; + tmp_attr.xfrm = kr->attribute_mask.xfrm & cur_secs->attributes.xfrm; + // HW supports CPUSVN to be set as 0. + // To be consistent with HW behaviour, we replace the cpusvn as DEFAULT_CPUSVN if the input cpusvn is 0. + if(pcl_consttime_memequal(&kr->cpu_svn, &dd.ddpk.cpu_svn, sizeof(sgx_cpu_svn_t))) + { + pcl_memcpy(&kr->cpu_svn, (void*)&DEFAULT_CPUSVN, sizeof(sgx_cpu_svn_t)); + } + + // Must not use swich else relocations + /* PCL UNUSED START * + switch (kr->key_name) { + case SGX_KEYSELECT_SEAL: + /* PCL UNUSED END */ + egetkey_status_t esa = pcl_check_isv_svn(kr, cur_secs); + if(EGETKEY_SUCCESS != esa)return esa; + esa = pcl_check_cpu_svn(kr); + if(EGETKEY_SUCCESS != esa)return esa; + // assemble derivation data + dd.size = sizeof(dd_seal_key_t); + if (kr->key_policy & SGX_KEYPOLICY_MRENCLAVE) { + pcl_memcpy(&dd.ddsk.mrenclave, &cur_secs->mr_enclave, sizeof(sgx_measurement_t)); + } + + if (kr->key_policy & SGX_KEYPOLICY_MRSIGNER) { + pcl_memcpy(&dd.ddsk.mrsigner, (void*)&cur_secs->mr_signer, sizeof(sgx_measurement_t)); + } + + pcl_memcpy(&dd.ddsk.tmp_attr, &tmp_attr, sizeof(sgx_attributes_t)); + pcl_memcpy(&dd.ddsk.attribute_mask, &kr->attribute_mask, sizeof(sgx_attributes_t)); + pcl_memcpy(dd.ddsk.csr_owner_epoch, (void*)SIMU_OWNER_EPOCH_MSR, sizeof(se_owner_epoch_t)); + pcl_memcpy(&dd.ddsk.cpu_svn,&kr->cpu_svn,sizeof(sgx_cpu_svn_t)); + dd.ddsk.isv_svn = kr->isv_svn; + dd.ddsk.isv_prod_id = cur_secs->isv_prod_id; + pcl_memcpy(&dd.ddsk.key_id, &kr->key_id, sizeof(sgx_key_id_t)); + + +/* PCL UNUSED START * + default: + return EGETKEY_INVALID_KEYNAME; + } +/* PCL UNUSED END */ + pcl_derive_key(&dd, okey); + return EGETKEY_SUCCESS; +} diff --git a/sdk/sample_libcrypto/Makefile b/sdk/sample_libcrypto/Makefile index f2479fc0..48f6d9b8 100644 --- a/sdk/sample_libcrypto/Makefile +++ b/sdk/sample_libcrypto/Makefile @@ -38,11 +38,18 @@ CXXFLAGS += -Werror -fno-rtti -fno-exceptions -fPIC CPPFLAGS := -isystem $(SGX_IPP_INC) \ -I$(COMMON_DIR)/inc/internal/ +CFLAGS += -fPIC -Werror -fno-exceptions -I$(SGX_IPP_INC) + LDFLAGS := -Bdynamic -L$(IPP_LIBS_DIR) $(LD_IPP) LDFLAGS += $(COMMON_LDFLAGS) -Wl,--version-script,sample_libcrypto.lds -Wl,--gc-sections OBJS := sample_libcrypto.o +IPPDISP_DIR := $(LINUX_SDK_DIR)/tlibcrypto/ipp/ipp_disp +C_SRC := $(wildcard $(IPPDISP_DIR)/*.c) +C_OBJS := $(patsubst $(IPPDISP_DIR)/%.c, %.o, $(C_SRC)) +C_OBJS := $(sort $(C_OBJS)) + LIBSAMPLECRYPTO := libsample_libcrypto.so $(BUILD_DIR): @@ -52,15 +59,18 @@ $(BUILD_DIR): all: $(LIBSAMPLECRYPTO) | $(BUILD_DIR) @$(CP) $< $| -$(LIBSAMPLECRYPTO): $(OBJS) +$(LIBSAMPLECRYPTO): $(OBJS) $(C_OBJS) $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(LIBSAMPLECRYPTO) $< -o $@ $(LDFLAGS) +$(C_OBJS): %.o: $(IPPDISP_DIR)/%.c + $(CC) $(CFLAGS) -c $< -o $@ + $(OBJS): %.o: %.cpp $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ .PHONY: clean clean: - @$(RM) $(OBJS) $(LIBSAMPLECRYPTO) $(BUILD_DIR)/$(LIBSAMPLECRYPTO) + @$(RM) $(OBJS) $(C_OBJS) $(LIBSAMPLECRYPTO) $(BUILD_DIR)/$(LIBSAMPLECRYPTO) .PHONY: rebuild rebuild: diff --git a/sdk/sample_libcrypto/sample_libcrypto.cpp b/sdk/sample_libcrypto/sample_libcrypto.cpp index 7e65db11..e000f928 100644 --- a/sdk/sample_libcrypto/sample_libcrypto.cpp +++ b/sdk/sample_libcrypto/sample_libcrypto.cpp @@ -228,7 +228,7 @@ static void sample_ipp_secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) return; } -IppStatus __STDCALL sample_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx_unused) +IppStatus IPP_STDCALL sample_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx_unused) { sample_status_t sample_ret; UNUSED(pCtx_unused); diff --git a/sdk/sign_tool/SignTool/manage_metadata.cpp b/sdk/sign_tool/SignTool/manage_metadata.cpp index 3d840861..bdebf2f5 100644 --- a/sdk/sign_tool/SignTool/manage_metadata.cpp +++ b/sdk/sign_tool/SignTool/manage_metadata.cpp @@ -512,9 +512,8 @@ bool CMetadata::build_layout_table() memset(&guard_page, 0, sizeof(guard_page)); guard_page.entry.id = LAYOUT_ID_GUARD; guard_page.entry.page_count = SE_GUARD_PAGE_SIZE >> SE_PAGE_SHIFT; - - size_t thread_start; - size_t thread_end; + + vector thread_layouts; // heap layout.entry.id = LAYOUT_ID_HEAP_MIN; layout.entry.page_count = (uint32_t)(m_create_param.heap_min_size >> SE_PAGE_SHIFT); @@ -540,33 +539,32 @@ bool CMetadata::build_layout_table() m_layouts.push_back(layout); } - // thread context memory layout - // guard page | stack | TCS | SSA | guard page | TLS - thread_start = m_layouts.size(); - //ulitity tcs + // guard page | stack | guard page | TCS | SSA | guard page | TLS + + // vector 'thread_layouts' serves as a template for thread context // guard page - m_layouts.push_back(guard_page); + thread_layouts.push_back(guard_page); // stack if(m_create_param.stack_max_size > m_create_param.stack_min_size) { layout.entry.id = LAYOUT_ID_STACK_MAX; layout.entry.page_count = (uint32_t)((m_create_param.stack_max_size - m_create_param.stack_min_size) >> SE_PAGE_SHIFT); - layout.entry.attributes = PAGE_ATTR_EADD | PAGE_ATTR_EEXTEND | PAGE_DIR_GROW_DOWN; // | PAGE_ATTR_POST_ADD | PAGE_ATTR_POST_REMOVE; + layout.entry.attributes = PAGE_ATTR_EADD | PAGE_ATTR_EEXTEND | PAGE_DIR_GROW_DOWN; layout.entry.si_flags = SI_FLAGS_RW; layout.entry.content_size = 0xCCCCCCCC; - m_layouts.push_back(layout); + thread_layouts.push_back(layout); } layout.entry.id = LAYOUT_ID_STACK_MIN; layout.entry.page_count = (uint32_t)(m_create_param.stack_min_size >> SE_PAGE_SHIFT); layout.entry.attributes = PAGE_ATTR_EADD | PAGE_ATTR_EEXTEND; layout.entry.si_flags = SI_FLAGS_RW; layout.entry.content_size = 0xCCCCCCCC; - m_layouts.push_back(layout); + thread_layouts.push_back(layout); // guard page - m_layouts.push_back(guard_page); + thread_layouts.push_back(guard_page); // tcs layout.entry.id = LAYOUT_ID_TCS; @@ -576,23 +574,23 @@ bool CMetadata::build_layout_table() tcs_t *tcs_template = (tcs_t *) alloc_buffer_from_metadata(TCS_TEMPLATE_SIZE); if(tcs_template == NULL) { - se_trace(SE_TRACE_ERROR, INVALID_ENCLAVE_ERROR); + se_trace(SE_TRACE_ERROR, INVALID_ENCLAVE_ERROR); return false; } - layout.entry.content_offset = (uint32_t)PTR_DIFF(tcs_template, m_metadata), + layout.entry.content_offset = (uint32_t)PTR_DIFF(tcs_template, m_metadata), layout.entry.content_size = TCS_TEMPLATE_SIZE; - m_layouts.push_back(layout); + thread_layouts.push_back(layout); memset(&layout, 0, sizeof(layout)); - // ssa + // ssa layout.entry.id = LAYOUT_ID_SSA; layout.entry.page_count = SSA_FRAME_SIZE * SSA_NUM; layout.entry.attributes = PAGE_ATTR_EADD | PAGE_ATTR_EEXTEND; layout.entry.si_flags = SI_FLAGS_RW; - m_layouts.push_back(layout); + thread_layouts.push_back(layout); // guard page - m_layouts.push_back(guard_page); + thread_layouts.push_back(guard_page); // td layout.entry.id = LAYOUT_ID_TD; @@ -604,10 +602,16 @@ bool CMetadata::build_layout_table() } layout.entry.attributes = PAGE_ATTR_EADD | PAGE_ATTR_EEXTEND; layout.entry.si_flags = SI_FLAGS_RW; - m_layouts.push_back(layout); + thread_layouts.push_back(layout); + + // adding utility thread context, part of its stack can be added and removed dynamically + for (auto l : thread_layouts) + { + if (l.entry.id == LAYOUT_ID_STACK_MAX) + l.entry.attributes |= PAGE_ATTR_POST_ADD | PAGE_ATTR_POST_REMOVE; + m_layouts.push_back(l); + } - thread_end = m_layouts.size(); - uint32_t tcs_min_pool = 0; uint32_t tcs_eremove = 0; if(m_create_param.tcs_min_pool > m_create_param.tcs_num - 1) @@ -621,66 +625,67 @@ bool CMetadata::build_layout_table() tcs_eremove = m_create_param.tcs_num -1 - m_create_param.tcs_min_pool; } - //tcs to fill the tcs mini pool + // adding thread contexts corresponding to tcs_min_pool if (tcs_min_pool > 0) { - // group for static thread contexts - memset(&layout, 0, sizeof(layout)); - layout.group.id = LAYOUT_ID_THREAD_GROUP; - layout.group.entry_count = (uint16_t)(thread_end - thread_start); - layout.group.load_times = tcs_min_pool; - m_layouts.push_back(layout); + auto end = m_layouts.end(); + m_layouts.insert(end, thread_layouts.begin(), thread_layouts.end()); + + if (tcs_min_pool > 1) + { + // group for tcs min pool + memset(&layout, 0, sizeof(layout)); + layout.group.id = LAYOUT_ID_THREAD_GROUP; + layout.group.entry_count = (uint16_t)(thread_layouts.size()); + layout.group.load_times = tcs_min_pool - 1; + m_layouts.push_back(layout); + } } - - //tcs will be eremoved + // adding thread contexts corresponding to tcs_eremove if (tcs_eremove > 0) { - for(size_t i = thread_start; i < thread_end; i++) - { - layout = m_layouts[i]; - if(layout.entry.id != LAYOUT_ID_GUARD) + for(auto l : thread_layouts) + { + if(l.entry.id != LAYOUT_ID_GUARD) { - layout.entry.attributes |= PAGE_ATTR_EREMOVE; + l.entry.attributes |= PAGE_ATTR_EREMOVE; } - m_layouts.push_back(layout); + m_layouts.push_back(l); } if (tcs_eremove > 1) { memset(&layout, 0, sizeof(layout)); layout.group.id = LAYOUT_ID_THREAD_GROUP; - layout.group.entry_count = (uint16_t)(thread_end - thread_start); - layout.group.load_times = tcs_eremove-1; + layout.group.entry_count = (uint16_t)(thread_layouts.size()); + layout.group.load_times = tcs_eremove - 1; m_layouts.push_back(layout); } } - // dynamic thread contexts + // dynamic thread contexts if (m_create_param.tcs_max_num > tcs_min_pool + 1) { - for(size_t i = thread_start; i < thread_end; i++) + for(auto l : thread_layouts) { - layout = m_layouts[i]; - if(layout.entry.id == LAYOUT_ID_STACK_MAX) + if(l.entry.id == LAYOUT_ID_STACK_MAX) { - layout.entry.id = (uint16_t)(LAYOUT_ID_HEAP_DYN_MIN - LAYOUT_ID_HEAP_MIN + layout.entry.id); - layout.entry.attributes = PAGE_ATTR_POST_ADD | PAGE_DIR_GROW_DOWN; + l.entry.id = (uint16_t)(LAYOUT_ID_HEAP_DYN_MIN - LAYOUT_ID_HEAP_MIN + l.entry.id); + l.entry.attributes = PAGE_ATTR_POST_ADD | PAGE_DIR_GROW_DOWN; } - else if(layout.entry.id != LAYOUT_ID_GUARD) + else if(l.entry.id != LAYOUT_ID_GUARD) { - layout.entry.id = (uint16_t)(LAYOUT_ID_HEAP_DYN_MIN - LAYOUT_ID_HEAP_MIN + layout.entry.id); - layout.entry.attributes = PAGE_ATTR_POST_ADD | PAGE_ATTR_DYN_THREAD; + l.entry.id = (uint16_t)(LAYOUT_ID_HEAP_DYN_MIN - LAYOUT_ID_HEAP_MIN + l.entry.id); + l.entry.attributes = PAGE_ATTR_POST_ADD | PAGE_ATTR_DYN_THREAD; } - m_layouts.push_back(layout); + m_layouts.push_back(l); } + // dynamic thread group - if (m_create_param.tcs_max_num > m_create_param.tcs_min_pool) - { - memset(&layout, 0, sizeof(layout)); - layout.group.id = LAYOUT_ID_THREAD_GROUP_DYN; - layout.group.entry_count = (uint16_t)(thread_end - thread_start); - layout.group.load_times = m_create_param.tcs_max_num - tcs_min_pool - 1; - m_layouts.push_back(layout); - } + memset(&layout, 0, sizeof(layout)); + layout.group.id = LAYOUT_ID_THREAD_GROUP_DYN; + layout.group.entry_count = (uint16_t)(thread_layouts.size()); + layout.group.load_times = m_create_param.tcs_max_num - tcs_min_pool - 1; + m_layouts.push_back(layout); } // update layout entries diff --git a/sdk/sign_tool/SignTool/sign_tool.cpp b/sdk/sign_tool/SignTool/sign_tool.cpp index 94494d8d..d320b1c4 100644 --- a/sdk/sign_tool/SignTool/sign_tool.cpp +++ b/sdk/sign_tool/SignTool/sign_tool.cpp @@ -76,6 +76,14 @@ #include #define SIGNATURE_SIZE 384 +#define REL_ERROR_BIT 0x1 +#define INIT_SEC_ERROR_BIT 0x2 + +#define IGNORE_REL_ERROR(x) (((x) & REL_ERROR_BIT) != 0) +#define IGNORE_INIT_SEC_ERROR(x) (((x) & INIT_SEC_ERROR_BIT) != 0) + + + typedef enum _file_path_t { @@ -134,7 +142,7 @@ static bool get_enclave_info(BinParser *parser, bin_fmt_t *bf, uint64_t * meta_o // measure_enclave(): // 1. Get the enclave hash by loading enclave // 2. Get the enclave info - metadata offset and enclave file format -static bool measure_enclave(uint8_t *hash, const char *dllpath, const xml_parameter_t *parameter, bool ignore_rel_error, metadata_t *metadata, uint64_t *meta_offset) +static bool measure_enclave(uint8_t *hash, const char *dllpath, const xml_parameter_t *parameter, uint32_t ignore_error_bits, metadata_t *metadata, uint64_t *meta_offset) { assert(hash && dllpath && metadata && meta_offset); bool res = false; @@ -167,6 +175,12 @@ static bool measure_enclave(uint8_t *hash, const char *dllpath, const xml_parame close_handle(fh); return false; } + if(parser->has_init_section() && IGNORE_INIT_SEC_ERROR(ignore_error_bits) == false) + { + se_trace(SE_TRACE_ERROR, INIT_SEC_ERROR); + close_handle(fh); + return false; + } // generate metadata CMetadata meta(metadata, parser.get()); @@ -191,7 +205,7 @@ static bool measure_enclave(uint8_t *hash, const char *dllpath, const xml_parame { no_rel = ElfHelper<32>::dump_textrels(parser.get()); } - if(no_rel == false && ignore_rel_error == false) + if(no_rel == false && (IGNORE_REL_ERROR(ignore_error_bits) == false)) { close_handle(fh); se_trace(SE_TRACE_ERROR, TEXT_REL_ERROR); @@ -531,7 +545,7 @@ static bool gen_enclave_signing_file(const enclave_css_t *enclave_css, const cha return true; } -static bool cmdline_parse(unsigned int argc, char *argv[], int *mode, const char **path, bool *ignore_rel_error) +static bool cmdline_parse(unsigned int argc, char *argv[], int *mode, const char **path, uint32_t *ignore_error_bits) { assert(mode!=NULL && path != NULL); if(argc<2) @@ -612,37 +626,42 @@ static bool cmdline_parse(unsigned int argc, char *argv[], int *mode, const char se_trace(SE_TRACE_ERROR, UNREC_CMD_ERROR, argv[1]); return false; } - unsigned int err_idx = 2; - for(; err_idx < argc; err_idx++) - { - if(!STRCMP(argv[err_idx], "-ignore-rel-error")) - break; - } - - unsigned int params_count = (unsigned)(sizeof(params_sign)/sizeof(params_sign[0])); - unsigned int params_count_min = 0; - unsigned int params_count_max =0; - for(unsigned int i=0; i< params_count; i++) - { - params_count_max ++; - if(params[tempmode][i].flag == PAR_REQUIRED) - params_count_min ++; - } - unsigned int additional_param = 2; - if(err_idx != argc) - additional_param++; - if(argcparams_count_max * 2 + additional_param) - return false; + uint32_t ie_bits = 0; - for(unsigned int i=2; i=params_count_max) + if(j == params_count) { + se_trace(SE_TRACE_ERROR, UNREC_OPTION_ERROR, argv[i]); return false; } } - for(unsigned int i = 0; i < params_count; i ++) + for(unsigned int i = 0; i < params_count; i++) { if(params[tempmode][i].flag == PAR_REQUIRED && params[tempmode][i].value == NULL) { @@ -683,13 +704,13 @@ static bool cmdline_parse(unsigned int argc, char *argv[], int *mode, const char return false; } } + // Set output parameters for(unsigned int i = 0; i < params_count; i++) { path[i] = params[tempmode][i].value; } *mode = tempmode; - if(err_idx != argc) - *ignore_rel_error = true; + *ignore_error_bits = ie_bits; return true; } @@ -773,30 +794,51 @@ static bool generate_output(int mode, int ktype, const uint8_t *enclave_hash, co #include "se_page_attr.h" static void metadata_cleanup(metadata_t *metadata, uint32_t size_to_reduce) { + layout_t *heap_max = NULL, *heap_init = NULL, *ut_stack_max = NULL; metadata->dirs[DIR_LAYOUT].size -= size_to_reduce; metadata->size -= size_to_reduce; - //if there exists LAYOUT_ID_HEAP_MAX, modify it so that it won't be included in the MRENCLAVE layout_t *start = GET_PTR(layout_t, metadata, metadata->dirs[DIR_LAYOUT].offset); layout_t *end = GET_PTR(layout_t, start, metadata->dirs[DIR_LAYOUT].size); for (layout_t *l = start; l < end; l++) { - if (l->entry.id == LAYOUT_ID_HEAP_MAX) - { - l->entry.si_flags = SI_FLAG_NONE; - l->entry.attributes &= (uint16_t)(~PAGE_ATTR_POST_ADD); + if (heap_max != NULL && heap_init != NULL && ut_stack_max != NULL) break; + + if ((heap_max == NULL) && (l->entry.id == LAYOUT_ID_HEAP_MAX)) + { + heap_max = l; + continue; + } + if ((heap_init == NULL) && (l->entry.id == LAYOUT_ID_HEAP_INIT)) + { + heap_init = l; + continue; + } + if ((ut_stack_max == NULL) && (l->entry.id == LAYOUT_ID_STACK_MAX)) + { + ut_stack_max = l; + continue; } } - //remove the PAGE_ATTR_POST_ADD attribute so that dynamic range won't be - //created during enclave loading time - for (layout_t *l = start; l < end; l++) + + // if there exists LAYOUT_ID_HEAP_MAX, modify it so that it won't be included + // in the MRENCLAVE, also remove the PAGE_ATTR_POST_ADD attribute so that + // dynamic range won't be created during enclave loading time + if (heap_max) { - if (l->entry.id == LAYOUT_ID_HEAP_INIT) - { - l->entry.attributes &= (uint16_t)(~PAGE_ATTR_POST_ADD); - break; - } + heap_max->entry.si_flags = SI_FLAG_NONE; + heap_max->entry.attributes &= (uint16_t)(~PAGE_ATTR_POST_ADD); + } + + if (heap_init) + { + heap_init->entry.attributes &= (uint16_t)(~PAGE_ATTR_POST_ADD); + } + + if (ut_stack_max) + { + ut_stack_max->entry.attributes &= (uint16_t)(~PAGE_ATTR_POST_ADD); } } @@ -825,7 +867,7 @@ static bool append_compatible_metadata(metadata_t *compat_metadata, metadata_t * return true; } -static bool generate_compatible_metadata(metadata_t *metadata) +static bool generate_compatible_metadata(metadata_t *metadata, const xml_parameter_t *parameter) { metadata_t *metadata2 = (metadata_t *)malloc(metadata->size); if(!metadata2) @@ -861,6 +903,7 @@ static bool generate_compatible_metadata(metadata_t *metadata) } } + // no dynamic layout, append the metadata directly if (first_dyn_entry == NULL) { ret = append_compatible_metadata(metadata2, metadata); @@ -892,52 +935,35 @@ static bool generate_compatible_metadata(metadata_t *metadata) return ret; } - //We have some static threads + layout_t *utility_start = NULL; + for (layout_t *l = start; l <= last; l++) + { + if (l->entry.id == LAYOUT_ID_GUARD) + { + utility_start = l; + break; + } + } + assert(utility_start != NULL); + + // entry/group layout if they all exist: + // utility thread | minpool thread | minpool group | eremove thread | eremove group | dyn thread | dyn group + + // build a group layout to represent all the possible minpool/eremoved layouts first = &utility_td[1]; + uint16_t num_of_entries = (uint16_t)(first - utility_start); - if (first->group.id == LAYOUT_ID_THREAD_GROUP) + memset(&tmp_layout, 0, sizeof(tmp_layout)); + tmp_layout.group.id = LAYOUT_ID_THREAD_GROUP; + tmp_layout.group.entry_count = num_of_entries; + tmp_layout.group.load_times = (uint32_t)parameter[TCSNUM].value - 1; + for (uint32_t i = 0; i < tmp_layout.group.entry_count; i++) { - if (last->group.id == LAYOUT_ID_THREAD_GROUP) - { - //utility thread | thread group for min pool | eremove thread | eremove thread group - if (first != last) - first->group.load_times += last->group.load_times + 1; - - //utility thread | thread group for min pool - } - //utility thread | thread group for min pool | eremove thread - else - { - first->group.load_times += 1; - } - size_to_reduce += (uint32_t)((size_t)last - (size_t)first); + tmp_layout.group.load_step += (((uint64_t)utility_start[i].entry.page_count) << SE_PAGE_SHIFT); } - else - { - memset(&tmp_layout, 0, sizeof(tmp_layout)); - tmp_layout.group.id = LAYOUT_ID_THREAD_GROUP; - //utility thread | eremove thread | eremove thread group - if (last->group.id == LAYOUT_ID_THREAD_GROUP) - { - tmp_layout.group.entry_count = (uint16_t)(((size_t)last - (size_t)first) / sizeof(layout_t)); - tmp_layout.group.load_times = last->group.load_times + 1; - } - //utility thread | eremove thread - else - { - tmp_layout.group.entry_count = (uint16_t)(((size_t)last - (size_t)first) / sizeof(layout_t) + 1); - tmp_layout.group.load_times = 1; - } - - for (uint32_t i = 0; i < tmp_layout.group.entry_count; i++) - { - tmp_layout.group.load_step += (((uint64_t)first[i].entry.page_count) << SE_PAGE_SHIFT); - } - memcpy_s(first, sizeof(layout_t), &tmp_layout, sizeof(layout_t)); - size_to_reduce += (uint32_t)((size_t)last - (size_t)first); - } - + memcpy_s(first, sizeof(layout_t), &tmp_layout, sizeof(layout_t)); + size_to_reduce += (uint32_t)((size_t)last - (size_t)first); metadata_cleanup(metadata2, size_to_reduce); ret = append_compatible_metadata(metadata2, metadata); free(metadata2); @@ -1032,20 +1058,20 @@ int main(int argc, char* argv[]) int key_type = UNIDENTIFIABLE_KEY; //indicate the type of the input key file size_t parameter_count = sizeof(parameter)/sizeof(parameter[0]); uint64_t meta_offset = 0; - bool ignore_rel_error = false; + uint32_t ignore_error_bits = 0; RSA *rsa = NULL; memset(&metadata_raw, 0, sizeof(metadata_raw)); -#if OPENSSL_VERSION_NUMBER < 0x10100000L + +#if OPENSSL_VERSION_NUMBER < 0x10100000L OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); #else OPENSSL_init_crypto(0, NULL); #endif - //Parse command line - if(cmdline_parse(argc, argv, &mode, path, &ignore_rel_error) == false) + if(cmdline_parse(argc, argv, &mode, path, &ignore_error_bits) == false) { se_trace(SE_TRACE_ERROR, USAGE_STRING); goto clear_return; @@ -1086,8 +1112,7 @@ int main(int argc, char* argv[]) goto clear_return; } - ignore_rel_error = true; - if(measure_enclave(enclave_hash, path[OUTPUT], parameter, ignore_rel_error, metadata, &meta_offset) == false) + if(measure_enclave(enclave_hash, path[OUTPUT], parameter, ignore_error_bits, metadata, &meta_offset) == false) { se_trace(SE_TRACE_ERROR, OVERALL_ERROR); goto clear_return; @@ -1106,7 +1131,7 @@ int main(int argc, char* argv[]) se_trace(SE_TRACE_ERROR, OVERALL_ERROR); goto clear_return; } - if(false == generate_compatible_metadata(metadata)) + if(false == generate_compatible_metadata(metadata, parameter)) { se_trace(SE_TRACE_ERROR, OVERALL_ERROR); goto clear_return; diff --git a/sdk/sign_tool/SignTool/util_st.h b/sdk/sign_tool/SignTool/util_st.h index ef1a038b..134531f7 100644 --- a/sdk/sign_tool/SignTool/util_st.h +++ b/sdk/sign_tool/SignTool/util_st.h @@ -40,30 +40,34 @@ #define USAGE_STRING \ "\nUsage: sgx_sign [options] file...\n"\ "Commands:\n"\ - " sign Sign the enclave using the private key\n"\ - " gendata Generate enclave signing material to be signed\n"\ - " catsig Generate the signed enclave with the input signature file, the\n"\ - " public key and the enclave signing material\n"\ - " dump Dump metadata information for a signed enclave file\n"\ + " sign Sign the enclave using the private key\n"\ + " gendata Generate enclave signing material to be signed\n"\ + " catsig Generate the signed enclave with the input signature file, the\n"\ + " public key and the enclave signing material\n"\ + " dump Dump metadata information for a signed enclave file\n"\ "Options:\n"\ - " -enclave Specify the enclave file to be signed or already signed\n"\ - " It is a required option for the four commands\n"\ - " -key Specify the key file\n"\ - " It is a required option for \"sign\" and \"catsig\"\n"\ - " -config Specify the configuration for the enclave\n"\ - " -out Specify the output file\n"\ - " It is a required option for \"sign\", \"gendata\" and \"catsig\"\n"\ - " -sig Specify the signature file for the enclave signing material\n" \ - " It is a required option for \"catsig\"\n"\ - " -unsigned Specify the enclave signing material generated by \"gendata\"\n" \ - " It is a required option for \"catsig\"\n" \ - " -dumpfile Specify a file to dump metadata information (text format)\n" \ - " It is a required option for \"dump\"\n" \ - " -cssfile Specify a file to dump the enclave SIGSTRUCT information (binary format)\n" \ - " -ignore-rel-error By default, sgx_sign provides an error for enclaves with\n" \ - " text relocations. You can ignore the error and continue signing\n" \ - " by providing this option. But it is recommended you eliminate the\n" \ - " text relocations instead of bypassing the error with this option.\n\n" \ + " -enclave Specify the enclave file to be signed or already signed\n"\ + " It is a required option for the four commands\n"\ + " -key Specify the key file\n"\ + " It is a required option for \"sign\" and \"catsig\"\n"\ + " -config Specify the configuration for the enclave\n"\ + " -out Specify the output file\n"\ + " It is a required option for \"sign\", \"gendata\" and \"catsig\"\n"\ + " -sig Specify the signature file for the enclave signing material\n" \ + " It is a required option for \"catsig\"\n"\ + " -unsigned Specify the enclave signing material generated by \"gendata\"\n" \ + " It is a required option for \"catsig\"\n" \ + " -dumpfile Specify a file to dump metadata information (text format)\n" \ + " It is a required option for \"dump\"\n" \ + " -cssfile Specify a file to dump the enclave SIGSTRUCT information (binary format)\n" \ + " -ignore-rel-error By default, sgx_sign provides an error for enclaves with\n" \ + " text relocations. You can ignore the error and continue signing\n" \ + " by providing this option. But it is recommended you eliminate the\n" \ + " text relocations instead of bypassing the error with this option.\n" \ + " -ignore-init-sec-error By default, sgx_sign provides an error for enclaves with .init section.\n" \ + " You can ignore the error and continue signing by providing this option.\n" \ + " But it is recommended you eliminate the section instead of bypassing\n" \ + " the error with this option.\n\n" \ "Run \"sgx_sign -help\" to get this help and exit.\n" \ "Run \"sgx_sign -version\" to output version information and exit.\n\n" @@ -88,6 +92,7 @@ #define INVALID_ENCLAVE_ERROR "The input enclave file is not correct.\n" #define REQUIRED_ENCLAVE_SIZE "The required memory is %lluB.\n" #define TEXT_REL_ERROR "The enclave image has text relocations.\n" +#define INIT_SEC_ERROR "The enclave image has .init section.\n" // error message for fill_enclave_css() #define UNSIGNED_FILE_ERROR "The unsigned file \"%s\" is not correct.\n" @@ -103,6 +108,7 @@ #define INVALID_FILE_NAME_ERROR "The File name is not correct for \"%s\" option.\n" #define LACK_REQUIRED_OPTION_ERROR "Option \"%s\" is required for the command \"%s\".\n" #define GIVE_INVALID_OPTION_ERROR "Option \"%s\" is invalid for the command \"%s\".\n" +#define UNREC_OPTION_ERROR "Cannot recognize the option \"%s\".\n" // error message for generate_output() #define LACK_PRI_KEY_ERROR "Private key is required for the \"sign\" command.\n" diff --git a/sdk/simulation/assembly/linux/lowlib.S b/sdk/simulation/assembly/linux/lowlib.S index e6481f59..acbd2966 100644 --- a/sdk/simulation/assembly/linux/lowlib.S +++ b/sdk/simulation/assembly/linux/lowlib.S @@ -34,7 +34,7 @@ .file "lowlib.S" - .text +.section .nipx,"ax",@progbits DECLARE_LOCAL_FUNC get_bp mov %xbp, %xax diff --git a/sdk/simulation/tinst/t_instructions.cpp b/sdk/simulation/tinst/t_instructions.cpp index d597da0f..0dcd8158 100644 --- a/sdk/simulation/tinst/t_instructions.cpp +++ b/sdk/simulation/tinst/t_instructions.cpp @@ -283,6 +283,9 @@ static void _EREPORT(const sgx_target_info_t* ti, const sgx_report_data_t* rd, s //////////////////////////////////////////////////////////////////////// +static void +_EEXIT(uintptr_t dest, uintptr_t xcx, uintptr_t xdx, uintptr_t xsi, uintptr_t xdi) __attribute__((section(".nipx"))); + static void _EEXIT(uintptr_t dest, uintptr_t xcx, uintptr_t xdx, uintptr_t xsi, uintptr_t xdi) { diff --git a/sdk/simulation/tinst/t_instructions.h b/sdk/simulation/tinst/t_instructions.h index 8e1ab72a..c28808b6 100644 --- a/sdk/simulation/tinst/t_instructions.h +++ b/sdk/simulation/tinst/t_instructions.h @@ -43,7 +43,7 @@ extern "C" { extern SE_DECLSPEC_EXPORT global_data_sim_t g_global_data_sim; uintptr_t _SE3(uintptr_t xax, uintptr_t xbx, uintptr_t xcx, - uintptr_t xdx, uintptr_t xsi, uintptr_t xdi); + uintptr_t xdx, uintptr_t xsi, uintptr_t xdi) __attribute__((section(".nipx"))); #ifdef __cplusplus } diff --git a/sdk/simulation/uae_service_sim/linux/Makefile b/sdk/simulation/uae_service_sim/linux/Makefile index 9b375b25..85caf55a 100644 --- a/sdk/simulation/uae_service_sim/linux/Makefile +++ b/sdk/simulation/uae_service_sim/linux/Makefile @@ -38,7 +38,7 @@ INCLUDES := -I.. \ -I$(LINUX_SDK_DIR)/tseal \ -I$(LINUX_SDK_DIR)/simulation/tinst \ -I$(LINUX_SDK_DIR)/simulation/urtssim \ - -I$(LINUX_EXTERNAL_DIR)/epid-sdk-3.0.0 \ + -I$(LINUX_EXTERNAL_DIR)/epid-sdk \ -I$(LINUX_EXTERNAL_DIR)/rdrand/ \ -I$(LINUX_PSW_DIR)/ae/inc \ -I$(LINUX_PSW_DIR)/ae/inc/internal \ diff --git a/sdk/simulation/uinst/td_mngr.h b/sdk/simulation/uinst/td_mngr.h index 5daf8c0f..ea8599a8 100644 --- a/sdk/simulation/uinst/td_mngr.h +++ b/sdk/simulation/uinst/td_mngr.h @@ -64,7 +64,7 @@ extern "C" { #include "gnu_tls.h" extern uint8_t __ImageBase; int td_mngr_set_td(void *enclave_base, tcs_t *tcs); -int td_mngr_restore_td(tcs_t *tcs); +int td_mngr_restore_td(tcs_t *tcs) __attribute__((section (".nipx"))); #ifdef __cplusplus } diff --git a/sdk/simulation/urtssim/enclave_creator_sim.cpp b/sdk/simulation/urtssim/enclave_creator_sim.cpp index 57d19d7d..3b1c39bb 100644 --- a/sdk/simulation/urtssim/enclave_creator_sim.cpp +++ b/sdk/simulation/urtssim/enclave_creator_sim.cpp @@ -245,6 +245,7 @@ int EnclaveCreatorSim::initialize(sgx_enclave_id_t enclave_id) info.cpu_features = 0; get_cpu_features(&info.cpu_features, (unsigned int*)info.cpuinfo_table); info.version = SDK_VERSION_1_5; + info.sealed_key = enclave->get_sealed_key(); status = enclave->ecall(ECMD_INIT_ENCLAVE, NULL, reinterpret_cast(&info)); //free the tcs used by initialization; enclave->get_thread_pool()->reset(); diff --git a/sdk/simulation/urtssim/urts_deploy.c b/sdk/simulation/urtssim/urts_deploy.c index f1fa8bc6..e4dca8a2 100644 --- a/sdk/simulation/urtssim/urts_deploy.c +++ b/sdk/simulation/urtssim/urts_deploy.c @@ -38,6 +38,12 @@ sgx_status_t sgx_create_enclave() return SGX_ERROR_UNEXPECTED; } +sgx_status_t sgx_create_encrypted_enclave() +{ + printf("Please use the correct uRTS library from PSW package.\n"); + return SGX_ERROR_UNEXPECTED; +} + void sgx_debug_load_state_add_element(){}; void sgx_debug_unload_state_remove_element(){}; void sgx_destroy_enclave(){}; diff --git a/sdk/tlibcrypto/Makefile b/sdk/tlibcrypto/Makefile index b59bc7fe..4ee1a5d7 100644 --- a/sdk/tlibcrypto/Makefile +++ b/sdk/tlibcrypto/Makefile @@ -72,9 +72,15 @@ LIB_NAME := libsgx_tcrypto_sgxssl.a else CPPFLAGS += -I$(SGX_IPP_INC) -OBJ += sgx_ecc256_common.o sgx_rsa_internal.o +CFLAGS += $(CPPFLAGS) $(ENCLAVE_CFLAGS) $(SGX_COMMON_CFLAGS) -Werror -fno-exceptions -fPIC + +OBJ += sgx_tcrypto_common.o sgx_rsa_internal.o SRCDIR := ipp +C_Files := $(wildcard $(SRCDIR)/ipp_disp/*.c) +C_OBJS := $(C_Files:.c=.o) +C_OBJS := $(sort $(C_OBJS)) + LIB_NAME := libsgx_tcrypto_ipp.a endif #!($(USE_OPT_LIBS), 1) @@ -98,14 +104,10 @@ $(TARGET): PREPRARE_SGX_SSL $(RM) -r $(BUILD_DIR)/.libs else -$(TARGET): $(OBJ) $(SHARED_OBJ) - $(MKDIR) $(BUILD_DIR)/.libippcore - $(RM) $(BUILD_DIR)/.libippcore/* - cd $(BUILD_DIR)/.libippcore && $(AR) x $(IPP_LIBS_DIR)/libippcore.a +$(TARGET): $(OBJ) $(SHARED_OBJ) $(C_OBJS) @$(CP) $(IPP_LIBS_DIR)/libippcp.a $(LIB_NAME) - $(AR) rsD $(LIB_NAME) $(OBJ) $(SHARED_OBJ) $(BUILD_DIR)/.libippcore/*.o + $(AR) rsD $(LIB_NAME) $(OBJ) $(SHARED_OBJ) $(C_OBJS) $(CP) $(LIB_NAME) $@ - $(RM) -r $(BUILD_DIR)/.libippcore endif #!($(USE_OPT_LIBS), 1) @@ -124,7 +126,7 @@ all: $(TARGET) | $(BUILD_DIR) .PHONY: clean clean: - @$(RM) *.o ipp/*.o sgxssl/*.o $(TARGET) $(BUILD_DIR)/$(TARGET) $(LIB_NAME) + @$(RM) *.o ipp/*.o ipp/ipp_disp/*.o sgxssl/*.o $(TARGET) $(BUILD_DIR)/$(TARGET) $(LIB_NAME) .PHONY: rebuild rebuild: diff --git a/sdk/tlibcrypto/ipp/init_tcrypto_lib.cpp b/sdk/tlibcrypto/ipp/init_tcrypto_lib.cpp index 1adf1111..91f00cf1 100644 --- a/sdk/tlibcrypto/ipp/init_tcrypto_lib.cpp +++ b/sdk/tlibcrypto/ipp/init_tcrypto_lib.cpp @@ -32,7 +32,6 @@ #include "sgx_tcrypto.h" #include "ippcp.h" -#include "ippcore.h" #include "se_cpu_feature.h" #include "se_cdefs.h" @@ -121,8 +120,8 @@ extern "C" sgx_status_t sgx_init_crypto_lib(uint64_t cpu_feature_indicator, uint } // Call SetCpuFeatures() to set the IPP library with the collected CPU features - ippCpuFeatures |= ippCPUID_NOCHECK; /* Force ippSetCpuFeatures to set CPU features without check */ - error_code = ippSetCpuFeatures(ippCpuFeatures); + ippCpuFeatures |= ippCPUID_NOCHECK; /* Force ippcpSetCpuFeatures to set CPU features without check */ + error_code = ippcpSetCpuFeatures(ippCpuFeatures); if (error_code != ippStsNoErr) { return SGX_ERROR_INVALID_PARAMETER; diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c new file mode 100644 index 00000000..d4246314 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppLibraryVersion*, y8_ippcpGetLibVersion, (void) ) +IPPAPI( const IppLibraryVersion*, l9_ippcpGetLibVersion, (void) ) + +IPPFUN( const IppLibraryVersion*,sgx_disp_ippcpGetLibVersion, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippcpGetLibVersion( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippcpGetLibVersion( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppLibraryVersion*, p8_ippcpGetLibVersion, (void) ) +IPPAPI( const IppLibraryVersion*, h9_ippcpGetLibVersion, (void) ) + +IPPFUN( const IppLibraryVersion*,sgx_disp_ippcpGetLibVersion, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippcpGetLibVersion( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippcpGetLibVersion( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c new file mode 100644 index 00000000..e3964e51 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDESGetSize,(int *size)) +IPPAPI(IppStatus, l9_ippsDESGetSize,(int *size)) + +IPPFUN(IppStatus,sgx_disp_ippsDESGetSize,(int *size)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDESGetSize( size ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDESGetSize( size ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDESGetSize,(int *size)) +IPPAPI(IppStatus, h9_ippsDESGetSize,(int *size)) + +IPPFUN(IppStatus,sgx_disp_ippsDESGetSize,(int *size)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDESGetSize( size ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDESGetSize( size ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c new file mode 100644 index 00000000..cd9542f0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDESInit( pKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDESInit( pKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, h9_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDESInit( pKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDESInit( pKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c new file mode 100644 index 00000000..231505e1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDESPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDESPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDESPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDESPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c new file mode 100644 index 00000000..d676b18e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDESUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDESUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, h9_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDESUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDESUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c new file mode 100644 index 00000000..37be47d0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESEncryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESEncryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESEncryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESEncryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c new file mode 100644 index 00000000..cefe8c46 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESDecryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESDecryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESDecryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESDecryptECB( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c new file mode 100644 index 00000000..366a34ed --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESEncryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESEncryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESEncryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESEncryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c new file mode 100644 index 00000000..78aa2c9c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESDecryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESDecryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int length, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESDecryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESDecryptCBC( pSrc, pDst, length, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c new file mode 100644 index 00000000..dd567379 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESEncryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESEncryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESEncryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESEncryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c new file mode 100644 index 00000000..87bc9092 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESDecryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESDecryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, h9_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int length, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESDecryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESDecryptCFB( pSrc, pDst, length, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c new file mode 100644 index 00000000..9a69bbd1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c new file mode 100644 index 00000000..6ee16307 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c new file mode 100644 index 00000000..cbe38703 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c new file mode 100644 index 00000000..aea78234 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c new file mode 100644 index 00000000..b923e673 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESGetSize,(int *pSize)) +IPPAPI(IppStatus, l9_ippsAESGetSize,(int *pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESGetSize,(int *pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESGetSize,(int *pSize)) +IPPAPI(IppStatus, h9_ippsAESGetSize,(int *pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESGetSize,(int *pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c new file mode 100644 index 00000000..26fd68c3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, h9_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c new file mode 100644 index 00000000..c63ee25b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESSetKey( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESSetKey( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, h9_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESSetKey( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESSetKey( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c new file mode 100644 index 00000000..8e0b1f53 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) +IPPAPI(IppStatus, l9_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESPack( pCtx, pBuffer, buffSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESPack( pCtx, pBuffer, buffSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) +IPPAPI(IppStatus, h9_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int buffSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESPack( pCtx, pBuffer, buffSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESPack( pCtx, pBuffer, buffSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c new file mode 100644 index 00000000..0936a23e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESUnpack( pBuffer, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESUnpack( pBuffer, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, h9_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESUnpack( pBuffer, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESUnpack( pBuffer, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c new file mode 100644 index 00000000..7c01f449 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +IPPAPI(IppStatus, h9_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c new file mode 100644 index 00000000..8f2f3e14 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +IPPAPI(IppStatus, h9_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c new file mode 100644 index 00000000..17e5bee7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c new file mode 100644 index 00000000..097e0ad6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c new file mode 100644 index 00000000..c1de9f4b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c new file mode 100644 index 00000000..6749ccf3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c new file mode 100644 index 00000000..eaaa5170 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c new file mode 100644 index 00000000..9df66590 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c new file mode 100644 index 00000000..ef0afe28 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c new file mode 100644 index 00000000..1ffe134c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c new file mode 100644 index 00000000..10e889f1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c new file mode 100644 index 00000000..4e1f79bb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c new file mode 100644 index 00000000..962898fd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c new file mode 100644 index 00000000..97f4dca8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c new file mode 100644 index 00000000..7f95a50a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c new file mode 100644 index 00000000..8a25fcbb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c new file mode 100644 index 00000000..fd180b07 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +IPPAPI(IppStatus, l9_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +IPPAPI(IppStatus, h9_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c new file mode 100644 index 00000000..110b405e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +IPPAPI(IppStatus, l9_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +IPPAPI(IppStatus, h9_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) + +IPPFUN(IppStatus,sgx_disp_ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, const Ipp8u* pTweakPT, const Ipp8u* pKey, int keyBitsize, int dataUnitBitsize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c new file mode 100644 index 00000000..d1f2247e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4GetSize,(int *pSize)) +IPPAPI(IppStatus, l9_ippsSMS4GetSize,(int *pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4GetSize,(int *pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4GetSize,(int *pSize)) +IPPAPI(IppStatus, h9_ippsSMS4GetSize,(int *pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4GetSize,(int *pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c new file mode 100644 index 00000000..22282a83 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +IPPAPI(IppStatus, h9_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c new file mode 100644 index 00000000..c8252959 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4SetKey( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4SetKey( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4SetKey( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4SetKey( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c new file mode 100644 index 00000000..e94793c5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c new file mode 100644 index 00000000..52285e90 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c new file mode 100644 index 00000000..550a3cae --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c new file mode 100644 index 00000000..38b859ed --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c new file mode 100644 index 00000000..dafca9b4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c new file mode 100644 index 00000000..72f7b43d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c new file mode 100644 index 00000000..dfa41507 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c new file mode 100644 index 00000000..0b99212f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c new file mode 100644 index 00000000..164d30a8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c new file mode 100644 index 00000000..3b943569 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c new file mode 100644 index 00000000..4ee80e45 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c new file mode 100644 index 00000000..7fb8ea37 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c new file mode 100644 index 00000000..0877a89d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c new file mode 100644 index 00000000..dd4082f1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c new file mode 100644 index 00000000..4d9cb221 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c new file mode 100644 index 00000000..3f70da9d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, l9_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, h9_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c new file mode 100644 index 00000000..8b3eb88b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c new file mode 100644 index 00000000..e367c817 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c new file mode 100644 index 00000000..dc0dca16 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMMessageLen( msgLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMMessageLen( msgLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMMessageLen( msgLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMMessageLen( msgLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c new file mode 100644 index 00000000..d1921e0b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMTagLen( tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMTagLen( tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMTagLen( tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMTagLen( tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c new file mode 100644 index 00000000..9c6b32b0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c new file mode 100644 index 00000000..c44f51dd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c new file mode 100644 index 00000000..ed2bcdcd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c new file mode 100644 index 00000000..cf7f6b96 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c new file mode 100644 index 00000000..5f3624cd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsAES_CCMGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsAES_CCMGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c new file mode 100644 index 00000000..6ff63f73 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) +IPPAPI(IppStatus, h9_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMInit( pKey, keyLen, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c new file mode 100644 index 00000000..d5e6e340 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMMessageLen( msgLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMMessageLen( msgLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMMessageLen( msgLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMMessageLen( msgLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c new file mode 100644 index 00000000..b1556b98 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMTagLen( tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMTagLen( tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMTagLen( tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMTagLen( tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c new file mode 100644 index 00000000..0e457309 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c new file mode 100644 index 00000000..f6e9c2c0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMEncrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c new file mode 100644 index 00000000..7e24b06b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMDecrypt( pSrc, pDst, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c new file mode 100644 index 00000000..a3cb6864 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CCMGetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CCMGetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) +IPPAPI(IppStatus, h9_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CCMGetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CCMGetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c new file mode 100644 index 00000000..3e6eb30a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMGetSize,(int * pSize)) +IPPAPI(IppStatus, l9_ippsAES_GCMGetSize,(int * pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMGetSize,(int * pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMGetSize,(int * pSize)) +IPPAPI(IppStatus, h9_ippsAES_GCMGetSize,(int * pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMGetSize,(int * pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c new file mode 100644 index 00000000..9beee372 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) +IPPAPI(IppStatus, h9_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c new file mode 100644 index 00000000..672b2c5a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMReset,(IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMReset( pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMReset( pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMReset,(IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMReset( pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMReset( pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c new file mode 100644 index 00000000..b0e59119 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMProcessIV( pIV, ivLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMProcessIV( pIV, ivLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMProcessIV( pIV, ivLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMProcessIV( pIV, ivLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c new file mode 100644 index 00000000..87488bbe --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c new file mode 100644 index 00000000..37066abf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c new file mode 100644 index 00000000..f923df69 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c new file mode 100644 index 00000000..937f69cf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c new file mode 100644 index 00000000..8f338f1d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +IPPAPI(IppStatus, h9_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c new file mode 100644 index 00000000..bb18aa4c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_XTSGetSize,(int * pSize)) +IPPAPI(IppStatus, l9_ippsAES_XTSGetSize,(int * pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSGetSize,(int * pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_XTSGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_XTSGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_XTSGetSize,(int * pSize)) +IPPAPI(IppStatus, h9_ippsAES_XTSGetSize,(int * pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSGetSize,(int * pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_XTSGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_XTSGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c new file mode 100644 index 00000000..5f013874 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) +IPPAPI(IppStatus, l9_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) +IPPAPI(IppStatus, h9_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c new file mode 100644 index 00000000..7b51bb6a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +IPPAPI(IppStatus, l9_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +IPPAPI(IppStatus, h9_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c new file mode 100644 index 00000000..e7056e25 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +IPPAPI(IppStatus, l9_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +IPPAPI(IppStatus, h9_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, const IppsAES_XTSSpec* pCtx, const Ipp8u* pTweak, int startCipherBlkNo)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c new file mode 100644 index 00000000..01aef61c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) +IPPAPI(IppStatus, l9_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) +IPPAPI(IppStatus, h9_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, Ipp8u* pV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c new file mode 100644 index 00000000..ed5fc10d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) +IPPAPI(IppStatus, l9_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) +IPPAPI(IppStatus, h9_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, Ipp8u* pSIV, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c new file mode 100644 index 00000000..d2e03682 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) +IPPAPI(IppStatus, l9_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) +IPPAPI(IppStatus, h9_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int* pAuthPassed, const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, const Ipp8u* pAD[], const int pADlen[], int numAD, const Ipp8u* pSIV)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c new file mode 100644 index 00000000..0e5600b1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CMACGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsAES_CMACGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CMACGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CMACGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CMACGetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsAES_CMACGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CMACGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CMACGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c new file mode 100644 index 00000000..951cca8b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) +IPPAPI(IppStatus, h9_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c new file mode 100644 index 00000000..e598346d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CMACUpdate( pSrc, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CMACUpdate( pSrc, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, h9_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CMACUpdate( pSrc, len, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CMACUpdate( pSrc, len, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c new file mode 100644 index 00000000..0338ba4e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CMACFinal( pMD, mdLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CMACFinal( pMD, mdLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, h9_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CMACFinal( pMD, mdLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CMACFinal( pMD, mdLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c new file mode 100644 index 00000000..e622f0da --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAES_CMACGetTag( pMD, mdLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAES_CMACGetTag( pMD, mdLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +IPPAPI(IppStatus, h9_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) + +IPPFUN(IppStatus,sgx_disp_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAES_CMACGetTag( pMD, mdLen, pState ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAES_CMACGetTag( pMD, mdLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c new file mode 100644 index 00000000..3ca632c6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +IPPAPI(IppStatus, l9_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +IPPAPI(IppStatus, h9_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c new file mode 100644 index 00000000..abbbff93 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourGetSize, (int* pSize)) +IPPAPI(IppStatus, l9_ippsARCFourGetSize, (int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourGetSize, (int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourGetSize, (int* pSize)) +IPPAPI(IppStatus, h9_ippsARCFourGetSize, (int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourGetSize, (int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c new file mode 100644 index 00000000..68032252 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourInit( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourInit( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, h9_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourInit( pKey, keyLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourInit( pKey, keyLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c new file mode 100644 index 00000000..98264a58 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourReset, (IppsARCFourState* pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourReset, (IppsARCFourState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourReset, (IppsARCFourState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourReset( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourReset( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourReset, (IppsARCFourState* pCtx)) +IPPAPI(IppStatus, h9_ippsARCFourReset, (IppsARCFourState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourReset, (IppsARCFourState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourReset( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourReset( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c new file mode 100644 index 00000000..7c851374 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c new file mode 100644 index 00000000..719e1962 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +IPPAPI(IppStatus, h9_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c new file mode 100644 index 00000000..1a4d5c4e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, h9_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c new file mode 100644 index 00000000..53508373 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, h9_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c new file mode 100644 index 00000000..d47c2fcb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA1GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSHA1GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c new file mode 100644 index 00000000..d66a7433 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Init,(IppsSHA1State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA1Init,(IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Init,(IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Init,(IppsSHA1State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA1Init,(IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Init,(IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c new file mode 100644 index 00000000..9d627302 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Duplicate,(const IppsSHA1State* pSrcCtx, IppsSHA1State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c new file mode 100644 index 00000000..c6ca1496 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c new file mode 100644 index 00000000..3d62efa3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c new file mode 100644 index 00000000..677b885a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c new file mode 100644 index 00000000..af606e40 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c new file mode 100644 index 00000000..48aaba57 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c new file mode 100644 index 00000000..1160a41c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA1MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA1MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA1MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA1MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c new file mode 100644 index 00000000..2716300a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA224GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSHA224GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c new file mode 100644 index 00000000..a583237f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Init,(IppsSHA224State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA224Init,(IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Init,(IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Init,(IppsSHA224State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA224Init,(IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Init,(IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c new file mode 100644 index 00000000..265490ad --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Duplicate,(const IppsSHA224State* pSrcCtx, IppsSHA224State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c new file mode 100644 index 00000000..70ff3d50 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c new file mode 100644 index 00000000..76b32176 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c new file mode 100644 index 00000000..493c0be7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c new file mode 100644 index 00000000..547cff88 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c new file mode 100644 index 00000000..a95d27fd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c new file mode 100644 index 00000000..bc32e4d2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA224MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA224MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA224MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA224MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c new file mode 100644 index 00000000..3aa16398 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA256GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSHA256GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c new file mode 100644 index 00000000..fd7e9409 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Init,(IppsSHA256State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA256Init,(IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Init,(IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Init,(IppsSHA256State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA256Init,(IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Init,(IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c new file mode 100644 index 00000000..889349cf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Duplicate,(const IppsSHA256State* pSrcCtx, IppsSHA256State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c new file mode 100644 index 00000000..5ea31e4c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c new file mode 100644 index 00000000..de52ffd9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c new file mode 100644 index 00000000..13ed6856 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c new file mode 100644 index 00000000..50416e08 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c new file mode 100644 index 00000000..36ada570 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c new file mode 100644 index 00000000..a82d4b38 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA256MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA256MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA256MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA256MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c new file mode 100644 index 00000000..5fd439d8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA384GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSHA384GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c new file mode 100644 index 00000000..41b4ea65 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Init,(IppsSHA384State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA384Init,(IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Init,(IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Init,(IppsSHA384State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA384Init,(IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Init,(IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c new file mode 100644 index 00000000..06d81d6e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Duplicate,(const IppsSHA384State* pSrcCtx, IppsSHA384State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c new file mode 100644 index 00000000..3711b0f0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c new file mode 100644 index 00000000..357c6e99 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c new file mode 100644 index 00000000..0ebf2f6a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c new file mode 100644 index 00000000..a263d2b4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c new file mode 100644 index 00000000..84451105 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c new file mode 100644 index 00000000..e2afeb8f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA384MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA384MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA384MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA384MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c new file mode 100644 index 00000000..eaac5dc1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA512GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSHA512GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c new file mode 100644 index 00000000..a8aa0501 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Init,(IppsSHA512State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA512Init,(IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Init,(IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Init,(IppsSHA512State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA512Init,(IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Init,(IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c new file mode 100644 index 00000000..a0570a42 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Duplicate,(const IppsSHA512State* pSrcCtx, IppsSHA512State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c new file mode 100644 index 00000000..d9d7bcb2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c new file mode 100644 index 00000000..92ea3c0b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c new file mode 100644 index 00000000..2912cbe8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c new file mode 100644 index 00000000..27f4728d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c new file mode 100644 index 00000000..436d54c8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, l9_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) +IPPAPI(IppStatus, h9_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c new file mode 100644 index 00000000..03c5c34d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSHA512MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSHA512MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSHA512MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSHA512MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c new file mode 100644 index 00000000..2f0866c4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsMD5GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsMD5GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c new file mode 100644 index 00000000..0437d7b4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Init,(IppsMD5State* pCtx)) +IPPAPI(IppStatus, l9_ippsMD5Init,(IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Init,(IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Init,(IppsMD5State* pCtx)) +IPPAPI(IppStatus, h9_ippsMD5Init,(IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Init,(IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c new file mode 100644 index 00000000..58a60b7f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Duplicate,(const IppsMD5State* pSrcCtx, IppsMD5State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c new file mode 100644 index 00000000..045e583d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c new file mode 100644 index 00000000..315242bd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) +IPPAPI(IppStatus, l9_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) +IPPAPI(IppStatus, h9_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c new file mode 100644 index 00000000..ebe0a290 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) +IPPAPI(IppStatus, l9_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) +IPPAPI(IppStatus, h9_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c new file mode 100644 index 00000000..f1e07c7f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) +IPPAPI(IppStatus, l9_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) +IPPAPI(IppStatus, h9_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c new file mode 100644 index 00000000..9317dc54 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) +IPPAPI(IppStatus, l9_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) +IPPAPI(IppStatus, h9_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c new file mode 100644 index 00000000..db74875f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMD5MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMD5MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMD5MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMD5MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c new file mode 100644 index 00000000..d7f3febf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSM3GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsSM3GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c new file mode 100644 index 00000000..c8de9e26 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Init,(IppsSM3State* pCtx)) +IPPAPI(IppStatus, l9_ippsSM3Init,(IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Init,(IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Init,(IppsSM3State* pCtx)) +IPPAPI(IppStatus, h9_ippsSM3Init,(IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Init,(IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Init( pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Init( pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c new file mode 100644 index 00000000..3c08888b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) +IPPAPI(IppStatus, l9_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) +IPPAPI(IppStatus, h9_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Duplicate,(const IppsSM3State* pSrcCtx, IppsSM3State* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c new file mode 100644 index 00000000..cce4b241 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Pack,(const IppsSM3State* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Pack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Pack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c new file mode 100644 index 00000000..8562681a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) +IPPAPI(IppStatus, l9_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) +IPPAPI(IppStatus, h9_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c new file mode 100644 index 00000000..3cb08e78 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) +IPPAPI(IppStatus, l9_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) +IPPAPI(IppStatus, h9_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c new file mode 100644 index 00000000..8b287b6b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) +IPPAPI(IppStatus, l9_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) +IPPAPI(IppStatus, h9_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3GetTag( pTag, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3GetTag( pTag, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c new file mode 100644 index 00000000..150eb224 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) +IPPAPI(IppStatus, l9_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) +IPPAPI(IppStatus, h9_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3Final( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3Final( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c new file mode 100644 index 00000000..f4b9d2cc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSM3MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSM3MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, h9_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) + +IPPFUN(IppStatus,sgx_disp_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSM3MessageDigest( pMsg, len, pMD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSM3MessageDigest( pMsg, len, pMD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c new file mode 100644 index 00000000..7b689bfc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHashGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashGetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsHashGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c new file mode 100644 index 00000000..05f1b54a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashInit( pCtx, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashInit( pCtx, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, h9_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashInit( pCtx, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashInit( pCtx, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c new file mode 100644 index 00000000..676a050e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashPack( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashPack( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, h9_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashPack,(const IppsHashState* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashPack( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashPack( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c new file mode 100644 index 00000000..048a3f01 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) +IPPAPI(IppStatus, l9_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) +IPPAPI(IppStatus, h9_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c new file mode 100644 index 00000000..96ee5786 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashDuplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashDuplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) +IPPAPI(IppStatus, h9_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate,(const IppsHashState* pSrcCtx, IppsHashState* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashDuplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashDuplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c new file mode 100644 index 00000000..4f1f96c8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +IPPAPI(IppStatus, l9_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashUpdate( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashUpdate( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +IPPAPI(IppStatus, h9_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashUpdate( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashUpdate( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c new file mode 100644 index 00000000..5c1d7e40 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) +IPPAPI(IppStatus, l9_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashGetTag( pMD, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashGetTag( pMD, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) +IPPAPI(IppStatus, h9_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashGetTag( pMD, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashGetTag( pMD, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c new file mode 100644 index 00000000..88849183 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +IPPAPI(IppStatus, l9_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashFinal( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashFinal( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +IPPAPI(IppStatus, h9_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashFinal( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashFinal( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c new file mode 100644 index 00000000..46fa685f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMessage( pMsg, len, pMD, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMessage( pMsg, len, pMD, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, h9_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMessage( pMsg, len, pMD, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMessage( pMsg, len, pMD, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c new file mode 100644 index 00000000..0fa711a5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_MD5, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_MD5, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_MD5, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_MD5( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_MD5( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_MD5, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_MD5, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_MD5, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_MD5( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_MD5( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c new file mode 100644 index 00000000..3b230a53 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SM3, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SM3, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SM3, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SM3( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SM3( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SM3, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SM3, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SM3, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SM3( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SM3( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c new file mode 100644 index 00000000..a953f0ee --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA1, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA1, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c new file mode 100644 index 00000000..4728eb7f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA1_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA1_NI( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA1_NI, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA1_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA1_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA1_NI( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c new file mode 100644 index 00000000..9484bf82 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA1_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA1_TT( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA1_TT, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA1_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA1_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA1_TT( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c new file mode 100644 index 00000000..2dceba97 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA256( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA256, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA256, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA256( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c new file mode 100644 index 00000000..1469a0a3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA256_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA256_NI( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA256_NI, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA256_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA256_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA256_NI( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c new file mode 100644 index 00000000..41e6cee1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA256_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA256_TT( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA256_TT, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA256_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA256_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA256_TT( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c new file mode 100644 index 00000000..102e7bbf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA224( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA224( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA224, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA224, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA224( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA224( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c new file mode 100644 index 00000000..4d94d005 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA224_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA224_NI( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA224_NI, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA224_NI, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_NI, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA224_NI( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA224_NI( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c new file mode 100644 index 00000000..d2589a22 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA224_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA224_TT( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA224_TT, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA224_TT, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_TT, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA224_TT( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA224_TT( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c new file mode 100644 index 00000000..56f6b0d8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA512( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA512( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA512, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA512, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA512( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA512( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c new file mode 100644 index 00000000..df329eff --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA384, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA384, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA384, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA384( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA384( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA384, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA384, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA384, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA384( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA384( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c new file mode 100644 index 00000000..4b744015 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_256, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_256, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA512_256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA512_256( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA512_256, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA512_256, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA512_256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA512_256( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c new file mode 100644 index 00000000..a23adede --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_224, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_224, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_224, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMethod_SHA512_224( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMethod_SHA512_224( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsHashMethod*, p8_ippsHashMethod_SHA512_224, (void) ) +IPPAPI( const IppsHashMethod*, h9_ippsHashMethod_SHA512_224, (void) ) + +IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_224, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMethod_SHA512_224( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMethod_SHA512_224( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c new file mode 100644 index 00000000..d114f290 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHashGetSize_rmf,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetSize_rmf,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashGetSize_rmf( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashGetSize_rmf( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, h9_ippsHashGetSize_rmf,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetSize_rmf,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashGetSize_rmf( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashGetSize_rmf( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c new file mode 100644 index 00000000..325430db --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashInit_rmf( pCtx, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashInit_rmf( pCtx, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashInit_rmf( pCtx, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashInit_rmf( pCtx, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c new file mode 100644 index 00000000..e9d0502b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashPack_rmf( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashPack_rmf( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, h9_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashPack_rmf( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashPack_rmf( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c new file mode 100644 index 00000000..768531bc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashUnpack_rmf( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashUnpack_rmf( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashUnpack_rmf( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashUnpack_rmf( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c new file mode 100644 index 00000000..55168743 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) +IPPAPI(IppStatus, h9_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c new file mode 100644 index 00000000..aaa57b59 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashUpdate_rmf( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashUpdate_rmf( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashUpdate_rmf( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashUpdate_rmf( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c new file mode 100644 index 00000000..7a762371 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashGetTag_rmf( pMD, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashGetTag_rmf( pMD, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashGetTag_rmf( pMD, tagLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashGetTag_rmf( pMD, tagLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c new file mode 100644 index 00000000..b1a2e25e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashFinal_rmf( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashFinal_rmf( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashFinal_rmf( pMD, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashFinal_rmf( pMD, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c new file mode 100644 index 00000000..7fb9d8bb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c new file mode 100644 index 00000000..e93249b8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, h9_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c new file mode 100644 index 00000000..f46d1cf9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c new file mode 100644 index 00000000..be406002 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c new file mode 100644 index 00000000..77f50926 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHMAC_GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_GetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsHMAC_GetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_GetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_GetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_GetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c new file mode 100644 index 00000000..2cbfd4f7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, h9_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c new file mode 100644 index 00000000..6509e35b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, h9_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c new file mode 100644 index 00000000..a3bb0c2d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +IPPAPI(IppStatus, h9_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Unpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Unpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c new file mode 100644 index 00000000..1fc46310 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +IPPAPI(IppStatus, h9_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c new file mode 100644 index 00000000..78d4def5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +IPPAPI(IppStatus, h9_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Update( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Update( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c new file mode 100644 index 00000000..11829901 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Final( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Final( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPAPI(IppStatus, h9_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Final( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Final( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c new file mode 100644 index 00000000..f81b4c94 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_GetTag( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_GetTag( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +IPPAPI(IppStatus, h9_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_GetTag( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_GetTag( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c new file mode 100644 index 00000000..1b9aa7fd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, h9_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) + +IPPFUN(IppStatus,sgx_disp_ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c new file mode 100644 index 00000000..e35915f0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHMACGetSize_rmf,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACGetSize_rmf,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACGetSize_rmf( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACGetSize_rmf( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, h9_ippsHMACGetSize_rmf,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACGetSize_rmf,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACGetSize_rmf( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACGetSize_rmf( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c new file mode 100644 index 00000000..f04640b4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c new file mode 100644 index 00000000..8a9969dd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, h9_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c new file mode 100644 index 00000000..7e31cc85 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACUnpack_rmf( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACUnpack_rmf( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACUnpack_rmf( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACUnpack_rmf( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c new file mode 100644 index 00000000..f89c68c7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +IPPAPI(IppStatus, h9_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c new file mode 100644 index 00000000..285777f9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACUpdate_rmf( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACUpdate_rmf( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACUpdate_rmf( pSrc, len, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACUpdate_rmf( pSrc, len, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c new file mode 100644 index 00000000..c859f479 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c new file mode 100644 index 00000000..a15a8ff4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, h9_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c new file mode 100644 index 00000000..235028a3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pKey, int keyLen, Ipp8u* pMD, int mdLen, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c new file mode 100644 index 00000000..0a8f8a39 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsBigNumGetSize,(int length, int* pSize)) +IPPAPI(IppStatus, l9_ippsBigNumGetSize,(int length, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsBigNumGetSize,(int length, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsBigNumGetSize( length, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsBigNumGetSize( length, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsBigNumGetSize,(int length, int* pSize)) +IPPAPI(IppStatus, h9_ippsBigNumGetSize,(int length, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsBigNumGetSize,(int length, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsBigNumGetSize( length, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsBigNumGetSize( length, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c new file mode 100644 index 00000000..9d8fdc0e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsBigNumInit,(int length, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsBigNumInit( length, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsBigNumInit( length, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsBigNumInit,(int length, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsBigNumInit( length, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsBigNumInit( length, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c new file mode 100644 index 00000000..b8dafeba --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPAPI(IppStatus, l9_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) + +IPPFUN(IppStatus,sgx_disp_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsCmpZero_BN( pBN, pResult ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsCmpZero_BN( pBN, pResult ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPAPI(IppStatus, h9_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) + +IPPFUN(IppStatus,sgx_disp_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsCmpZero_BN( pBN, pResult ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsCmpZero_BN( pBN, pResult ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c new file mode 100644 index 00000000..8102931c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +IPPAPI(IppStatus, l9_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) + +IPPFUN(IppStatus,sgx_disp_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsCmp_BN( pA, pB, pResult ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsCmp_BN( pA, pB, pResult ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +IPPAPI(IppStatus, h9_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) + +IPPFUN(IppStatus,sgx_disp_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsCmp_BN( pA, pB, pResult ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsCmp_BN( pA, pB, pResult ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c new file mode 100644 index 00000000..67766b8e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +IPPAPI(IppStatus, l9_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGetSize_BN( pBN, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGetSize_BN( pBN, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +IPPAPI(IppStatus, h9_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGetSize_BN( pBN, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGetSize_BN( pBN, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c new file mode 100644 index 00000000..1cc25609 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSet_BN( sgn, length, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSet_BN( sgn, length, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSet_BN( sgn, length, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSet_BN( sgn, length, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c new file mode 100644 index 00000000..f2ff0947 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGet_BN( pSgn, pLength, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGet_BN( pSgn, pLength, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGet_BN( pSgn, pLength, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGet_BN( pSgn, pLength, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c new file mode 100644 index 00000000..f4e49e25 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRef_BN( pSgn, bitSize, ppData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRef_BN( pSgn, bitSize, ppData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRef_BN( pSgn, bitSize, ppData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRef_BN( pSgn, bitSize, ppData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c new file mode 100644 index 00000000..d5cc1247 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c new file mode 100644 index 00000000..46de105c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsAdd_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsAdd_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsAdd_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsAdd_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c new file mode 100644 index 00000000..377df263 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSub_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSub_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSub_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSub_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c new file mode 100644 index 00000000..276d2552 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMul_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMul_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMul_BN( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMul_BN( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c new file mode 100644 index 00000000..c72e3e56 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMAC_BN_I( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMAC_BN_I( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMAC_BN_I( pA, pB, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMAC_BN_I( pA, pB, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c new file mode 100644 index 00000000..41f476ae --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDiv_BN( pA, pB, pQ, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDiv_BN( pA, pB, pQ, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDiv_BN( pA, pB, pQ, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDiv_BN( pA, pB, pQ, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c new file mode 100644 index 00000000..9b0b9aee --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMod_BN( pA, pM, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMod_BN( pA, pM, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMod_BN( pA, pM, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMod_BN( pA, pM, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c new file mode 100644 index 00000000..afb19063 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +IPPAPI(IppStatus, l9_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) + +IPPFUN(IppStatus,sgx_disp_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGcd_BN( pA, pB, pGCD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGcd_BN( pA, pB, pGCD ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +IPPAPI(IppStatus, h9_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) + +IPPFUN(IppStatus,sgx_disp_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGcd_BN( pA, pB, pGCD ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGcd_BN( pA, pB, pGCD ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c new file mode 100644 index 00000000..ddf6a35a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPAPI(IppStatus, l9_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) + +IPPFUN(IppStatus,sgx_disp_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsModInv_BN( pA, pM, pInv ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsModInv_BN( pA, pM, pInv ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPAPI(IppStatus, h9_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) + +IPPFUN(IppStatus,sgx_disp_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsModInv_BN( pA, pM, pInv ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsModInv_BN( pA, pM, pInv ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c new file mode 100644 index 00000000..bacce2c8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsSetOctString_BN( pStr, strLen, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsSetOctString_BN( pStr, strLen, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsSetOctString_BN( pStr, strLen, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsSetOctString_BN( pStr, strLen, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c new file mode 100644 index 00000000..9142aee4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGetOctString_BN( pStr, strLen, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGetOctString_BN( pStr, strLen, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, h9_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) + +IPPFUN(IppStatus,sgx_disp_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGetOctString_BN( pStr, strLen, pBN ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGetOctString_BN( pStr, strLen, pBN ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c new file mode 100644 index 00000000..bfd8ee5f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPAPI(IppStatus, l9_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontGetSize( method, length, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontGetSize( method, length, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPAPI(IppStatus, h9_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontGetSize( method, length, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontGetSize( method, length, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c new file mode 100644 index 00000000..365d0f73 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontInit( method, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontInit( method, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPAPI(IppStatus, h9_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontInit( method, length, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontInit( method, length, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c new file mode 100644 index 00000000..12317bc9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontSet( pModulo, size, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontSet( pModulo, size, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPAPI(IppStatus, h9_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontSet( pModulo, size, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontSet( pModulo, size, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c new file mode 100644 index 00000000..bafbd82b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontGet( pModulo, pSize, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontGet( pModulo, pSize, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +IPPAPI(IppStatus, h9_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontGet( pModulo, pSize, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontGet( pModulo, pSize, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c new file mode 100644 index 00000000..35bea1f1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontForm( pA, pCtx, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontForm( pA, pCtx, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontForm( pA, pCtx, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontForm( pA, pCtx, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c new file mode 100644 index 00000000..93fc5ce2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontMul( pA, pB, m, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontMul( pA, pB, m, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontMul( pA, pB, m, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontMul( pA, pB, m, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c new file mode 100644 index 00000000..9d2bf549 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsMontExp( pA, pE, m, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsMontExp( pA, pE, m, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) +IPPAPI(IppStatus, h9_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) + +IPPFUN(IppStatus,sgx_disp_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsMontExp( pA, pE, m, pR ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsMontExp( pA, pE, m, pR ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c new file mode 100644 index 00000000..7e86b1b5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsPRNGGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGGetSize,(int* pSize)) +IPPAPI(IppStatus, h9_ippsPRNGGetSize,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSize,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGGetSize( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGGetSize( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c new file mode 100644 index 00000000..d3f60a15 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGInit( seedBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGInit( seedBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGInit( seedBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGInit( seedBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c new file mode 100644 index 00000000..575e5395 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGSetModulus( pMod, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGSetModulus( pMod, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGSetModulus( pMod, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGSetModulus( pMod, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c new file mode 100644 index 00000000..ddb3928a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGSetH0( pH0, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGSetH0( pH0, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGSetH0( pH0, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGSetH0( pH0, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c new file mode 100644 index 00000000..c5f2427b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGSetAugment( pAug, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGSetAugment( pAug, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGSetAugment( pAug, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGSetAugment( pAug, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c new file mode 100644 index 00000000..03cf6826 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGSetSeed( pSeed, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGSetSeed( pSeed, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGSetSeed( pSeed, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGSetSeed( pSeed, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c new file mode 100644 index 00000000..e7b327ac --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +IPPAPI(IppStatus, l9_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGGetSeed( pCtx, pSeed ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGGetSeed( pCtx, pSeed ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +IPPAPI(IppStatus, h9_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGGetSeed( pCtx, pSeed ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGGetSeed( pCtx, pSeed ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c new file mode 100644 index 00000000..55a1fb6f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGen( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGen( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGen( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGen( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c new file mode 100644 index 00000000..e83fbc4a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGen_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGen_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGen_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGen_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c new file mode 100644 index 00000000..36c693e2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGenRDRAND( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGenRDRAND( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGenRDRAND( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGenRDRAND( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c new file mode 100644 index 00000000..0aa9ef09 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c new file mode 100644 index 00000000..3283fcad --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTRNGenRDSEED( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTRNGenRDSEED( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTRNGenRDSEED( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTRNGenRDSEED( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c new file mode 100644 index 00000000..8e3f1fe8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, h9_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c new file mode 100644 index 00000000..e58ff219 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPAPI(IppStatus, l9_ippsPrimeGetSize,(int nMaxBits, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeGetSize( nMaxBits, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeGetSize( nMaxBits, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPAPI(IppStatus, h9_ippsPrimeGetSize,(int nMaxBits, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeGetSize( nMaxBits, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeGetSize( nMaxBits, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c new file mode 100644 index 00000000..9dc717a5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeInit( nMaxBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeInit( nMaxBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, h9_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeInit( nMaxBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeInit( nMaxBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c new file mode 100644 index 00000000..8e3dc06c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c new file mode 100644 index 00000000..2e84ceba --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c new file mode 100644 index 00000000..f91d0672 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c new file mode 100644 index 00000000..2a6a1bfa --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c new file mode 100644 index 00000000..89d3333b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeGet( pPrime, pLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeGet( pPrime, pLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, h9_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeGet( pPrime, pLen, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeGet( pPrime, pLen, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c new file mode 100644 index 00000000..33bd4dea --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeGet_BN( pPrime, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeGet_BN( pPrime, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, h9_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeGet_BN( pPrime, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeGet_BN( pPrime, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c new file mode 100644 index 00000000..8256791a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeSet( pPrime, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeSet( pPrime, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, h9_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeSet( pPrime, nBits, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeSet( pPrime, nBits, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c new file mode 100644 index 00000000..4be8e6b8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsPrimeSet_BN( pPrime, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsPrimeSet_BN( pPrime, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, h9_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsPrimeSet_BN( pPrime, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsPrimeSet_BN( pPrime, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c new file mode 100644 index 00000000..d5472193 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, h9_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c new file mode 100644 index 00000000..a617c4f6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, h9_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c new file mode 100644 index 00000000..5a04af7e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c new file mode 100644 index 00000000..adf1fef1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c new file mode 100644 index 00000000..2039c734 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, h9_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c new file mode 100644 index 00000000..9fdf5990 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, h9_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c new file mode 100644 index 00000000..1a09fbb7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c new file mode 100644 index 00000000..bc385b96 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c new file mode 100644 index 00000000..130bded4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPAPI(IppStatus, h9_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c new file mode 100644 index 00000000..c8fbf925 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, h9_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c new file mode 100644 index 00000000..85d1b63c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, const IppsBigNumState* pFactorQ, const IppsBigNumState* pCrtExpP, const IppsBigNumState* pCrtExpQ, const IppsBigNumState* pInverseQ, IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c new file mode 100644 index 00000000..be44b5ed --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c new file mode 100644 index 00000000..2d0d64a3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c new file mode 100644 index 00000000..1fedd434 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, h9_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c new file mode 100644 index 00000000..840ad19e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c new file mode 100644 index 00000000..d8a512a2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c new file mode 100644 index 00000000..376938ca --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_GenerateKeys,(const IppsBigNumState* pSrcPublicExp, IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pPrivateKeyType2, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c new file mode 100644 index 00000000..73a9a3aa --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsRSA_ValidateKeys,(int* pResult, const IppsRSAPublicKeyState* pPublicKey, const IppsRSAPrivateKeyState* pPrivateKeyType2, const IppsRSAPrivateKeyState* pPrivateKeyType1, Ipp8u* pScratchBuffer, int nTrials, IppsPrimeState* pPrimeGen, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c new file mode 100644 index 00000000..a146d0b6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c new file mode 100644 index 00000000..313f29f2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c new file mode 100644 index 00000000..5a063660 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pLabel, int labLen, const Ipp8u* pSeed, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c new file mode 100644 index 00000000..ea12a0bb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, const Ipp8u* pLab, int labLen, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c new file mode 100644 index 00000000..f3fc4d4e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, Ipp8u* pDst, const IppsRSAPublicKeyState* pKey, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c new file mode 100644 index 00000000..da0379de --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c new file mode 100644 index 00000000..be3532c7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c new file mode 100644 index 00000000..9d59f454 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c new file mode 100644 index 00000000..b2d5d91f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c new file mode 100644 index 00000000..373dd523 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c new file mode 100644 index 00000000..b1ae509f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c new file mode 100644 index 00000000..001f9317 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c new file mode 100644 index 00000000..a7c65877 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, const IppsRSAPrivateKeyState* pPrvKey, const IppsRSAPublicKeyState* pPubKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c new file mode 100644 index 00000000..11087b47 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, const IppsHashMethod* pMethod, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c new file mode 100644 index 00000000..14156ffa --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const char*, y8_ippsDLGetResultString, (IppDLResult code)) +IPPAPI( const char*, l9_ippsDLGetResultString, (IppDLResult code)) + +IPPFUN( const char*,sgx_disp_ippsDLGetResultString, (IppDLResult code)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLGetResultString( code ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLGetResultString( code ); + } else + return NULL; +} +#else + + +IPPAPI( const char*, p8_ippsDLGetResultString, (IppDLResult code)) +IPPAPI( const char*, h9_ippsDLGetResultString, (IppDLResult code)) + +IPPFUN( const char*,sgx_disp_ippsDLGetResultString, (IppDLResult code)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLGetResultString( code ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLGetResultString( code ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c new file mode 100644 index 00000000..ff5d3e15 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +IPPAPI(IppStatus, l9_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +IPPAPI(IppStatus, h9_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c new file mode 100644 index 00000000..f336de29 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c new file mode 100644 index 00000000..52c02447 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, h9_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPPack( pCtx, pBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPPack( pCtx, pBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c new file mode 100644 index 00000000..01cfe195 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPUnpack( pBuffer, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPUnpack( pBuffer, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c new file mode 100644 index 00000000..cea5f151 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPSet( pP, pR, pG, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPSet( pP, pR, pG, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPSet( pP, pR, pG, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPSet( pP, pR, pG, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c new file mode 100644 index 00000000..3adcf019 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGet( pP, pR, pG, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGet( pP, pR, pG, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGet( pP, pR, pG, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGet( pP, pR, pG, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c new file mode 100644 index 00000000..693dfc18 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPSetDP( pDP, tag, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPSetDP( pDP, tag, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPSetDP( pDP, tag, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPSetDP( pDP, tag, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c new file mode 100644 index 00000000..3e3d2593 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGetDP( pDP, tag, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGetDP( pDP, tag, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGetDP( pDP, tag, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGetDP( pDP, tag, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c new file mode 100644 index 00000000..91d232df --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c new file mode 100644 index 00000000..15554f46 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c new file mode 100644 index 00000000..f8e5037b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c new file mode 100644 index 00000000..1115a466 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c new file mode 100644 index 00000000..024ae525 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c new file mode 100644 index 00000000..55d5f9a8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c new file mode 100644 index 00000000..61430791 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) +IPPAPI(IppStatus, h9_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c new file mode 100644 index 00000000..091b6254 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c new file mode 100644 index 00000000..4e01aaf8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c new file mode 100644 index 00000000..38e2d49e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c new file mode 100644 index 00000000..8a9b757a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c new file mode 100644 index 00000000..9420ecf9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const char*, y8_ippsECCGetResultString, (IppECResult code)) +IPPAPI( const char*, l9_ippsECCGetResultString, (IppECResult code)) + +IPPFUN( const char*,sgx_disp_ippsECCGetResultString, (IppECResult code)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCGetResultString( code ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCGetResultString( code ); + } else + return NULL; +} +#else + + +IPPAPI( const char*, p8_ippsECCGetResultString, (IppECResult code)) +IPPAPI( const char*, h9_ippsECCGetResultString, (IppECResult code)) + +IPPFUN( const char*,sgx_disp_ippsECCGetResultString, (IppECResult code)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCGetResultString( code ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCGetResultString( code ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c new file mode 100644 index 00000000..916b612c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSize,(int feBitSize, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSize,(int feBitSize, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSize( feBitSize, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSize( feBitSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSize,(int feBitSize, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSize,(int feBitSize, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSize( feBitSize, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSize( feBitSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c new file mode 100644 index 00000000..41a0df50 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd128r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd128r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd128r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd128r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd128r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd128r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c new file mode 100644 index 00000000..f83b30e0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r2,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r2,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r2,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd128r2( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd128r2( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd128r2,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd128r2,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r2,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd128r2( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd128r2( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c new file mode 100644 index 00000000..aa58fffd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd192r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd192r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd192r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd192r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd192r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd192r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd192r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd192r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd192r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd192r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c new file mode 100644 index 00000000..ed34b289 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd224r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd224r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd224r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd224r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd224r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd224r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd224r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd224r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd224r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd224r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c new file mode 100644 index 00000000..f6ffe8f3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd256r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd256r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd256r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd256r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd256r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd256r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd256r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd256r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd256r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd256r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c new file mode 100644 index 00000000..8938333a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd384r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd384r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd384r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd384r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd384r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd384r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd384r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd384r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd384r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd384r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c new file mode 100644 index 00000000..e7949235 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd521r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd521r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd521r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStd521r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStd521r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStd521r1,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStd521r1,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd521r1,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStd521r1( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStd521r1( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c new file mode 100644 index 00000000..1cf3b510 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetSizeStdSM2,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStdSM2,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStdSM2,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetSizeStdSM2( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetSizeStdSM2( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetSizeStdSM2,(int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPGetSizeStdSM2,(int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStdSM2,(int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetSizeStdSM2( pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetSizeStdSM2( pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c new file mode 100644 index 00000000..0d0d490e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInit( feBitSize, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInit( feBitSize, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInit( feBitSize, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInit( feBitSize, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c new file mode 100644 index 00000000..4c90a2c6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd128r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd128r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd128r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd128r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd128r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd128r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd128r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd128r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c new file mode 100644 index 00000000..5f8cb9c1 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd128r2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd128r2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd128r2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd128r2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd128r2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd128r2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd128r2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd128r2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c new file mode 100644 index 00000000..4a507f57 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c new file mode 100644 index 00000000..e93528eb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c new file mode 100644 index 00000000..b2d90e90 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c new file mode 100644 index 00000000..94b137cd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c new file mode 100644 index 00000000..ee7f0adf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c new file mode 100644 index 00000000..3f633bae --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPInitStdSM2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPInitStdSM2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStdSM2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPInitStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPInitStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPInitStdSM2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPInitStdSM2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPInitStdSM2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPInitStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPInitStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c new file mode 100644 index 00000000..42131d0c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c new file mode 100644 index 00000000..6778d998 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd( flag, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd( flag, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd( flag, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd( flag, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c new file mode 100644 index 00000000..64d05b05 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd128r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd128r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd128r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd128r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd128r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd128r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd128r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd128r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c new file mode 100644 index 00000000..2752a333 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd128r2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd128r2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd128r2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd128r2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd128r2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd128r2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd128r2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd128r2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c new file mode 100644 index 00000000..5b7bbdcc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c new file mode 100644 index 00000000..26948b5c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c new file mode 100644 index 00000000..6c6f1d8f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c new file mode 100644 index 00000000..452461b2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c new file mode 100644 index 00000000..34ba35c7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c new file mode 100644 index 00000000..4ebb0300 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetStdSM2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetStdSM2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStdSM2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetStdSM2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetStdSM2,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetStdSM2,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c new file mode 100644 index 00000000..df29fae3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStd192r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStd192r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c new file mode 100644 index 00000000..7681c1a2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStd224r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStd224r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c new file mode 100644 index 00000000..e713dae4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStd256r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStd256r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c new file mode 100644 index 00000000..8ddafb64 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStd384r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStd384r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c new file mode 100644 index 00000000..50e16aa7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStd521r1( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStd521r1( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c new file mode 100644 index 00000000..8eb15db9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPBindGxyTblStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPBindGxyTblStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPBindGxyTblStdSM2( pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPBindGxyTblStdSM2( pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c new file mode 100644 index 00000000..47056e4b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c new file mode 100644 index 00000000..c9123b9e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetOrderBitSize( pBitSize, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetOrderBitSize( pBitSize, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetOrderBitSize( pBitSize, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetOrderBitSize( pBitSize, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c new file mode 100644 index 00000000..84f9fb77 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPValidate( nTrials, pResult, pECC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPValidate( nTrials, pResult, pECC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPValidate( nTrials, pResult, pECC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPValidate( nTrials, pResult, pECC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c new file mode 100644 index 00000000..1e2e469b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPPointGetSize,(int feBitSize, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPPointGetSize( feBitSize, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPPointGetSize( feBitSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, h9_ippsECCPPointGetSize,(int feBitSize, int* pSize)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPPointGetSize( feBitSize, pSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPPointGetSize( feBitSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c new file mode 100644 index 00000000..76629df5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +IPPAPI(IppStatus, l9_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPPointInit( feBitSize, pPoint ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPPointInit( feBitSize, pPoint ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +IPPAPI(IppStatus, h9_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPPointInit( feBitSize, pPoint ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPPointInit( feBitSize, pPoint ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c new file mode 100644 index 00000000..67d1cdd9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetPoint( pX, pY, pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetPoint( pX, pY, pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetPoint( pX, pY, pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetPoint( pX, pY, pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c new file mode 100644 index 00000000..cb9560e2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetPointAtInfinity( pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetPointAtInfinity( pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetPointAtInfinity( pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetPointAtInfinity( pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c new file mode 100644 index 00000000..6850c542 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGetPoint( pX, pY, pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGetPoint( pX, pY, pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGetPoint( pX, pY, pPoint, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGetPoint( pX, pY, pPoint, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c new file mode 100644 index 00000000..8a7a58cf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPCheckPoint( pP, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPCheckPoint( pP, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPCheckPoint( pP, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPCheckPoint( pP, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c new file mode 100644 index 00000000..1062d6ca --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPComparePoint( pP, pQ, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPComparePoint( pP, pQ, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPComparePoint( pP, pQ, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPComparePoint( pP, pQ, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c new file mode 100644 index 00000000..12112d54 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPNegativePoint( pP, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPNegativePoint( pP, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPNegativePoint( pP, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPNegativePoint( pP, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c new file mode 100644 index 00000000..9dff6c59 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPAddPoint( pP, pQ, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPAddPoint( pP, pQ, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPAddPoint( pP, pQ, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPAddPoint( pP, pQ, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c new file mode 100644 index 00000000..d72920c6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPMulPointScalar( pP, pK, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPMulPointScalar( pP, pK, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPMulPointScalar( pP, pK, pR, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPMulPointScalar( pP, pK, pR, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c new file mode 100644 index 00000000..179c948e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPGenKeyPair( pPrivate, pPublic, pECC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPGenKeyPair( pPrivate, pPublic, pECC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPGenKeyPair( pPrivate, pPublic, pECC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPGenKeyPair( pPrivate, pPublic, pECC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c new file mode 100644 index 00000000..921c6651 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPPublicKey( pPrivate, pPublic, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPPublicKey( pPrivate, pPublic, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPPublicKey( pPrivate, pPublic, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPPublicKey( pPrivate, pPublic, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c new file mode 100644 index 00000000..cd442cb9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c new file mode 100644 index 00000000..6918a2a0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c new file mode 100644 index 00000000..efc7ba2b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c new file mode 100644 index 00000000..147bf341 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c new file mode 100644 index 00000000..bcee13d2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c new file mode 100644 index 00000000..f6ba91d7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c new file mode 100644 index 00000000..e7b2c73d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c new file mode 100644 index 00000000..63f3ec8f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c new file mode 100644 index 00000000..a499350d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c new file mode 100644 index 00000000..9ed22c09 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, l9_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, h9_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) + +IPPFUN(IppStatus,sgx_disp_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pECC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pECC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pECC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c new file mode 100644 index 00000000..58d3e4ad --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) +IPPAPI(IppStatus, l9_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpGetSize( bitSize, pStateSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpGetSize( bitSize, pStateSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) +IPPAPI(IppStatus, h9_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpGetSize( bitSize, pStateSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpGetSize( bitSize, pStateSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c new file mode 100644 index 00000000..66dc743f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) +IPPAPI(IppStatus, l9_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpInitArbitrary( pPrime, primeBitSize, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpInitArbitrary( pPrime, primeBitSize, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) +IPPAPI(IppStatus, h9_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpInitArbitrary( pPrime, primeBitSize, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpInitArbitrary( pPrime, primeBitSize, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c new file mode 100644 index 00000000..8fb8f5a4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI(IppStatus, l9_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpInitFixed( primeBitSize, method, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpInitFixed( primeBitSize, method, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI(IppStatus, h9_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpInitFixed( primeBitSize, method, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpInitFixed( primeBitSize, method, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c new file mode 100644 index 00000000..9525cbc4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI(IppStatus, l9_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpInit( pPrime, primeBitSize, method, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpInit( pPrime, primeBitSize, method, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI(IppStatus, h9_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpInit( pPrime, primeBitSize, method, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpInit( pPrime, primeBitSize, method, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c new file mode 100644 index 00000000..773aaae2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p192r1,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p192r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p192r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p192r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p192r1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p192r1,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p192r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p192r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p192r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p192r1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c new file mode 100644 index 00000000..ddb2a942 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p224r1,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p224r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p224r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p224r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p224r1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p224r1,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p224r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p224r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p224r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p224r1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c new file mode 100644 index 00000000..3f556e8a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256r1,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p256r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p256r1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p256r1,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p256r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p256r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p256r1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c new file mode 100644 index 00000000..b633bf85 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p384r1,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p384r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p384r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p384r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p384r1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p384r1,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p384r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p384r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p384r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p384r1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c new file mode 100644 index 00000000..4391d435 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p521r1,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p521r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p521r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p521r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p521r1( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p521r1,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p521r1,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p521r1,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p521r1( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p521r1( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c new file mode 100644 index 00000000..b361f434 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256sm2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256sm2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256sm2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p256sm2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p256sm2( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p256sm2,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p256sm2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256sm2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p256sm2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p256sm2( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c new file mode 100644 index 00000000..1d39ef79 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256bn, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256bn, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256bn, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p256bn( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p256bn( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p256bn, (void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p256bn, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256bn, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p256bn( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p256bn( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c new file mode 100644 index 00000000..c93c7e76 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_p256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_p256( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_p256, (void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_p256, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_p256( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_p256( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c new file mode 100644 index 00000000..94856345 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_pArb, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_pArb, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_pArb, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMethod_pArb( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMethod_pArb( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpMethod_pArb, (void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpMethod_pArb, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_pArb, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMethod_pArb( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMethod_pArb( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c new file mode 100644 index 00000000..c2425195 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) +IPPAPI(IppStatus, l9_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxGetSize( pGroundGF, degree, pStateSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxGetSize( pGroundGF, degree, pStateSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) +IPPAPI(IppStatus, h9_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxGetSize( pGroundGF, degree, pStateSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxGetSize( pGroundGF, degree, pStateSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c new file mode 100644 index 00000000..c5473fd4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, l9_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, ne, method, pGFpx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, ne, method, pGFpx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, h9_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, ne, method, pGFpx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, ne, method, pGFpx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c new file mode 100644 index 00000000..f2779e8d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, l9_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, method, pGFpx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, method, pGFpx ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, h9_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, method, pGFpx ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, method, pGFpx ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c new file mode 100644 index 00000000..4baae18e --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2_epid2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2_epid2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_binom2_epid2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_binom2_epid2( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_binom2_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_binom2_epid2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2_epid2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_binom2_epid2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_binom2_epid2( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c new file mode 100644 index 00000000..fa2bf85f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3_epid2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3_epid2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_binom3_epid2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_binom3_epid2( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_binom3_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_binom3_epid2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3_epid2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_binom3_epid2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_binom3_epid2( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c new file mode 100644 index 00000000..2ad1b31c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_binom2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_binom2( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_binom2,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_binom2,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_binom2( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_binom2( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c new file mode 100644 index 00000000..a6af05df --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_binom3( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_binom3( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_binom3,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_binom3,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_binom3( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_binom3( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c new file mode 100644 index 00000000..dad8915c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_binom( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_binom( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_binom,(void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_binom,(void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom,(void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_binom( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_binom( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c new file mode 100644 index 00000000..9be23575 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_com, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_com, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_com, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpxMethod_com( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpxMethod_com( ); + } else + return NULL; +} +#else + + +IPPAPI( const IppsGFpMethod*, p8_ippsGFpxMethod_com, (void) ) +IPPAPI( const IppsGFpMethod*, h9_ippsGFpxMethod_com, (void) ) + +IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_com, (void) ) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpxMethod_com( ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpxMethod_com( ); + } else + return NULL; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c new file mode 100644 index 00000000..6dec9e20 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) +IPPAPI(IppStatus, l9_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGF, pBufferSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGF, pBufferSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) +IPPAPI(IppStatus, h9_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGF, pBufferSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGF, pBufferSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c new file mode 100644 index 00000000..f225ca88 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPAPI(IppStatus, l9_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpElementGetSize( pGFp, pElementSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpElementGetSize( pGFp, pElementSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPAPI(IppStatus, h9_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpElementGetSize( pGFp, pElementSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpElementGetSize( pGFp, pElementSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c new file mode 100644 index 00000000..9e38ca87 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpElementInit( pA, lenA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpElementInit( pA, lenA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpElementInit( pA, lenA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpElementInit( pA, lenA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c new file mode 100644 index 00000000..18292291 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElement( pA, nsA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElement( pA, nsA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElement( pA, nsA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElement( pA, nsA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c new file mode 100644 index 00000000..5a2e8c4a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) +IPPAPI(IppStatus, l9_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElementRegular( pBN, pElm, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElementRegular( pBN, pElm, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) +IPPAPI(IppStatus, h9_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElementRegular( pBN, pElm, pGF ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElementRegular( pBN, pElm, pGF ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c new file mode 100644 index 00000000..3b14b20f --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c new file mode 100644 index 00000000..46c627ac --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c new file mode 100644 index 00000000..a94c96c5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) +IPPAPI(IppStatus, l9_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGF, hashID ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGF, hashID ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) +IPPAPI(IppStatus, h9_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGF, hashID ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGF, hashID ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c new file mode 100644 index 00000000..9ec88b72 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGF, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGF, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, h9_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGF, pMethod ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGF, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c new file mode 100644 index 00000000..587d45ad --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpCpyElement( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpCpyElement( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpCpyElement( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpCpyElement( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c new file mode 100644 index 00000000..455b0128 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpGetElement( pA, pDataA, nsA, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpGetElement( pA, pDataA, nsA, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpGetElement( pA, pDataA, nsA, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpGetElement( pA, pDataA, nsA, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c new file mode 100644 index 00000000..9500eecc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c new file mode 100644 index 00000000..2a2685c2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpCmpElement( pA, pB, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpCmpElement( pA, pB, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpCmpElement( pA, pB, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpCmpElement( pA, pB, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c new file mode 100644 index 00000000..50958145 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpIsZeroElement( pA, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpIsZeroElement( pA, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpIsZeroElement( pA, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpIsZeroElement( pA, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c new file mode 100644 index 00000000..1a6196be --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpIsUnityElement( pA, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpIsUnityElement( pA, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpIsUnityElement( pA, pResult, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpIsUnityElement( pA, pResult, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c new file mode 100644 index 00000000..27e3501d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpConj( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpConj( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpConj( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpConj( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c new file mode 100644 index 00000000..e8e7f75b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpNeg( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpNeg( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpNeg( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpNeg( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c new file mode 100644 index 00000000..ddf009f4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpInv( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpInv( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpInv( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpInv( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c new file mode 100644 index 00000000..d1b4eccf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSqrt( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSqrt( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSqrt( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSqrt( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c new file mode 100644 index 00000000..96645bb5 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSqr( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSqr( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSqr( pA, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSqr( pA, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c new file mode 100644 index 00000000..f3826179 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpAdd( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpAdd( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpAdd( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpAdd( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c new file mode 100644 index 00000000..21be2c95 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSub( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSub( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSub( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSub( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c new file mode 100644 index 00000000..1613d882 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMul( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMul( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMul( pA, pB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMul( pA, pB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c new file mode 100644 index 00000000..2d5bd25b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c new file mode 100644 index 00000000..91b4a65b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMultiExp( ppElmA, ppE, nItems, pElmR, pGF, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMultiExp( ppElmA, ppE, nItems, pElmR, pGF, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMultiExp( ppElmA, ppE, nItems, pElmR, pGF, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMultiExp( ppElmA, ppE, nItems, pElmR, pGF, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c new file mode 100644 index 00000000..516a9fa3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c new file mode 100644 index 00000000..d12e2444 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c new file mode 100644 index 00000000..7dd64353 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, h9_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c new file mode 100644 index 00000000..3d4ec005 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) +IPPAPI(IppStatus, l9_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECGetSize( pGF, pCtxSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECGetSize( pGF, pCtxSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) +IPPAPI(IppStatus, h9_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECGetSize( pGF, pCtxSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECGetSize( pGF, pCtxSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c new file mode 100644 index 00000000..b01759bb --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInit( pGF, pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInit( pGF, pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInit, (const IppsGFpState* pGF, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInit( pGF, pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInit( pGF, pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c new file mode 100644 index 00000000..a893101c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSet( pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSet( pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSet( pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSet( pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c new file mode 100644 index 00000000..3da1445d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c new file mode 100644 index 00000000..54f375f2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd128r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd128r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd128r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd128r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c new file mode 100644 index 00000000..608ef720 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd128r2( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd128r2( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd128r2( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd128r2( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c new file mode 100644 index 00000000..29b9e025 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd192r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd192r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd192r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd192r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c new file mode 100644 index 00000000..02e51d28 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd224r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd224r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd224r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd224r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c new file mode 100644 index 00000000..0ac8abc7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd256r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd256r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd256r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd256r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c new file mode 100644 index 00000000..3ab358ff --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd384r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd384r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd384r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd384r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c new file mode 100644 index 00000000..596796dc --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStd521r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStd521r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStd521r1( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStd521r1( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c new file mode 100644 index 00000000..69dfa4f8 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStdSM2( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStdSM2( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStdSM2( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStdSM2( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c new file mode 100644 index 00000000..f3d21ed0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECInitStdBN256( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECInitStdBN256( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECInitStdBN256( pGF, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECInitStdBN256( pGF, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c new file mode 100644 index 00000000..91e5189a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStd192r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStd192r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStd192r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStd192r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c new file mode 100644 index 00000000..15399ed2 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStd224r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStd224r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStd224r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStd224r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c new file mode 100644 index 00000000..8ed9f108 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStd256r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStd256r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStd256r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStd256r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c new file mode 100644 index 00000000..b5e06ee3 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStd384r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStd384r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStd384r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStd384r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c new file mode 100644 index 00000000..32931c90 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStd521r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStd521r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStd521r1( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStd521r1( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c new file mode 100644 index 00000000..c29ce9fe --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECBindGxyTblStdSM2( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECBindGxyTblStdSM2( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECBindGxyTblStdSM2( pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECBindGxyTblStdSM2( pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c new file mode 100644 index 00000000..bd390598 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECGet( ppGF, pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECGet( ppGF, pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGet,(IppsGFpState** const ppGF, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECGet( ppGF, pA, pB, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECGet( ppGF, pA, pB, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c new file mode 100644 index 00000000..c9b20df0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECGetSubgroup( ppGF, pX, pY, pOrder, pCofactor, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECGetSubgroup( ppGF, pX, pY, pOrder, pCofactor, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECGetSubgroup( ppGF, pX, pY, pOrder, pCofactor, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECGetSubgroup( ppGF, pX, pY, pOrder, pCofactor, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c new file mode 100644 index 00000000..f2923d89 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +IPPAPI(IppStatus, l9_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +IPPAPI(IppStatus, h9_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c new file mode 100644 index 00000000..46e5784d --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c new file mode 100644 index 00000000..7c057e93 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) +IPPAPI(IppStatus, l9_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECPointGetSize( pEC, pSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECPointGetSize( pEC, pSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) +IPPAPI(IppStatus, h9_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECPointGetSize( pEC, pSizeInBytes ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECPointGetSize( pEC, pSizeInBytes ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c new file mode 100644 index 00000000..b9ae93d0 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECPointInit( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECPointInit( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECPointInit( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECPointInit( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c new file mode 100644 index 00000000..cc6f2d03 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPointAtInfinity( pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPointAtInfinity( pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPointAtInfinity( pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPointAtInfinity( pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c new file mode 100644 index 00000000..9634bd4c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c new file mode 100644 index 00000000..b294a3e9 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c new file mode 100644 index 00000000..899f5959 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c new file mode 100644 index 00000000..47aa5e75 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECMakePoint( pX, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECMakePoint( pX, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECMakePoint( pX, pPoint, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECMakePoint( pX, pPoint, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c new file mode 100644 index 00000000..b1efb258 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c new file mode 100644 index 00000000..93b014a4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c new file mode 100644 index 00000000..76601748 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c new file mode 100644 index 00000000..7cfd3a5c --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c new file mode 100644 index 00000000..337d7c50 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECTstPoint( pP, pResult, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECTstPoint( pP, pResult, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECTstPoint( pP, pResult, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECTstPoint( pP, pResult, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c new file mode 100644 index 00000000..3f92f129 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c new file mode 100644 index 00000000..6eb24354 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECCpyPoint( pA, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECCpyPoint( pA, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECCpyPoint( pA, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECCpyPoint( pA, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c new file mode 100644 index 00000000..98aeab5b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c new file mode 100644 index 00000000..9d0da9de --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECNegPoint( pP, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECNegPoint( pP, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECNegPoint( pP, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECNegPoint( pP, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c new file mode 100644 index 00000000..47542ff7 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECAddPoint( pP, pQ, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECAddPoint( pP, pQ, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, h9_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECAddPoint( pP, pQ, pR, pEC ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECAddPoint( pP, pQ, pR, pEC ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c new file mode 100644 index 00000000..2d947e26 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c new file mode 100644 index 00000000..b528a3fd --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, h9_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c new file mode 100644 index 00000000..a0b6fa04 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c new file mode 100644 index 00000000..396dce40 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c new file mode 100644 index 00000000..74d2bed4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c new file mode 100644 index 00000000..d57b8c1a --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c new file mode 100644 index 00000000..45bdf6d6 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c new file mode 100644 index 00000000..859fe4cf --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c new file mode 100644 index 00000000..b5da2fc4 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c new file mode 100644 index 00000000..3ec5d385 --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c new file mode 100644 index 00000000..6da31c5b --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, const IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c new file mode 100644 index 00000000..eb8169ee --- /dev/null +++ b/sdk/tlibcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c @@ -0,0 +1,54 @@ +#include "ippcp.h" + +#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + + +IPPAPI(IppStatus, y8_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return l9_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return y8_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#else + + +IPPAPI(IppStatus, p8_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, h9_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus,sgx_disp_ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsGFpECPoint* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u features; + ippcpGetCpuFeatures( &features ); + + if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { /* HasweLl ia32=H9, x64=L9 */ + return h9_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { /* Nehalem or Westmer = PenrYn + SSE42 + ?CLMUL + ?AES + ?SHA */ + return p8_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} +#endif diff --git a/sdk/tlibcrypto/ipp/sgx_ecc256.cpp b/sdk/tlibcrypto/ipp/sgx_ecc256.cpp index 2e31dfbb..9c0fc188 100644 --- a/sdk/tlibcrypto/ipp/sgx_ecc256.cpp +++ b/sdk/tlibcrypto/ipp/sgx_ecc256.cpp @@ -30,7 +30,7 @@ */ -#include "sgx_ecc256_common.h" +#include "sgx_tcrypto_common.h" /* @@ -62,7 +62,7 @@ sgx_status_t sgx_ecc256_open_context(sgx_ecc_state_handle_t* p_ecc_handle) *p_ecc_handle = NULL; return SGX_ERROR_UNEXPECTED; } - ipp_ret = ippsECCPSetStd(IppECCPStd256r1, p_ecc_state); + ipp_ret = ippsECCPSetStd256r1(p_ecc_state); if (ipp_ret != ippStsNoErr) { SAFE_FREE(p_ecc_state); diff --git a/sdk/tlibcrypto/ipp/sgx_ecc256_ecdsa.cpp b/sdk/tlibcrypto/ipp/sgx_ecc256_ecdsa.cpp index cdf9f64d..d595201f 100644 --- a/sdk/tlibcrypto/ipp/sgx_ecc256_ecdsa.cpp +++ b/sdk/tlibcrypto/ipp/sgx_ecc256_ecdsa.cpp @@ -30,7 +30,7 @@ */ -#include "sgx_ecc256_common.h" +#include "sgx_tcrypto_common.h" const uint32_t sgx_nistp256_r[] = { @@ -80,7 +80,7 @@ sgx_status_t sgx_ecdsa_sign(const uint8_t *p_data, ERROR_BREAK(ipp_ret); // Prepare the message used to sign. - ipp_ret = ippsHashMessage(p_data, data_size, (Ipp8u*)hash, IPP_ALG_HASH_SHA256); + ipp_ret = ippsHashMessage_rmf(p_data, data_size, (Ipp8u*)hash, ippsHashMethod_SHA256_TT()); ERROR_BREAK(ipp_ret); /* Byte swap in creation of Big Number from SHA256 hash output */ ipp_ret = sgx_ipp_newBN(NULL, sizeof(hash), &p_hash_bn); @@ -219,7 +219,7 @@ sgx_status_t sgx_ecdsa_verify(const uint8_t *p_data, ERROR_BREAK(ipp_ret); // Prepare the message used to sign. - ipp_ret = ippsHashMessage(p_data, data_size, (Ipp8u*)hash, IPP_ALG_HASH_SHA256); + ipp_ret = ippsHashMessage_rmf(p_data, data_size, (Ipp8u*)hash, ippsHashMethod_SHA256_TT()); ERROR_BREAK(ipp_ret); /* Byte swap in creation of Big Number from SHA256 hash output */ ipp_ret = sgx_ipp_newBN(NULL, sizeof(hash), &p_hash_bn); diff --git a/sdk/tlibcrypto/ipp/sgx_ecc256_internal.cpp b/sdk/tlibcrypto/ipp/sgx_ecc256_internal.cpp index 6177877f..7d9f86bd 100644 --- a/sdk/tlibcrypto/ipp/sgx_ecc256_internal.cpp +++ b/sdk/tlibcrypto/ipp/sgx_ecc256_internal.cpp @@ -32,7 +32,7 @@ -#include "sgx_ecc256_common.h" +#include "sgx_tcrypto_common.h" #include "sgx_ecc256_internal.h" @@ -96,7 +96,7 @@ sgx_status_t sgx_ecc256_compute_shared_point(sgx_ec256_private_t *p_private_b, if (ipp_result != ippECValid ) { - ipp_ret = ippStsIvalidPublicKey; + ipp_ret = ippStsPointAtInfinity; break; } @@ -125,7 +125,7 @@ sgx_status_t sgx_ecc256_compute_shared_point(sgx_ec256_private_t *p_private_b, if (ipp_result != ippECValid) { - ipp_ret = ippStsIvalidPublicKey; + ipp_ret = ippStsPointAtInfinity; break; } diff --git a/sdk/tlibcrypto/ipp/sgx_rsa3072.cpp b/sdk/tlibcrypto/ipp/sgx_rsa3072.cpp index cfd775ae..fda4278c 100644 --- a/sdk/tlibcrypto/ipp/sgx_rsa3072.cpp +++ b/sdk/tlibcrypto/ipp/sgx_rsa3072.cpp @@ -30,7 +30,7 @@ */ -#include "sgx_ecc256_common.h" +#include "sgx_tcrypto_common.h" sgx_status_t sgx_rsa3072_sign(const uint8_t * p_data, diff --git a/sdk/tlibcrypto/ipp/sgx_rsa_encryption.cpp b/sdk/tlibcrypto/ipp/sgx_rsa_encryption.cpp index b978bf71..f4a7d6ae 100644 --- a/sdk/tlibcrypto/ipp/sgx_rsa_encryption.cpp +++ b/sdk/tlibcrypto/ipp/sgx_rsa_encryption.cpp @@ -36,17 +36,15 @@ * Wrapper for rsa operation functions * */ -#include "util.h" -#include -#include -#include -#include #include +#include +#include #include "sgx_error.h" -#include "ipp_wrapper.h" #include "sgx_trts.h" +#include "ipp_wrapper.h" + +#include "sgx_tcrypto_common.h" -#define RSA_SEED_SIZE_SHA256 32 sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned char *p_n, unsigned char *p_d, unsigned char *p_e, unsigned char *p_p, unsigned char *p_q, unsigned char *p_dmp1, @@ -58,10 +56,9 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned } IppsRSAPrivateKeyState *p_pri_key = NULL; - IppsRSAPublicKeyState *p_pub_key = NULL; + IppsRSAPublicKeyState *p_pub_key = NULL; IppStatus error_code = ippStsNoErr; sgx_status_t ret_code = SGX_ERROR_UNEXPECTED; - IppsPRNGState *p_rand = NULL; IppsPrimeState *p_prime = NULL; Ipp8u * scratch_buffer = NULL; int pri_size = 0; @@ -72,14 +69,9 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned do { - //create a new PRNG - // - error_code = newPRNG(&p_rand); - ERROR_BREAK(error_code); - //create a new prime number generator // - error_code = newPrimeGen(n_byte_size * 8 / 2, &p_prime); + error_code = sgx_ipp_newPrimeGen(n_byte_size * 8 / 2, &p_prime); ERROR_BREAK(error_code); //allocate and init private key of type 2 @@ -99,23 +91,23 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned //allocate and initialize RSA BNs // - error_code = newBN((const Ipp32u*)p_e, e_byte_size, &bn_e_s); + error_code = sgx_ipp_newBN((const Ipp32u*)p_e, e_byte_size, &bn_e_s); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size, &bn_n); + error_code = sgx_ipp_newBN(NULL, n_byte_size, &bn_n); ERROR_BREAK(error_code); - error_code = newBN(NULL, e_byte_size, &bn_e); + error_code = sgx_ipp_newBN(NULL, e_byte_size, &bn_e); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size, &bn_d); + error_code = sgx_ipp_newBN(NULL, n_byte_size, &bn_d); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size / 2, &bn_p); + error_code = sgx_ipp_newBN(NULL, n_byte_size / 2, &bn_p); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size / 2, &bn_q); + error_code = sgx_ipp_newBN(NULL, n_byte_size / 2, &bn_q); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size / 2, &bn_dmp1); + error_code = sgx_ipp_newBN(NULL, n_byte_size / 2, &bn_dmp1); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size / 2, &bn_dmq1); + error_code = sgx_ipp_newBN(NULL, n_byte_size / 2, &bn_dmq1); ERROR_BREAK(error_code); - error_code = newBN(NULL, n_byte_size / 2, &bn_iqmp); + error_code = sgx_ipp_newBN(NULL, n_byte_size / 2, &bn_iqmp); ERROR_BREAK(error_code); //generate RSA key components with n_byte_size modulus and p_e public exponent @@ -128,8 +120,8 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned scratch_buffer, 1, p_prime, - ippsPRNGen, - p_rand); + sgx_ipp_DRNGen, + NULL); ERROR_BREAK(error_code); //extract private key components into BNs @@ -155,7 +147,7 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned //validate generated keys // - ippsRSA_ValidateKeys(&validate_keys, p_pub_key, p_pri_key, NULL, scratch_buffer, 10, p_prime, ippsPRNGen, p_rand); + ippsRSA_ValidateKeys(&validate_keys, p_pub_key, p_pri_key, NULL, scratch_buffer, 10, p_prime, sgx_ipp_DRNGen, NULL); if (validate_keys != IPP_IS_VALID) { break; } @@ -199,17 +191,16 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned } while (0); - secure_free_BN(bn_e_s, e_byte_size); - secure_free_BN(bn_e, e_byte_size); - secure_free_BN(bn_d, n_byte_size); - secure_free_BN(bn_n, n_byte_size); - secure_free_BN(bn_p, n_byte_size / 2); - secure_free_BN(bn_q, n_byte_size / 2); - secure_free_BN(bn_dmp1, n_byte_size / 2); - secure_free_BN(bn_dmq1, n_byte_size / 2); - secure_free_BN(bn_iqmp, n_byte_size / 2); + sgx_ipp_secure_free_BN(bn_e_s, e_byte_size); + sgx_ipp_secure_free_BN(bn_e, e_byte_size); + sgx_ipp_secure_free_BN(bn_d, n_byte_size); + sgx_ipp_secure_free_BN(bn_n, n_byte_size); + sgx_ipp_secure_free_BN(bn_p, n_byte_size / 2); + sgx_ipp_secure_free_BN(bn_q, n_byte_size / 2); + sgx_ipp_secure_free_BN(bn_dmp1, n_byte_size / 2); + sgx_ipp_secure_free_BN(bn_dmq1, n_byte_size / 2); + sgx_ipp_secure_free_BN(bn_iqmp, n_byte_size / 2); - SAFE_FREE_MM(p_rand); SAFE_FREE_MM(p_prime); secure_free_rsa_pri2_key(n_byte_size / 2, p_pri_key); secure_free_rsa_pub_key(n_byte_size, e_byte_size, p_pub_key); @@ -218,17 +209,17 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned return ret_code; } -sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsigned char *g_rsa_key_e, const unsigned char *g_rsa_key_p, const unsigned char *g_rsa_key_q, - const unsigned char *g_rsa_key_dmp1, const unsigned char *g_rsa_key_dmq1, const unsigned char *g_rsa_key_iqmp, +sgx_status_t sgx_create_rsa_priv2_key(int mod_size, int exp_size, const unsigned char *p_rsa_key_e, const unsigned char *p_rsa_key_p, const unsigned char *p_rsa_key_q, + const unsigned char *p_rsa_key_dmp1, const unsigned char *p_rsa_key_dmq1, const unsigned char *p_rsa_key_iqmp, void **new_pri_key2) { (void)(exp_size); - (void)(g_rsa_key_e); + (void)(p_rsa_key_e); IppsRSAPrivateKeyState *p_rsa2 = NULL; IppsBigNumState *p_p = NULL, *p_q = NULL, *p_dmp1 = NULL, *p_dmq1 = NULL, *p_iqmp = NULL; int rsa2_size = 0; sgx_status_t ret_code = SGX_ERROR_UNEXPECTED; - if (prime_size <= 0 || g_rsa_key_p == NULL || g_rsa_key_q == NULL || g_rsa_key_dmp1 == NULL || g_rsa_key_dmq1 == NULL || g_rsa_key_iqmp == NULL || new_pri_key2 == NULL) { + if (mod_size <= 0 || p_rsa_key_p == NULL || p_rsa_key_q == NULL || p_rsa_key_dmp1 == NULL || p_rsa_key_dmq1 == NULL || p_rsa_key_iqmp == NULL || new_pri_key2 == NULL) { return SGX_ERROR_INVALID_PARAMETER; } @@ -237,24 +228,24 @@ sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsign //generate and assign RSA components BNs // - error_code = newBN((const Ipp32u*)g_rsa_key_p, prime_size / 2, &p_p); + error_code = sgx_ipp_newBN((const Ipp32u*)p_rsa_key_p, mod_size / 2, &p_p); ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)g_rsa_key_q, prime_size / 2, &p_q); + error_code = sgx_ipp_newBN((const Ipp32u*)p_rsa_key_q, mod_size / 2, &p_q); ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)g_rsa_key_dmp1, prime_size / 2, &p_dmp1); + error_code = sgx_ipp_newBN((const Ipp32u*)p_rsa_key_dmp1, mod_size / 2, &p_dmp1); ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)g_rsa_key_dmq1, prime_size / 2, &p_dmq1); + error_code = sgx_ipp_newBN((const Ipp32u*)p_rsa_key_dmq1, mod_size / 2, &p_dmq1); ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)g_rsa_key_iqmp, prime_size / 2, &p_iqmp); + error_code = sgx_ipp_newBN((const Ipp32u*)p_rsa_key_iqmp, mod_size / 2, &p_iqmp); ERROR_BREAK(error_code); //allocate and initialize private key of type 2 // - error_code = ippsRSA_GetSizePrivateKeyType2(prime_size / 2 * 8, prime_size / 2 * 8, &rsa2_size); + error_code = ippsRSA_GetSizePrivateKeyType2(mod_size / 2 * 8, mod_size / 2 * 8, &rsa2_size); ERROR_BREAK(error_code); p_rsa2 = (IppsRSAPrivateKeyState *)malloc(rsa2_size); NULL_BREAK(p_rsa2); - error_code = ippsRSA_InitPrivateKeyType2(prime_size / 2 * 8, prime_size / 2 * 8, p_rsa2, rsa2_size); + error_code = ippsRSA_InitPrivateKeyType2(mod_size / 2 * 8, mod_size / 2 * 8, p_rsa2, rsa2_size); ERROR_BREAK(error_code); //setup private key with values of input components @@ -266,21 +257,21 @@ sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsign ret_code = SGX_SUCCESS; } while (0); - secure_free_BN(p_p, prime_size / 2); - secure_free_BN(p_q, prime_size / 2); - secure_free_BN(p_dmp1, prime_size / 2); - secure_free_BN(p_dmq1, prime_size / 2); - secure_free_BN(p_iqmp, prime_size / 2); + sgx_ipp_secure_free_BN(p_p, mod_size / 2); + sgx_ipp_secure_free_BN(p_q, mod_size / 2); + sgx_ipp_secure_free_BN(p_dmp1, mod_size / 2); + sgx_ipp_secure_free_BN(p_dmq1, mod_size / 2); + sgx_ipp_secure_free_BN(p_iqmp, mod_size / 2); if (ret_code != SGX_SUCCESS) { - secure_free_rsa_pri2_key(prime_size, p_rsa2); + secure_free_rsa_pri2_key(mod_size, p_rsa2); } return ret_code; } -sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1) +sgx_status_t sgx_create_rsa_pub1_key(int mod_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1) { - if (new_pub_key1 == NULL || prime_size <= 0 || exp_size <= 0 || le_n == NULL || le_e == NULL) { + if (new_pub_key1 == NULL || mod_size <= 0 || exp_size <= 0 || le_n == NULL || le_e == NULL) { return SGX_ERROR_INVALID_PARAMETER; } @@ -293,18 +284,18 @@ sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigne //generate and assign RSA components BNs // - error_code = newBN((const Ipp32u*)le_n, prime_size, &p_n); + error_code = sgx_ipp_newBN((const Ipp32u*)le_n, mod_size, &p_n); ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)le_e, exp_size, &p_e); + error_code = sgx_ipp_newBN((const Ipp32u*)le_e, exp_size, &p_e); ERROR_BREAK(error_code); //allocate and initialize public key // - error_code = ippsRSA_GetSizePublicKey(prime_size * 8, exp_size * 8, &rsa_size); + error_code = ippsRSA_GetSizePublicKey(mod_size * 8, exp_size * 8, &rsa_size); ERROR_BREAK(error_code); p_pub_key = (IppsRSAPublicKeyState *)malloc(rsa_size); NULL_BREAK(p_pub_key); - error_code = ippsRSA_InitPublicKey(prime_size * 8, exp_size * 8, p_pub_key, rsa_size); + error_code = ippsRSA_InitPublicKey(mod_size * 8, exp_size * 8, p_pub_key, rsa_size); ERROR_BREAK(error_code); //setup public key with values of input components @@ -316,11 +307,11 @@ sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigne ret_code = SGX_SUCCESS; } while (0); - secure_free_BN(p_n, prime_size); - secure_free_BN(p_e, exp_size); + sgx_ipp_secure_free_BN(p_n, mod_size); + sgx_ipp_secure_free_BN(p_e, exp_size); if (ret_code != SGX_SUCCESS) { - secure_free_rsa_pub_key(prime_size, exp_size, p_pub_key); + secure_free_rsa_pub_key(mod_size, exp_size, p_pub_key); } return ret_code; @@ -408,58 +399,6 @@ sgx_status_t sgx_rsa_priv_decrypt_sha256(void* rsa_key, unsigned char* pout_data return ret_code; } -sgx_status_t sgx_create_rsa_priv1_key(int n_byte_size, int e_byte_size, int d_byte_size, const unsigned char *le_n, const unsigned char *le_e, - const unsigned char *le_d, void **new_pri_key1) -{ - if (n_byte_size <= 0 || e_byte_size <= 0 || d_byte_size <= 0 || new_pri_key1 == NULL || - le_n == NULL || le_e == NULL || le_d == NULL) { - return SGX_ERROR_INVALID_PARAMETER; - } - - IppsRSAPrivateKeyState *p_rsa1 = NULL; - IppsBigNumState *p_n = NULL, *p_d = NULL; - int rsa1_size = 0; - sgx_status_t ret_code = SGX_ERROR_UNEXPECTED; - - IppStatus error_code = ippStsNoErr; - do { - - //generate and assign RSA components BNs - // - error_code = newBN((const Ipp32u*)le_n, n_byte_size, &p_n); - ERROR_BREAK(error_code); - error_code = newBN((const Ipp32u*)le_d, d_byte_size, &p_d); - ERROR_BREAK(error_code); - - //allocate and init private key of type 1 - // - error_code = ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size); - ERROR_BREAK(error_code); - p_rsa1 = (IppsRSAPrivateKeyState *)malloc(rsa1_size); - NULL_BREAK(p_rsa1); - error_code = ippsRSA_InitPrivateKeyType1(n_byte_size * 8, d_byte_size * 8, p_rsa1, rsa1_size); - ERROR_BREAK(error_code); - - //setup private key with values of input components - // - error_code = ippsRSA_SetPrivateKeyType1(p_n, p_d, p_rsa1); - ERROR_BREAK(error_code); - - *new_pri_key1 = p_rsa1; - ret_code = SGX_SUCCESS; - - } while (0); - - secure_free_BN(p_n, n_byte_size); - secure_free_BN(p_d, d_byte_size); - if (ret_code != SGX_SUCCESS) { - secure_free_rsa_pri1_key(n_byte_size, d_byte_size, p_rsa1); - } - - return ret_code; -} - - sgx_status_t sgx_free_rsa_key(void *p_rsa_key, sgx_rsa_key_type_t key_type, int mod_size, int exp_size) { if (key_type == SGX_RSA_PRIVATE_KEY) { (void)(exp_size); @@ -493,22 +432,22 @@ sgx_status_t sgx_calculate_ecdsa_priv_key(const unsigned char* hash_drg, int has //allocate and initialize BNs // - ipp_status = newBN(reinterpret_cast(hash_drg), hash_drg_len, &bn_d); + ipp_status = sgx_ipp_newBN(reinterpret_cast(hash_drg), hash_drg_len, &bn_d); ERROR_BREAK(ipp_status); //generate mod to be n-1 where n is order of ECC Group // - ipp_status = newBN(reinterpret_cast(sgx_nistp256_r_m1), sgx_nistp256_r_m1_len, &bn_m); + ipp_status = sgx_ipp_newBN(reinterpret_cast(sgx_nistp256_r_m1), sgx_nistp256_r_m1_len, &bn_m); ERROR_BREAK(ipp_status); //allocate memory for output BN // - ipp_status = newBN(NULL, sgx_nistp256_r_m1_len, &bn_o); + ipp_status = sgx_ipp_newBN(NULL, sgx_nistp256_r_m1_len, &bn_o); ERROR_BREAK(ipp_status); //create big number with value of 1 // - ipp_status = newBN(&i, sizeof(Ipp32u), &bn_one); + ipp_status = sgx_ipp_newBN(&i, sizeof(Ipp32u), &bn_one); ERROR_BREAK(ipp_status); //calculate output's BN value @@ -533,16 +472,16 @@ sgx_status_t sgx_calculate_ecdsa_priv_key(const unsigned char* hash_drg, int has } while (0); if (NULL != bn_d) { - secure_free_BN(bn_d, hash_drg_len); + sgx_ipp_secure_free_BN(bn_d, hash_drg_len); } if (NULL != bn_m) { - secure_free_BN(bn_m, sgx_nistp256_r_m1_len); + sgx_ipp_secure_free_BN(bn_m, sgx_nistp256_r_m1_len); } if (NULL != bn_o) { - secure_free_BN(bn_o, sgx_nistp256_r_m1_len); + sgx_ipp_secure_free_BN(bn_o, sgx_nistp256_r_m1_len); } if (NULL != bn_one) { - secure_free_BN(bn_one, sizeof(uint32_t)); + sgx_ipp_secure_free_BN(bn_one, sizeof(uint32_t)); } if (ret_code != SGX_SUCCESS) { (void)memset_s(out_key, out_key_len, 0, out_key_len); diff --git a/sdk/tlibcrypto/ipp/sgx_rsa_internal.cpp b/sdk/tlibcrypto/ipp/sgx_rsa_internal.cpp index 6eaf1e2e..6fa3fcb7 100644 --- a/sdk/tlibcrypto/ipp/sgx_rsa_internal.cpp +++ b/sdk/tlibcrypto/ipp/sgx_rsa_internal.cpp @@ -29,77 +29,9 @@ * */ -/** -* File: -* sgx_rsa_encryption.cpp -* Description: -* Wrapper for rsa operation functions -* -*/ -#include "util.h" -#include -#include -#include #include #include -#include "sgx_error.h" -#include "sgx_tcrypto.h" #include "ipp_wrapper.h" -#include "sgx_trts.h" - -#define RSA_SEED_SIZE_SHA256 32 - -extern "C" IppStatus newPrimeGen(int nMaxBits, IppsPrimeState ** pPrimeG) -{ - if (pPrimeG == NULL || nMaxBits <= 0) { - return ippStsBadArgErr; - } - int ctxSize = 0; - IppStatus error_code = ippsPrimeGetSize(nMaxBits, &ctxSize); - if (error_code != ippStsNoErr) { - return error_code; - } - IppsPrimeState* pCtx = (IppsPrimeState *)malloc(ctxSize); - if (pCtx == NULL) { - return ippStsMemAllocErr; - } - - error_code = ippsPrimeInit(nMaxBits, pCtx); - if (error_code != ippStsNoErr) { - free(pCtx); - return error_code; - } - - *pPrimeG = pCtx; - return error_code; -} - -extern "C" IppStatus newPRNG(IppsPRNGState **pRandGen) -{ - if (pRandGen == NULL) { - return ippStsBadArgErr; - } - int ctxSize = 0; - IppStatus error_code = ippsPRNGGetSize(&ctxSize); - if (error_code != ippStsNoErr) { - return error_code; - } - - IppsPRNGState* pCtx = (IppsPRNGState *)malloc(ctxSize); - if (pCtx == NULL) { - return ippStsMemAllocErr; - } - - error_code = ippsPRNGInit(160, pCtx); - if (error_code != ippStsNoErr) { - free(pCtx); - return error_code; - } - - *pRandGen = pCtx; - return error_code; -} - extern "C" IppStatus newBN(const Ipp32u *data, int size_in_bytes, IppsBigNumState **p_new_BN) { @@ -141,43 +73,6 @@ extern "C" IppStatus newBN(const Ipp32u *data, int size_in_bytes, IppsBigNumStat } -extern "C" void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1) -{ - if (n_byte_size <= 0 || d_byte_size <= 0 || pri_key1 == NULL) { - if (pri_key1) - free(pri_key1); - return; - } - - int rsa1_size = 0; - if (ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size) != ippStsNoErr) { - free(pri_key1); - return; - } - /* Clear the buffer before free. */ - memset_s(pri_key1, rsa1_size, 0, rsa1_size); - free(pri_key1); - return; -} - -extern "C" void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2) -{ - if (p_byte_size <= 0 || pri_key2 == NULL) { - if (pri_key2) - free(pri_key2); - return; - } - - int rsa2_size = 0; - if (ippsRSA_GetSizePrivateKeyType2(p_byte_size / 2 * 8, p_byte_size / 2 * 8, &rsa2_size) != ippStsNoErr) { - free(pri_key2); - return; - } - /* Clear the buffer before free. */ - memset_s(pri_key2, rsa2_size, 0, rsa2_size); - free(pri_key2); - return; -} extern "C" void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) { @@ -204,6 +99,24 @@ extern "C" void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) return; } +extern "C" void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2) +{ + if (p_byte_size <= 0 || pri_key2 == NULL) { + if (pri_key2) + free(pri_key2); + return; + } + + int rsa2_size = 0; + if (ippsRSA_GetSizePrivateKeyType2(p_byte_size / 2 * 8, p_byte_size / 2 * 8, &rsa2_size) != ippStsNoErr) { + free(pri_key2); + return; + } + /* Clear the buffer before free. */ + memset_s(pri_key2, rsa2_size, 0, rsa2_size); + free(pri_key2); + return; +} extern "C" void secure_free_rsa_pub_key(int n_byte_size, int e_byte_size, IppsRSAPublicKeyState *pub_key) { diff --git a/sdk/tlibcrypto/ipp/sgx_sha256.cpp b/sdk/tlibcrypto/ipp/sgx_sha256.cpp index 01fad587..c9eef674 100644 --- a/sdk/tlibcrypto/ipp/sgx_sha256.cpp +++ b/sdk/tlibcrypto/ipp/sgx_sha256.cpp @@ -29,9 +29,8 @@ * */ - -#include "sgx_tcrypto.h" #include "ippcp.h" +#include "sgx_tcrypto.h" #include "stdlib.h" #ifndef SAFE_FREE @@ -46,19 +45,19 @@ sgx_status_t sgx_sha256_init(sgx_sha_state_handle_t* p_sha_handle) { IppStatus ipp_ret = ippStsNoErr; - IppsHashState* p_temp_state = NULL; + IppsHashState_rmf* p_temp_state = NULL; if (p_sha_handle == NULL) return SGX_ERROR_INVALID_PARAMETER; int ctx_size = 0; - ipp_ret = ippsHashGetSize(&ctx_size); + ipp_ret = ippsHashGetSize_rmf(&ctx_size); if (ipp_ret != ippStsNoErr) return SGX_ERROR_UNEXPECTED; - p_temp_state = (IppsHashState*)(malloc(ctx_size)); + p_temp_state = (IppsHashState_rmf*)(malloc(ctx_size)); if (p_temp_state == NULL) return SGX_ERROR_OUT_OF_MEMORY; - ipp_ret = ippsHashInit(p_temp_state, IPP_ALG_HASH_SHA256); + ipp_ret = ippsHashInit_rmf(p_temp_state, ippsHashMethod_SHA256_TT()); if (ipp_ret != ippStsNoErr) { SAFE_FREE(p_temp_state); @@ -88,7 +87,7 @@ sgx_status_t sgx_sha256_update(const uint8_t *p_src, uint32_t src_len, sgx_sha_s return SGX_ERROR_INVALID_PARAMETER; } IppStatus ipp_ret = ippStsNoErr; - ipp_ret = ippsHashUpdate(p_src, src_len, (IppsHashState*)sha_handle); + ipp_ret = ippsHashUpdate_rmf(p_src, src_len, (IppsHashState_rmf*)sha_handle); switch (ipp_ret) { case ippStsNoErr: return SGX_SUCCESS; @@ -110,7 +109,7 @@ sgx_status_t sgx_sha256_get_hash(sgx_sha_state_handle_t sha_handle, sgx_sha256_h return SGX_ERROR_INVALID_PARAMETER; } IppStatus ipp_ret = ippStsNoErr; - ipp_ret = ippsHashGetTag((Ipp8u*)p_hash, SGX_SHA256_HASH_SIZE, (IppsHashState*)sha_handle); + ipp_ret = ippsHashGetTag_rmf((Ipp8u*)p_hash, SGX_SHA256_HASH_SIZE, (IppsHashState_rmf*)sha_handle); switch (ipp_ret) { case ippStsNoErr: return SGX_SUCCESS; diff --git a/sdk/tlibcrypto/ipp/sgx_sha256_msg.cpp b/sdk/tlibcrypto/ipp/sgx_sha256_msg.cpp index 0def9733..b848c78b 100644 --- a/sdk/tlibcrypto/ipp/sgx_sha256_msg.cpp +++ b/sdk/tlibcrypto/ipp/sgx_sha256_msg.cpp @@ -53,7 +53,7 @@ sgx_status_t sgx_sha256_msg(const uint8_t *p_src, uint32_t src_len, sgx_sha256_h } IppStatus ipp_ret = ippStsNoErr; - ipp_ret = ippsHashMessage((const Ipp8u *) p_src, src_len, (Ipp8u *)p_hash, IPP_ALG_HASH_SHA256); + ipp_ret = ippsHashMessage_rmf((const Ipp8u *) p_src, src_len, (Ipp8u *)p_hash, ippsHashMethod_SHA256_TT()); switch (ipp_ret) { case ippStsNoErr: return SGX_SUCCESS; diff --git a/sdk/tlibcrypto/ipp/sgx_ecc256_common.cpp b/sdk/tlibcrypto/ipp/sgx_tcrypto_common.cpp similarity index 84% rename from sdk/tlibcrypto/ipp/sgx_ecc256_common.cpp rename to sdk/tlibcrypto/ipp/sgx_tcrypto_common.cpp index 6f00012f..8980f662 100644 --- a/sdk/tlibcrypto/ipp/sgx_ecc256_common.cpp +++ b/sdk/tlibcrypto/ipp/sgx_tcrypto_common.cpp @@ -30,7 +30,7 @@ */ -#include "sgx_ecc256_common.h" +#include "sgx_tcrypto_common.h" IppStatus sgx_ipp_newBN(const Ipp32u *p_data, int size_in_bytes, IppsBigNumState **p_new_BN) @@ -105,7 +105,7 @@ void sgx_ipp_secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) return; } -IppStatus __STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx) +IppStatus IPP_STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx) { sgx_status_t sgx_ret; UNUSED(pCtx); @@ -127,3 +127,30 @@ IppStatus __STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx) } return ippStsNoErr; } + + +IppStatus sgx_ipp_newPrimeGen(int nMaxBits, IppsPrimeState ** pPrimeG) +{ + if (pPrimeG == NULL || nMaxBits <= 0) { + return ippStsBadArgErr; + } + int ctxSize = 0; + IppStatus error_code = ippsPrimeGetSize(nMaxBits, &ctxSize); + if (error_code != ippStsNoErr) { + return error_code; + } + IppsPrimeState* pCtx = (IppsPrimeState *)malloc(ctxSize); + if (pCtx == NULL) { + return ippStsMemAllocErr; + } + + error_code = ippsPrimeInit(nMaxBits, pCtx); + if (error_code != ippStsNoErr) { + free(pCtx); + return error_code; + } + + *pPrimeG = pCtx; + return error_code; +} + diff --git a/sdk/tlibcrypto/ipp/sgx_ecc256_common.h b/sdk/tlibcrypto/ipp/sgx_tcrypto_common.h similarity index 90% rename from sdk/tlibcrypto/ipp/sgx_ecc256_common.h rename to sdk/tlibcrypto/ipp/sgx_tcrypto_common.h index 518042ef..794bd65a 100644 --- a/sdk/tlibcrypto/ipp/sgx_ecc256_common.h +++ b/sdk/tlibcrypto/ipp/sgx_tcrypto_common.h @@ -30,12 +30,12 @@ */ -#ifndef _SGX_ECC256_COMMON_H_ -#define _SGX_ECC256_COMMON_H_ +#ifndef _SGX_TCRYPTO_COMMON_H_ +#define _SGX_TCRYPTO_COMMON_H_ +#include "ippcp.h" #include "sgx_trts.h" #include "sgx_tcrypto.h" -#include "ippcp.h" #include "util.h" #include "stdlib.h" #include "string.h" @@ -47,10 +47,13 @@ #define SAFE_FREE(ptr) {if (NULL != (ptr)) {free(ptr); (ptr)=NULL;}} #endif +#define RSA_SEED_SIZE_SHA256 32 + IppStatus sgx_ipp_newBN(const Ipp32u *p_data, int size_in_bytes, IppsBigNumState **p_new_BN); void sgx_ipp_secure_free_BN(IppsBigNumState *pBN, int size_in_bytes); -IppStatus __STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx); +IppStatus IPP_STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx); +IppStatus sgx_ipp_newPrimeGen(int nMaxBits, IppsPrimeState ** pPrimeG); static inline IppStatus check_copy_size(size_t target_size, size_t source_size) diff --git a/sdk/tlibcrypto/sgxssl/sgx_rsa_encryption.cpp b/sdk/tlibcrypto/sgxssl/sgx_rsa_encryption.cpp index 846a6eea..10542315 100644 --- a/sdk/tlibcrypto/sgxssl/sgx_rsa_encryption.cpp +++ b/sdk/tlibcrypto/sgxssl/sgx_rsa_encryption.cpp @@ -124,13 +124,13 @@ sgx_status_t sgx_create_rsa_key_pair(int n_byte_size, int e_byte_size, unsigned return ret_code; } -sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsigned char *g_rsa_key_e, const unsigned char *g_rsa_key_p, const unsigned char *g_rsa_key_q, - const unsigned char *g_rsa_key_dmp1, const unsigned char *g_rsa_key_dmq1, const unsigned char *g_rsa_key_iqmp, +sgx_status_t sgx_create_rsa_priv2_key(int mod_size, int exp_size, const unsigned char *p_rsa_key_e, const unsigned char *p_rsa_key_p, const unsigned char *p_rsa_key_q, + const unsigned char *p_rsa_key_dmp1, const unsigned char *p_rsa_key_dmq1, const unsigned char *p_rsa_key_iqmp, void **new_pri_key2) { - if (prime_size <= 0 || exp_size <= 0 || new_pri_key2 == NULL || - g_rsa_key_e == NULL || g_rsa_key_p == NULL || g_rsa_key_q == NULL || g_rsa_key_dmp1 == NULL || - g_rsa_key_dmq1 == NULL || g_rsa_key_iqmp == NULL) { + if (mod_size <= 0 || exp_size <= 0 || new_pri_key2 == NULL || + p_rsa_key_e == NULL || p_rsa_key_p == NULL || p_rsa_key_q == NULL || p_rsa_key_dmp1 == NULL || + p_rsa_key_dmq1 == NULL || p_rsa_key_iqmp == NULL) { return SGX_ERROR_INVALID_PARAMETER; } @@ -156,17 +156,17 @@ sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsign // convert RSA params, factors to BNs // - p = BN_lebin2bn(g_rsa_key_p, (prime_size / 2), p); + p = BN_lebin2bn(p_rsa_key_p, (mod_size / 2), p); BN_CHECK_BREAK(p); - q = BN_lebin2bn(g_rsa_key_q, (prime_size / 2), q); + q = BN_lebin2bn(p_rsa_key_q, (mod_size / 2), q); BN_CHECK_BREAK(q); - dmp1 = BN_lebin2bn(g_rsa_key_dmp1, (prime_size / 2), dmp1); + dmp1 = BN_lebin2bn(p_rsa_key_dmp1, (mod_size / 2), dmp1); BN_CHECK_BREAK(dmp1); - dmq1 = BN_lebin2bn(g_rsa_key_dmq1, (prime_size / 2), dmq1); + dmq1 = BN_lebin2bn(p_rsa_key_dmq1, (mod_size / 2), dmq1); BN_CHECK_BREAK(dmq1); - iqmp = BN_lebin2bn(g_rsa_key_iqmp, (prime_size / 2), iqmp); + iqmp = BN_lebin2bn(p_rsa_key_iqmp, (mod_size / 2), iqmp); BN_CHECK_BREAK(iqmp); - e = BN_lebin2bn(g_rsa_key_e, (exp_size), e); + e = BN_lebin2bn(p_rsa_key_e, (exp_size), e); BN_CHECK_BREAK(e); // calculate n value @@ -248,9 +248,9 @@ sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsign return ret_code; } -sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1) +sgx_status_t sgx_create_rsa_pub1_key(int mod_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1) { - if (new_pub_key1 == NULL || prime_size <= 0 || exp_size <= 0 || le_n == NULL || le_e == NULL) { + if (new_pub_key1 == NULL || mod_size <= 0 || exp_size <= 0 || le_n == NULL || le_e == NULL) { return SGX_ERROR_INVALID_PARAMETER; } @@ -263,7 +263,7 @@ sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigne do { //convert input buffers to BNs // - n = BN_lebin2bn(le_n, prime_size, n); + n = BN_lebin2bn(le_n, mod_size, n); BN_CHECK_BREAK(n); e = BN_lebin2bn(le_e, exp_size, e); BN_CHECK_BREAK(e); @@ -369,64 +369,6 @@ sgx_status_t sgx_rsa_priv_decrypt_sha256(void* rsa_key, unsigned char* pout_data return ret_code; } -sgx_status_t sgx_create_rsa_priv1_key(int n_byte_size, int e_byte_size, int d_byte_size, const unsigned char *le_n, const unsigned char *le_e, - const unsigned char *le_d, void **new_pri_key1) -{ - if (n_byte_size <= 0 || e_byte_size <= 0 || d_byte_size <= 0 || new_pri_key1 == NULL || - le_n == NULL || le_e == NULL || le_d == NULL) { - return SGX_ERROR_INVALID_PARAMETER; - } - - EVP_PKEY *rsa_key = NULL; - RSA *rsa_ctx = NULL; - sgx_status_t ret_code = SGX_ERROR_UNEXPECTED; - BIGNUM* n = NULL; - BIGNUM* e = NULL; - BIGNUM* d = NULL; - - do { - //convert input buffers to BNs - // - n = BN_lebin2bn(le_n, n_byte_size, n); - BN_CHECK_BREAK(n); - e = BN_lebin2bn(le_e, e_byte_size, e); - BN_CHECK_BREAK(e); - d = BN_lebin2bn(le_d, d_byte_size, d); - BN_CHECK_BREAK(d); - - // allocates and initializes an RSA key structure - // - rsa_ctx = RSA_new(); - rsa_key = EVP_PKEY_new(); - - if (rsa_ctx == NULL || rsa_key == NULL || !EVP_PKEY_assign_RSA(rsa_key, rsa_ctx)) { - RSA_free(rsa_ctx); - rsa_ctx = NULL; - break; - } - - //set n, e values of RSA key - //Calling set functions transfers the memory management of input BNs to the RSA object, - //and therefore the values that have been passed in should not be freed by the caller after these functions has been called. - // - if (!RSA_set0_key(rsa_ctx, n, e, d)) { - break; - } - - *new_pri_key1 = rsa_key; - ret_code = SGX_SUCCESS; - } while (0); - - if (ret_code != SGX_SUCCESS) { - EVP_PKEY_free(rsa_key); - BN_clear_free(n); - BN_clear_free(e); - BN_clear_free(d); - } - - return ret_code; -} - sgx_status_t sgx_free_rsa_key(void *p_rsa_key, sgx_rsa_key_type_t key_type, int mod_size, int exp_size) { (void)(key_type); (void)(mod_size); diff --git a/sdk/tlibcxx/README.sgx b/sdk/tlibcxx/README.sgx index c3cfb597..414ed215 100644 --- a/sdk/tlibcxx/README.sgx +++ b/sdk/tlibcxx/README.sgx @@ -1,18 +1,18 @@ Version: 3.9 Changes: - * Add __sgx to __config for SGX specific configuration. + * Add __sgx to __config for Intel® Software Guard Extensions (Intel® SGX) specific configuration. * Define _LIBCPP_HAS_NO_THREADS, _LIBCPP_HAS_NO_STDIN, _LIBCPP_HAS_NO_STDOUT, _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE. - * Use SGX C++ runtime library (cpprt from libcxxrt project ) instead. + * Use Intel® SGX C++ runtime library (cpprt from libcxxrt project ) instead. * Disable unsupported data types and interfaces. * Disable features that depend on I/O operations. - * Use SGX mutex, condition variable and spinlock instead of libc++ implementation. + * Use Intel® SGX mutex, condition variable and spinlock instead of libc++ implementation. * Use sgx_read_rand for generating random numbers. * Disable randon until we determine whether it's used safely. * Do not include Windows/Linux system headers directly. * Fix MSVC and GCC warnings with unused parameters. TODO: - * Merge SGX mutex and condition variable into libc++'s mutex and and condition variable. + * Merge Intel® SGX mutex and condition variable into libc++'s mutex and and condition variable. * Merge atomic support for ICC. * Update cpprt (libcxxrt project) or replace with libcxxabi (component of LLVM project). diff --git a/sdk/trts/init_enclave.cpp b/sdk/trts/init_enclave.cpp index 247b5b46..15668291 100644 --- a/sdk/trts/init_enclave.cpp +++ b/sdk/trts/init_enclave.cpp @@ -55,9 +55,9 @@ uint64_t g_cpu_feature_indicator = 0; int EDMM_supported = 0; sdk_version_t g_sdk_version = SDK_VERSION_1_5; -const volatile global_data_t g_global_data = {1, 2, 3, 4, +const volatile global_data_t g_global_data __attribute__((section(".niprod"))) = {1, 2, 3, 4, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, {{{0, 0, 0, 0, 0, 0, 0}}}}; -uint32_t g_enclave_state = ENCLAVE_INIT_NOT_STARTED; +uint32_t g_enclave_state __attribute__((section(".nipd"))) = ENCLAVE_INIT_NOT_STARTED; extern "C" { uintptr_t __stack_chk_guard = 0; @@ -67,6 +67,9 @@ uintptr_t __stack_chk_guard = 0; __weak_alias(__intel_security_cookie, __stack_chk_guard); } +extern sgx_status_t pcl_entry(void* enclave_base,void* ms) __attribute__((weak)); +extern "C" int init_enclave(void *enclave_base, void *ms) __attribute__((section(".nipx"))); + // init_enclave() // Initialize enclave. // Parameters: @@ -83,6 +86,22 @@ extern "C" int init_enclave(void *enclave_base, void *ms) return -1; } + if(NULL != pcl_entry) + { + // LFENCE before pcl_entry + sgx_lfence(); + system_features_t * csi = (system_features_t *)ms; + if(NULL == csi->sealed_key) + { + return -1; + } + sgx_status_t ret = pcl_entry(enclave_base, csi->sealed_key); + if(SGX_SUCCESS != ret) + { + return -1; + } + } + // relocation if(0 != relocate_enclave(enclave_base)) { @@ -161,16 +180,11 @@ sgx_status_t do_init_enclave(void *ms, void *tcs) } #ifndef SE_SIM - thread_data_t *thread_data = GET_PTR(thread_data_t, tcs, g_global_data.td_template.self_addr); - if (thread_data == NULL) + if (SGX_SUCCESS != do_init_thread(tcs, true)) { return SGX_ERROR_UNEXPECTED; } - do_init_thread(tcs); - thread_data->flags = SGX_UTILITY_THREAD; - - /* for EDMM, we need to accept the trimming of the POST_REMOVE pages. */ if (EDMM_supported) { diff --git a/sdk/trts/linux/trts_pic.S b/sdk/trts/linux/trts_pic.S index 62a26b51..ce5cbcac 100644 --- a/sdk/trts/linux/trts_pic.S +++ b/sdk/trts/linux/trts_pic.S @@ -40,7 +40,8 @@ #include "trts_pic.h" - .text + /* .text */ + .section .nipx,"ax",@progbits DECLARE_LOCAL_FUNC get_enclave_base lea_pic __ImageBase, %xax @@ -114,9 +115,25 @@ DECLARE_GLOBAL_FUNC enclave_entry * ---------------------------------------------------------------------- */ .cfi_startproc + + /* Clear unused general registers */ + xor %xdx, %xdx + add %xdx, %xdx /* OF = SF = AF = CF = 0; ZF = PF = 1 */ +#if defined(LINUX64) + xor %r8, %r8 + xor %r9, %r9 + xor %r10, %r10 + xor %r11, %r11 + xor %r12, %r12 + xor %r13, %r13 + xor %r14, %r14 + xor %r15, %r15 +#endif + + /* switch to trusted stack */ cmp $0, %xax jne .Ldo_handler /* handle exception state */ - xor %xdx, %xdx + /* xor %xdx, %xdx xdx is cssa, make sure it is 0 */ READ_TD_DATA last_sp cmp $0, %xax jne .Lswitch_stack @@ -549,15 +566,14 @@ DECLARE_LOCAL_FUNC continue_execution mov %xdi, %xcx #endif mov SE_WORDSIZE*0(%xcx), %xax - push %xax # push xax + push %xax /* push xax */ mov SE_WORDSIZE*1(%xcx), %xax - push %xax # push xcx - mov SE_WORDSIZE*4(%xcx), %xax # xax: xsp -# x86_64 requires a 128-bytes red zone. We need to allocate buffer to avoid touching the red zone. - sub $(SE_WORDSIZE + RED_ZONE_SIZE), %xax # allocate buffer to skip the red zone (if any) and save the xip - # RED_ZONE_SIZE: 0(i386), 128-bytes(x86_64) + push %xax /* push xcx */ + mov SE_WORDSIZE*4(%xcx), %xax /* xax: xsp */ +/* x86_64 requires a 128-bytes red zone. We need to allocate buffer to avoid touching the red zone. */ + sub $(SE_WORDSIZE + RED_ZONE_SIZE), %xax /* allocate buffer to skip red zone and save xip */ -# restore registers except xax, xcx, xsp +/* restore registers except xax, xcx, xsp */ mov SE_WORDSIZE*2(%xcx), %xdx mov SE_WORDSIZE*3(%xcx), %xbx mov SE_WORDSIZE*5(%xcx), %xbp @@ -573,7 +589,7 @@ DECLARE_LOCAL_FUNC continue_execution mov SE_WORDSIZE*14(%xcx), %r14 mov SE_WORDSIZE*15(%xcx), %r15 push SE_WORDSIZE*16(%xcx) - popf # make sure the following instructions do not affect flags + popf /* make sure the following instructions do not affect flags */ #else push SE_WORDSIZE*8(%xcx) popf @@ -582,13 +598,14 @@ DECLARE_LOCAL_FUNC continue_execution #ifdef LINUX64 mov SE_WORDSIZE*17(%xcx), %xcx #else - mov SE_WORDSIZE*9(%xcx), %xcx # xcx: xip + mov SE_WORDSIZE*9(%xcx), %xcx /* xcx: xip */ #endif -# do not setup the new stack until info is not needed any more -# otherwise, info will be overwritten - mov %xcx, (%xax) # save xip to the new stack - pop %xcx # restore xcx - pop %xsp # xsp: xax +/* do not setup the new stack until info is not needed any more + * otherwise, info will be overwritten + */ + mov %xcx, (%xax) /* save xip to the new stack */ + pop %xcx /* restore xcx */ + pop %xsp /* xsp: xax */ xchg %xax, %xsp - ret $(RED_ZONE_SIZE) # pop xip and red zone (if any) + ret $(RED_ZONE_SIZE) /* pop xip and red zone (if any) */ diff --git a/sdk/trts/trts_add_trim.cpp b/sdk/trts/trts_add_trim.cpp index 3c2abcad..230a3501 100644 --- a/sdk/trts/trts_add_trim.cpp +++ b/sdk/trts/trts_add_trim.cpp @@ -135,9 +135,32 @@ int accept_post_remove(const volatile layout_t *layout_start, const volatile lay return 0; } +static int check_heap_dyn_range(void *addr, size_t page_count, struct dynamic_flags_attributes *fa) +{ + size_t heap_dyn_start, heap_dyn_size; + + heap_dyn_start = (size_t)get_heap_base() + get_heap_min_size(); + heap_dyn_size = get_heap_size() - get_heap_min_size(); + + if ((size_t)addr >= heap_dyn_start + && (size_t)addr + (page_count << SE_PAGE_SHIFT) <= heap_dyn_start + heap_dyn_size) + { + if (fa != NULL) + { + fa->si_flags = SI_FLAGS_RW; + fa->attributes = PAGE_ATTR_POST_ADD; + } + return 0; + } + else + { + return -1; + } +} + static int check_dynamic_entry_range(void *addr, size_t page_count, uint16_t entry_id, size_t entry_offset, struct dynamic_flags_attributes *fa) { - const volatile layout_t *layout = NULL, *heap_max_layout; + const volatile layout_t *layout = NULL; size_t entry_start_addr; uint32_t entry_page_count; @@ -150,14 +173,6 @@ static int check_dynamic_entry_range(void *addr, size_t page_count, uint16_t ent entry_start_addr = (size_t)get_enclave_base() + (size_t)layout->entry.rva + entry_offset; entry_page_count = layout->entry.page_count; - - // if there exists LAYOUT_ID_HEAP_MAX, we should include it as well - if ((entry_id == LAYOUT_ID_HEAP_INIT) - && (heap_max_layout = get_dynamic_layout_by_id(LAYOUT_ID_HEAP_MAX))) - { - entry_page_count += heap_max_layout->entry.page_count; - } - if ((size_t)addr >= entry_start_addr && (size_t)addr + (page_count << SE_PAGE_SHIFT) <= entry_start_addr + ((size_t)entry_page_count << SE_PAGE_SHIFT)) { @@ -174,15 +189,28 @@ static int check_dynamic_entry_range(void *addr, size_t page_count, uint16_t ent } } +static int check_utility_thread_dynamic_stack(void *addr, size_t page_count, struct dynamic_flags_attributes *fa) +{ + return check_dynamic_entry_range(addr, page_count, LAYOUT_ID_STACK_MAX, 0, fa); +} + // Verify if the range specified belongs to a dynamic range recorded in metadata. static int check_dynamic_range(void *addr, size_t page_count, size_t *offset, struct dynamic_flags_attributes *fa) { const volatile layout_t *dt_layout = NULL; - // check heap range - if (0 == check_dynamic_entry_range(addr, page_count, LAYOUT_ID_HEAP_INIT, 0, fa)) + // check for integer overflow + if ((size_t)addr > SIZE_MAX - (page_count << SE_PAGE_SHIFT)) + return -1; + + // check heap dynamic range + if (0 == check_heap_dyn_range(addr, page_count, fa)) return 0; - + + // check dynamic stack within utility thread + if (0 == check_utility_thread_dynamic_stack(addr, page_count, fa)) + return 0; + // check dynamic thread entries range if (NULL != (dt_layout = get_dynamic_layout_by_id(LAYOUT_ID_THREAD_GROUP_DYN))) { @@ -236,7 +264,7 @@ int is_dynamic_thread_exist() uint32_t get_dynamic_stack_max_page() { - const volatile layout_t * layout = get_dynamic_layout_by_id(LAYOUT_ID_STACK_DYN_MAX); + const volatile layout_t * layout = get_dynamic_layout_by_id(LAYOUT_ID_STACK_MAX); if (!layout) return 0; else diff --git a/sdk/trts/trts_ecall.cpp b/sdk/trts/trts_ecall.cpp index fbe10143..d4f0de9b 100644 --- a/sdk/trts/trts_ecall.cpp +++ b/sdk/trts/trts_ecall.cpp @@ -104,6 +104,16 @@ static sgx_status_t get_func_addr(uint32_t ordinal, void **addr) return SGX_SUCCESS; } +static bool is_utility_thread() +{ + thread_data_t *thread_data = get_thread_data(); + if ((thread_data != NULL) && (thread_data->flags & SGX_UTILITY_THREAD)) + { + return true; + } + return false; +} + typedef struct _tcs_node_t { uintptr_t tcs; @@ -111,8 +121,6 @@ typedef struct _tcs_node_t } tcs_node_t; static tcs_node_t *g_tcs_node = NULL; -static sgx_spinlock_t g_tcs_node_lock = SGX_SPINLOCK_INITIALIZER; - static uintptr_t g_tcs_cookie = 0; #define ENC_TCS_POINTER(x) (uintptr_t)(x) ^ g_tcs_cookie #define DEC_TCS_POINTER(x) (void *)((x) ^ g_tcs_cookie) @@ -127,6 +135,9 @@ static uintptr_t g_tcs_cookie = 0; // static sgx_status_t do_save_tcs(void *ptcs) { + if(!is_utility_thread()) + return SGX_ERROR_UNEXPECTED; + if(unlikely(g_tcs_cookie == 0)) { uintptr_t rand = 0; @@ -138,12 +149,10 @@ static sgx_status_t do_save_tcs(void *ptcs) } } while(rand == 0); - sgx_spin_lock(&g_tcs_node_lock); if(g_tcs_cookie == 0) { g_tcs_cookie = rand; } - sgx_spin_unlock(&g_tcs_node_lock); } tcs_node_t *tcs_node = (tcs_node_t *)malloc(sizeof(tcs_node_t)); @@ -154,10 +163,8 @@ static sgx_status_t do_save_tcs(void *ptcs) tcs_node->tcs = ENC_TCS_POINTER(ptcs); - sgx_spin_lock(&g_tcs_node_lock); tcs_node->next = g_tcs_node; g_tcs_node = tcs_node; - sgx_spin_unlock(&g_tcs_node_lock); return SGX_SUCCESS; } @@ -171,7 +178,9 @@ static sgx_status_t do_save_tcs(void *ptcs) // static void do_del_tcs(void *ptcs) { - sgx_spin_lock(&g_tcs_node_lock); + if(!is_utility_thread()) + return; + if (g_tcs_node != NULL) { if (DEC_TCS_POINTER(g_tcs_node->tcs) == ptcs) @@ -198,7 +207,6 @@ static void do_del_tcs(void *ptcs) } } } - sgx_spin_unlock(&g_tcs_node_lock); } static volatile bool g_is_first_ecall = true; @@ -261,24 +269,11 @@ static void init_static_stack_canary(void *tcs) *canary = (size_t)__stack_chk_guard; } -static bool is_utility_thread() -{ - thread_data_t *thread_data = get_thread_data(); - if ((thread_data != NULL) && (thread_data->flags & SGX_UTILITY_THREAD)) - { - return true; - } - else - { - return false; - } -} - -sgx_status_t do_init_thread(void *tcs) +sgx_status_t do_init_thread(void *tcs, bool enclave_init) { thread_data_t *thread_data = GET_PTR(thread_data_t, tcs, g_global_data.td_template.self_addr); #ifndef SE_SIM - size_t saved_stack_commit_addr = thread_data->stack_commit_addr; + size_t saved_stack_commit_addr = thread_data->stack_commit_addr; bool thread_first_init = (saved_stack_commit_addr == 0) ? true : false; #endif size_t stack_guard = thread_data->stack_guard; @@ -292,25 +287,28 @@ sgx_status_t do_init_thread(void *tcs) thread_data->first_ssa_gpr += (size_t)tcs; thread_data->tls_array += (size_t)tcs; thread_data->tls_addr += (size_t)tcs; - thread_data->last_sp -= (size_t)STATIC_STACK_SIZE; thread_data->stack_base_addr -= (size_t)STATIC_STACK_SIZE; thread_data->stack_guard = stack_guard; thread_data->flags = thread_flags; init_static_stack_canary(tcs); -#ifndef SE_SIM - if (EDMM_supported && is_dynamic_thread(tcs)) + if (enclave_init) { - if (thread_first_init) - { + thread_data->flags = SGX_UTILITY_THREAD; + } +#ifndef SE_SIM + if (thread_first_init) + { + if (EDMM_supported && (enclave_init || is_dynamic_thread(tcs))) + { uint32_t page_count = get_dynamic_stack_max_page(); thread_data->stack_commit_addr += ((sys_word_t)page_count << SE_PAGE_SHIFT); } - else - { - thread_data->stack_commit_addr = saved_stack_commit_addr; - } + } + else + { + thread_data->stack_commit_addr = saved_stack_commit_addr; } #endif @@ -340,7 +338,7 @@ sgx_status_t do_ecall(int index, void *ms, void *tcs) thread_data_t *thread_data = get_thread_data(); if( (NULL == thread_data) || ((thread_data->stack_base_addr == thread_data->last_sp) && (0 != g_global_data.thread_policy))) { - status = do_init_thread(tcs); + status = do_init_thread(tcs, false); if(0 != status) { return status; @@ -350,35 +348,32 @@ sgx_status_t do_ecall(int index, void *ms, void *tcs) return status; } -sgx_status_t do_ecall_add_thread(void *ms, void *tcs) +sgx_status_t do_ecall_add_thread(void *ms) { sgx_status_t status = SGX_ERROR_UNEXPECTED; if(!is_utility_thread()) return status; - struct ms_tcs *ms_tcs = (struct ms_tcs*)ms; - if (ms_tcs == NULL) + struct ms_tcs *tcs = (struct ms_tcs*)ms; + if (tcs == NULL) { return status; } - if (!sgx_is_outside_enclave(ms_tcs, sizeof(struct ms_tcs))) + if (!sgx_is_outside_enclave(tcs, sizeof(struct ms_tcs))) { abort(); } - void* ptcs = ms_tcs->ptcs; + const struct ms_tcs mtcs = *tcs; + void* ptcs = mtcs.ptcs; if (ptcs == NULL) { return status; } - status = do_init_thread(tcs); - if(SGX_SUCCESS != status) - { - return status; - } + __builtin_ia32_lfence(); status = do_save_tcs(ptcs); if(SGX_SUCCESS != status) @@ -409,12 +404,9 @@ sgx_status_t do_uninit_enclave(void *tcs) #ifndef SE_SIM if(is_dynamic_thread_exist() && !is_utility_thread()) return SGX_ERROR_UNEXPECTED; -#endif - sgx_spin_lock(&g_tcs_node_lock); +#endif tcs_node_t *tcs_node = g_tcs_node; g_tcs_node = NULL; - sgx_spin_unlock(&g_tcs_node_lock); - while (tcs_node != NULL) { if (DEC_TCS_POINTER(tcs_node->tcs) == tcs) diff --git a/sdk/trts/trts_internal.h b/sdk/trts/trts_internal.h index 6ef5d20f..3d14c805 100644 --- a/sdk/trts/trts_internal.h +++ b/sdk/trts/trts_internal.h @@ -64,12 +64,12 @@ void *get_enclave_base(); int get_enclave_state(); void set_enclave_state(int state); -sgx_status_t do_init_thread(void *tcs); -sgx_status_t do_init_enclave(void *ms, void *tcs); +sgx_status_t do_init_thread(void *tcs, bool enclave_init); +sgx_status_t do_init_enclave(void *ms, void *tcs) __attribute__((section(".nipx"))); sgx_status_t do_ecall(int index, void *ms, void *tcs); sgx_status_t do_oret(void *ms); sgx_status_t trts_handle_exception(void *tcs); -sgx_status_t do_ecall_add_thread(void *ms, void *tcs); +sgx_status_t do_ecall_add_thread(void *ms); sgx_status_t do_uninit_enclave(void *tcs); int check_static_stack_canary(void *tcs); #ifdef __cplusplus diff --git a/sdk/trts/trts_nsp.cpp b/sdk/trts/trts_nsp.cpp index b119c96d..d4e82641 100644 --- a/sdk/trts/trts_nsp.cpp +++ b/sdk/trts/trts_nsp.cpp @@ -71,6 +71,8 @@ static void init_stack_guard(void *tcs) thread_data->stack_guard = tmp_stack_guard; } +extern "C" int enter_enclave(int index, void *ms, void *tcs, int cssa) __attribute__((section(".nipx"))); + extern "C" int enter_enclave(int index, void *ms, void *tcs, int cssa) { if(sgx_is_enclave_crashed()) @@ -97,9 +99,7 @@ extern "C" int enter_enclave(int index, void *ms, void *tcs, int cssa) } else if(index == ECMD_MKTCS) { - // Initialize stack guard if necessary - init_stack_guard(tcs); - error = do_ecall_add_thread(ms, tcs); + error = do_ecall_add_thread(ms); } else if(index == ECMD_UNINIT_ENCLAVE) { diff --git a/sdk/trts/trts_shared_constants.h b/sdk/trts/trts_shared_constants.h index 1aa120c7..1695b904 100644 --- a/sdk/trts/trts_shared_constants.h +++ b/sdk/trts/trts_shared_constants.h @@ -29,6 +29,7 @@ * */ + /* * trts_shared_constants.h: * Defines constants shared in C/C++ code and assembly code. diff --git a/sdk/trts/trts_xsave.cpp b/sdk/trts/trts_xsave.cpp index 53fcbd90..ee0ffac6 100644 --- a/sdk/trts/trts_xsave.cpp +++ b/sdk/trts/trts_xsave.cpp @@ -41,7 +41,7 @@ //FXRSTOR only cares about the first 512 bytes, while //XRSTOR in compacted mode will ignore the first 512 bytes. extern "C" SE_DECLSPEC_ALIGN(XSAVE_ALIGN_SIZE) const uint32_t -SYNTHETIC_STATE[SYNTHETIC_STATE_SIZE/sizeof(uint32_t)] = { +SYNTHETIC_STATE[SYNTHETIC_STATE_SIZE/sizeof(uint32_t)] __attribute__((section(".niprod"))) = { 0x037F, 0, 0, 0, 0, 0, 0x1F80, 0xFFFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -53,10 +53,10 @@ SYNTHETIC_STATE[SYNTHETIC_STATE_SIZE/sizeof(uint32_t)] = { 0, 0, 0, 0x80000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // XCOMP_BV[63] = 1, compaction mode }; -int g_xsave_enabled = 0; // flag to indicate whether xsave is enabled or not +int g_xsave_enabled __attribute__((section(".nipd"))) = 0; // flag to indicate whether xsave is enabled or not #ifdef SE_SIM -uint32_t g_xsave_mask_high = 0xFFFFFFFF; -uint32_t g_xsave_mask_low = 0xFFFFFFFF; +uint32_t g_xsave_mask_high __attribute__((section(".nipd"))) = 0xFFFFFFFF; +uint32_t g_xsave_mask_low __attribute__((section(".nipd"))) = 0xFFFFFFFF; #endif // EENTER will set xcr0 with secs.attr.xfrm, diff --git a/sdk/tsetjmp/_setjmp.S b/sdk/tsetjmp/_setjmp.S index 33290faf..0a8bb26d 100644 --- a/sdk/tsetjmp/_setjmp.S +++ b/sdk/tsetjmp/_setjmp.S @@ -184,20 +184,12 @@ DECLARE_GLOBAL_FUNC longjmp cmpl $0, %eax jz .crash addl $(2*SE_WORDSIZE), %esp - /* restore xbp and xsp, push them to stack */ + /* restore xsp */ movl (SE_WORDSIZE + 8*SE_WORDSIZE)(%esp), %eax movl (_JB_ESP * SE_WORDSIZE)(%eax), %ebx - movl (_JB_EBP * SE_WORDSIZE)(%eax), %ecx call get_stack_guard xorl %eax, %ebx - xorl %eax, %ecx pushl %ebx - pushl %ecx - /* check restored ebp is on current statck */ - call is_valid_sp - cmpl $0, %eax - jz .crash - popl %ecx /* check restored esp is on current statck */ call is_valid_sp cmpl $0, %eax @@ -240,19 +232,11 @@ DECLARE_GLOBAL_FUNC longjmp cmpl $0, %eax jz .crash popq %rdi - /* restore xbp and xsp, push them to stack */ - movq (_JB_RBP * SE_WORDSIZE)(%rdi),%rcx + /* restore xsp*/ movq (_JB_RSP * SE_WORDSIZE)(%rdi),%rdx call get_stack_guard - xorq %rax, %rcx xorq %rax, %rdx pushq %rdx - pushq %rcx - /* check restored rbp is on current statck */ - popq %rdi - call is_valid_sp - cmpl $0, %eax - jz .crash /* check restored rsp is on current statck */ popq %rdi call is_valid_sp diff --git a/sdk/ukey_exchange/Makefile b/sdk/ukey_exchange/Makefile index 2aaefad6..9be7f0a1 100644 --- a/sdk/ukey_exchange/Makefile +++ b/sdk/ukey_exchange/Makefile @@ -44,7 +44,7 @@ vpath %.cpp $(COMMON_DIR)/src vpath %.c $(TOP_DIR)/common/src -CXXFLAGS += -fPIC -fno-rtti $(INCLUDE) +CXXFLAGS += -fPIC -fno-exceptions -fno-rtti $(INCLUDE) CFLAGS += -fPIC $(INCLUDE) OBJ := ukey_exchange.o se_thread.o ukey_exchange_version.o
      -
    • Eclipse* Mars 1 with CDT IDE for C/C++ Developers (version 4.5.1). To use this version, install Java* Development Kit (JDK) or Java* Runtime Environment (JRE) version 1.8 or above.
    • +
    • Eclipse* Oxygen 3 with CDT IDE for C/C++ Developers (version 4.7.3). To use this version, install Java* Development Kit (JDK) or Java* Runtime Environment (JRE) version 1.8 or above.
    • gcc/g++ tools
    • Openssl*
    • Intel(R) SGX SDK for Linux* OS
    • diff --git a/Linux_SGXEclipsePlugin/clean.sh b/Linux_SGXEclipsePlugin/clean.sh index ba0f7bc7..41d3ec68 100755 --- a/Linux_SGXEclipsePlugin/clean.sh +++ b/Linux_SGXEclipsePlugin/clean.sh @@ -13,7 +13,7 @@ rm -fv build_directory/features/com.intel.sgx.feature/build.xml rm -fv build_directory/features/com.intel.sgx.feature/*.zip rm -rfv build_directory/nestedJars rm -rfv build_directory/updatesite/sgx-eclipse-plugin -find . -name "*.zip" ! -name "eclipse_mars.v4.5.1_x64.zip" | xargs rm -rfv +find . -name "*.zip" ! -name "eclipse_oxygen.v4.7.3_x64.zip" | xargs rm -rfv find . -name "javaCompiler*" | xargs rm -rfv find . -name "@*" | xargs rm -rfv find build_directory -maxdepth 1 -mindepth 1 | grep -v "features" | grep -v "plugins" | grep -v "sites" | grep -v "updatesite" | xargs rm -frv diff --git a/Linux_SGXEclipsePlugin/readme.txt b/Linux_SGXEclipsePlugin/readme.txt index a767f8ca..e602a686 100644 --- a/Linux_SGXEclipsePlugin/readme.txt +++ b/Linux_SGXEclipsePlugin/readme.txt @@ -6,8 +6,8 @@ $DELETE_CURRENT_ECLIPSE - Delete current eclipse or not. Generally this variable The following plugins are pre-requisites to be installed in Eclipse before trying to build the plugin. -1. Eclipse IDE for C/C++ Developers 4.5.1.20150917-1200 (tested_version) -2. Eclipse PDE Plug-in Developer Resources 3.11.1.v20150904-0345 (tested_version) +1. Eclipse IDE for C/C++ Developers 4.7.3.20180308-1800 (tested_version) +2. Eclipse PDE Plug-in Developer Resources 3.13.3.v20180301-11 (tested_version) run ./build.sh from command line under current directory. Once the build script is run, the folder build_directory/updatesite/sgx-eclipse-plugin contains the update site. This is the path that needs to be provided to the eclipse while doing installation. diff --git a/SampleCode/SampleEnclavePCL/App/App.cpp b/SampleCode/SampleEnclavePCL/App/App.cpp new file mode 100644 index 00000000..9ef3dbe9 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/App.cpp @@ -0,0 +1,367 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include +#include + +# include +# include +# define MAX_PATH FILENAME_MAX + +#include "sgx_urts.h" +#include "App.h" +#include "Enclave_u.h" +#include "Seal_u.h" + +#define SEAL_FILENAME "Seal.signed.so" +#define SEALED_KEY_FILE_NAME "sealed_key.bin" +#define TOKEN_FILENAME "enclave.token" + +/* Global EID shared by multiple threads */ +sgx_enclave_id_t global_eid = 0; + +typedef struct _sgx_errlist_t { + sgx_status_t err; + const char *msg; + const char *sug; /* Suggestion */ +} sgx_errlist_t; + +/* Error code returned by sgx_create_enclave */ +static sgx_errlist_t sgx_errlist[] = { + { + SGX_ERROR_UNEXPECTED, + "Unexpected error occurred.", + NULL + }, + { + SGX_ERROR_INVALID_PARAMETER, + "Invalid parameter.", + NULL + }, + { + SGX_ERROR_OUT_OF_MEMORY, + "Out of memory.", + NULL + }, + { + SGX_ERROR_ENCLAVE_LOST, + "Power transition occurred.", + "Please refer to the sample \"PowerTransition\" for details." + }, + { + SGX_ERROR_INVALID_ENCLAVE, + "Invalid enclave image.", + NULL + }, + { + SGX_ERROR_INVALID_ENCLAVE_ID, + "Invalid enclave identification.", + NULL + }, + { + SGX_ERROR_INVALID_SIGNATURE, + "Invalid enclave signature.", + NULL + }, + { + SGX_ERROR_OUT_OF_EPC, + "Out of EPC memory.", + NULL + }, + { + SGX_ERROR_NO_DEVICE, + "Invalid Intel(R) SGX device.", + "Please make sure Intel(R) SGX module is enabled in the BIOS, and install Intel(R) SGX driver afterwards." + }, + { + SGX_ERROR_MEMORY_MAP_CONFLICT, + "Memory map conflicted.", + NULL + }, + { + SGX_ERROR_INVALID_METADATA, + "Invalid enclave metadata.", + NULL + }, + { + SGX_ERROR_DEVICE_BUSY, + "Intel(R) SGX device was busy.", + NULL + }, + { + SGX_ERROR_INVALID_VERSION, + "Enclave version was invalid.", + NULL + }, + { + SGX_ERROR_INVALID_ATTRIBUTE, + "Enclave was not authorized.", + NULL + }, + { + SGX_ERROR_ENCLAVE_FILE_ACCESS, + "Can't open enclave file.", + NULL + }, + { + SGX_ERROR_PCL_ENCRYPTED, + "sgx_create_enclave can't open encrypted enclave.", + NULL + }, + { + SGX_ERROR_PCL_NOT_ENCRYPTED, + "sgx_create_encrypted_enclave can't open not-encrypted enclave.", + NULL + }, + { + SGX_ERROR_PCL_MAC_MISMATCH, + "PCL detected invalid section in encrypted enclave.", + NULL + }, + { + SGX_ERROR_PCL_SHA_MISMATCH, + "PCL sealed key SHA mismatch.", + NULL + }, + { + SGX_ERROR_PCL_GUID_MISMATCH, + "PCL sealed key GUID mismatch.", + NULL + }, +}; + +/* Check error conditions for loading enclave */ +void print_error_message(sgx_status_t ret) +{ + size_t idx = 0; + size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0]; + + for (idx = 0; idx < ttl; idx++) { + if(ret == sgx_errlist[idx].err) { + if(NULL != sgx_errlist[idx].sug) + printf("Info: %s\n", sgx_errlist[idx].sug); + printf("Error: %s\n", sgx_errlist[idx].msg); + break; + } + } + + if (idx == ttl) + printf("Error: Unexpected error occurred.\n"); +} + +/* Initialize the enclave: + * Step 1: try to retrieve the launch token saved by last transaction + * Step 2: call sgx_create_enclave to initialize an enclave instance + * Step 3: save the launch token if it is updated + */ +sgx_status_t initialize_enclave ( const char *file_name, sgx_enclave_id_t* eid ) +{ + char token_path[MAX_PATH] = {'\0'}; + sgx_launch_token_t token = {0}; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + int updated = 0; + size_t read_num = 0; + + /* Step 1: try to retrieve the launch token saved by last transaction + * if there is no token, then create a new one. + */ + /* try to get the token saved in $HOME */ + const char *home_dir = getpwuid(getuid())->pw_dir; + + if (home_dir != NULL && + (strlen(home_dir)+strlen("/")+sizeof(TOKEN_FILENAME)+1) <= MAX_PATH) { + /* compose the token path */ + strncpy(token_path, home_dir, strlen(home_dir)); + strncat(token_path, "/", strlen("/")); + strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)+1); + } else { + /* if token path is too long or $HOME is NULL */ + strncpy(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)); + } + + FILE *fp = fopen(token_path, "rb"); + if (fp == NULL && (fp = fopen(token_path, "wb")) == NULL) { + printf("Warning: Failed to create/open the launch token file \"%s\".\n", token_path); + } + + if (fp != NULL) { + /* read the token from saved file */ + read_num = fread(token, 1, sizeof(sgx_launch_token_t), fp); + if (read_num != 0 && read_num != sizeof(sgx_launch_token_t)) { + /* if token is invalid, clear the buffer */ + memset(&token, 0x0, sizeof(sgx_launch_token_t)); + printf("Warning: Invalid launch token read from \"%s\".\n", token_path); + } + } + /* Step 2: call sgx_create_enclave to initialize an enclave instance */ + /* Debug Support: set 2nd parameter to 1 */ +#ifdef SGX_USE_PCL + bool open_seal_enclave = true; + uint8_t* sealed_blob = NULL; + FILE *fsealp = fopen(SEALED_KEY_FILE_NAME, "rb"); + size_t sealed_blob_size = 0; + if(NULL != fsealp) + { + // Read file size: + fseek(fsealp, 0L, SEEK_END); + sealed_blob_size = ftell(fsealp); + fseek(fsealp, 0L, SEEK_SET); + // Read file into buffer: + sealed_blob = new uint8_t[sealed_blob_size]; + read_num = fread(sealed_blob, 1, sealed_blob_size, fsealp); + if ( read_num != sealed_blob_size ) + { + printf ( "Warning: Failed to read sealed blob.\n" ); + } + else + { + open_seal_enclave = false; + } + fclose(fsealp); + } + if (true == open_seal_enclave) + { + printf ("Open Seal Enclave: %s\n", SEAL_FILENAME ); + sgx_enclave_id_t seal_eid = 0; + ret = sgx_create_enclave( + SEAL_FILENAME, + SGX_DEBUG_FLAG, + &token, + &updated, + &seal_eid, + NULL); + if (SGX_SUCCESS != ret) + { + print_error_message(ret); + if(NULL != fp) + { + fclose(fp); + } + return ret; + } + ret = ecall_get_sealed_blob_size(seal_eid, &sealed_blob_size); + if (ret != SGX_SUCCESS || UINT32_MAX == sealed_blob_size) + { + printf("ecall_get_sealed_blob_size: ret = %d, sealed_blob_size = %ld\n", ret, sealed_blob_size); + sgx_destroy_enclave(seal_eid); + return ret; + } + //printf("ecall_get_sealed_blob_size: ret = %d, sealed_blob_size = %ld\n", ret, sealed_blob_size); + sealed_blob = new uint8_t[sealed_blob_size]; + sgx_status_t gret = SGX_ERROR_UNEXPECTED; + ret = ecall_generate_sealed_blob(seal_eid, &gret, sealed_blob, sealed_blob_size); + if ((SGX_SUCCESS != ret) || (SGX_SUCCESS != gret)) + { + printf("ecall_generate_sealed_blob: ret = %d, gret = 0x%x\n", ret, gret); + sgx_destroy_enclave(seal_eid); + delete sealed_blob; + return ret; + } + sgx_destroy_enclave(seal_eid); + fsealp = fopen(SEALED_KEY_FILE_NAME, "wb"); + if(NULL != fsealp) + { + fwrite(sealed_blob, 1, sealed_blob_size, fsealp); + fclose(fsealp); + } + } + // Load the PCL protected Enclave: + ret = sgx_create_encrypted_enclave(file_name, SGX_DEBUG_FLAG, &token, &updated, eid, NULL, sealed_blob); + delete sealed_blob; +#else // SGX_USE_PCL + ret = sgx_create_enclave(file_name, SGX_DEBUG_FLAG, &token, &updated, eid, NULL); +#endif // SGX_USE_PCL + if (ret != SGX_SUCCESS) { + print_error_message(ret); + if (fp != NULL) fclose(fp); + return ret; + } + + /* Step 3: save the launch token if it is updated */ + if (updated == FALSE || fp == NULL) { + /* if the token is not updated, or file handler is invalid, do not perform saving */ + if (fp != NULL) fclose(fp); + return SGX_SUCCESS; + } + + /* reopen the file with write capablity */ + fp = freopen(token_path, "wb", fp); + if (fp == NULL) return SGX_SUCCESS; + size_t write_num = fwrite(token, 1, sizeof(sgx_launch_token_t), fp); + if (write_num != sizeof(sgx_launch_token_t)) + printf("Warning: Failed to save launch token to \"%s\".\n", token_path); + fclose(fp); + return SGX_SUCCESS; +} + +/* OCall functions */ +void ocall_print_string(const char *str) +{ + /* Proxy/Bridge will check the length and null-terminate + * the input string to prevent buffer overflow. + */ + printf("%s", str); +} + + +/* Application entry */ +int SGX_CDECL main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + + /* Initialize the enclave */ + if ( initialize_enclave ( ENCLAVE_FILENAME, &global_eid ) < 0 ){ + return -1; + } + + /* Utilize edger8r attributes */ + edger8r_array_attributes(); + edger8r_pointer_attributes(); + edger8r_type_attributes(); + edger8r_function_attributes(); + + /* Utilize trusted libraries */ + ecall_libc_functions(); + ecall_libcxx_functions(); + ecall_thread_functions(); + + /* Destroy the enclave */ + sgx_destroy_enclave(global_eid); + + printf("Info: SampleEnclave successfully returned.\n"); + + return 0; +} + diff --git a/SampleCode/SampleEnclavePCL/App/App.h b/SampleCode/SampleEnclavePCL/App/App.h new file mode 100644 index 00000000..36c45b0e --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/App.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _APP_H_ +#define _APP_H_ + +#include +#include +#include +#include + +#include "sgx_error.h" /* sgx_status_t */ +#include "sgx_eid.h" /* sgx_enclave_id_t */ + +#ifndef TRUE +# define TRUE 1 +#endif + +#ifndef FALSE +# define FALSE 0 +#endif + +#define TOKEN_FILENAME "enclave.token" +#define ENCLAVE_FILENAME "enclave.signed.so" +#define SEAL_TOKEN_FILENAME "seal.token" +#define SEAL_FILENAME "Seal.signed.so" +#define SEALED_KEY_FILE_NAME "sealed_key.bin" + +extern sgx_enclave_id_t global_eid; /* global enclave id */ + +#if defined(__cplusplus) +extern "C" { +#endif + +void edger8r_array_attributes(void); +void edger8r_type_attributes(void); +void edger8r_pointer_attributes(void); +void edger8r_function_attributes(void); + +void ecall_libc_functions(void); +void ecall_libcxx_functions(void); +void ecall_thread_functions(void); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_APP_H_ */ diff --git a/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp new file mode 100644 index 00000000..9904948f --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Arrays.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_array_attributes: + * Invokes ECALLs declared with array attributes. + */ +void edger8r_array_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + /* user_check */ + int arr1[4] = {0, 1, 2, 3}; + ret = ecall_array_user_check(global_eid, arr1); + if (ret != SGX_SUCCESS) + abort(); + + /* make sure arr1 is changed */ + for (int i = 0; i < 4; i++) + assert(arr1[i] == (3 - i)); + + /* in */ + int arr2[4] = {0, 1, 2, 3}; + ret = ecall_array_in(global_eid, arr2); + if (ret != SGX_SUCCESS) + abort(); + + /* arr2 is not changed */ + for (int i = 0; i < 4; i++) + assert(arr2[i] == i); + + /* out */ + int arr3[4] = {0, 1, 2, 3}; + ret = ecall_array_out(global_eid, arr3); + if (ret != SGX_SUCCESS) + abort(); + + /* arr3 is changed */ + for (int i = 0; i < 4; i++) + assert(arr3[i] == (3 - i)); + + /* in, out */ + int arr4[4] = {0, 1, 2, 3}; + ret = ecall_array_in_out(global_eid, arr4); + if (ret != SGX_SUCCESS) + abort(); + + /* arr4 is changed */ + for (int i = 0; i < 4; i++) + assert(arr4[i] == (3 - i)); + + /* isary */ + array_t arr5 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + ret = ecall_array_isary(global_eid, arr5); + if (ret != SGX_SUCCESS) + abort(); + + /* arr5 is changed */ + for (int i = 0; i < 10; i++) + assert(arr5[i] == (9 - i)); +} diff --git a/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp new file mode 100644 index 00000000..57f4fbf8 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Functions.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* No need to implement memccpy here! */ + +/* edger8r_function_attributes: + * Invokes ECALL declared with calling convention attributes. + * Invokes ECALL declared with [public]. + */ +void edger8r_function_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_function_calling_convs(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_function_public(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + /* user shall not invoke private function here */ + int runned = 0; + ret = ecall_function_private(global_eid, &runned); + if (ret != SGX_ERROR_ECALL_NOT_ALLOWED || runned != 0) + abort(); +} + +/* ocall_function_allow: + * The OCALL invokes the [allow]ed ECALL 'edger8r_private'. + */ +void ocall_function_allow(void) +{ + int runned = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_function_private(global_eid, &runned); + if (ret != SGX_SUCCESS || runned != 1) + abort(); +} diff --git a/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp new file mode 100644 index 00000000..a7c22f3d --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Pointers.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_pointer_attributes: + * Invokes the ECALLs declared with pointer attributes. + */ +void edger8r_pointer_attributes(void) +{ + int val = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + char c[128] = {0}; + size_t len = 0; + memset(c, 0xe, 128); + ret = ecall_pointer_user_check(global_eid, &len, &c, 128); + if (ret != SGX_SUCCESS) + abort(); + assert(strcmp(c, "SGX_SUCCESS") == 0); + + + val = 0; + ret = ecall_pointer_in(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 0); + + val = 0; + ret = ecall_pointer_out(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + val = 0; + ret = ecall_pointer_in_out(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + ret = ocall_pointer_attr(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + char str1[] = "1234567890"; + ret = ecall_pointer_string(global_eid, str1); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str1, "0987654321", strlen(str1)) == 0); + + const char str2[] = "1234567890"; + ret = ecall_pointer_string_const(global_eid, str2); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str2, "1234567890", strlen(str2)) == 0); + + char str3[] = "1234567890"; + ret = ecall_pointer_size(global_eid, (void*)str3, strlen(str3)); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str3, "0987654321", strlen(str3)) == 0); + + char str4[] = "1234567890"; + ret = ecall_pointer_isptr_readonly(global_eid, (buffer_t)str4, strlen(str4)); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str4, "1234567890", strlen(str4)) == 0); + + int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + ret = ecall_pointer_count(global_eid, arr, 10); + if (ret != SGX_SUCCESS) + abort(); + + for (int i = 0; i < 10; i++) + assert(arr[i] == (9 - i)); + + return; +} + +/* ocall_pointer_user_check: + * The OCALL declared with [user_check]. + */ +void ocall_pointer_user_check(int* val) +{ + (void)val; + assert(val != NULL); +} + +/* ocall_pointer_in: + * The OCALL declared with [in]. + */ +void ocall_pointer_in(int* val) +{ + *val = 1234; +} + +/* ocall_pointer_out: + * The OCALL declared with [out]. + */ +void ocall_pointer_out(int* val) +{ + *val = 1234; +} + +/* ocall_pointer_in_out: + * The OCALL declared with [in, out]. + */ +void ocall_pointer_in_out(int* val) +{ + *val = 1234; +} diff --git a/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp new file mode 100644 index 00000000..e56e2299 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/Edger8rSyntax/Types.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_type_attributes: + * Invokes ECALLs declared with basic types. + */ +void edger8r_type_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_type_char(global_eid, (char)0x12); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_int(global_eid, (int)1234); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_float(global_eid, (float)1234.0); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_double(global_eid, (double)1234.5678); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_size_t(global_eid, (size_t)12345678); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_wchar_t(global_eid, (wchar_t)0x1234); + if (ret != SGX_SUCCESS) + abort(); + + struct struct_foo_t g = {1234, 5678}; + ret = ecall_type_struct(global_eid, g); + if (ret != SGX_SUCCESS) + abort(); + + union union_foo_t val = {0}; + ret = ecall_type_enum_union(global_eid, ENUM_FOO_0, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val.union_foo_0 == 2); +} diff --git a/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp new file mode 100644 index 00000000..0d2b5dd6 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libc.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* ecall_libc_functions: + * Invokes standard C functions. + */ +void ecall_libc_functions(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_malloc_free(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + int cpuid[4] = {0x1, 0x0, 0x0, 0x0}; + ret = ecall_sgx_cpuid(global_eid, cpuid, 0x0); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp new file mode 100644 index 00000000..223ef486 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Libcxx.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include "../App.h" +#include "Enclave_u.h" + +/* ecall_libcxx_functions: + * Invokes standard C++ functions. + */ +void ecall_libcxx_functions(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_exception(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_map(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp new file mode 100644 index 00000000..c4d21c4c --- /dev/null +++ b/SampleCode/SampleEnclavePCL/App/TrustedLibrary/Thread.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include +using namespace std; + +#include "../App.h" +#include "Enclave_u.h" + +static size_t counter = 0; + +void increase_counter(void) +{ + size_t cnr = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_increase_counter(global_eid, &cnr); + if (cnr != 0) counter = cnr; + if (ret != SGX_SUCCESS) + abort(); +} + +void data_producer(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_producer(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} + +void data_consumer(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_consumer(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} + +/* ecall_thread_functions: + * Invokes thread functions including mutex, condition variable, etc. + */ +void ecall_thread_functions(void) +{ + thread adder1(increase_counter); + thread adder2(increase_counter); + thread adder3(increase_counter); + thread adder4(increase_counter); + + adder1.join(); + adder2.join(); + adder3.join(); + adder4.join(); + + assert(counter == 4*LOOPS_PER_THREAD); + + printf("Info: executing thread synchronization, please wait... \n"); + /* condition variable */ + thread consumer1(data_consumer); + thread producer0(data_producer); + thread consumer2(data_consumer); + thread consumer3(data_consumer); + thread consumer4(data_consumer); + + consumer1.join(); + consumer2.join(); + consumer3.join(); + consumer4.join(); + producer0.join(); +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp new file mode 100644 index 00000000..e1fbae1a --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Test Array Attributes */ + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_array_user_check: + * [user_check] parameter does not perfrom copy operations. + */ +void ecall_array_user_check(int arr[4]) +{ + if (sgx_is_outside_enclave(arr, 4 * sizeof(int)) != 1) + abort(); + + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = 3 - i; + } +} + +/* ecall_array_in: + * arr[] is copied to trusted domain, but modified + * results will not be reflected to the untrusted side. + */ +void ecall_array_in(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = (3 - i); + } +} + +/* ecall_array_out: + * arr[] is allocated inside the enclave, and it will be copied + * to the untrusted side + */ +void ecall_array_out(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + /* arr is not copied from App */ + assert(arr[i] == 0); + arr[i] = (3 - i); + } +} + +/* ecall_array_in_out: + * arr[] will be allocated inside the enclave, content of arr[] will be copied either. + * After ECALL returns, the results will be copied to the outside. + */ +void ecall_array_in_out(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = (3 - i); + } +} + +/* ecall_array_isary: + * [isary] tells Edger8r that user defined 'array_t' is an array type. + */ +void ecall_array_isary(array_t arr) +{ + if (sgx_is_outside_enclave(arr, sizeof(array_t)) != 1) + abort(); + + int n = sizeof(array_t)/sizeof(arr[0]); + for (int i = 0; i < n; i++) { + assert(arr[i] == i); + arr[i] = (n - 1 - i); + } +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl new file mode 100644 index 00000000..3b35d681 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Arrays.edl @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Arrays.edl - Samples for array attributes. */ + +enclave { + + /* + * Only for fixed-size array (size is explicitly specified). + */ + + trusted { + + /* + * []: can be used to declare an array. + * [user_check]: + * pointer of the array won't be valified, and the buffer pointed by 'arr' + * is not copied into the enclave either. But enclave can modify the memory outside. + */ + + public void ecall_array_user_check([user_check] int arr[4]); + + /* + * [in]: + * buffer for the array will be allocated inside the enclave, + * content of the array will be copied into the new allocated memory inside. + * Any changes performed inside the enclave will not affect the array outside. + */ + + public void ecall_array_in([in] int arr[4]); + + /* + * [out]: + * buffer for the array will be allocated inside the enclave, + * but the content of the array won't be copied. After ECALL returns, + * the buffer inside the enclave will copied into outside array. + */ + + public void ecall_array_out([out] int arr[4]); + + /* + * [in, out]: + * buffer for the array will be allocated inside the enclave, + * the content of the array will be copied either. After ECALL returns, + * the buffer inside the enclave will by copied into outside array again. + */ + + public void ecall_array_in_out([in, out] int arr[4]); + + /* + * [isary]: + * tells Edger8r the user defined 'array_t' is an array type, 'arr' will be + * treated as a pointer, no memory copied either due to [user_check]. + * For OCALLs, 'arr' shall point to the memory outside the enclave. + */ + + public void ecall_array_isary([user_check, isary] array_t arr); + + }; + + untrusted { + + /* + * [user_check|in|out|in,out|isary] can also be used in OCALLs, refer to the "User Guide" for details. + */ + + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp new file mode 100644 index 00000000..914f5cd1 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Calling Conventions */ + +#include +#include + +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_function_calling_convs: + * memccpy is defined in system C library. + */ +void ecall_function_calling_convs(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + char s1[] = "1234567890"; + char s2[] = "0987654321"; + + char buf[BUFSIZ] = {'\0'}; + memcpy(buf, s1, strlen(s1)); + + ret = memccpy(NULL, s1, s2, '\0', strlen(s1)); + + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(s1, s2, strlen(s1)) == 0); + + return; +} + +/* ecall_function_public: + * The public ECALL that invokes the OCALL 'ocall_function_allow'. + */ +void ecall_function_public(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ocall_function_allow(); + if (ret != SGX_SUCCESS) + abort(); + + return; +} + +/* ecall_function_private: + * The private ECALL that only can be invoked in the OCALL 'ocall_function_allow'. + */ +int ecall_function_private(void) +{ + return 1; +} + diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl new file mode 100644 index 00000000..3d33b01b --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Functions.edl @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Functions.edl - Samples for function attributes. */ + +enclave { + + /* + * Following keywords/attributes are supported for untrusted functions: + * cdecl, stdcall, fastcall, dllimport (only for Windows). + * [public] is only supported for the trusted functions. + * Trusted function will be treated as [private] w/o the [public]. + */ + + trusted { + + public void ecall_function_calling_convs(void); + + /* + * [public]: + * public ECALL can be called directly in App. + */ + + public void ecall_function_public(void); + + /* + * [private]: + * private ECALL cannot be called directly in App. + */ + + int ecall_function_private(void); + + }; + + untrusted { + + /* + * [cdecl]: + * tells edger8r the calling convention of the OCALLs is 'cdecl'. + * [dllimport]: + * indicats the OCALL is provided in DLLs. + * + * Note: memccpy() is provided by MS system DLL, we don't need to implement it in App side. + */ + + [cdecl, dllimport] void *memccpy([in, out, size=len] void *dest, [in, size=len] const void *src, int val, size_t len); + + /* + * [allow]: + * OCALL 'ocall_function_allow' can invoke ECALL 'ecall_function_private' in App side. + * + * Note: No ECALL can be called in OCALL w/o [allow]. + */ + + void ocall_function_allow(void) allow(ecall_function_private); + + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp new file mode 100644 index 00000000..70ccfc0d --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Pointer Auttributes */ + +#include +#include + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* checksum_internal: + * get simple checksum of input buffer and length + */ +int32_t checksum_internal(char *buf, size_t count) +{ + register int32_t sum = 0; + int16_t *ptr = (int16_t *)buf; + + /* Main summing loop */ + while(count > 1) { + sum = sum + *ptr++; + count = count - 2; + } + + /* Add left-over byte, if any */ + if (count > 0) + sum = sum + *((char *)ptr); + + return ~sum; +} + +/* ecall_pointer_user_check, ecall_pointer_in, ecall_pointer_out, ecall_pointer_in_out: + * The root ECALLs to test [in], [out], [user_check] attributes. + */ +size_t ecall_pointer_user_check(void *val, size_t sz) +{ + /* check if the buffer is allocated outside */ + if (sgx_is_outside_enclave(val, sz) != 1) + abort(); + + char tmp[100] = {0}; + size_t len = sz>100?100:sz; + + /* copy the memory into the enclave to make sure 'val' + * is not being changed in checksum_internal() */ + memcpy(tmp, val, len); + + int32_t sum = checksum_internal((char *)tmp, len); + printf("Checksum(0x%p, %zu) = 0x%x\n", + val, len, (unsigned int)sum); + + /* modify outside memory directly */ + memcpy(val, "SGX_SUCCESS", len>12?12:len); + + return len; +} + +/* ecall_pointer_in: + * the buffer of val is copied to the enclave. + */ + +void ecall_pointer_in(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + *val = 1234; +} + +/* ecall_pointer_out: + * the buffer of val is copied to the untrusted side. + */ +void ecall_pointer_out(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + assert(*val == 0); + *val = 1234; +} + +/* ecall_pointer_in_out: + * the buffer of val is double-copied. + */ +void ecall_pointer_in_out(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + *val = 1234; +} + +/* ocall_pointer_attr: + * The root ECALL that test OCALL [in], [out], [user_check]. + */ +void ocall_pointer_attr(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + int val = 0; + ret = ocall_pointer_user_check(&val); + if (ret != SGX_SUCCESS) + abort(); + + val = 0; + ret = ocall_pointer_in(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 0); + + val = 0; + ret = ocall_pointer_out(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + val = 0; + ret = ocall_pointer_in_out(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + return; +} + +/* ecall_pointer_string: + * [string] defines a string. + */ +void ecall_pointer_string(char *str) +{ + strncpy(str, "0987654321", strlen(str)); +} + +/* ecall_pointer_string_const: + * const [string] defines a string that cannot be modified. + */ +void ecall_pointer_string_const(const char *str) +{ + char* temp = new char[strlen(str)]; + strncpy(temp, str, strlen(str)); + delete []temp; +} + +/* ecall_pointer_size: + * 'len' needs to be specified to tell Edger8r the length of 'str'. + */ +void ecall_pointer_size(void *ptr, size_t len) +{ + strncpy((char*)ptr, "0987654321", len); +} + +/* ecall_pointer_count: + * 'cnt' needs to be specified to tell Edger8r the number of elements in 'arr'. + */ +void ecall_pointer_count(int *arr, int cnt) +{ + for (int i = (cnt - 1); i >= 0; i--) + arr[i] = (cnt - 1 - i); +} + +/* ecall_pointer_isptr_readonly: + * 'buf' is user defined type, shall be tagged with [isptr]. + * if it's not writable, [readonly] shall be specified. + */ +void ecall_pointer_isptr_readonly(buffer_t buf, size_t len) +{ + strncpy((char*)buf, "0987654321", len); +} + diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl new file mode 100644 index 00000000..bc7c928f --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Pointers.edl @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Pointers.edl - Samples for pointer attributes. */ + +enclave { + + /* + * Following keywords/attributes are supported for pointers in Edger8r: + * in, out, user_check, + * string, wstring, + * const, size, count, isptr, readonly + */ + + trusted { + + /* + * [user_check]: + * the pointer won't be validated, and the buffer pointed by + * 'val' is not copied into the enclave either. But Enclave + * can modify the memory pointed by 'val'. + */ + + public size_t ecall_pointer_user_check([user_check] void *val, size_t sz); + + /* + * [in]: + * buffer with the same size will be allocated inside the enclave, + * content pointed by 'val' will be copied into the new allocated + * memory inside. Any changes performed inside the enclave will not + * affect the buffer outside. + */ + + public void ecall_pointer_in([in] int *val); + + /* + * [out]: + * buffer with the same size will be allocated inside the enclave, + * but the content pointed by 'val' won't be copied. But after return, + * the buffer inside the enclave will copied into outside 'val'. + */ + + public void ecall_pointer_out([out] int *val); + + /* + * [in, out]: + * buffer with the same size will be allocated inside the enclave, + * the content pointed by 'val' will be copied either. After return, + * the buffer inside the enclave will by copied into outside 'val' again. + */ + + public void ecall_pointer_in_out([in, out] int *val); + + /* + * [string]: + * the attribute tells Edger8r 'str' is NULL terminated string, so strlen + * will be used to count the length of buffer pointed by 'str'. + */ + + public void ecall_pointer_string([in, out, string] char *str); + + /* + * [const]: + * the attribute tells Edger8r the buffer pointed by 'str' cannot be modified, + * so users cannot decorate 'str' with [out] attribute anymore. + */ + + public void ecall_pointer_string_const([in, string] const char *str); + + /* + * [size]: + * the attribute tells Edger8r the length of buffer in byte pointed by 'ptr' + * (shall be copied or not). + * Note: Users shall not specify [size] on [string] parameters. + */ + + public void ecall_pointer_size([in, out, size=len] void *ptr, size_t len); + + /* + * [count]: + * the attribute tells Edger8r the number of integers to be copied from 'arr'. + */ + + public void ecall_pointer_count([in, out, count=cnt] int *arr, int cnt); + + /* + * [isptr]: + * tells Edger8r the user defined type is a pointer; + * [readonly]: + * forbids the buffer allocated inside the enclave to be copied back to App + * (cannot use with [out]). + */ + + public void ecall_pointer_isptr_readonly([in, isptr, readonly, size=len] buffer_t buf, size_t len); + + }; + + /* + * Users can define multiple trusted/untrusted blocks, + * edger8r will merged them into one trusted/untrusted block. + */ + trusted { + /* + * Test pointer attributes in OCALLs + */ + + public void ocall_pointer_attr(void); + + }; + + untrusted { + + /* + * [user_check]: + * the pointer won't be valified, and the buffer pointed by 'val' is not + * copied to outside buffer either. Besides 'App' cannot modify the memory + * pointer by 'val'. + */ + + void ocall_pointer_user_check([user_check] int *val); + + /* + * [in]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' will be copied into the new allocated memory outside. + * Any changes performed by 'App' will not affect the buffer pointed by 'val'. + */ + + void ocall_pointer_in([in] int *val); + + /* + * [out]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' won't be copied. But after return, the buffer outside + * will be copied into the enclave. + */ + + void ocall_pointer_out([out] int *val); + + /* + * [in, out]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' will be copied either. After return, the buffer outside + * will copied into the enclave. + */ + + void ocall_pointer_in_out([in, out] int *val); + + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp new file mode 100644 index 00000000..8554a65e --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Basic Types */ + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" +#include +#include + +/* used to eliminate `unused variable' warning */ +#define UNUSED(val) (void)(val) + +#define ULP 2 + +/* used to compare double variables in order to avoid compile warnings */ +bool almost_equal(double x, double y) +{ + /* the machine epsilon has to be scaled to the magnitude of the larger value + and multiplied by the desired precision in ULPs (units in the last place) */ + return std::abs(x-y) <= std::numeric_limits::epsilon() * std::abs(x+y) * ULP; +} + +/* used to compare double variables in order to avoid compile warnings */ +bool almost_equal(float x, float y) +{ + /* the machine epsilon has to be scaled to the magnitude of the larger value + and multiplied by the desired precision in ULPs (units in the last place) */ + return std::abs(x-y) <= std::numeric_limits::epsilon() * std::abs(x+y) * ULP; +} + +/* ecall_type_char: + * [char] value passed by App. + */ +void ecall_type_char(char val) +{ + assert(val == 0x12); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_int: + * [int] value passed by App. + */ +void ecall_type_int(int val) +{ + assert(val == 1234); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_float: + * [float] value passed by App. + */ +void ecall_type_float(float val) +{ + assert(almost_equal(val, (float)1234.0)); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_double: + * [double] value passed by App. + */ +void ecall_type_double(double val) +{ + assert(almost_equal(val, (double)1234.5678)); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_size_t: + * [size_t] value passed by App. + */ +void ecall_type_size_t(size_t val) +{ + assert(val == (size_t)12345678); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_wchar_t: + * [wchar_t] value passed by App. + */ +void ecall_type_wchar_t(wchar_t val) +{ + assert(val == (wchar_t)0x1234); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_struct: + * struct_foo_t is defined in EDL and can be used in ECALL. + */ +void ecall_type_struct(struct struct_foo_t val) +{ + assert(val.struct_foo_0 == 1234); + assert(val.struct_foo_1 == 5678); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* + * ecall_type_enum_union: + * enum_foo_t/union_foo_t is defined in EDL + * and can be used in ECALL. + */ +void ecall_type_enum_union(enum enum_foo_t val1, union union_foo_t *val2) +{ + if (sgx_is_outside_enclave(val2, sizeof(union union_foo_t)) != 1) + abort(); + val2->union_foo_0 = 1; + val2->union_foo_1 = 2; /* overwrite union_foo_0 */ + assert(val1 == ENUM_FOO_0); +#ifndef DEBUG + UNUSED(val1); +#endif +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl new file mode 100644 index 00000000..55c61d03 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Edger8rSyntax/Types.edl @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Types.edl - Samples for basic types. */ + +enclave { + + /* + * Following types can be supported in Edger8r: + * char, short, int, float, double, void, + * int8_t, int16_t, int32_t, int64_t, + * size_t, wchar_t, + * uint8_t, uint16_t, uint32_t, uint64_t, + * unsigned, struct, enum, union. + */ + + /* + * We will demo few types in ECALL functions, data + * types in OCALL functions can be handled either. + */ + + /* structure definition */ + struct struct_foo_t { + /* Basic types can be used in structure. */ + uint32_t struct_foo_0; + uint64_t struct_foo_1; + }; + + /* enum definition */ + enum enum_foo_t { + ENUM_FOO_0 = 0, + ENUM_FOO_1 = 1 + }; + + /* union definition */ + union union_foo_t { + uint32_t union_foo_0; + uint32_t union_foo_1; + uint64_t union_foo_3; + }; + + trusted { + + public void ecall_type_char(char val); + public void ecall_type_int(int val); + + public void ecall_type_float(float val); + public void ecall_type_double(double val); + + public void ecall_type_size_t(size_t val); + public void ecall_type_wchar_t(wchar_t val); + + public void ecall_type_struct(struct struct_foo_t val); + public void ecall_type_enum_union(enum enum_foo_t val1, [user_check] union union_foo_t *val2); + + /* for using user defined types, please refer to Pointers.edl, Arrays.edl. */ + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml b/SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml new file mode 100644 index 00000000..e94c9bc5 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave.config.xml @@ -0,0 +1,12 @@ + + 0 + 0 + 0x40000 + 0x100000 + 10 + 1 + + 0 + 0 + 0xFFFFFFFF + diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp b/SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp new file mode 100644 index 00000000..f0b9db0f --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include /* vsnprintf */ + +#include "Enclave.h" +#include "Enclave_t.h" /* print_string */ + +/* + * printf: + * Invokes OCALL to display the enclave buffer to the terminal. + */ +void printf(const char *fmt, ...) +{ + char buf[BUFSIZ] = {'\0'}; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + ocall_print_string(buf); +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave.edl b/SampleCode/SampleEnclavePCL/Enclave/Enclave.edl new file mode 100644 index 00000000..a3de4438 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave.edl @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Enclave.edl - Top EDL file. */ + +enclave { + + include "user_types.h" /* buffer_t */ + + /* Import ECALL/OCALL from sub-directory EDLs. + * [from]: specifies the location of EDL file. + * [import]: specifies the functions to import, + * [*]: implies to import all functions. + */ + + from "Edger8rSyntax/Types.edl" import *; + from "Edger8rSyntax/Pointers.edl" import *; + from "Edger8rSyntax/Arrays.edl" import *; + from "Edger8rSyntax/Functions.edl" import *; + + from "TrustedLibrary/Libc.edl" import *; + from "TrustedLibrary/Libcxx.edl" import ecall_exception, ecall_map; + from "TrustedLibrary/Thread.edl" import *; + + /* + * ocall_print_string - invokes OCALL to display string buffer inside the enclave. + * [in]: copy the string buffer to App outside. + * [string]: specifies 'str' is a NULL terminated buffer. + */ + untrusted { + void ocall_print_string([in, string] const char *str); + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave.h b/SampleCode/SampleEnclavePCL/Enclave/Enclave.h new file mode 100644 index 00000000..ed83970d --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _ENCLAVE_H_ +#define _ENCLAVE_H_ + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +void printf(const char *fmt, ...); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_ENCLAVE_H_ */ diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave.lds b/SampleCode/SampleEnclavePCL/Enclave/Enclave.lds new file mode 100644 index 00000000..f5f35d5b --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave.lds @@ -0,0 +1,10 @@ +enclave.so +{ + global: + g_global_data_sim; + g_global_data; + enclave_entry; + g_peak_heap_used; + local: + *; +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem b/SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem new file mode 100644 index 00000000..529d07be --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/Enclave_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp new file mode 100644 index 00000000..fa50118e --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include "sgx_cpuid.h" + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_malloc_free: + * Uses malloc/free to allocate/free trusted memory. + */ +void ecall_malloc_free(void) +{ + void *ptr = malloc(100); + assert(ptr != NULL); + memset(ptr, 0x0, 100); + free(ptr); +} + +/* ecall_sgx_cpuid: + * Uses sgx_cpuid to get CPU features and types. + */ +void ecall_sgx_cpuid(int cpuinfo[4], int leaf) +{ + sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl new file mode 100644 index 00000000..0fb71cb3 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libc.edl @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Libc.edl - EDL sample for trusted C library. */ + +enclave { + + from "sgx_tstdc.edl" import sgx_oc_cpuidex; + + /* + * A subset of the C99 standard is supported as well as SGX customized functions: + * sgx_cpuid, etc. + */ + + trusted { + /* + * Utilize malloc/free in enclave. + */ + public void ecall_malloc_free(void); + + /* + * Utilize SGX version __cpuid() in enclave. + */ + public void ecall_sgx_cpuid([in, out] int cpuinfo[4], int leaf); + }; +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp new file mode 100644 index 00000000..2b06ed00 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include + +#include "../Enclave.h" +#include "Enclave_t.h" + +/* + * ecall_exception: + * throw/catch C++ exception inside the enclave. + */ + +void ecall_exception(void) +{ + std::string foo = "foo"; + try { + throw std::runtime_error(foo); + } + catch (std::runtime_error const& e) { + assert( foo == e.what() ); + std::runtime_error clone(""); + clone = e; + assert(foo == clone.what() ); + } + catch (...) { + assert( false ); + } +} + +#include +#include + +using namespace std; + +/* + * ecall_map: + * Utilize STL in the enclave. + */ +void ecall_map(void) +{ + typedef map > map_t; + typedef map_t::value_type map_value; + map_t m; + + m.insert(map_value('a', 1)); + m.insert(map_value('b', 2)); + m.insert(map_value('c', 3)); + m.insert(map_value('d', 4)); + + assert(m['a'] == 1); + assert(m['b'] == 2); + assert(m['c'] == 3); + assert(m['d'] == 4); + + assert(m.find('e') == m.end()); + + return; +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl new file mode 100644 index 00000000..9bcddb86 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Libcxx.edl @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Libcxx.edl - EDL sample for trusted C++ library. */ + +enclave { + + /* + * A subset of the C++03 standard is supported. + */ + + trusted { + /* + * Throw/catch exception inside the enclave. + */ + public void ecall_exception(void); + + /* + * Utilize inside the enclave. + */ + public void ecall_map(void); + }; +}; diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp new file mode 100644 index 00000000..22f43464 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../Enclave.h" +#include "Enclave_t.h" + +#include "sgx_thread.h" + +static size_t global_counter = 0; +static sgx_thread_mutex_t global_mutex = SGX_THREAD_MUTEX_INITIALIZER; + +#define BUFFER_SIZE 50 + +typedef struct { + int buf[BUFFER_SIZE]; + int occupied; + int nextin; + int nextout; + sgx_thread_mutex_t mutex; + sgx_thread_cond_t more; + sgx_thread_cond_t less; +} cond_buffer_t; + +static cond_buffer_t buffer = {{0, 0, 0, 0, 0, 0}, 0, 0, 0, + SGX_THREAD_MUTEX_INITIALIZER, SGX_THREAD_COND_INITIALIZER, SGX_THREAD_COND_INITIALIZER}; + +/* + * ecall_increase_counter: + * Utilize thread APIs inside the enclave. + */ +size_t ecall_increase_counter(void) +{ + size_t ret = 0; + for (int i = 0; i < LOOPS_PER_THREAD; i++) { + sgx_thread_mutex_lock(&global_mutex); + /* mutually exclusive adding */ + size_t tmp = global_counter; + global_counter = ++tmp; + if (4*LOOPS_PER_THREAD == global_counter) + ret = global_counter; + sgx_thread_mutex_unlock(&global_mutex); + } + return ret; +} + +void ecall_producer(void) +{ + for (int i = 0; i < 4*LOOPS_PER_THREAD; i++) { + cond_buffer_t *b = &buffer; + sgx_thread_mutex_lock(&b->mutex); + while (b->occupied >= BUFFER_SIZE) + sgx_thread_cond_wait(&b->less, &b->mutex); + b->buf[b->nextin] = b->nextin; + b->nextin++; + b->nextin %= BUFFER_SIZE; + b->occupied++; + sgx_thread_cond_signal(&b->more); + sgx_thread_mutex_unlock(&b->mutex); + } +} + +void ecall_consumer(void) +{ + for (int i = 0; i < LOOPS_PER_THREAD; i++) { + cond_buffer_t *b = &buffer; + sgx_thread_mutex_lock(&b->mutex); + while(b->occupied <= 0) + sgx_thread_cond_wait(&b->more, &b->mutex); + b->buf[b->nextout++] = 0; + b->nextout %= BUFFER_SIZE; + b->occupied--; + sgx_thread_cond_signal(&b->less); + sgx_thread_mutex_unlock(&b->mutex); + } +} diff --git a/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl new file mode 100644 index 00000000..7e9af63f --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Enclave/TrustedLibrary/Thread.edl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Thread.edl - EDL sample for trusted thread library. */ + +enclave { + + from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; + + trusted { + /* + * Use SGX mutex. + */ + public size_t ecall_increase_counter(); + + /* + * Use SGX condition variables. + */ + public void ecall_producer(); + public void ecall_consumer(); + + }; +}; diff --git a/SampleCode/SampleEnclavePCL/Include/user_types.h b/SampleCode/SampleEnclavePCL/Include/user_types.h new file mode 100644 index 00000000..478af7cf --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Include/user_types.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* User defined types */ + + +#define LOOPS_PER_THREAD 500 + +typedef void *buffer_t; +typedef int array_t[10]; + diff --git a/SampleCode/SampleEnclavePCL/Makefile b/SampleCode/SampleEnclavePCL/Makefile new file mode 100644 index 00000000..1484900b --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Makefile @@ -0,0 +1,330 @@ +# +# Copyright (C) 2011-2018 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +######## SGX SDK Settings ######## + +SGX_SDK ?= /opt/intel/sgxsdk +SGX_MODE ?= HW +SGX_ARCH ?= x64 +SGX_DEBUG ?= 1 +SGX_PCL ?= 1 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + + +ifeq ($(SGX_ARCH), x86) +ifneq ($(SGX_PCL), 0) +$(error SGX PCL feature is not supported for 32bit mode!) +else + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +endif +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g + Encryption_Tool_Flags := -d +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_Cpp_Files := App/App.cpp $(wildcard App/Edger8rSyntax/*.cpp) $(wildcard App/TrustedLibrary/*.cpp) +App_Include_Paths := -IInclude -IApp -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +ifneq ($(SGX_PCL), 0) +App_C_Flags += -DSGX_USE_PCL -I../Seal +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_Cpp_Objects := $(App_Cpp_Files:.cpp=.o) + +App_Name := app + +######## Enclave Settings ######## + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif +Crypto_Library_Name := sgx_tcrypto + +Enclave_Cpp_Files := Enclave/Enclave.cpp $(wildcard Enclave/Edger8rSyntax/*.cpp) $(wildcard Enclave/TrustedLibrary/*.cpp) +Enclave_Include_Paths := -IInclude -IEnclave -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/libcxx + +CC_BELOW_4_9 := $(shell expr "`$(CC) -dumpversion`" \< "4.9") +ifeq ($(CC_BELOW_4_9), 1) + Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -ffunction-sections -fdata-sections -fstack-protector +else + Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -ffunction-sections -fdata-sections -fstack-protector-strong +endif + +Enclave_C_Flags += $(Enclave_Include_Paths) +Enclave_Cpp_Flags := $(Enclave_C_Flags) -std=c++11 -nostdinc++ + +# To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries: +# 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options, +# so that the whole content of trts is included in the enclave. +# 2. For other libraries, you just need to pull the required symbols. +# Use `--start-group' and `--end-group' to link these libraries. +# Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options. +# Otherwise, you may get some undesirable errors. +Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 -Wl,--gc-sections \ + -Wl,--version-script=Enclave/Enclave.lds + +Enclave_Cpp_Objects := $(Enclave_Cpp_Files:.cpp=.o) + +Enclave_Name := enclave.so +Signed_Enclave_Name := enclave.signed.so +Enclave_Config_File := Enclave/Enclave.config.xml + +Unsigned_Enclave_Name := $(Enclave_Name) +Encrypted_Enclave_Name := $(Enclave_Name).enc + +Seal_Enclave_Name := Seal.so +Signed_Seal_Enclave_Name := Seal.signed.so +Seal_Enclave_Cpp_Files := Seal/Seal.cpp +Seal_Enclave_Cpp_Objects := $(Seal_Enclave_Cpp_Files:.cpp=.o) +Seal_Enclave_Config_File := Seal/Seal.config.xml + +PCL_LINK_FLAGS := + +ifneq ($(SGX_PCL),0) + +Pcl_Encryption_Tool := $(SGX_SDK)/bin/x64/sgx_encrypt +PCL_KEY := ./debug_mock_key.bin + +ifneq ($(SGX_MODE), HW) +PCL_LIB_NAME := sgx_pclsim +else # ifneq ($(SGX_MODE), HW) +PCL_LIB_NAME := sgx_pcl +endif # ifneq ($(SGX_MODE), HW) + +PCL_LINK_FLAGS = -Wl,--whole-archive -l$(PCL_LIB_NAME) -Wl,--no-whole-archive +endif # ifneq ($(SGX_PCL),0) + + +ifeq ($(SGX_MODE), HW) +ifeq ($(SGX_DEBUG), 1) + Build_Mode = HW_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = HW_PRERELEASE +else + Build_Mode = HW_RELEASE +endif +else +ifeq ($(SGX_DEBUG), 1) + Build_Mode = SIM_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = SIM_PRERELEASE +else + Build_Mode = SIM_RELEASE +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: .config_$(Build_Mode)_$(SGX_ARCH)$(SGX_PCL) $(App_Name) $(Enclave_Name) $(Seal_Enclave_Name) + @echo "The project has been built in release hardware mode." + @echo "Please sign the $(Enclave_Name) first with your signing key before you run the $(App_Name) to launch and access the enclave." + @echo "To sign the enclave use the command:" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave $(Enclave_Name) -out <$(Signed_Enclave_Name)> -config $(Enclave_Config_File)" + @echo "You can also sign the enclave using an external signing tool." + @echo "To build the project in simulation mode set SGX_MODE=SIM. To build the project in prerelease mode set SGX_PRERELEASE=1 and SGX_MODE=HW." +else +all: .config_$(Build_Mode)_$(SGX_ARCH)$(SGX_PCL) $(Signed_Seal_Enclave_Name) $(App_Name) $(Signed_Enclave_Name) +ifeq ($(Build_Mode), HW_DEBUG) + @echo "The project has been built in debug hardware mode." +else ifeq ($(Build_Mode), SIM_DEBUG) + @echo "The project has been built in debug simulation mode." +else ifeq ($(Build_Mode), HW_PRERELEASE) + @echo "The project has been built in pre-release hardware mode." +else ifeq ($(Build_Mode), SIM_PRERELEASE) + @echo "The project has been built in pre-release simulation mode." +else + @echo "The project has been built in release simulation mode." +endif +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/$(App_Name) + @echo "RUN => $(App_Name) [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + +######## App Objects ######## + +App/Enclave_u.c: $(SGX_EDGER8R) Enclave/Enclave.edl + @cd App && $(SGX_EDGER8R) --untrusted ../Enclave/Enclave.edl --search-path ../Enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Enclave_u.o: App/Enclave_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +App/Seal_u.c: $(SGX_EDGER8R) Seal/Seal.edl + @cd App && $(SGX_EDGER8R) --untrusted ../Seal/Seal.edl --search-path ../Seal --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Seal_u.o: App/Seal_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +App/%.o: App/%.cpp + @$(CXX) $(App_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(App_Name): App/Seal_u.o App/Enclave_u.o $(App_Cpp_Objects) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + +.config_$(Build_Mode)_$(SGX_ARCH)$(SGX_PCL): + @rm -f .config_* $(App_Name) $(Enclave_Name) $(Signed_Enclave_Name) $(App_Cpp_Objects) App/Enclave_u.* $(Enclave_Cpp_Objects) Enclave/Enclave_t.* $(Encrypted_Enclave_Name) $(Seal_Enclave_Name) $(Signed_Seal_Enclave_Name) App/Seal_u.* $(Seal_Enclave_Cpp_Objects) Seal/Seal_t.* sealed_key.bin + @touch .config_$(Build_Mode)_$(SGX_ARCH)$(SGX_PCL) + +######## Sealing enclave Objects ######## + +Seal/Seal_t.c: $(SGX_EDGER8R) Seal/Seal.edl + @cd Seal && $(SGX_EDGER8R) --trusted ../Seal/Seal.edl --search-path ../Seal --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Seal/Seal_t.o: Seal/Seal_t.c + @$(CC) $(Enclave_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +Seal/%.o: Seal/%.cpp + @$(CXX) $(Enclave_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(Seal_Enclave_Name): Seal/Seal_t.o $(Seal_Enclave_Cpp_Objects) + @$(CXX) $^ -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Signed_Seal_Enclave_Name): $(Seal_Enclave_Name) + @$(SGX_ENCLAVE_SIGNER) sign -key Seal/Seal_private.pem -enclave $(Seal_Enclave_Name) -out $@ -config $(Seal_Enclave_Config_File) + @echo "SIGN => $@" + +######## Enclave Objects ######## + +Enclave/Enclave_t.c: $(SGX_EDGER8R) Enclave/Enclave.edl + @cd Enclave && $(SGX_EDGER8R) --trusted ../Enclave/Enclave.edl --search-path ../Enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Enclave/Enclave_t.o: Enclave/Enclave_t.c + @$(CC) $(Enclave_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave/%.o: Enclave/%.cpp + @$(CXX) $(Enclave_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(Enclave_Name): Enclave/Enclave_t.o $(Enclave_Cpp_Objects) + @$(CXX) $^ -o $@ $(Enclave_Link_Flags) $(PCL_LINK_FLAGS) + @echo "LINK => $@" + +# encrypted enclave required only for PCL build +ifneq ($(SGX_PCL),0) + +$(Encrypted_Enclave_Name): $(Enclave_Name) $(Pcl_Encryption_Tool) + @$(Pcl_Encryption_Tool) -i $< -o $@ -k $(PCL_KEY) $(Encryption_Tool_Flags) + @echo "Encrypted => $@" + +endif # ifneq ($(SGX_PCL),0) + +ifneq ($(SGX_PCL), 0) +$(Signed_Enclave_Name): $(Encrypted_Enclave_Name) +else +$(Signed_Enclave_Name): $(Enclave_Name) +endif + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave/Enclave_private.pem -enclave $< -out $@ -config $(Enclave_Config_File) + @echo "SIGN => $@" + +.PHONY: clean + +clean: + @rm -f .config_* $(App_Name) $(Enclave_Name) $(Signed_Enclave_Name) $(App_Cpp_Objects) App/Enclave_u.* $(Enclave_Cpp_Objects) Enclave/Enclave_t.* $(Encrypted_Enclave_Name) $(Seal_Enclave_Name) $(Signed_Seal_Enclave_Name) App/Seal_u.* $(Seal_Enclave_Cpp_Objects) Seal/Seal_t.* sealed_key.bin + diff --git a/SampleCode/SampleEnclavePCL/README.md b/SampleCode/SampleEnclavePCL/README.md new file mode 100644 index 00000000..dfbbc0b4 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/README.md @@ -0,0 +1,38 @@ +Intel(R) Software Guard Extensions Protected Code Loader (Intel(R) SGX PCL) for Linux\* OS +================================================ +Introduction +------------ +Intel(R) SGX PCL is intended to protect Intellectual Property (IP) within the code for Intel(R) SGX enclave applications running on the Linux* OS. + +**Problem:** Intel(R) SGX provides integrity of code and confidentiality and integrity of data at run-time. However, it does NOT provide confidentiality of code offline as a binary file on disk. Adversaries can reverse engineer the binary enclave shared object. + +**Solution:** The enclave shared object (.so) is encrypted at build time. It is decrypted at enclave load time. + +Intel(R) SGX PCL provides: +1. **sgx_encrypt:** A tool to encrypt the shared object at build time. + + See sources at sdk\encrypt_enclave. + +2. **libsgx_pcl.a:** A library that is statically linked to the enclave and enables the decryption of the enclave at load time. + + See sources at sdk\protected_code_loader. + +3. **SampleEnclavePCL:** Sample code which demonstrates how the tool and lib need to be integrated into an existing enclave project. + +Pupose of this code sample: +-------------------------- +Enclave writers should compare SampleEnclave and SampleEnclavePCL. This demonstrates how the Intel(R) SGX PCL is to be integrated into the project of the enclave writer. + +Documentation +------------- +See more elaborate documentation at [Intel(R) SGX Protected Code Loader for Linux User Guide](https://github.com/intel/linux-sgx-pcl/blob/master/Intel(R)%20SGX%20Protected%20Code%20Loader%20for%20Linux%20User%20Guide.pdf). + +Build and test the Intel(R) SGX PCL with the sample code +-------------------------------------------------------- + +- To compile and run the sample +``` + $ cd SampleEnclavePCL + $ make + $ ./app +``` diff --git a/SampleCode/SampleEnclavePCL/Seal/Seal.config.xml b/SampleCode/SampleEnclavePCL/Seal/Seal.config.xml new file mode 100644 index 00000000..e94c9bc5 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Seal/Seal.config.xml @@ -0,0 +1,12 @@ + + 0 + 0 + 0x40000 + 0x100000 + 10 + 1 + + 0 + 0 + 0xFFFFFFFF + diff --git a/SampleCode/SampleEnclavePCL/Seal/Seal.cpp b/SampleCode/SampleEnclavePCL/Seal/Seal.cpp new file mode 100644 index 00000000..69536d32 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Seal/Seal.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include "Seal_t.h" +#include +#include + +/** + * @func provision_key_mock assigns the decryption key + * @param uint8_t* key_ptr: pointer to a key buffer allocated by caller. + * @param uint32_t key_len: key buffer size. + * @return sgx_status_t + * SGX_ERROR_INVALID_PARAMETER if key size is not SGX_AESGCM_KEY_SIZE or if key_ptr is NULL + * SGX_SUCCESS if success + * Notice: Function returns a hardcoded key. Never use in release code!!! + * ISV must replace with secured key provisioning scheme, e.g. using remote attestation & TLS. + */ +sgx_status_t provision_key_mock (uint8_t* key_ptr, uint32_t key_len ) +{ + if ( (NULL == key_ptr) || (SGX_AESGCM_KEY_SIZE != key_len)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + const uint8_t key[SGX_AESGCM_KEY_SIZE] = + { 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88, 0x99, 0x99 }; + memcpy (key_ptr, key, key_len); + return SGX_SUCCESS; +} + +/* + * @func provision_key provisions the key to the ISVs platform + * @param uint8_t* key_ptr is the resulting decryption key + * @param uint32_t key_len is key size in bytes + * @return sgx_status_t, SGX_SUCCESS if function passes + * @warning ISV must replace content of this function with ISVs scheme to provision + * the decryption key to the platform + */ +sgx_status_t provision_key( uint8_t* key_ptr, uint32_t key_len ) +{ + /* + * ISV must replace call to provision_key_mock with an alternative ISV's secured key provisioning scheme, e.g. using remote attestation & TLS. + * For more details, see 'Intel(R) SGX PCL Linux User Guide.pdf', chapter 'Integration with PCL', sub chapter 'Sealing Enclave'. + */ + return provision_key_mock(key_ptr, key_len); +} + +extern "C" +{ + +/* + * @func ecall_get_sealed_blob_size returns the PCL sealed blob size + * @return size_t, size of PCL sealed blob size in bytes + */ +size_t ecall_get_sealed_blob_size() +{ + return (size_t)sgx_calc_sealed_data_size ( SGX_PCL_GUID_SIZE, SGX_AESGCM_KEY_SIZE ); +} + +/* + * @func ecall_generate_sealed_blob generates the sealed blob + * @param uint8_t* sealed_blob is the resulting sealed blob + * @param uint32_t sealed_blob_size is sealed blob size in bytes + * @return sgx_status_t + * SGX_ERROR_INVALID_PARAMETER if sealed_blob is NULL or if sealed_blob_size does not match PCL sealed blob size + * The respective error in case provision_key or sgx_seal_data fail + * SGX_SUCCESS if function passes + */ +sgx_status_t ecall_generate_sealed_blob(uint8_t* sealed_blob, size_t sealed_blob_size) +{ + if ((NULL == sealed_blob) || (ecall_get_sealed_blob_size() != sealed_blob_size)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + sgx_status_t retstatus = SGX_ERROR_UNEXPECTED; + uint8_t key[SGX_AESGCM_KEY_SIZE] = { 0 }; + + retstatus = provision_key(key, SGX_AESGCM_KEY_SIZE); + if (retstatus != SGX_SUCCESS ) + { + return retstatus; + } + + retstatus = sgx_seal_data ( + SGX_PCL_GUID_SIZE, // AAD size + g_pcl_guid, // AAD + SGX_AESGCM_KEY_SIZE, // Key len + key, // Key + sealed_blob_size, // Resulting blob size + (sgx_sealed_data_t*)sealed_blob ); // Resulting blob + + memset(key, 0,SGX_AESGCM_KEY_SIZE); + return retstatus; +} + +}; // extern "C" + diff --git a/SampleCode/SampleEnclavePCL/Seal/Seal.edl b/SampleCode/SampleEnclavePCL/Seal/Seal.edl new file mode 100644 index 00000000..662d5664 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Seal/Seal.edl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Enclave.edl - Top EDL file. */ + +enclave { + +/* Import ECALL/OCALL from sub-directory EDLs. + * [from]: specifies the location of EDL file. + * [import]: specifies the functions to import, + * [*]: implies to import all functions. + */ + + + trusted { + public size_t ecall_get_sealed_blob_size (); + public sgx_status_t ecall_generate_sealed_blob ( + [out, count=sealed_blob_size]uint8_t* sealed_blob, + size_t sealed_blob_size ); + + }; + +}; diff --git a/SampleCode/SampleEnclavePCL/Seal/Seal.lds b/SampleCode/SampleEnclavePCL/Seal/Seal.lds new file mode 100644 index 00000000..f5f35d5b --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Seal/Seal.lds @@ -0,0 +1,10 @@ +enclave.so +{ + global: + g_global_data_sim; + g_global_data; + enclave_entry; + g_peak_heap_used; + local: + *; +}; diff --git a/SampleCode/SampleEnclavePCL/Seal/Seal_private.pem b/SampleCode/SampleEnclavePCL/Seal/Seal_private.pem new file mode 100644 index 00000000..529d07be --- /dev/null +++ b/SampleCode/SampleEnclavePCL/Seal/Seal_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/SampleCode/SampleEnclavePCL/debug_mock_key.bin b/SampleCode/SampleEnclavePCL/debug_mock_key.bin new file mode 100644 index 00000000..508ec123 --- /dev/null +++ b/SampleCode/SampleEnclavePCL/debug_mock_key.bin @@ -0,0 +1 @@ +""33DDUUffwwˆˆ™™ \ No newline at end of file diff --git a/buildenv.mk b/buildenv.mk index 7f4806bd..1d32d277 100644 --- a/buildenv.mk +++ b/buildenv.mk @@ -57,6 +57,9 @@ CP := /bin/cp -f MKDIR := mkdir -p STRIP := strip OBJCOPY := objcopy +NIPX := .nipx +NIPD := .nipd +NIPRODT := .niprod # clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat # thus it will cause build error when this variable is used by our Makefile, @@ -188,5 +191,5 @@ endif SGX_IPP_DIR := $(ROOT_DIR)/external/ippcp_internal SGX_IPP_INC := $(SGX_IPP_DIR)/inc IPP_LIBS_DIR := $(SGX_IPP_DIR)/lib/linux/$(IPP_SUBDIR) -LD_IPP := -lippcp -lippcore +LD_IPP := -lippcp diff --git a/common/inc/internal/ae_ipp.h b/common/inc/internal/ae_ipp.h index 3a90f1bb..948a0eba 100644 --- a/common/inc/internal/ae_ipp.h +++ b/common/inc/internal/ae_ipp.h @@ -33,7 +33,6 @@ #ifndef _AE_IPP_H #define _AE_IPP_H -#include "ippcore.h" #include "ippcp.h" #endif diff --git a/common/inc/internal/ipp_wrapper.h b/common/inc/internal/ipp_wrapper.h index 1935da05..8cc5f04d 100644 --- a/common/inc/internal/ipp_wrapper.h +++ b/common/inc/internal/ipp_wrapper.h @@ -34,17 +34,6 @@ #include "ippcp.h" -#ifndef CLEAR_FREE_MEM -#define CLEAR_FREE_MEM(address, size) { \ - if (address != NULL) { \ - if (size > 0) { \ - (void)memset_s(address, size, 0, size); \ - } \ - free(address); \ - } \ -} -#endif - #ifndef SAFE_FREE_MM #define SAFE_FREE_MM(ptr) {\ if(ptr != NULL) \ @@ -76,12 +65,6 @@ IppStatus create_rsa_priv2_key(int p_byte_size, const Ipp32u *p, const Ipp32u *q IppStatus create_rsa_pub_key(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *e, IppsRSAPublicKeyState **new_pub_key); -IppStatus create_validate_rsa_key_pair(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *d, const Ipp32u *e, const Ipp32u *p, const Ipp32u *q, - const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, - IppsRSAPrivateKeyState **new_pri_key, IppsRSAPublicKeyState **new_pub_key, int *validate_result); - -IppStatus get_pub_key(const IppsRSAPublicKeyState *pub_key, int *e_byte_size, Ipp32u *e, int *n_byte_size, Ipp32u *n); - void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes); void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1); diff --git a/common/inc/internal/metadata.h b/common/inc/internal/metadata.h index d4a5d1d8..b237e57f 100644 --- a/common/inc/internal/metadata.h +++ b/common/inc/internal/metadata.h @@ -38,7 +38,10 @@ /* version of metadata */ #define MAJOR_VERSION 2 //MAJOR_VERSION should not larger than 0ffffffff -#define MINOR_VERSION 2 //MINOR_VERSION should not larger than 0ffffffff +#define MINOR_VERSION 3 //MINOR_VERSION should not larger than 0ffffffff + +#define SGX_2_1_MAJOR_VERSION 2 //MAJOR_VERSION should not larger than 0ffffffff +#define SGX_2_1_MINOR_VERSION 2 //MINOR_VERSION should not larger than 0ffffffff #define SGX_2_0_MAJOR_VERSION 2 //MAJOR_VERSION should not larger than 0ffffffff #define SGX_2_0_MINOR_VERSION 1 //MINOR_VERSION should not larger than 0ffffffff diff --git a/common/inc/internal/pcl_common.h b/common/inc/internal/pcl_common.h new file mode 100644 index 00000000..ed001d35 --- /dev/null +++ b/common/inc/internal/pcl_common.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef PCL_COMMON_H +#define PCL_COMMON_H + +/* + * This file includes definition used by PCL library and encryption tool + */ + +#define IN +#define OUT +#define INOUT + +// Define both ASSERT_CONCAT and ASSERT_CONCAT_ so that __COUNTER__ receives a value +#define ASSERT_CONCAT_(a, b) a##b +#ifndef ASSERT_CONCAT +#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) +#endif // #ifndef ASSERT_CONCAT +#define PCL_COMPILE_TIME_ASSERT(exp) \ +enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(exp)) } + +// PCL uses AES with 16 Bytes block size +#define PCL_AES_BLOCK_LEN (16) +#define PCL_COUNTER_SIZE (16) +#define PCL_AES_BLOCK_LEN_BITS (128) + +#define PCLTBL_SECTION_NAME ".pcltbl" + +typedef struct iv_t_ +{ + uint8_t val[SGX_AESGCM_IV_SIZE]; + uint8_t reserved[4]; +}iv_t; + +typedef struct rva_size_tag_iv_t_ +{ + size_t rva; + size_t size; + sgx_cmac_128bit_tag_t tag; + iv_t iv; +}rva_size_tag_iv_t; + +// Hardcoded maximal size of sealed bolb. ISV can modify if requried +#define PCL_SEALED_BLOB_SIZE (0x250) +#define SGX_PCL_GUID_SIZE (16) +// Hardcoded maximal number of encrypted sections. ISV can modify if requried +#define PCL_MAX_NUM_ENCRYPTED_SECTIONS (0x80) + +typedef enum pcl_status_e_ +{ + PCL_PLAIN = 0xABABABAB, + PCL_CIPHER = 0xBCBCBCBC, + PCL_RUNNING = 0xDEDEDEDE, + PCL_DONE = 0xFAFAFAFA, +}pcl_status_e; + +typedef struct pcl_table_t_ +{ + pcl_status_e pcl_state; // Current state of PCL + uint32_t reserved1[3]; // Must be 0 + uint8_t pcl_guid[SGX_PCL_GUID_SIZE]; // GUID must match GUID in Sealed blob + size_t sealed_blob_size; // Size of selaed blob + uint32_t reserved2[2]; // Must be 0 + uint8_t sealed_blob[PCL_SEALED_BLOB_SIZE]; // For security, sealed blob is copied into enclave + uint8_t decryption_key_hash[SGX_SHA256_HASH_SIZE]; // SHA256 digest of decryption key + uint32_t num_rvas; // Number of RVAs + uint32_t reserved3[3]; // Must be 0 + rva_size_tag_iv_t rvas_sizes_tags_ivs[PCL_MAX_NUM_ENCRYPTED_SECTIONS]; // Array of rva_size_tag_iv_t +}pcl_table_t; + +#endif // #ifndef PCL_COMMON_H + diff --git a/common/inc/internal/rts.h b/common/inc/internal/rts.h index f51a149d..2e4d2fad 100644 --- a/common/inc/internal/rts.h +++ b/common/inc/internal/rts.h @@ -35,6 +35,8 @@ #include "se_types.h" #include "rts_cmd.h" +#pragma pack(push, 1) + typedef struct _ocall_context_t { uintptr_t shadow0; @@ -61,7 +63,8 @@ typedef enum { SDK_VERSION_1_5, SDK_VERSION_2_0, - SDK_VERSION_2_1 + SDK_VERSION_2_1, + SDK_VERSION_2_2 } sdk_version_t; typedef struct _system_features @@ -74,6 +77,7 @@ typedef struct _system_features */ uint64_t system_feature_set[1]; uint32_t cpuinfo_table[8][4]; + uint8_t* sealed_key; }system_features_t; // current system_feature_set only contains one element of type uint64_t, the highest @@ -89,5 +93,6 @@ typedef enum EDMM_MODPR = -4, }edmm_ocall_t; +#pragma pack(pop) #endif diff --git a/common/inc/internal/se_version.h b/common/inc/internal/se_version.h index a457b4ff..5423869c 100644 --- a/common/inc/internal/se_version.h +++ b/common/inc/internal/se_version.h @@ -28,6 +28,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -#define STRFILEVER "2.1.102.43402" +#define STRFILEVER "2.1.3.44322" #define COPYRIGHT "Copyright (C) 2018 Intel Corporation" diff --git a/common/inc/sgx_error.h b/common/inc/sgx_error.h index 7505555d..815e7a24 100644 --- a/common/inc/sgx_error.h +++ b/common/inc/sgx_error.h @@ -91,6 +91,12 @@ typedef enum _status_t SGX_ERROR_NO_PRIVILEGE = SGX_MK_ERROR(0x5002), /* Not enough privilege to perform the operation */ + /* SGX Protected Code Loader Error codes*/ + SGX_ERROR_PCL_ENCRYPTED = SGX_MK_ERROR(0x6001), /* trying to encrypt an already encrypted enclave */ + SGX_ERROR_PCL_NOT_ENCRYPTED = SGX_MK_ERROR(0x6002), /* trying to load a plain enclave using sgx_create_encrypted_enclave */ + SGX_ERROR_PCL_MAC_MISMATCH = SGX_MK_ERROR(0x6003), /* section mac result does not match build time mac */ + SGX_ERROR_PCL_SHA_MISMATCH = SGX_MK_ERROR(0x6004), /* Unsealed key MAC does not match MAC of key hardcoded in enclave binary */ + SGX_ERROR_PCL_GUID_MISMATCH = SGX_MK_ERROR(0x6005), /* GUID in sealed blob does not match GUID hardcoded in enclave binary */ /* SGX errors are only used in the file API when there is no appropriate EXXX (EINVAL, EIO etc.) error code */ SGX_ERROR_FILE_BAD_STATUS = SGX_MK_ERROR(0x7001), /* The file is in bad status, run sgx_clearerr to try and fix it */ @@ -103,7 +109,8 @@ typedef enum _status_t SGX_ERROR_FILE_FLUSH_FAILED = SGX_MK_ERROR(0x7008), /* fflush operation (to disk) failed (only used when no EXXX is returned) */ SGX_ERROR_FILE_CLOSE_FAILED = SGX_MK_ERROR(0x7009), /* fclose operation (to disk) failed (only used when no EXXX is returned) */ - SGX_INTERNAL_ERROR_ENCLAVE_CREATE_INTERRUPTED = SGX_MK_ERROR(0xF001), /* The ioctl for enclave_create unexpectedly failed with EINTR. */ + + SGX_INTERNAL_ERROR_ENCLAVE_CREATE_INTERRUPTED = SGX_MK_ERROR(0xF001), /* The ioctl for enclave_create unexpectedly failed with EINTR. */ } sgx_status_t; diff --git a/common/inc/sgx_key_exchange.h b/common/inc/sgx_key_exchange.h index 96dcd22d..c200d445 100644 --- a/common/inc/sgx_key_exchange.h +++ b/common/inc/sgx_key_exchange.h @@ -49,7 +49,6 @@ typedef enum _ra_key_type_t { SGX_RA_KEY_SK = 1, SGX_RA_KEY_MK, - SGX_RA_KEY_VK, } sgx_ra_key_type_t; typedef struct _ra_msg1_t diff --git a/common/inc/sgx_pcl_guid.h b/common/inc/sgx_pcl_guid.h new file mode 100644 index 00000000..e5d24f78 --- /dev/null +++ b/common/inc/sgx_pcl_guid.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef SGX_PCL_GUID_H +#define SGX_PCL_GUID_H +/* + * GUID enables coupling of PCL lib (e.g. libsgx_pcl.a) and sealed blob + * Before the PCL unseals the sealed blob, the PCL must verify the AAD + * portion of the sealed blob equals the GUID embedded in enclave binary. + */ +// SGX_PCL_GUID_SIZE must equal 16 Bytes +#ifndef SGX_PCL_GUID_SIZE + +#define SGX_PCL_GUID_SIZE (16) + +#else // SGX_PCL_GUID_SIZE is defined: // #ifndef SGX_PCL_GUID_SIZE + +#if (16 != SGX_PCL_GUID_SIZE) +#error SGX_PCL_GUID_SIZE != 16 +#endif // #if (16 != SGX_PCL_GUID_SIZE) + +#endif // #ifndef SGX_PCL_GUID_SIZE + +/* g_pcl_guid is used by: + * 1. Sealing enclave (decryption-key provisioning enclave) + * as AAD for the sealed key blob. + * 2. Encryption tool which embeds the GUID into the PCL enclave binary. + */ +uint8_t g_pcl_guid[SGX_PCL_GUID_SIZE] = +{0x95, 0x48, 0x6e, 0x8f, 0x8f, 0x4a, 0x41, 0x4f, 0xb1, 0x27, 0x46, 0x21, 0xa8, 0x59, 0xa8, 0xac}; + +#endif // #ifndef SGX_PCL_GUID_H diff --git a/common/inc/sgx_tcrypto.h b/common/inc/sgx_tcrypto.h index c5fd3041..24df102b 100644 --- a/common/inc/sgx_tcrypto.h +++ b/common/inc/sgx_tcrypto.h @@ -709,7 +709,7 @@ extern "C" { * * Parameters: * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h - * Inputs: rsa_key - Pointer to the EVP_PKEY struct containting RSA private key. + * Inputs: rsa_key - Pointer to the RSA private key. * pin_data - Pointer to the input ciphertext buffer. * pin_len - Ciphertext buffer size. * Output: pout_data - Pointer to the output buffer. @@ -722,7 +722,7 @@ extern "C" { * * Parameters: * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h - * Inputs: rsa_key - Pointer to the EVP_PKEY struct containting RSA public key. + * Inputs: rsa_key - Pointer to the RSA public key. * pin_data - Pointer to the input data buffer. * pin_len - Input buffer size. * Output: pout_data - Pointer to the output buffer. @@ -735,49 +735,33 @@ extern "C" { * * Parameters: * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h - * Inputs: prime_size - Pointer to the modulus size. - * exp_size - Pointer to the public exponent e size. - * g_rsa_key_e - Pointer to the public exponent e buffer. - * g_rsa_key_p - Pointer to the prime number p. - * g_rsa_key_q - Pointer to the prime number q. - * g_rsa_key_dmp1 - Pointer to dmp1 [d mod (p-1)]. - * g_rsa_key_dmq1 - Pointer to dmq1 [d mod (q-1)]. - * g_rsa_key_iqmp - Pointer to iqmp [q^-1 mod p]. + * Inputs: mod_size - Size in bytes of the key modulus. + * exp_size - Size in bytes of the public exponent e. + * p_rsa_key_e - Pointer to the public exponent e buffer. + * p_rsa_key_p - Pointer to the prime number p. + * p_rsa_key_q - Pointer to the prime number q. + * p_rsa_key_dmp1 - Pointer to dmp1 [d mod (p-1)]. + * p_rsa_key_dmq1 - Pointer to dmq1 [d mod (q-1)]. + * p_rsa_key_iqmp - Pointer to iqmp [q^-1 mod p]. * Output: new_pri_key2 - Pointer to the generated private key. * */ - sgx_status_t sgx_create_rsa_priv2_key(int prime_size, int exp_size, const unsigned char *g_rsa_key_e, const unsigned char *g_rsa_key_p, const unsigned char *g_rsa_key_q, - const unsigned char *g_rsa_key_dmp1, const unsigned char *g_rsa_key_dmq1, const unsigned char *g_rsa_key_iqmp, + sgx_status_t sgx_create_rsa_priv2_key(int mod_size, int exp_size, const unsigned char *p_rsa_key_e, const unsigned char *p_rsa_key_p, const unsigned char *p_rsa_key_q, + const unsigned char *p_rsa_key_dmp1, const unsigned char *p_rsa_key_dmq1, const unsigned char *p_rsa_key_iqmp, void **new_pri_key2); - /** Create RSA private key using input buffer factors in little endian. - * - * Parameters: - * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h - * Inputs: n_byte_size - Pointer to the modulus size. - * e_byte_size - Pointer to the public exponent e size. - * d_byte_size - Pointer to the private exponent d size. - * le_e - Pointer to the public exponent e buffer. - * le_n - Pointer to the modulus n. - * le_d - Pointer to the private exponent d. - * Output: new_pri_key1 - Pointer to the generated private key. - * - */ - sgx_status_t sgx_create_rsa_priv1_key(int n_byte_size, int e_byte_size, int d_byte_size, const unsigned char *le_n, const unsigned char *le_e, - const unsigned char *le_d, void **new_pri_key1); - /** Create RSA public key using input buffer factors in little endian. * * Parameters: * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h - * Inputs: prime_size - Pointer to the modulus size. - * exp_size - Pointer to the public exponent e size. + * Inputs: mod_size - Size in bytes of the key modulus. + * exp_size - Size in bytes of the public exponent e. * le_n - Pointer to the modulus n buffer. * le_e - Pointer to the public exponent e buffer. * Output: new_pub_key1 - Pointer to the generated public key. * */ - sgx_status_t sgx_create_rsa_pub1_key(int prime_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1); + sgx_status_t sgx_create_rsa_pub1_key(int mod_size, int exp_size, const unsigned char *le_n, const unsigned char *le_e, void **new_pub_key1); /** Clear and free RSA key which was generated by one of the Tcrypto "sgx_create_rsa_*" APIs. * diff --git a/common/inc/sgx_tkey_exchange.h b/common/inc/sgx_tkey_exchange.h index 0b03eb3a..15d2113a 100644 --- a/common/inc/sgx_tkey_exchange.h +++ b/common/inc/sgx_tkey_exchange.h @@ -147,8 +147,7 @@ sgx_status_t SGXAPI sgx_ra_init_ex( * protocol message 3 produced by sgx_ra_proc_msg2. * * @param context Context returned by sgx_ra_init. - * @param type The specifier of keys, can be SGX_RA_KEY_MK, SGX_RA_KEY_SK - * and SGX_RA_VK. + * @param type The specifier of keys, can be SGX_RA_KEY_MK, SGX_RA_KEY_SK. * @param p_key The key returned. * @return sgx_status_t SGX_SUCCESS Indicates success. * SGX_ERROR_INVALID_PARAMETER Indicates an error that diff --git a/common/inc/sgx_trts.h b/common/inc/sgx_trts.h index a7e757b9..044d0a83 100644 --- a/common/inc/sgx_trts.h +++ b/common/inc/sgx_trts.h @@ -68,7 +68,7 @@ int SGXAPI sgx_is_outside_enclave(const void *addr, size_t size); * 1 - the enclave state is crashed. * 0 - the enclave state is not crashed. */ -int SGXAPI sgx_is_enclave_crashed(void); +int SGXAPI sgx_is_enclave_crashed(void) __attribute__((section(".nipx"))); /* sgx_read_rand() diff --git a/common/inc/sgx_urts.h b/common/inc/sgx_urts.h index 5e74cbc7..570ff86d 100644 --- a/common/inc/sgx_urts.h +++ b/common/inc/sgx_urts.h @@ -55,6 +55,15 @@ typedef uint8_t sgx_launch_token_t[1024]; sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, sgx_launch_token_t *launch_token, int *launch_token_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr); +sgx_status_t SGXAPI sgx_create_encrypted_enclave( + const char *file_name, + const int debug, + sgx_launch_token_t *launch_token, + int *launch_token_updated, + sgx_enclave_id_t *enclave_id, + sgx_misc_attribute_t *misc_attr, + uint8_t* sealed_key); + sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id); #ifdef __cplusplus diff --git a/common/src/ipp_rsa_key.cpp b/common/src/ipp_rsa_key.cpp deleted file mode 100644 index 928300a7..00000000 --- a/common/src/ipp_rsa_key.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** -* File: -* ipp_rsa_key.cpp -*Description: -* Wrapper for rsa key operation functions (public key generation and free excluded) -* -*/ - -#include "ipp_wrapper.h" -#include "util.h" - -#include -#include -#include -#include - -extern "C" int memset_s(void *s, size_t smax, int c, size_t n); - -static IppStatus newPRNG(IppsPRNGState **pRandGen) -{ - if(pRandGen == NULL) - return ippStsBadArgErr; - int ctxSize = 0; - IppStatus error_code = ippsPRNGGetSize(&ctxSize); - if(error_code != ippStsNoErr) - return error_code; - IppsPRNGState* pCtx = (IppsPRNGState *) malloc(ctxSize); - if(pCtx == NULL) - return ippStsMemAllocErr; - - error_code = ippsPRNGInit(160, pCtx); - if(error_code != ippStsNoErr) - { - free(pCtx); - return error_code; - } - - *pRandGen = pCtx; - return error_code; -} - -static IppStatus newPrimeGen(int nMaxBits, IppsPrimeState ** pPrimeG) -{ - if(pPrimeG == NULL || nMaxBits <= 0 ) - return ippStsBadArgErr; - int ctxSize = 0; - IppStatus error_code = ippsPrimeGetSize(nMaxBits, &ctxSize); - if(error_code != ippStsNoErr) - return error_code; - IppsPrimeState* pCtx = (IppsPrimeState *) malloc(ctxSize); - if(pCtx == NULL) - return ippStsMemAllocErr; - - error_code = ippsPrimeInit(nMaxBits, pCtx); - if(error_code != ippStsNoErr) - { - free(pCtx); - return error_code; - } - - *pPrimeG = pCtx; - return error_code; -} - - -extern "C" IppStatus create_rsa_priv2_key(int p_byte_size, const Ipp32u *p, const Ipp32u *q, - const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, - IppsRSAPrivateKeyState **new_pri_key2) -{ - IppsRSAPrivateKeyState *p_rsa2 = NULL; - IppsBigNumState *p_p = NULL, *p_q = NULL, *p_dmp1 = NULL, *p_dmq1 = NULL, *p_iqmp = NULL; - int rsa2_size = 0; - - if(p_byte_size <= 0 || p == NULL || q == NULL || dmp1 == NULL || dmq1 == NULL || iqmp == NULL || new_pri_key2 == NULL) - { - return ippStsBadArgErr; - } - - IppStatus error_code = ippStsNoErr; - do{ - error_code = newBN(p, p_byte_size, &p_p); - ERROR_BREAK(error_code); - error_code = newBN(q, p_byte_size, &p_q); - ERROR_BREAK(error_code); - error_code = newBN(dmp1, p_byte_size, &p_dmp1); - ERROR_BREAK(error_code); - error_code = newBN(dmq1, p_byte_size, &p_dmq1); - ERROR_BREAK(error_code); - error_code = newBN(iqmp, p_byte_size, &p_iqmp); - ERROR_BREAK(error_code); - error_code = ippsRSA_GetSizePrivateKeyType2(p_byte_size * 8, p_byte_size * 8, &rsa2_size); - ERROR_BREAK(error_code); - p_rsa2 = (IppsRSAPrivateKeyState *)malloc(rsa2_size); - NULL_BREAK(p_rsa2); - - error_code = ippsRSA_InitPrivateKeyType2(p_byte_size * 8, p_byte_size * 8, p_rsa2, rsa2_size); - ERROR_BREAK(error_code); - error_code = ippsRSA_SetPrivateKeyType2(p_p, p_q, p_dmp1, p_dmq1, p_iqmp, p_rsa2); - ERROR_BREAK(error_code); - }while(0); - - secure_free_BN(p_p, p_byte_size); - secure_free_BN(p_q, p_byte_size); - secure_free_BN(p_dmp1, p_byte_size); - secure_free_BN(p_dmq1, p_byte_size); - secure_free_BN(p_iqmp, p_byte_size); - - if(error_code != ippStsNoErr || p_rsa2 == NULL) - { - if(error_code == ippStsNoErr ) - error_code = ippStsMemAllocErr; - - /* Clear sensitive data before free */ - secure_free_rsa_pri2_key(p_byte_size, p_rsa2); - return error_code; - } - - *new_pri_key2 = p_rsa2; - return error_code; -} - -extern "C" IppStatus create_rsa_priv1_key(int n_byte_size, int d_byte_size, const Ipp32u *n, const Ipp32u *d, IppsRSAPrivateKeyState **new_pri_key1) -{ - IppsRSAPrivateKeyState *p_rsa1 = NULL; - IppsBigNumState *p_n = NULL, *p_d = NULL; - int rsa1_size = 0; - if(n_byte_size <= 0 || d_byte_size <= 0 || n == NULL || d == NULL || new_pri_key1 == NULL) - { - return ippStsBadArgErr; - } - IppStatus error_code = ippStsNoErr; - do{ - error_code = newBN(n, n_byte_size, &p_n); - ERROR_BREAK(error_code); - error_code = newBN(d, d_byte_size, &p_d); - ERROR_BREAK(error_code); - - error_code = ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size); - ERROR_BREAK(error_code); - p_rsa1 = (IppsRSAPrivateKeyState *)malloc(rsa1_size); - NULL_BREAK(p_rsa1); - error_code = ippsRSA_InitPrivateKeyType1(n_byte_size * 8, d_byte_size * 8, p_rsa1, rsa1_size); - ERROR_BREAK(error_code); - error_code = ippsRSA_SetPrivateKeyType1(p_n, p_d, p_rsa1); - ERROR_BREAK(error_code); - }while(0); - secure_free_BN(p_n, n_byte_size); - secure_free_BN(p_d, d_byte_size); - if(error_code != ippStsNoErr || p_rsa1 == NULL) - { - if(error_code == ippStsNoErr ) - error_code = ippStsMemAllocErr; - - /* Clear sensitive data before free */ - secure_free_rsa_pri1_key(n_byte_size, d_byte_size, p_rsa1); - return error_code; - } - - *new_pri_key1 = p_rsa1; - return error_code; -} - - -extern "C" IppStatus create_validate_rsa_key_pair(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *d, const Ipp32u *e, const Ipp32u *p, const Ipp32u *q, - const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, - IppsRSAPrivateKeyState **new_pri_key, IppsRSAPublicKeyState **new_pub_key, int *validate_result) -{ - if(n_byte_size <= 0 || e_byte_size <= 0 || n == NULL || d == NULL || e == NULL || - p == NULL || q == NULL || dmp1 == NULL || dmq1 == NULL || iqmp == NULL || new_pri_key == NULL || - new_pub_key == NULL || validate_result == NULL) - { - return ippStsBadArgErr; - } - IppsRSAPrivateKeyState *p_pri_key1 = NULL, *p_pri_key2 = NULL; - IppsRSAPublicKeyState *p_pub_key = NULL; - IppStatus error_code = ippStsNoErr; - IppsPRNGState *p_rand = NULL; - IppsPrimeState *p_prime = NULL; - Ipp8u * scratch_buffer = NULL; - int result = IPP_IS_VALID; - int max_size = 0, pri1_size = 0, pri2_size = 0, pub_size = 0; - - do - { - /* Generate the pri_key1, pri_key2 and pub_key */ - error_code = create_rsa_priv1_key(n_byte_size, n_byte_size, n, d, &p_pri_key1); - ERROR_BREAK(error_code); - error_code = create_rsa_priv2_key(n_byte_size/2, p, q, dmp1, dmq1, iqmp, &p_pri_key2); - ERROR_BREAK(error_code); - error_code = create_rsa_pub_key(n_byte_size, e_byte_size, n, e, &p_pub_key); - ERROR_BREAK(error_code); - - /* Generate random state and prime state */ - error_code = newPRNG(&p_rand); - ERROR_BREAK(error_code); - error_code = newPrimeGen(n_byte_size * 8 / 2, &p_prime); - ERROR_BREAK(error_code); - - /* Allocate scratch buffer */ - error_code = ippsRSA_GetBufferSizePrivateKey(&pri1_size, p_pri_key1); - ERROR_BREAK(error_code); - error_code = ippsRSA_GetBufferSizePrivateKey(&pri2_size, p_pri_key2); - ERROR_BREAK(error_code); - max_size = MAX(pri1_size, pri2_size); - error_code = ippsRSA_GetBufferSizePublicKey(&pub_size, p_pub_key); - ERROR_BREAK(error_code); - max_size = MAX(max_size, pub_size); - scratch_buffer = (Ipp8u *)malloc(max_size); - NULL_BREAK(scratch_buffer); - memset(scratch_buffer, 0, max_size); - - /* Validate keys */ - error_code = ippsRSA_ValidateKeys(&result, p_pub_key, p_pri_key2, p_pri_key1, scratch_buffer, 10, p_prime, ippsPRNGen, p_rand); - ERROR_BREAK(error_code); - }while(0); - SAFE_FREE_MM(p_rand); - SAFE_FREE_MM(p_prime); - secure_free_rsa_pri2_key(n_byte_size/2, p_pri_key2); - - if(error_code != ippStsNoErr || scratch_buffer == NULL) - { - if(error_code == ippStsNoErr) - error_code = ippStsMemAllocErr; - - SAFE_FREE_MM(scratch_buffer); - secure_free_rsa_pri1_key(n_byte_size, n_byte_size, p_pri_key1); - secure_free_rsa_pub_key(n_byte_size, e_byte_size, p_pub_key); - return error_code; - } - SAFE_FREE_MM(scratch_buffer); - *new_pri_key = p_pri_key1; - *new_pub_key = p_pub_key; - *validate_result = result; - return error_code; -} - -extern "C" IppStatus get_pub_key(const IppsRSAPublicKeyState *pub_key, int *e_byte_size, Ipp32u *e, int *n_byte_size, Ipp32u *n) -{ - IppStatus error_code = ippStsNoErr; - IppsBigNumState *p_n=NULL, *p_e=NULL; - - if(!pub_key || !e_byte_size || !e || !n_byte_size || !n) - { - return ippStsBadArgErr; - } - do - { - error_code = newBN(NULL, SE_KEY_SIZE, &p_n); - ERROR_BREAK(error_code); - error_code = newBN(NULL, sizeof(Ipp32u), &p_e); - ERROR_BREAK(error_code); - - error_code = ippsRSA_GetPublicKey(p_n, p_e, pub_key); - ERROR_BREAK(error_code); - - IppsBigNumSGN sgn = IppsBigNumPOS; - Ipp32u *pdata = NULL; - int length_in_bit = 0; - - - error_code = ippsRef_BN(&sgn, &length_in_bit, &pdata, p_n); - ERROR_BREAK(error_code); - *n_byte_size = ROUND_TO(length_in_bit, 8)/8; - memset(n, 0, *n_byte_size); - memcpy(n, pdata, ROUND_TO(length_in_bit, 8)/8); - - error_code = ippsRef_BN(&sgn, &length_in_bit, &pdata, p_e); - ERROR_BREAK(error_code); - *e_byte_size = ROUND_TO(length_in_bit, 8)/8; - memset(e, 0, *e_byte_size); - memcpy(e, pdata, ROUND_TO(length_in_bit, 8)/8); - } while(0); - - secure_free_BN(p_n, SE_KEY_SIZE); - secure_free_BN(p_e, sizeof(Ipp32u)); - return error_code; -} - -extern "C" void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1) -{ - if(n_byte_size <= 0 || d_byte_size <= 0 || pri_key1 == NULL) - { - if(pri_key1) - free(pri_key1); - return; - } - - int rsa1_size = 0; - if(ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size) != ippStsNoErr) - { - free(pri_key1); - return; - } - /* Clear the buffer before free. */ - memset_s(pri_key1, rsa1_size, 0, rsa1_size); - free(pri_key1); - return; -} - -extern "C" void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2) -{ - if(p_byte_size <= 0 || pri_key2 == NULL) - { - if(pri_key2) - free(pri_key2); - return; - } - - int rsa2_size = 0; - if(ippsRSA_GetSizePrivateKeyType2(p_byte_size * 8, p_byte_size * 8, &rsa2_size) != ippStsNoErr) - { - free(pri_key2); - return; - } - /* Clear the buffer before free. */ - memset_s(pri_key2, rsa2_size, 0, rsa2_size); - free(pri_key2); - return; -} diff --git a/common/src/linux/xsave_gnu.S b/common/src/linux/xsave_gnu.S index a2124bcf..2df71303 100644 --- a/common/src/linux/xsave_gnu.S +++ b/common/src/linux/xsave_gnu.S @@ -82,7 +82,7 @@ #endif .endm -.text +.section .nipx,"ax",@progbits DECLARE_LOCAL_FUNC restore_xregs #if defined(LINUX32) mov SE_WORDSIZE(%esp), %ecx diff --git a/download_prebuilt.sh b/download_prebuilt.sh index e8084078..7c915c13 100755 --- a/download_prebuilt.sh +++ b/download_prebuilt.sh @@ -33,13 +33,13 @@ top_dir=`dirname $0` out_dir=$top_dir -optlib_name=optimized_libs-2.1.2.tar -ae_file_name=prebuilt-ae-2.1.2.tar -server_url_path=https://download.01.org/intel-sgx/linux-2.1.2/ +optlib_name=optimized_libs-2.1.3.tar +ae_file_name=prebuilt-ae-2.1.3.tar +server_url_path=https://download.01.org/intel-sgx/linux-2.1.3/ server_optlib_url=$server_url_path/$optlib_name server_ae_url=$server_url_path/$ae_file_name -optlib_sha256=239cae39f87934d56c4eb919a4702c6ac82c19957b9a8d56c02b10eb4e27f573 -ae_sha256=55ebe53b724d66f045c4c05020610d0fc7771d5dc58aaff270ccaee82b5d0d65 +optlib_sha256=b8091d8ad9ea91949610468944b2604c858833f70099c7d369234acd3d62c774 +ae_sha256=022fadd5a72234282176c09695c08b755defcffb82ea47b7dd9337c2f43b8378 rm -rf $out_dir/$optlib_name wget $server_optlib_url -P $out_dir if [ $? -ne 0 ]; then diff --git a/external/epid-sdk-3.0.0/CHANGELOG.md b/external/epid-sdk-3.0.0/CHANGELOG.md deleted file mode 100644 index 36657a30..00000000 --- a/external/epid-sdk-3.0.0/CHANGELOG.md +++ /dev/null @@ -1,87 +0,0 @@ -# Intel(R) EPID SDK ChangeLog {#ChangeLog} - -## [3.0.0] - -### New in This Release - -* Support for verification of EPID 1.1 members. - -* Make-based build system support. - -* Sample material includes compressed keys. - -* Enhanced documentation, including step-by-step walkthroughs of - example applications. - -* Validated on additional IoT platforms. - - - Ostro Linux - - - Snappy Ubuntu Core - - -### Changes - -* A new verifier API has been added to set the basename to be used for - verification. Verifier APIs that used to accept basenames now use - the basename set via EpidVerifierSetBasename. - -* The verifier pre-computation structure has been changed to include - the group ID to allow detection of errors that result from providing - a pre-computation blob from a different group to EpidVerifierCreate. - - -### Fixes - -* The kEpidxxxRevoked enums have been renamed to be consistent with - other result return values. - - -### Known Issues - -* SHA-512/256 hash algorithm is not supported. - - -## [2.0.0] - 2016-07-20 - -### New in This Release - -* Signed binary issuer material support. - - - Binary issuer material validation APIs. - - - Updated sample issuer material. - - - Updated samples that parse signed binary issuer material. - -* Compressed member private key support. - -* Validated on additional IoT platforms. - - - Windows 10 IoT Core - - - WindRiver IDP - - -### Changes - -* The default hash algorithm has changed. It is now SHA-512. - -* Functions that returned `EpidNullPtrErr` now return `EpidBadArgErr` - instead. - - -### Fixes - -* Updated build flags to work around GCC 4.8.5 defect. - - -## [1.0.0] - 2016-03-03 - -### New in This Release - -* Basic sign and verify functionality - -* Dynamic join support for member - -* Apache 2.0 License diff --git a/external/epid-sdk-3.0.0/Makefile.in b/external/epid-sdk-3.0.0/Makefile.in deleted file mode 100644 index 6520e53d..00000000 --- a/external/epid-sdk-3.0.0/Makefile.in +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/make -f -include ../../buildenv.mk - -#variables are set by configure -prefix = @prefix@ -installdir = $(prefix)/ -epidinstalldir = $(installdir)/epid-sdk -CFLAGS = @CFLAGS@ - -#g++ flags -CXX_FLAGS := $(CFLAGS) -O2 -Werror -Wall -Wextra -Wno-missing-braces \ - -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-unused-function \ - -fno-strict-aliasing -Wno-unused-but-set-variable -Wno-comment -DNDEBUG -fPIC -#gcc flags -CC_FLAGS := $(CXX_FLAGS) -D_IPP_v50_ -D_IPP_DEBUG - -#intel c++ compiler flags -ICPC_FLAGS := $(CFLAGS) -O2 -Werror -Wall -Wextra -DNDEBUG -#intel c compiler flags -ICC_FLAGS := $(ICPC_FLAGS) -D_IPP_v50_ -D_IPP_DEBUG - -#check if architecture was specified -#or take it by shell command -ifeq ($(findstring -m32,$(CFLAGS)),-m32) - ARCH = x86 - CXXFLAGS += -m32 -else ifeq ($(findstring -m64,$(CFLAGS)),-m64) - ARCH = x86_64 - CXXFLAGS += -m64 -else - ARCH := $(shell uname -m) -endif - -#set tools and flags depending on specified compiler -ifeq ($(CC),icc) - CFLAGS := $(ICC_FLAGS) - CXXFLAGS := $(ICPC_FLAGS) - AR = xiar -else ifeq ($(CC),cc) - CFLAGS := $(CC_FLAGS) -ifeq ($(ARCH),x86) - CFLAGS += -m32 -endif -else - CFLAGS := $(CC_FLAGS) - CXXFLAGS := $(CXX_FLAGS) - ARCH = x86 -endif - -#set c++11 for all c++ compilers -CXXFLAGS += -std=c++11 - -#set flags for unit tests executables -GTEST_FLAGS = --gtest_color=yes \ - --gtest_print_time=1 \ - --gtest_output=xml - -export CC AR LDFLAGS ARCH CFLAGS -export CXX CXXFLAGS -export epidinstalldir -export GTEST_FLAGS - -#just output -$(info $$ccompiler is [${CC}]) -$(info $$cxxcompiler is [${CXX}]) -$(info $$architecture is [${ARCH}]) - -#targets part -all: ipp common member verifier dropt - -clean: - $(MAKE) -C ./ext/ipp/sources/ippcp clean - $(MAKE) -C ./ext/ipp/sources/ippcpepid clean - $(MAKE) -C ./epid/common/ clean - $(MAKE) -C ./epid/member/ clean - $(MAKE) -C ./epid/verifier/ clean - $(MAKE) -C ./example/util/ clean - $(MAKE) -C ./example/ clean - $(MAKE) -C ./tools/ clean - $(MAKE) -C ./epid/common-testhelper/ clean - $(MAKE) -C ./ext/dropt/ clean - -install: - $(MAKE) -C ./ext/ipp/sources/ippcp install - $(MAKE) -C ./ext/ipp/sources/ippcpepid install - $(MAKE) -C ./epid/common/ install - $(MAKE) -C ./epid/member/ install - $(MAKE) -C ./epid/verifier/ install - $(MAKE) -C ./example/ install - $(MAKE) -C ./tools/ install - $(MAKE) -C ./epid/common-testhelper/ install - -uninstall: - rm -rf $(epidinstalldir) - -ipp: - $(MAKE) -C ./ext/ipp/sources/ippcp all - $(MAKE) -C ./ext/ipp/sources/ippcpepid all ARCH=$(ARCH) - -common: - $(MAKE) -C ./epid/common/ all - -member: - $(MAKE) -C ./epid/member/ all - -verifier: - $(MAKE) -C ./epid/verifier/ all - -dropt: - $(MAKE) -C ./ext/dropt/ all - -examples_util: - $(MAKE) -C ./example/util/ all - -check: - $(MAKE) -C ./ext/gtest/ all - $(MAKE) -C ./epid/common-testhelper/ all - $(MAKE) -C ./epid/common-testhelper/ check - $(MAKE) -C ./epid/common/ check - $(MAKE) -C ./epid/member/ check - $(MAKE) -C ./epid/verifier/ check - -examples: - $(MAKE) -C ./example/ all - -epid_tools: - $(MAKE) -C ./tools/ all - -build: all check install diff --git a/external/epid-sdk-3.0.0/SConstruct b/external/epid-sdk-3.0.0/SConstruct deleted file mode 100644 index 195222d8..00000000 --- a/external/epid-sdk-3.0.0/SConstruct +++ /dev/null @@ -1,237 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -"""use scons -k to invoke all builds regardless of unit test failures -""" -import string -import sys -import SCons.Script -import os.path -from parts import * - -print "**************** TOOLS ****************" -print '* Python Version:', string.split(sys.version, " ", 1)[0] -print '* SCons Version:', SCons.__version__ -print '* Parts Version:', PartsExtensionVersion() -print "***************************************" - -def PrintCompilerVersion(env): - """ - Function to print version of compilers used for build - Args: - env: Environment to get compilers version - """ - res = '' - if 'INTELC_VERSION' in env: - res += 'ICC ' + env['INTELC_VERSION'] + ';' - if 'MSVC_VERSION' in env: - res += 'MS ' + env['MSVC_VERSION'] + ';' - if 'GXX_VERSION' in env: - res += 'GXX ' + env['GXX_VERSION'] + ';' - if 'GCC_VERSION' in env: - res += 'GCC ' + env['GCC_VERSION'] + ';' - print 'Compiler Version: ', res - -def include_parts(part_list, **kwargs): - for parts_file in part_list: - if os.path.isfile(DefaultEnvironment().subst(parts_file)): - Part(parts_file=parts_file, **kwargs) - -######## Part groups #################################################### -ipp_parts = ['ext/ipp/ippcp.parts', - 'ext/ipp/ippcpepid.parts', - 'ext/ipp/ippcommon.parts'] -utest_parts = ['ext/gtest/gtest.parts', - 'epid/common-testhelper/common-testhelper.parts'] -common_parts = ['epid/common/common.parts'] -member_parts = ['epid/member/member.parts'] -verifier_parts = ['epid/verifier/verifier.parts'] -util_parts = ['example/util/util.parts'] -example_parts = ['ext/dropt/dropt.parts', - 'example/verifysig/verifysig.parts', - 'example/signmsg/signmsg.parts', - 'example/data/data.parts', - 'example/compressed_data/compressed_data.parts'] -tools_parts = ['tools/revokegrp/revokegrp.parts', - 'tools/revokekey/revokekey.parts', - 'tools/revokesig/revokesig.parts', - 'tools/extractkeys/extractkeys.parts', - 'tools/extractgrps/extractgrps.parts'] -testbot_test_parts = ['test/testbot/testbot.parts', - 'test/testbot/signmsg/signmsg_testbot.parts', - 'test/testbot/verifysig/verifysig_testbot.parts', - 'test/testbot/integration/integration_testbot.parts', - 'test/testbot/ssh_remote/ssh_remote_testbot.parts', - 'test/testbot/revokegrp/revokegrp_testbot.parts', - 'test/testbot/revokekey/revokekey_testbot.parts', - 'test/testbot/revokesig/revokesig_testbot.parts', - 'test/testbot/extractkeys/extractkeys_testbot.parts', - 'test/testbot/extractgrps/extractgrps_testbot.parts'] -package_parts = ['ext/gtest/gtest.parts', - 'ext/ipp/ippcommon.parts', - 'ext/ipp/ippcp.parts', - 'ext/ipp/ippcpepid.parts', - 'package.parts'] -internal_tools_parts = ['ext/dropt/dropt.parts', - 'tools/ikgfwrapper/ikgfwrapper.parts'] -######## End Part groups ############################################### -######## Commandline option setup ####################################### -product_variants = [ - 'production', - 'internal-test', - 'package-epid-sdk', - 'internal-tools' -] - -default_variant = 'production' - -def is_production(): - return GetOption("product-variant") == 'production' - -def is_internal_test(): - return GetOption("product-variant") == 'internal-test' - -def is_internal_tools(): - return GetOption("product-variant") == 'internal-tools' - -def is_package(): - return GetOption("product-variant") == 'package-epid-sdk' - -def use_commercial_ipp(): - return GetOption("use-commercial-ipp") - -def variant_dirname(): - s = GetOption("product-variant") - if s == 'production': - return 'epid-sdk' - elif s == 'package-epid-sdk': - return 'epid-sdk' - else: - return s - -AddOption("--product-variant", "--prod-var", nargs=1, - help=("Select product variant to build. Possible " - "options are: {0}. The default is {1} if no option " - "is specified").format(", ".join(product_variants), - default_variant), - action='store', dest='product-variant', type='choice', - choices=product_variants, default=default_variant) - -AddOption("--use-commercial-ipp", - help=("Link with commercial IPP. The IPPROOT environment variable " - "must be set."), - action='store_true', dest='use-commercial-ipp', - default=False) - -SetOptionDefault("PRODUCT_VARIANT", variant_dirname()) - -######## End Commandline option setup ################################### - - -# fix for parts 0.10.8 until we get better logic to extract ${CC} -SetOptionDefault('PARTS_USE_SHORT_TOOL_NAMES', 1) - -def set_default_production_options(): - SetOptionDefault('TARGET_PLATFORM', 'x86_64') - SetOptionDefault('CONFIG', 'release') - - SetOptionDefault('TARGET_VARIANT', '${TARGET_OS}-${TARGET_ARCH}') - - SetOptionDefault('INSTALL_ROOT', - '#_install/${PRODUCT_VARIANT}') - - SetOptionDefault('INSTALL_TOOLS_BIN', - '$INSTALL_ROOT/tools') - - SetOptionDefault('INSTALL_SAMPLE_BIN', - '$INSTALL_ROOT/example') - - SetOptionDefault('INSTALL_EPID_INCLUDE', - '$INSTALL_ROOT/include/epid') - - SetOptionDefault('INSTALL_IPP_INCLUDE', - '$INSTALL_ROOT/include/ext/ipp/include') - - SetOptionDefault('INSTALL_TEST_BIN', - '$INSTALL_ROOT/test') - - SetOptionDefault('INSTALL_LIB', - '$INSTALL_ROOT/lib/${TARGET_VARIANT}') - - SetOptionDefault('INSTALL_SAMPLE_DATA', - '$INSTALL_ROOT/example') - - SetOptionDefault('INSTALL_TOOLS_DATA', - '$INSTALL_ROOT/tools') - - SetOptionDefault('PACKAGE_DIR', - '#_package') - - SetOptionDefault('PACKAGE_ROOT', - '#_package/${PRODUCT_VARIANT}') - - SetOptionDefault('ROOT', - '#') - - SetOptionDefault('PACKAGE_NAME', - '{PRODUCT_VARIANT}') - -if is_production(): - set_default_production_options() - ipp_mode = ['install_lib'] - if use_commercial_ipp(): - ipp_mode.append('use_commercial_ipp') - include_parts(ipp_parts, mode=ipp_mode, - INSTALL_INCLUDE='${INSTALL_IPP_INCLUDE}') - include_parts(utest_parts + common_parts + - member_parts + verifier_parts, - mode=['install_lib'], - INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}') - include_parts(util_parts + example_parts, - INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}', - INSTALL_BIN='${INSTALL_SAMPLE_BIN}', - INSTALL_DATA='${INSTALL_SAMPLE_DATA}') - include_parts(tools_parts, - INSTALL_BIN='${INSTALL_TOOLS_BIN}', - INSTALL_DATA='${INSTALL_TOOLS_DATA}') - PrintCompilerVersion(DefaultEnvironment()) - Default('all') - Default('run_utest::') - -if is_internal_test(): - set_default_production_options() - include_parts(ipp_parts) - include_parts(utest_parts + common_parts + - member_parts + verifier_parts) - include_parts(util_parts + example_parts, - INSTALL_BIN='${INSTALL_SAMPLE_BIN}', - INSTALL_DATA='${INSTALL_SAMPLE_DATA}') - include_parts(tools_parts, INSTALL_BIN='${INSTALL_TOOLS_BIN}') - include_parts(testbot_test_parts) - Default('all') - -if is_internal_tools(): - set_default_production_options() - include_parts(ipp_parts + utest_parts + common_parts + util_parts) - include_parts(internal_tools_parts, INSTALL_BIN='${INSTALL_TOOLS_BIN}') - Default('ikgfwrapper') - -if is_package(): - set_default_production_options() - include_parts(package_parts, - mode=['install_package'], - INSTALL_TOP_LEVEL='${PACKAGE_ROOT}') - Default('package') diff --git a/external/epid-sdk-3.0.0/configure.ac b/external/epid-sdk-3.0.0/configure.ac deleted file mode 100644 index c5d30827..00000000 --- a/external/epid-sdk-3.0.0/configure.ac +++ /dev/null @@ -1,20 +0,0 @@ -AC_INIT([Intel(R) EPID SDK],[ ]) - -# save flags -CFLAGS_OLD="$CFLAGS" -CPPFLAGS_OLD="$CPPFLAGS" - -#c compiler priority -AC_PROG_CC([gcc icc cc]) -#c++ compiler priority -AC_PROG_CXX([g++ icpc c++]) - -# restore flags -CFLAGS="$CFLAGS_OLD" -CPPFLAGS="$CPPFLAGS_OLD" - -# default install path is current directory -AC_PREFIX_DEFAULT([`pwd`/_install]) -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT - diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/common-testhelper.parts b/external/epid-sdk-3.0.0/epid/common-testhelper/common-testhelper.parts deleted file mode 100644 index 99365c9d..00000000 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/common-testhelper.parts +++ /dev/null @@ -1,91 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ -Import('*') -env.PartName('common-testhelper') - -src_files = Pattern(src_dir='.', - includes=['*-testhelper.cc'], - excludes=[], - recursive=False).files() -inc_files = Pattern(src_dir='.', - includes=['*-testhelper.h'], - excludes=[], - recursive=False).files() -epid11_src_files = Pattern(src_dir='1.1', - includes=['*-testhelper.cc'], - excludes=[], - recursive=False).files() -epid11_inc_files = Pattern(src_dir='1.1', - includes=['*-testhelper.h'], - excludes=[], - recursive=False).files() -test_data_files = Pattern(src_dir='testdata', - includes=['*'], - excludes=[], - recursive=True) -epid11_test_data_files = Pattern(src_dir='1.1/testdata', - includes=['*'], - excludes=[], - recursive=True) - -# unit tests -utest_files = Pattern(src_dir='.', - includes=['*-test.cc'], - excludes=[], - recursive=True).files() - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='epid/${PART_SHORT_NAME}') - env.InstallTopLevel(inc_files, sub_dir='epid/${PART_SHORT_NAME}') - env.InstallTopLevel(utest_files, - sub_dir='epid/${PART_SHORT_NAME}/unittests') - env.InstallTopLevel(test_data_files, - sub_dir='epid/${PART_SHORT_NAME}/testdata') - - env.InstallTopLevel(epid11_src_files, sub_dir='epid/${PART_SHORT_NAME}/1.1') - env.InstallTopLevel(epid11_inc_files, sub_dir='epid/${PART_SHORT_NAME}/1.1') - env.InstallTopLevel(epid11_test_data_files, - sub_dir='epid/${PART_SHORT_NAME}/1.1/testdata') - - parts_file = ['common-testhelper.parts'] - env.InstallTopLevel(parts_file, sub_dir='epid/${PART_SHORT_NAME}') - makefile = ['Makefile'] - env.InstallTopLevel(makefile, sub_dir='epid/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('common'), - ]) - - env.Append(CPPPATH='#') - - testenv = env.Clone() - - outputs = env.Library('${PART_NAME}', src_files + epid11_src_files) - env.Sdk(outputs) - - testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}" - testenv.UnitTest("utest", - utest_files, - command_args=[ - '--gtest_color=yes', - '--gtest_print_time=1', - '--gtest_output=xml', - '--gtest_filter=**', - ], - make_pdb=(env.isConfigBasedOn('debug')), - depends=[Component('gtest'), - Component('common-testhelper')], - INSTALL_BIN='${INSTALL_TEST_BIN}') diff --git a/external/epid-sdk-3.0.0/epid/member/Makefile b/external/epid-sdk-3.0.0/epid/member/Makefile deleted file mode 100644 index abeaac56..00000000 --- a/external/epid-sdk-3.0.0/epid/member/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/make -f - -#define path variables -IPP_SRC_INCLUDE_DIR = ../../ext/ipp/sources/ippcp/src/ -IPP_INCLUDE_DIR = ../../ext/ipp/sources/include/ -GTEST_INCLUDE_DIR = ../../ext/ - -LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/ -TEST_INSTALL_DIR = $(epidinstalldir)/test/ -HEADERS_INSTALL_DIR := $(epidinstalldir)/include/epid/member/ - -API_HEADERS_INSTALL = ./api.h - -MEMBER_INCLUDE_DIR = ../../ - -MEMBER_SRC = $(wildcard ./src/*.c) -MEMBER_OBJ = $(sort $(MEMBER_SRC:.c=.o)) -MEMBER_LIB = ./libmember.a - -MEMBER_UTEST_EXE = ./member-utest -MEMBER_UTEST_SRC = $(wildcard ./unittests/*.cc) -MEMBER_UTEST_OBJ = $(sort $(MEMBER_UTEST_SRC:.cc=.o)) -LIB_MEMBER_DIR = . -LIB_VERIFIER_DIR = ../verifier -LIB_COMMON_TESTHELPER_DIR = ../common-testhelper -LIB_COMMON_DIR = ../common -LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src -LIB_IPPCPEPID_DIR = ../../ext/ipp/sources/ippcpepid/src - -#set flags for linker -LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \ - -L$(LIB_MEMBER_DIR) -L$(LIB_VERIFIER_DIR) -L$(LIB_COMMON_DIR) \ - -L$(LIB_IPPCPEPID_DIR) -L$(LIB_IPPCP_DIR) -lgtest -lcommon-testhelper \ - -lmember -lverifier -lcommon -lippcpepid -lippcp - -$(MEMBER_OBJ): %.o: %.c - $(CC) $(CFLAGS) -I$(IPP_INCLUDE_DIR) -I$(IPP_SRC_INCLUDE_DIR) \ - -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@ - -$(MEMBER_LIB): $(MEMBER_OBJ) - $(AR) rc $(MEMBER_LIB) $(MEMBER_OBJ) - ranlib $(MEMBER_LIB) - -$(MEMBER_UTEST_EXE): $(MEMBER_UTEST_OBJ) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -$(MEMBER_UTEST_OBJ): %.o: %.cc - $(CXX) -o $@ $(CXXFLAGS) -I$(MEMBER_INCLUDE_DIR) \ - -I$(GTEST_INCLUDE_DIR) -c $^ - -build: all - -all: $(MEMBER_LIB) - -install: - mkdir -p '$(LIB_INSTALL_DIR)' - mkdir -p '$(HEADERS_INSTALL_DIR)' - cp $(MEMBER_LIB) '$(LIB_INSTALL_DIR)' - cp $(API_HEADERS_INSTALL) '$(HEADERS_INSTALL_DIR)' -#install tests if they exist -ifneq (,$(wildcard $(MEMBER_UTEST_EXE))) - mkdir -p '$(TEST_INSTALL_DIR)' - cp $(MEMBER_UTEST_EXE) '$(TEST_INSTALL_DIR)' -endif - -check: $(MEMBER_UTEST_EXE) run - -run: - $(MEMBER_UTEST_EXE) $(GTEST_FLAGS) - -clean: - rm -f $(MEMBER_OBJ) \ - $(MEMBER_LIB) \ - $(MEMBER_UTEST_OBJ) \ - $(MEMBER_UTEST_EXE) \ - *.xml diff --git a/external/epid-sdk-3.0.0/epid/member/api.h b/external/epid-sdk-3.0.0/epid/member/api.h deleted file mode 100644 index 6b834f55..00000000 --- a/external/epid-sdk-3.0.0/epid/member/api.h +++ /dev/null @@ -1,491 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ -#ifndef EPID_MEMBER_API_H_ -#define EPID_MEMBER_API_H_ - -#include -#include "epid/common/stdtypes.h" -#include "epid/common/types.h" -#include "epid/common/errors.h" -#include "epid/common/bitsupplier.h" - -#ifdef __cplusplus -extern "C"{ -#endif - -/*! - * \file - * \brief Intel(R) EPID SDK member API. - */ - -/// Member functionality -/*! - \defgroup EpidMemberModule member - - Defines the APIs needed by Intel(R) EPID members. Each member - context (::MemberCtx) represents membership in a single group. - - \ingroup EpidModule - @{ -*/ - -/// Internal context of member. -typedef struct MemberCtx MemberCtx; - -/// Pre-computed member settings. -/*! - Serialized form of the information about a member that remains stable for - a given set of keys. - - \note e12 = 0 implies that this data is not valid - */ -#pragma pack(1) -typedef struct MemberPrecomp { - GtElemStr e12; ///< an element in GT - GtElemStr e22; ///< an element in GT - GtElemStr e2w; ///< an element in GT - GtElemStr ea2; ///< an element in GT -} MemberPrecomp; - -/// Pre-computed signature. -/*! - Serialized form of an intermediate signature that does not depend on - basename or message. This can be used to time-shift compute time needed to - sign a message. - */ -typedef struct PreComputedSignature { - G1ElemStr B; ///< an element in G1 - G1ElemStr K; ///< an element in G1 - G1ElemStr T; ///< an element in G1 - G1ElemStr R1; ///< an element in G1 - GtElemStr R2; ///< an element in G1 - FpElemStr a; ///< an integer between [0, p-1] - FpElemStr b; ///< an integer between [0, p-1] - FpElemStr rx; ///< an integer between [0, p-1] - FpElemStr rf; ///< an integer between [0, p-1] - FpElemStr ra; ///< an integer between [0, p-1] - FpElemStr rb; ///< an integer between [0, p-1] -} PreComputedSignature; -#pragma pack() - -/// Creates a new member context. -/*! - Must be called to create the member context that is used by - other "Member" APIs. - - Allocates memory for the context, then initializes it. - - EpidMemberDelete() must be called to safely release the member context. - - \param[in] pub_key - The group certificate. - \param[in] priv_key - The member private key. - \param[in] precomp - Optional pre-computed data. If NULL the value is computed internally and is - readable using EpidMemberWritePrecomp(). - \param[in] rnd_func - Random number generator. - \param[in] rnd_param - Pass through context data for rnd_func. - \param[out] ctx - Newly constructed member context. - - \returns ::EpidStatus - - \warning - For security rnd_func should be a cryptographically secure random - number generator. - - \note - If the result is not ::kEpidNoErr the content of ctx is undefined. - - \see EpidMemberDelete - \see EpidMemberWritePrecomp - */ -EpidStatus EpidMemberCreate(GroupPubKey const* pub_key, PrivKey const* priv_key, - MemberPrecomp const* precomp, BitSupplier rnd_func, - void* rnd_param, MemberCtx** ctx); - -/// Deletes an existing member context. -/*! - Must be called to safely release a member context created using - EpidMemberCreate(). - - De-initializes the context, frees memory used by the context, and sets the - context pointer to NULL. - - \param[in,out] ctx - The member context. Can be NULL. - - \see EpidMemberCreate - */ -void EpidMemberDelete(MemberCtx** ctx); - -/// Serializes the pre-computed member settings. -/*! - \param[in] ctx - The member context. - \param[out] precomp - The Serialized pre-computed member settings. - - \returns ::EpidStatus - - \note - If the result is not ::kEpidNoErr, the content of precomp is undefined. - */ -EpidStatus EpidMemberWritePrecomp(MemberCtx const* ctx, MemberPrecomp* precomp); - -/// Sets the hash algorithm to be used by a member. -/*! - \param[in] ctx - The member context. - \param[in] hash_alg - The hash algorithm to use. - - \returns ::EpidStatus - - \note - If the result is not ::kEpidNoErr, the hash algorithm used by the member is - undefined. - - \see EpidMemberCreate - \see ::HashAlg - */ -EpidStatus EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg); - -/// Computes the size in bytes required for an Intel(R) EPID signature. -/*! - \param[in] sig_rl - The signature based revocation list that is used. NULL is treated as - a zero length list. - - \returns - Size in bytes of an Intel(R) EPID signature including proofs for each entry - in the signature based revocation list. - - \see ::SigRl -*/ -size_t EpidGetSigSize(SigRl const* sig_rl); - -/// Writes an Intel(R) EPID signature. -/*! - \param[in] ctx - The member context. - \param[in] msg - The message to sign. - \param[in] msg_len - The length in bytes of message. - \param[in] basename - Optional basename. If basename is NULL a random basename is used. - Signatures generated using random basenames are anonymous. Signatures - generated using the same basename are linkable by the verifier. If a - basename is provided, it must already be registered, or - ::kEpidBadArgErr is returned. - \param[in] basename_len - The size of basename in bytes. Must be 0 basename is NULL. - \param[in] sig_rl - The signature based revocation list. - \param[in] sig_rl_size - The size in bytes of the signature based revocation list. - \param[out] sig - The generated signature - \param[in] sig_len - The size of signature in bytes. Must be equal to value returned by - EpidGetSigSize(). - - \returns ::EpidStatus - - \note - If the result is not ::kEpidNoErr the content of sig is undefined. - - \see - EpidMemberCreate - \see - EpidMemberSetHashAlg - \see - EpidGetSigSize - */ -EpidStatus EpidSign(MemberCtx const* ctx, void const* msg, size_t msg_len, - void const* basename, size_t basename_len, - SigRl const* sig_rl, size_t sig_rl_size, EpidSignature* sig, - size_t sig_len); - -/// Registers a basename with a member. -/*! - - To prevent loss of privacy, the member keeps a list of basenames - (corresponding to authorized verifiers). The member signs a message - with a basename only if the basename is in the member's basename - list. - - \warning - The use of a name-based signature creates a platform unique - pseudonymous identifier. Because it reduces the member's privacy, the - user should be notified when it is used and should have control over - its use. - - \param[in] ctx - The member context. - \param[in] basename - The basename. - \param[in] basename_len - Length of the basename. - - \returns ::EpidStatus - - \retval ::kEpidDuplicateErr - The basename was already registered. - - \note - If the result is not ::kEpidNoErr or ::kEpidDuplicateErr it is undefined if the - basename is registered. - */ -EpidStatus EpidRegisterBaseName(MemberCtx* ctx, void const* basename, - size_t basename_len); - -/// Extends the member's pool of pre-computed signatures. -/*! - Can either generate new pre-computed signatures or import existing ones. - ::EpidWritePreSigs can be used to export pre-computed signatures. - - \param[in] ctx - The member context. - \param[in] number_presigs - The number of pre-computed signatures to add to the internal pool. - \param[in,out] presigs - Optional array of valid pre-computed signatures to import. If presigs is not - NULL it most contain at least number_presigs pre-computed signatures. - - \returns ::EpidStatus - - \note - presigs buffer is zeroed out before return to prevent pre-computed - signatures from being reused. - - \note - If the result is not ::kEpidNoErr the state of the pre-computed signature - pool, and of presigs, is undefined. - - \see ::EpidMemberCreate - \see ::EpidWritePreSigs - */ -EpidStatus EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs, - PreComputedSignature* presigs); - -/// Gets the number of pre-computed signatures in the member's pool. -/*! - \param[in] ctx - The member context. - - \returns - Number of remaining pre-computed signatures. Returns 0 if ctx is NULL. - - \see ::EpidMemberCreate - \see ::EpidWritePreSigs -*/ -size_t EpidGetNumPreSigs(MemberCtx const* ctx); - -/// Serializes pre-computed signatures from the member's pool. -/*! - Removes requested number of pre-computed signatures from member's pool and - stores them in presigs array. Use ::EpidAddPreSigs to add pre-computed - signatures to the pool. - - \param[in] ctx - The member context. - \param[out] presigs - An existing buffer of pre-computed signatures. - \param[in] number_presigs - Number of pre-computed signatures to read. Number_presigs must not be greater - than the value returned by ::EpidGetNumPreSigs. - - \returns ::EpidStatus - - \note - If the result is not ::kEpidNoErr the state of the pre-computed signature - pool, and of presigs, is undefined. - - \see ::EpidMemberCreate - \see ::EpidGetNumPreSigs - \see ::EpidAddPreSigs -*/ -EpidStatus EpidWritePreSigs(MemberCtx* ctx, PreComputedSignature* presigs, - size_t number_presigs); - -/// Creates a request to join a group. -/*! - The created request is part of the interaction with an issuer needed to join - a group. This interaction with the issuer is outside the scope of this API. - - \param[in] pub_key - The group certificate of group to join. - \param[in] ni - The nonce chosen by issuer as part of join protocol. - \param[in] f - A randomly selected integer in [1, p-1]. - \param[in] rnd_func - Random number generator. - \param[in] rnd_param - Pass through context data for rnd_func. - \param[in] hash_alg - The hash algorithm to be used. - \param[out] join_request - The join request. - - \returns ::EpidStatus - - \warning - For security rnd_func should be a cryptographically secure random - number generator. - - \note - The default hash algorithm in Member is SHA-512. This is the - recommended option if you do not override the hash algorithm - elsewhere. - - \note - If the result is not ::kEpidNoErr, the content of join_request is undefined. - - \see ::HashAlg - */ -EpidStatus EpidRequestJoin(GroupPubKey const* pub_key, IssuerNonce const* ni, - FpElemStr const* f, BitSupplier rnd_func, - void* rnd_param, HashAlg hash_alg, - JoinRequest* join_request); - -/// Creates a basic signature for use in constrained environment. -/*! - Used in constrained environments where, due to limited memory, it may not - be possible to process through a large and potentially unbounded revocation - list. - - \param[in] ctx - The member context. - \param[in] msg - The message. - \param[in] msg_len - The length of message in bytes. - \param[in] basename - Optional basename. If basename is NULL a random basename is used. - Signatures generated using random basenames are anonymous. Signatures - generated using the same basename are linkable by the verifier. If a - basename is provided it must already be registered or - ::kEpidBadArgErr is returned. - \param[in] basename_len - The size of basename in bytes. Must be 0 basename is NULL. - \param[out] sig - The generated basic signature - - \returns ::EpidStatus - - \note - This function should be used in conjunction with EpidNrProve() - - \note - If the result is not ::kEpidNoErr the content of sig, is undefined. - - \see EpidMemberCreate - \see EpidNrProve - */ -EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, - void const* basename, size_t basename_len, - BasicSignature* sig); - -/// Calculates a non-revoked proof for a single signature based revocation -/// list entry. -/*! - Used in constrained environments where, due to limited memory, it may not - be possible to process through a large and potentially unbounded revocation - list. - - \param[in] ctx - The member context. - \param[in] msg - The message. - \param[in] msg_len - The length of message in bytes. - \param[in] sig - The basic signature. - \param[in] sigrl_entry - The signature based revocation list entry. - \param[out] proof - The generated non-revoked proof. - - \returns ::EpidStatus - - \note - This function should be used in conjunction with EpidSignBasic(). - - \note - If the result is not ::kEpidNoErr, the content of proof is undefined. - - \see EpidMemberCreate - \see EpidSignBasic - */ -EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, - BasicSignature const* sig, SigRlEntry const* sigrl_entry, - NrProof* proof); - -/// Tests if a member private key is valid without checking revocation. -/*! - Used to check that a member private key is a valid key for a group. This - is useful as a cross check when creating a new member private key as part of - the join process - - \param[in] pub_key - The public key of the group. - \param[in] priv_key - The private key to check. - - \result bool - - \retval true - if the private key is valid for the group of the public key - \retval false - if the private key is not valid for the group of the public key - - - \see EpidRequestJoin - */ -bool EpidIsPrivKeyInGroup(GroupPubKey const* pub_key, PrivKey const* priv_key); - -/// Decompresses compressed member private key. -/*! - - Converts a compressed member private key into a member - private key for use by other member APIs. - - \param[in] pub_key - The public key of the group. - \param[in] compressed_privkey - The compressed member private key to be decompressed. - \param[out] priv_key - The member private key. - - \returns ::EpidStatus - */ -EpidStatus EpidDecompressPrivKey(GroupPubKey const* pub_key, - CompressedPrivKey const* compressed_privkey, - PrivKey* priv_key); - -/*! @} */ - -#ifdef __cplusplus -} -#endif - -#endif // EPID_MEMBER_API_H_ diff --git a/external/epid-sdk-3.0.0/epid/member/member.parts b/external/epid-sdk-3.0.0/epid/member/member.parts deleted file mode 100644 index ee560106..00000000 --- a/external/epid-sdk-3.0.0/epid/member/member.parts +++ /dev/null @@ -1,84 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ -Import('*') -env.PartName('member') - -api_headers = Pattern(src_dir='.', - includes=['api.h'], - recursive=False).files() -src_files = Pattern(src_dir='src', - includes=['*.c'], - recursive=False).files() -internal_headers = Pattern(src_dir='src', - includes=['*.h'], - recursive=False).files() - -utest_files = Pattern(src_dir='unittests', - includes=['*-test.cc', - '*-testhelper.cc',], - recursive=False).files() -utest_headers = Pattern(src_dir='unittests', - includes=['*-testhelper.h',], - recursive=False).files() - -build_files = Pattern(src_dir='.', - includes=['*.parts', 'Makefile'], - recursive=False).files() - -if 'install_package' in env['MODE']: - env.InstallTopLevel(api_headers, - sub_dir='epid/${PART_SHORT_NAME}') - env.InstallTopLevel(src_files + internal_headers, - sub_dir='epid/${PART_SHORT_NAME}/src') - env.InstallTopLevel(utest_files + utest_headers, - sub_dir='epid/${PART_SHORT_NAME}/unittests') - - env.InstallTopLevel(build_files, sub_dir='epid/${PART_SHORT_NAME}') - -else: - env.DependsOn([ - Component('common'), - ]) - - env.Append(CPPPATH='#') - - testenv = env.Clone() - - outputs = env.Library('${PART_NAME}', src_files) - env.Sdk(outputs) - env.SdkInclude(api_headers, sub_dir='epid/${PART_SHORT_NAME}') - - if 'install_lib' in env['MODE']: - env.InstallLib(outputs) - env.InstallInclude(api_headers, sub_dir='${PART_SHORT_NAME}') - - #unit tests - testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}" - testenv.UnitTest("utest", - utest_files, - command_args=[ - '--gtest_color=yes', - '--gtest_print_time=1', - '--gtest_output=xml', - '--gtest_filter=**', - ], - make_pdb=(env.isConfigBasedOn('debug') or - env.isConfigBasedOn('static_crt_debug')), - depends=[Component('gtest'), - Component('common-testhelper'), - Component('member'), - Component('verifier')], - INSTALL_BIN='${INSTALL_TEST_BIN}') diff --git a/external/epid-sdk-3.0.0/epid/member/src/context.c b/external/epid-sdk-3.0.0/epid/member/src/context.c deleted file mode 100644 index 227bf12a..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/context.c +++ /dev/null @@ -1,423 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Member context implementation. - */ - -#include - -#include "epid/member/api.h" -#include "epid/member/src/context.h" -#include "epid/member/src/privkey.h" -#include "epid/common/src/memory.h" - -/// Perform pre-computation and store in context -static EpidStatus DoPrecomputation(MemberCtx* ctx); - -/// Read Member precomp -static EpidStatus ReadPrecomputation(MemberPrecomp const* precomp_str, - MemberCtx* ctx); - -EpidStatus EpidMemberCreate(GroupPubKey const* pub_key, PrivKey const* priv_key, - MemberPrecomp const* precomp, BitSupplier rnd_func, - void* rnd_param, MemberCtx** ctx) { - EpidStatus result = kEpidErr; - MemberCtx* member_ctx = NULL; - - if (!pub_key || !priv_key || !rnd_func || !ctx) { - return kEpidBadArgErr; - } - - // The member verifies that gid in public key and in private key - // match. If mismatch, abort and return operation failed. - if (memcmp(&pub_key->gid, &priv_key->gid, sizeof(GroupId))) { - return kEpidBadArgErr; - } - - // Allocate memory for VerifierCtx - member_ctx = SAFE_ALLOC(sizeof(MemberCtx)); - if (!member_ctx) { - return kEpidMemAllocErr; - } - - do { - // set the default hash algorithm to sha512 - member_ctx->hash_alg = kSha512; - - // Internal representation of Epid2Params - result = CreateEpid2Params(&member_ctx->epid2_params); - if (kEpidNoErr != result) { - break; - } - // Internal representation of Group Pub Key - result = - CreateGroupPubKey(pub_key, member_ctx->epid2_params->G1, - member_ctx->epid2_params->G2, &member_ctx->pub_key); - if (kEpidNoErr != result) { - break; - } - // Internal representation of Member Priv Key - result = CreatePrivKey(priv_key, member_ctx->epid2_params->G1, - member_ctx->epid2_params->Fp, &member_ctx->priv_key); - if (kEpidNoErr != result) { - break; - } - // Allocate member_ctx->e12 - result = NewFfElement(member_ctx->epid2_params->GT, &member_ctx->e12); - if (kEpidNoErr != result) { - break; - } - // Allocate member_ctx->e22 - result = NewFfElement(member_ctx->epid2_params->GT, &member_ctx->e22); - if (kEpidNoErr != result) { - break; - } - // Allocate member_ctx->e2w - result = NewFfElement(member_ctx->epid2_params->GT, &member_ctx->e2w); - if (kEpidNoErr != result) { - break; - } - // Allocate member_ctx->ea2 - result = NewFfElement(member_ctx->epid2_params->GT, &member_ctx->ea2); - if (kEpidNoErr != result) { - break; - } - // precomputation - if (precomp != NULL) { - result = ReadPrecomputation(precomp, member_ctx); - } else { - result = DoPrecomputation(member_ctx); - } - if (kEpidNoErr != result) { - break; - } - result = SetKeySpecificCommitValues(pub_key, &member_ctx->commit_values); - if (kEpidNoErr != result) { - break; - } - - member_ctx->rnd_func = rnd_func; - member_ctx->rnd_param = rnd_param; - member_ctx->allowed_basenames = NULL; - - if (!CreateStack(sizeof(PreComputedSignature), &member_ctx->presigs)) { - result = kEpidMemAllocErr; - break; - } - - *ctx = member_ctx; - result = kEpidNoErr; - } while (0); - - if (kEpidNoErr != result) { - DeleteFfElement(&member_ctx->ea2); - DeleteFfElement(&member_ctx->e2w); - DeleteFfElement(&member_ctx->e22); - DeleteFfElement(&member_ctx->e12); - DeleteEpid2Params(&member_ctx->epid2_params); - DeleteGroupPubKey(&member_ctx->pub_key); - DeletePrivKey(&member_ctx->priv_key); - DeleteStack(&member_ctx->presigs); - SAFE_FREE(member_ctx); - } - - return (result); -} - -void EpidMemberDelete(MemberCtx** ctx) { - if (ctx && *ctx) { - DeleteGroupPubKey(&(*ctx)->pub_key); - DeleteFfElement(&(*ctx)->e12); - DeleteFfElement(&(*ctx)->e22); - DeleteFfElement(&(*ctx)->e2w); - DeleteFfElement(&(*ctx)->ea2); - DeleteEpid2Params(&(*ctx)->epid2_params); - DeletePrivKey(&(*ctx)->priv_key); - DeleteBasenames(&(*ctx)->allowed_basenames); - DeleteStack(&(*ctx)->presigs); - SAFE_FREE(*ctx); - } -} - -EpidStatus EpidMemberWritePrecomp(MemberCtx const* ctx, - MemberPrecomp* precomp) { - EpidStatus result = kEpidErr; - FfElement* e12 = NULL; // an element in GT - FfElement* e22 = NULL; // an element in GT - FfElement* e2w = NULL; // an element in GT - FfElement* ea2 = NULL; // an element in GT - FiniteField* GT = NULL; // Finite field GT(Fq12 ) - if (!ctx) { - return kEpidBadArgErr; - } - if (!precomp) { - return kEpidBadArgErr; - } - if (!ctx->e12 || !ctx->e22 || !ctx->e2w || !ctx->ea2 || !ctx->epid2_params || - !(ctx->epid2_params->GT)) { - return kEpidBadArgErr; - } - e12 = ctx->e12; - e22 = ctx->e22; - e2w = ctx->e2w; - ea2 = ctx->ea2; - GT = ctx->epid2_params->GT; - result = WriteFfElement(GT, e12, &(precomp->e12), sizeof(precomp->e12)); - if (kEpidNoErr != result) { - return result; - } - result = WriteFfElement(GT, e22, &(precomp->e22), sizeof(precomp->e22)); - if (kEpidNoErr != result) { - return result; - } - result = WriteFfElement(GT, e2w, &(precomp->e2w), sizeof(precomp->e2w)); - if (kEpidNoErr != result) { - return result; - } - result = WriteFfElement(GT, ea2, &(precomp->ea2), sizeof(precomp->ea2)); - if (kEpidNoErr != result) { - return result; - } - return result; -} - -EpidStatus EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg) { - if (!ctx) return kEpidBadArgErr; - if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg) - return kEpidBadArgErr; - ctx->hash_alg = hash_alg; - return kEpidNoErr; -} - -EpidStatus EpidRegisterBaseName(MemberCtx* ctx, void const* basename, - size_t basename_len) { - EpidStatus result = kEpidErr; - if (basename_len == 0) { - return kEpidBadArgErr; - } - if (!ctx || !basename) { - return kEpidBadArgErr; - } - - if (ContainsBasename(ctx->allowed_basenames, basename, basename_len)) { - return kEpidDuplicateErr; - } - - result = AddBasename(&ctx->allowed_basenames, basename, basename_len); - - return result; -} - -void DeleteBasenames(AllowedBasename** rootnode) { - if (rootnode && *rootnode) { - AllowedBasename* currentnode = *rootnode; - while (currentnode) { - AllowedBasename* deletenode = currentnode; - currentnode = currentnode->next; - SAFE_FREE(deletenode); - } - *rootnode = NULL; - } -} - -EpidStatus AddBasename(AllowedBasename** rootnode, void const* basename, - size_t length) { - EpidStatus result = kEpidErr; - AllowedBasename* newnode = NULL; - AllowedBasename* currentnode = NULL; - if (length > (SIZE_MAX - sizeof(AllowedBasename)) + 1) { - return kEpidBadArgErr; - } - if (!basename) { - return kEpidBadArgErr; - } - - newnode = SAFE_ALLOC(sizeof(AllowedBasename) + (length - 1)); - if (!newnode) { - return kEpidMemAllocErr; - } - newnode->next = NULL; - newnode->length = length; - // Memory copy is used to copy a flexible array - if (0 != memcpy_S(newnode->name, length, basename, length)) { - SAFE_FREE(newnode); - return kEpidBadArgErr; - } - if (*rootnode == NULL) { - *rootnode = newnode; - return kEpidNoErr; - } - currentnode = *rootnode; - while (currentnode->next != NULL) { - currentnode = currentnode->next; - } - currentnode->next = newnode; - result = kEpidNoErr; - - return result; -} - -bool ContainsBasename(AllowedBasename const* rootnode, void const* basename, - size_t length) { - if (length != 0) { - while (rootnode != NULL) { - if (rootnode->length == length) { - if (!memcmp(rootnode->name, basename, length)) { - return true; - } - } - rootnode = rootnode->next; - } - } - return false; -} - -EpidStatus EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs, - PreComputedSignature* presigs) { - PreComputedSignature* new_presigs; - if (!ctx) return kEpidBadArgErr; - if (!ctx->presigs) return kEpidBadArgErr; - - if (0 == number_presigs) return kEpidNoErr; - if (number_presigs > SIZE_MAX / sizeof(PreComputedSignature)) - return kEpidBadArgErr; // integer overflow - - new_presigs = - (PreComputedSignature*)StackPushN(ctx->presigs, number_presigs, presigs); - if (!new_presigs) return kEpidMemAllocErr; - - if (presigs) { - memset(presigs, 0, number_presigs * sizeof(PreComputedSignature)); - } else { - size_t i; - for (i = 0; i < number_presigs; i++) { - EpidStatus sts = EpidComputePreSig(ctx, &new_presigs[i]); - if (kEpidNoErr != sts) { - // roll back pre-computed-signature pool - StackPopN(ctx->presigs, number_presigs, 0); - return sts; - } - } - } - return kEpidNoErr; -} - -size_t EpidGetNumPreSigs(MemberCtx const* ctx) { - return (ctx && ctx->presigs) ? StackGetSize(ctx->presigs) : (size_t)0; -} - -EpidStatus EpidWritePreSigs(MemberCtx* ctx, PreComputedSignature* presigs, - size_t number_presigs) { - if (!ctx || (!presigs && (0 != number_presigs))) return kEpidBadArgErr; - if (!ctx->presigs) return kEpidBadArgErr; - - if (0 == number_presigs) return kEpidNoErr; - - return StackPopN(ctx->presigs, number_presigs, presigs) ? kEpidNoErr - : kEpidBadArgErr; -} - -static EpidStatus DoPrecomputation(MemberCtx* ctx) { - EpidStatus result = kEpidErr; - FfElement* e12 = NULL; - FfElement* e22 = NULL; - FfElement* e2w = NULL; - FfElement* ea2 = NULL; - Epid2Params_* params = NULL; - GroupPubKey_* pub_key = NULL; - PairingState* ps_ctx = NULL; - if (!ctx) { - return kEpidBadArgErr; - } - if (!ctx->epid2_params || !ctx->epid2_params->GT || - !ctx->epid2_params->pairing_state || !ctx->pub_key || !ctx->priv_key || - !ctx->e12 || !ctx->e22 || !ctx->e2w || !ctx->ea2) { - return kEpidBadArgErr; - } - pub_key = ctx->pub_key; - params = ctx->epid2_params; - e12 = ctx->e12; - e22 = ctx->e22; - e2w = ctx->e2w; - ea2 = ctx->ea2; - ps_ctx = params->pairing_state; - // do precomputation - // 1. The member computes e12 = pairing(h1, g2). - result = Pairing(ps_ctx, e12, pub_key->h1, params->g2); - if (kEpidNoErr != result) { - return result; - } - // 2. The member computes e22 = pairing(h2, g2). - result = Pairing(ps_ctx, e22, pub_key->h2, params->g2); - if (kEpidNoErr != result) { - return result; - } - // 3. The member computes e2w = pairing(h2, w). - result = Pairing(ps_ctx, e2w, pub_key->h2, pub_key->w); - if (kEpidNoErr != result) { - return result; - } - // 4. The member computes ea2 = pairing(A, g2). - result = Pairing(ps_ctx, ea2, ctx->priv_key->A, params->g2); - if (kEpidNoErr != result) { - return result; - } - return kEpidNoErr; -} - -static EpidStatus ReadPrecomputation(MemberPrecomp const* precomp_str, - MemberCtx* ctx) { - EpidStatus result = kEpidErr; - FfElement* e12 = NULL; - FfElement* e22 = NULL; - FfElement* e2w = NULL; - FfElement* ea2 = NULL; - FiniteField* GT = NULL; - Epid2Params_* params = NULL; - if (!ctx || !precomp_str) { - return kEpidBadArgErr; - } - if (!ctx->epid2_params || !ctx->epid2_params->GT || !ctx->e12 || !ctx->e22 || - !ctx->e2w || !ctx->ea2) { - return kEpidBadArgErr; - } - params = ctx->epid2_params; - GT = params->GT; - e12 = ctx->e12; - e22 = ctx->e22; - e2w = ctx->e2w; - ea2 = ctx->ea2; - - result = ReadFfElement(GT, &precomp_str->e12, sizeof(precomp_str->e12), e12); - if (kEpidNoErr != result) { - return result; - } - result = ReadFfElement(GT, &precomp_str->e22, sizeof(precomp_str->e22), e22); - if (kEpidNoErr != result) { - return result; - } - result = ReadFfElement(GT, &precomp_str->e2w, sizeof(precomp_str->e2w), e2w); - if (kEpidNoErr != result) { - return result; - } - result = ReadFfElement(GT, &precomp_str->ea2, sizeof(precomp_str->ea2), ea2); - if (kEpidNoErr != result) { - return result; - } - return kEpidNoErr; -} diff --git a/external/epid-sdk-3.0.0/epid/member/src/context.h b/external/epid-sdk-3.0.0/epid/member/src/context.h deleted file mode 100644 index 73adb2e1..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/context.h +++ /dev/null @@ -1,85 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ -#ifndef EPID_MEMBER_SRC_CONTEXT_H_ -#define EPID_MEMBER_SRC_CONTEXT_H_ -/*! - * \file - * \brief Member context interface. - */ - -#include -#include "epid/member/api.h" -#include "epid/common/errors.h" -#include "epid/common/src/epid2params.h" -#include "epid/common/src/grouppubkey.h" -#include "epid/common/src/stack.h" -#include "epid/common/src/commitment.h" -#include "epid/member/src/privkey.h" - -/// Internal implementation of base name -typedef struct AllowedBasename { - struct AllowedBasename* next; ///< pointer to the next base name - size_t length; ///< size of base name - uint8_t name[1]; ///< base name (flexible array) -} AllowedBasename; - -/// Member context definition -struct MemberCtx { - GroupPubKey_* pub_key; ///< group public key - FfElement* e12; ///< an element in GT - FfElement* e22; ///< an element in GT - FfElement* e2w; ///< an element in GT - FfElement* ea2; ///< an element in GT - Epid2Params_* epid2_params; ///< Intel(R) EPID 2.0 params - PrivKey_* priv_key; ///< Member private key - - BitSupplier rnd_func; ///< Pseudo random number generation function - void* rnd_param; ///< Pointer to user context for rnd_func - HashAlg hash_alg; ///< Hash algorithm to use - AllowedBasename* allowed_basenames; ///< Base name list - Stack* presigs; ///< Pre-computed signatures pool - CommitValues commit_values; ///< Values that are hashed to create commitment -}; - -/// Delete base name list -void DeleteBasenames(AllowedBasename** rootnode); - -/// Add new base name to list -EpidStatus AddBasename(AllowedBasename** rootnode, void const* basename, - size_t length); - -/// Check if given base name exist in the list -bool ContainsBasename(AllowedBasename const* rootnode, void const* basename, - size_t length); - -/// Performs Pre-computation that can be used to speed up signing -/*! - \warning - Do not re-use the same pre-computed signature to generate more than - one signature. If a pre-computed signature is used for computing - two signatures, an attacker could learn the Intel(R) EPID private key. - - \param[in] ctx - The member context. - \param[out] precompsig - The pre-computed signature. - - \returns ::EpidStatus - */ -EpidStatus EpidComputePreSig(MemberCtx const* ctx, - PreComputedSignature* precompsig); - -#endif // EPID_MEMBER_SRC_CONTEXT_H_ diff --git a/external/epid-sdk-3.0.0/epid/member/src/nr_prove.c b/external/epid-sdk-3.0.0/epid/member/src/nr_prove.c deleted file mode 100644 index 6fc7613e..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/nr_prove.c +++ /dev/null @@ -1,277 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EpidNrProve implementation. - */ -#include "epid/common/src/memory.h" -#include "epid/member/api.h" -#include "epid/member/src/context.h" - -/// Handle SDK Error with Break -#define BREAK_ON_EPID_ERROR(ret) \ - if (kEpidNoErr != (ret)) { \ - break; \ - } - -/// Count of elements in array -#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) - -#pragma pack(1) -/// Storage for values to create commitment in NrProve algorithm -typedef struct NrVerifyCommitValues { - BigNumStr p; //!< A large prime (256-bit) - G1ElemStr g1; //!< Generator of G1 (512-bit) - G1ElemStr b; //!< (element of G1): part of basic signature Sigma0 - G1ElemStr k; //!< (element of G1): part of basic signature Sigma0 - G1ElemStr bp; //!< (element of G1): one entry in SigRL - G1ElemStr kp; //!< (element of G1): one entry in SigRL - G1ElemStr t; //!< element of G1 - G1ElemStr r1; //!< element of G1 - G1ElemStr r2; //!< element of G1 - uint8_t msg[1]; //!< message -} NrVerifyCommitValues; -#pragma pack() - -EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, - BasicSignature const* sig, SigRlEntry const* sigrl_entry, - NrProof* proof) { - EpidStatus res = kEpidErr; - NrVerifyCommitValues* commit_values = NULL; - size_t const commit_len = sizeof(*commit_values) - 1 + msg_len; - EcPoint* T = NULL; - EcPoint* R1 = NULL; - EcPoint* R2 = NULL; - FfElement* mu = NULL; - FfElement* nu = NULL; - FfElement* rmu = NULL; - FfElement* rnu = NULL; - FfElement* c = NULL; - FfElement* smu = NULL; - FfElement* snu = NULL; - EcPoint* B = NULL; - EcPoint* K = NULL; - EcPoint* rlB = NULL; - EcPoint* rlK = NULL; - FfElement const* f = NULL; - if (!ctx || (0 != msg_len && !msg) || !sig || !sigrl_entry || !proof) - return kEpidBadArgErr; - if (msg_len > ((SIZE_MAX - sizeof(*commit_values)) + 1)) - return kEpidBadArgErr; - if (!ctx->epid2_params || !ctx->priv_key) return kEpidBadArgErr; - - do { - bool is_identity = false; - BigNumStr mu_str = {0}; - BigNumStr nu_str = {0}; - BigNumStr rmu_str = {0}; - BigNumStr rnu_str = {0}; - BitSupplier rnd_func = ctx->rnd_func; - void* rnd_param = ctx->rnd_param; - FiniteField* Fp = ctx->epid2_params->Fp; - EcGroup* G1 = ctx->epid2_params->G1; - static const BigNumStr one = { - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}}; - - // Check required parameters - if (!ctx->priv_key->f || !rnd_func || !Fp || !G1) return kEpidBadArgErr; - - f = ctx->priv_key->f; - - commit_values = SAFE_ALLOC(commit_len); - if (!commit_values) { - res = kEpidMemAllocErr; - break; - } - - // The following variables T, R1, R2 (elements of G1), and mu, nu, - // rmu, rnu, c, smu, snu (256-bit integers) are used. - res = NewEcPoint(G1, &T); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &R1); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &R2); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &mu); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &nu); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &rmu); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &rnu); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &c); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &smu); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &snu); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &B); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &K); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &rlB); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &rlK); - BREAK_ON_EPID_ERROR(res); - - res = ReadEcPoint(G1, (const uint8_t*)&(sig->B), sizeof(sig->B), B); - BREAK_ON_EPID_ERROR(res); - res = ReadEcPoint(G1, (const uint8_t*)&(sig->K), sizeof(sig->K), K); - BREAK_ON_EPID_ERROR(res); - res = ReadEcPoint(G1, (const uint8_t*)&(sigrl_entry->b), - sizeof(sigrl_entry->b), rlB); - BREAK_ON_EPID_ERROR(res); - res = ReadEcPoint(G1, (const uint8_t*)&(sigrl_entry->k), - sizeof(sigrl_entry->k), rlK); - BREAK_ON_EPID_ERROR(res); - - // 1. The member chooses random mu from [1, p-1]. - res = FfGetRandom(Fp, &one, rnd_func, rnd_param, mu); - BREAK_ON_EPID_ERROR(res); - // 2. The member computes nu = (- f * mu) mod p. - res = FfMul(Fp, mu, f, nu); - BREAK_ON_EPID_ERROR(res); - res = FfNeg(Fp, nu, nu); - BREAK_ON_EPID_ERROR(res); - // 3. The member computes T = G1.sscmMultiExp(K', mu, B', nu). - res = WriteFfElement(Fp, mu, (uint8_t*)&mu_str, sizeof(mu_str)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, nu, (uint8_t*)&nu_str, sizeof(nu_str)); - BREAK_ON_EPID_ERROR(res); - { - EcPoint const* points[2]; - BigNumStr const* exponents[2]; - points[0] = rlK; - points[1] = rlB; - exponents[0] = &mu_str; - exponents[1] = &nu_str; - res = EcSscmMultiExp(G1, points, exponents, COUNT_OF(points), T); - BREAK_ON_EPID_ERROR(res); - } - // 4. The member chooses rmu, rnu randomly from [1, p-1]. - res = FfGetRandom(Fp, &one, rnd_func, rnd_param, rmu); - BREAK_ON_EPID_ERROR(res); - res = FfGetRandom(Fp, &one, rnd_func, rnd_param, rnu); - BREAK_ON_EPID_ERROR(res); - // 5. The member computes R1 = G1.sscmMultiExp(K, rmu, B, rnu). - res = WriteFfElement(Fp, rmu, (uint8_t*)&rmu_str, sizeof(rmu_str)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, rnu, (uint8_t*)&rnu_str, sizeof(rnu_str)); - BREAK_ON_EPID_ERROR(res); - { - EcPoint const* points[2]; - BigNumStr const* exponents[2]; - points[0] = K; - points[1] = B; - exponents[0] = &rmu_str; - exponents[1] = &rnu_str; - res = EcSscmMultiExp(G1, points, exponents, COUNT_OF(points), R1); - BREAK_ON_EPID_ERROR(res); - } - // 6. The member computes R2 = G1.sscmMultiExp(K', rmu, B', rnu). - { - EcPoint const* points[2]; - BigNumStr const* exponents[2]; - points[0] = rlK; - points[1] = rlB; - exponents[0] = &rmu_str; - exponents[1] = &rnu_str; - res = EcSscmMultiExp(G1, points, exponents, COUNT_OF(points), R2); - BREAK_ON_EPID_ERROR(res); - } - // 7. The member computes c = Fp.hash(p || g1 || B || K || B' || - // K' || T || R1 || R2 || m). Refer to Section 7.1 for hash - // operation over a prime field. - - // commit_values is allocated such that there are msg_len bytes available - // starting at commit_values->msg - if (msg) { - // Memory copy is used to copy a message of variable length - if (0 != memcpy_S(&commit_values->msg[0], msg_len, msg, msg_len)) { - res = kEpidBadArgErr; - break; - } - } - commit_values->p = ctx->commit_values.p; - commit_values->g1 = ctx->commit_values.g1; - commit_values->b = sig->B; - commit_values->k = sig->K; - commit_values->bp = sigrl_entry->b; - commit_values->kp = sigrl_entry->k; - res = WriteEcPoint(G1, T, (uint8_t*)&commit_values->t, - sizeof(commit_values->t)); - BREAK_ON_EPID_ERROR(res); - res = WriteEcPoint(G1, R1, (uint8_t*)&commit_values->r1, - sizeof(commit_values->r1)); - BREAK_ON_EPID_ERROR(res); - res = WriteEcPoint(G1, R2, (uint8_t*)&commit_values->r2, - sizeof(commit_values->r2)); - BREAK_ON_EPID_ERROR(res); - res = FfHash(Fp, (uint8_t*)commit_values, commit_len, ctx->hash_alg, c); - BREAK_ON_EPID_ERROR(res); - - // 8. The member computes smu = (rmu + c * mu) mod p. - res = FfMul(Fp, c, mu, smu); - BREAK_ON_EPID_ERROR(res); - res = FfAdd(Fp, rmu, smu, smu); - BREAK_ON_EPID_ERROR(res); - // 9. The member computes snu = (rnu + c * nu) mod p. - res = FfMul(Fp, c, nu, snu); - BREAK_ON_EPID_ERROR(res); - res = FfAdd(Fp, rnu, snu, snu); - BREAK_ON_EPID_ERROR(res); - // 10. The member outputs sigma = (T, c, smu, snu), a non-revoked - // proof. If G1.is_identity(T) = true, the member also outputs - // "failed". - - proof->T = commit_values->t; - res = WriteFfElement(Fp, c, (uint8_t*)&proof->c, sizeof(proof->c)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, smu, (uint8_t*)&proof->smu, sizeof(proof->smu)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, snu, (uint8_t*)&proof->snu, sizeof(proof->snu)); - BREAK_ON_EPID_ERROR(res); - - res = EcIsIdentity(G1, T, &is_identity); - BREAK_ON_EPID_ERROR(res); - if (is_identity) { - res = kEpidSigRevokedInSigRl; - BREAK_ON_EPID_ERROR(res); - } - res = kEpidNoErr; - } while (0); - - f = NULL; - SAFE_FREE(commit_values) - DeleteEcPoint(&T); - DeleteEcPoint(&R1); - DeleteEcPoint(&R2); - DeleteFfElement(&mu); - DeleteFfElement(&nu); - DeleteFfElement(&rmu); - DeleteFfElement(&rnu); - DeleteFfElement(&c); - DeleteFfElement(&smu); - DeleteFfElement(&snu); - DeleteEcPoint(&B); - DeleteEcPoint(&K); - DeleteEcPoint(&rlB); - DeleteEcPoint(&rlK); - - return res; -} diff --git a/external/epid-sdk-3.0.0/epid/member/src/presig.c b/external/epid-sdk-3.0.0/epid/member/src/presig.c deleted file mode 100644 index 9f057f8a..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/presig.c +++ /dev/null @@ -1,229 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EpidComputePreSig implementation. - */ - -#include "epid/member/src/context.h" - -/// Handle SDK Error with Break -#define BREAK_ON_EPID_ERROR(ret) \ - if (kEpidNoErr != (ret)) { \ - break; \ - } - -/// Count of elements in array -#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) - -EpidStatus EpidComputePreSig(MemberCtx const* ctx, - PreComputedSignature* precompsig) { - EpidStatus res = kEpidNotImpl; - - EcPoint* B = NULL; - EcPoint* K = NULL; - EcPoint* T = NULL; - EcPoint* R1 = NULL; - - FfElement* R2 = NULL; - - FfElement* a = NULL; - FfElement* b = NULL; - FfElement* rx = NULL; - FfElement* rf = NULL; - FfElement* ra = NULL; - FfElement* rb = NULL; - FfElement* t1 = NULL; - FfElement* t2 = NULL; - FfElement* f = NULL; - - if (!ctx || !precompsig) return kEpidBadArgErr; - if (!ctx->epid2_params || !ctx->pub_key || !ctx->priv_key) - return kEpidBadArgErr; - - do { - // handy shorthands: - EcGroup* G1 = ctx->epid2_params->G1; - FiniteField* GT = ctx->epid2_params->GT; - FiniteField* Fp = ctx->epid2_params->Fp; - EcPoint* h2 = ctx->pub_key->h2; - EcPoint* A = ctx->priv_key->A; - FfElement* x = ctx->priv_key->x; - BigNumStr f_str = {0}; - BigNumStr a_str = {0}; - BigNumStr t1_str = {0}; - BigNumStr rf_str = {0}; - BigNumStr t2_str = {0}; - BigNumStr ra_str = {0}; - static const BigNumStr one = { - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}}; - - if (!G1 || !GT || !Fp || !h2 || !A || !x || !ctx->priv_key->f || - !ctx->e12 || !ctx->e22 || !ctx->e2w || !ctx->ea2) { - res = kEpidBadArgErr; - BREAK_ON_EPID_ERROR(res); - } - f = ctx->priv_key->f; - // The following variables B, K, T, R1 (elements of G1), R2 - // (elements of GT), a, b, rx, rf, ra, rb, t1, t2 (256-bit - // integers) are used. - res = NewEcPoint(G1, &B); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &K); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &T); - BREAK_ON_EPID_ERROR(res); - res = NewEcPoint(G1, &R1); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(GT, &R2); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &a); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &b); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &rx); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &rf); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &ra); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &rb); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &t1); - BREAK_ON_EPID_ERROR(res); - res = NewFfElement(Fp, &t2); - BREAK_ON_EPID_ERROR(res); - // 1. The member expects the pre-computation is done (e12, e22, e2w, - // ea2). Refer to Section 3.5 for the computation of these - // values. - - // 2. The member verifies gid in public key matches gid in private - // key. - // 3. The member computes B = G1.getRandom(). - res = EcGetRandom(G1, ctx->rnd_func, ctx->rnd_param, B); - BREAK_ON_EPID_ERROR(res); - // 4. The member computes K = G1.sscmExp(B, f). - res = WriteFfElement(Fp, f, &f_str, sizeof(f_str)); - BREAK_ON_EPID_ERROR(res); - res = EcExp(G1, B, &f_str, K); - BREAK_ON_EPID_ERROR(res); - // 5. The member chooses randomly an integers a from [1, p-1]. - res = FfGetRandom(Fp, &one, ctx->rnd_func, ctx->rnd_param, a); - BREAK_ON_EPID_ERROR(res); - // 6. The member computes T = G1.sscmExp(h2, a). - res = WriteFfElement(Fp, a, &a_str, sizeof(a_str)); - BREAK_ON_EPID_ERROR(res); - res = EcExp(G1, h2, &a_str, T); - BREAK_ON_EPID_ERROR(res); - // 7. The member computes T = G1.mul(T, A). - res = EcMul(G1, T, A, T); - BREAK_ON_EPID_ERROR(res); - // 8. The member computes b = (a * x) mod p. - res = FfMul(Fp, a, x, b); - BREAK_ON_EPID_ERROR(res); - // 9. The member chooses rx, rf, ra, rb randomly from [1, p-1]. - res = FfGetRandom(Fp, &one, ctx->rnd_func, ctx->rnd_param, rx); - BREAK_ON_EPID_ERROR(res); - res = FfGetRandom(Fp, &one, ctx->rnd_func, ctx->rnd_param, rf); - BREAK_ON_EPID_ERROR(res); - res = FfGetRandom(Fp, &one, ctx->rnd_func, ctx->rnd_param, ra); - BREAK_ON_EPID_ERROR(res); - res = FfGetRandom(Fp, &one, ctx->rnd_func, ctx->rnd_param, rb); - BREAK_ON_EPID_ERROR(res); - // 10. The member computes t1 = (- rx) mod p. - res = FfNeg(Fp, rx, t1); - BREAK_ON_EPID_ERROR(res); - // 11. The member computes t2 = (rb - a * rx) mod p. - res = FfMul(Fp, a, rx, t2); - BREAK_ON_EPID_ERROR(res); - res = FfNeg(Fp, t2, t2); - BREAK_ON_EPID_ERROR(res); - res = FfAdd(Fp, rb, t2, t2); - BREAK_ON_EPID_ERROR(res); - // 12. The member computes R1 = G1.sscmExp(B, rf). - res = WriteFfElement(Fp, rf, &rf_str, sizeof(rf_str)); - BREAK_ON_EPID_ERROR(res); - res = EcExp(G1, B, &rf_str, R1); - BREAK_ON_EPID_ERROR(res); - // 13. The member computes R2 = GT.sscmMultiExp(ea2, t1, e12, rf, - // e22, t2, e2w, ra). - res = WriteFfElement(Fp, t1, &t1_str, sizeof(t1_str)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, t2, &t2_str, sizeof(t2_str)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, ra, &ra_str, sizeof(ra_str)); - BREAK_ON_EPID_ERROR(res); - { - FfElement const* points[4]; - BigNumStr const* exponents[4]; - points[0] = ctx->ea2; - points[1] = ctx->e12; - points[2] = ctx->e22; - points[3] = ctx->e2w; - exponents[0] = &t1_str; - exponents[1] = &rf_str; - exponents[2] = &t2_str; - exponents[3] = &ra_str; - res = FfMultiExp(GT, points, exponents, COUNT_OF(points), R2); - BREAK_ON_EPID_ERROR(res); - } - // 14. The member sets and outputs pre-sigma = (B, K, T, a, b, rx, - // rf, ra, rb, R1, R2). - res = WriteEcPoint(G1, B, &precompsig->B, sizeof(precompsig->B)); - BREAK_ON_EPID_ERROR(res); - res = WriteEcPoint(G1, K, &precompsig->K, sizeof(precompsig->K)); - BREAK_ON_EPID_ERROR(res); - res = WriteEcPoint(G1, T, &precompsig->T, sizeof(precompsig->T)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, a, &precompsig->a, sizeof(precompsig->a)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, b, &precompsig->b, sizeof(precompsig->b)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, rx, &precompsig->rx, sizeof(precompsig->rx)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, rf, &precompsig->rf, sizeof(precompsig->rf)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, ra, &precompsig->ra, sizeof(precompsig->ra)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(Fp, rb, &precompsig->rb, sizeof(precompsig->rb)); - BREAK_ON_EPID_ERROR(res); - res = WriteEcPoint(G1, R1, &precompsig->R1, sizeof(precompsig->R1)); - BREAK_ON_EPID_ERROR(res); - res = WriteFfElement(GT, R2, &precompsig->R2, sizeof(precompsig->R2)); - BREAK_ON_EPID_ERROR(res); - // 15. The member stores pre-sigma in the secure storage of the - // member. - res = kEpidNoErr; - } while (0); - - f = NULL; - DeleteEcPoint(&B); - DeleteEcPoint(&K); - DeleteEcPoint(&T); - DeleteEcPoint(&R1); - DeleteFfElement(&R2); - DeleteFfElement(&a); - DeleteFfElement(&b); - DeleteFfElement(&rx); - DeleteFfElement(&rf); - DeleteFfElement(&ra); - DeleteFfElement(&rb); - DeleteFfElement(&t1); - DeleteFfElement(&t2); - - return (res); -} diff --git a/external/epid-sdk-3.0.0/epid/member/src/privkey.c b/external/epid-sdk-3.0.0/epid/member/src/privkey.c deleted file mode 100644 index a34d8965..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/privkey.c +++ /dev/null @@ -1,84 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Private key implementation. - */ - -#include "epid/common/src/memory.h" -#include "epid/member/src/privkey.h" - -EpidStatus CreatePrivKey(PrivKey const* priv_key_str, EcGroup* G1, - FiniteField* Fp, PrivKey_** priv_key) { - EpidStatus result = kEpidErr; - PrivKey_* priv_key_ = NULL; - - // check parameters - if (!priv_key_str || !G1 || !Fp || !priv_key) return kEpidBadArgErr; - - do { - priv_key_ = SAFE_ALLOC(sizeof(*priv_key_)); - - if (!priv_key_) { - result = kEpidMemAllocErr; - break; - } - - result = NewEcPoint(G1, &priv_key_->A); - if (kEpidNoErr != result) break; - - result = NewFfElement(Fp, &priv_key_->x); - if (kEpidNoErr != result) break; - - result = NewFfElement(Fp, &priv_key_->f); - if (kEpidNoErr != result) break; - - priv_key_->gid = priv_key_str->gid; - - result = ReadEcPoint(G1, &priv_key_str->A, sizeof(priv_key_str->A), - priv_key_->A); - if (kEpidNoErr != result) break; - - result = ReadFfElement(Fp, &priv_key_str->x, sizeof(priv_key_str->x), - priv_key_->x); - if (kEpidNoErr != result) break; - - result = ReadFfElement(Fp, &priv_key_str->f, sizeof(priv_key_str->f), - priv_key_->f); - if (kEpidNoErr != result) break; - - *priv_key = priv_key_; - result = kEpidNoErr; - } while (0); - - if (kEpidNoErr != result) { - DeletePrivKey(&priv_key_); - } - - return (result); -} - -void DeletePrivKey(PrivKey_** priv_key) { - if (priv_key) { - if (*priv_key) { - DeleteEcPoint(&((*priv_key)->A)); - DeleteFfElement(&((*priv_key)->x)); - DeleteFfElement(&((*priv_key)->f)); - } - SAFE_FREE(*priv_key); - } -} diff --git a/external/epid-sdk-3.0.0/epid/member/src/privkey.h b/external/epid-sdk-3.0.0/epid/member/src/privkey.h deleted file mode 100644 index 1981a67e..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/privkey.h +++ /dev/null @@ -1,67 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ -#ifndef EPID_MEMBER_SRC_PRIVKEY_H_ -#define EPID_MEMBER_SRC_PRIVKEY_H_ -/*! -* \file - * \brief Private key private interface. -* \addtogroup EpidCommon -* @{ -*/ -#include "epid/common/errors.h" -#include "epid/common/math/ecgroup.h" -#include "epid/common/types.h" - -/*! - * \brief - * Internal implementation of PrivKey - */ -typedef struct PrivKey_ { - GroupId gid; ///< group ID - EcPoint* A; ///< an element in G1 - FfElement* x; ///< an integer between [0, p-1] - FfElement* f; ///< an integer between [0, p-1] -} PrivKey_; - -/// Constructs internal representation of PrivKey -/*! - This function allocates memory and initializes gid, A, x, f parameters. - - \param[in] priv_key_str - Serialized representation of private key - \param[in] G1 - EcGroup containing element A - \param[in] Fp - FiniteField containing elements x and f - \param[out] priv_key - Newly created private key: (gid, A, x, f) - - \returns ::EpidStatus -*/ -EpidStatus CreatePrivKey(PrivKey const* priv_key_str, EcGroup* G1, - FiniteField* Fp, PrivKey_** priv_key); - -/// Deallocate storage for internal representation of PrivKey -/*! - Frees memory pointed to by Member private key. Nulls the pointer. - - \param[in] priv_key - Member private key to be freed -*/ -void DeletePrivKey(PrivKey_** priv_key); - -/*! @} */ -#endif // EPID_MEMBER_SRC_PRIVKEY_H_ diff --git a/external/epid-sdk-3.0.0/epid/member/src/request_join.c b/external/epid-sdk-3.0.0/epid/member/src/request_join.c deleted file mode 100644 index 981bfff7..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/request_join.c +++ /dev/null @@ -1,418 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EpidRequestJoin implementation. - */ - -#include -#include -#include "epid/common/src/epid2params.h" -#include "epid/common/math/finitefield.h" -#include "epid/common/math/ecgroup.h" - -#pragma pack(1) -/// Storage for values to create commitment in Sign and Verify algorithms -typedef struct JoinPCommitValues { - BigNumStr p; ///< Intel(R) EPID 2.0 parameter p - G1ElemStr g1; ///< Intel(R) EPID 2.0 parameter g1 - G2ElemStr g2; ///< Intel(R) EPID 2.0 parameter g2 - G1ElemStr h1; ///< Group public key value h1 - G1ElemStr h2; ///< Group public key value h2 - G2ElemStr w; ///< Group public key value w - G1ElemStr F; ///< Variable F computed in algorithm - G1ElemStr R; ///< Variable R computed in algorithm - IssuerNonce NI; ///< Nonce -} JoinPCommitValues; -#pragma pack() - -/// Handle SDK Error with Break -#define BREAK_ON_EPID_ERROR(ret) \ - if (kEpidNoErr != (ret)) { \ - break; \ - } - -EpidStatus EpidRequestJoin(GroupPubKey const* pub_key, IssuerNonce const* ni, - FpElemStr const* f, BitSupplier rnd_func, - void* rnd_param, HashAlg hash_alg, - JoinRequest* join_request) { - EpidStatus sts; - static const BigNumStr one = { - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}}; - BigNumStr r_str; - JoinPCommitValues commit_values; - Epid2Params_* params = NULL; - FfElement* r_el = NULL; - FfElement* f_el = NULL; - FfElement* c_el = NULL; - FfElement* cf_el = NULL; - FfElement* s_el = NULL; - EcPoint* f_pt = NULL; - EcPoint* r_pt = NULL; - EcPoint* h1_pt = NULL; - - if (!pub_key || !ni || !f || !rnd_func || !join_request) { - return kEpidBadArgErr; - } - if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg) { - return kEpidBadArgErr; - } - - do { - sts = CreateEpid2Params(¶ms); - BREAK_ON_EPID_ERROR(sts); - if (!params->Fp || !params->G1) { - sts = kEpidBadArgErr; - break; - } - sts = NewFfElement(params->Fp, &r_el); - BREAK_ON_EPID_ERROR(sts); - sts = NewFfElement(params->Fp, &f_el); - BREAK_ON_EPID_ERROR(sts); - sts = NewFfElement(params->Fp, &c_el); - BREAK_ON_EPID_ERROR(sts); - sts = NewFfElement(params->Fp, &cf_el); - BREAK_ON_EPID_ERROR(sts); - sts = NewFfElement(params->Fp, &s_el); - BREAK_ON_EPID_ERROR(sts); - sts = NewEcPoint(params->G1, &f_pt); - BREAK_ON_EPID_ERROR(sts); - sts = NewEcPoint(params->G1, &h1_pt); - BREAK_ON_EPID_ERROR(sts); - sts = NewEcPoint(params->G1, &r_pt); - BREAK_ON_EPID_ERROR(sts); - - sts = ReadFfElement(params->Fp, (uint8_t const*)f, sizeof(*f), f_el); - BREAK_ON_EPID_ERROR(sts); - sts = ReadEcPoint(params->G1, (uint8_t*)&pub_key->h1, sizeof(pub_key->h1), - h1_pt); - BREAK_ON_EPID_ERROR(sts); - - // Step 1. The member chooses a random integer r from [1, p-1]. - sts = FfGetRandom(params->Fp, &one, rnd_func, rnd_param, r_el); - BREAK_ON_EPID_ERROR(sts); - sts = WriteFfElement(params->Fp, r_el, (uint8_t*)&r_str, sizeof(r_str)); - - // Step 2. The member computes F = G1.sscmExp(h1, f). - sts = EcExp(params->G1, h1_pt, (BigNumStr const*)f, f_pt); - BREAK_ON_EPID_ERROR(sts); - - // Step 3. The member computes R = G1.sscmExp(h1, r). - sts = EcExp(params->G1, h1_pt, (BigNumStr const*)&r_str, r_pt); - BREAK_ON_EPID_ERROR(sts); - - // Step 4. The member computes c = Fp.hash(p || g1 || g2 || h1 || h2 || w || - // F || R || NI). Refer to Section 7.1 for hash operation over a prime - // field. - sts = WriteBigNum(params->p, sizeof(commit_values.p), - (uint8_t*)&commit_values.p); - BREAK_ON_EPID_ERROR(sts); - sts = WriteEcPoint(params->G1, params->g1, (uint8_t*)&commit_values.g1, - sizeof(commit_values.g1)); - BREAK_ON_EPID_ERROR(sts); - sts = WriteEcPoint(params->G2, params->g2, (uint8_t*)&commit_values.g2, - sizeof(commit_values.g2)); - BREAK_ON_EPID_ERROR(sts); - commit_values.h1 = pub_key->h1; - commit_values.h2 = pub_key->h2; - commit_values.w = pub_key->w; - sts = WriteEcPoint(params->G1, f_pt, (uint8_t*)&commit_values.F, - sizeof(commit_values.F)); - BREAK_ON_EPID_ERROR(sts); - sts = WriteEcPoint(params->G1, r_pt, (uint8_t*)&commit_values.R, - sizeof(commit_values.R)); - BREAK_ON_EPID_ERROR(sts); - commit_values.NI = *ni; - sts = FfHash(params->Fp, (uint8_t*)&commit_values, sizeof(commit_values), - hash_alg, c_el); - BREAK_ON_EPID_ERROR(sts); - - // Step 5. The member computes s = (r + c * f) mod p. - sts = FfMul(params->Fp, c_el, f_el, cf_el); - BREAK_ON_EPID_ERROR(sts); - sts = FfAdd(params->Fp, r_el, cf_el, s_el); - BREAK_ON_EPID_ERROR(sts); - - // Step 6. The output join request is (F, c, s). - sts = WriteFfElement(params->Fp, c_el, (uint8_t*)&join_request->c, - sizeof(join_request->c)); - BREAK_ON_EPID_ERROR(sts); - sts = WriteFfElement(params->Fp, s_el, (uint8_t*)&join_request->s, - sizeof(join_request->s)); - BREAK_ON_EPID_ERROR(sts); - sts = WriteEcPoint(params->G1, f_pt, (uint8_t*)&join_request->F, - sizeof(join_request->F)); - BREAK_ON_EPID_ERROR(sts); - - sts = kEpidNoErr; - } while (0); - DeleteEcPoint(&h1_pt); - DeleteEcPoint(&r_pt); - DeleteEcPoint(&f_pt); - DeleteFfElement(&s_el); - DeleteFfElement(&cf_el); - DeleteFfElement(&c_el); - DeleteFfElement(&f_el); - DeleteFfElement(&r_el); - DeleteEpid2Params(¶ms); - return sts; -} - -// implements section 3.2.2 "Validation of Private Key" from -// Intel(R) EPID 2.0 Spec -bool EpidIsPrivKeyInGroup(GroupPubKey const* pub_key, PrivKey const* priv_key) { - bool result; - - // Intel(R) EPID Parameters - Epid2Params_* params = NULL; - PairingState* ps = NULL; - - // private key - EcPoint* a_pt = NULL; // an element in G1 - FfElement* x_el = NULL; // an integer between [1, p-1] - FfElement* f_el = NULL; // an integer between [1, p-1] - - // public key - EcPoint* h1_pt = NULL; // an element in G1 - EcPoint* h2_pt = NULL; // an element in G1 - EcPoint* w_pt = NULL; // an element in G2 - - // local variables - EcPoint* t1_pt = NULL; // an element in G2 - EcPoint* t2_pt = NULL; // an element in G1 - FfElement* t3_el = NULL; // an element in GT - FfElement* t4_el = NULL; // an element in GT - - if (!pub_key || !priv_key) { - return false; - } - - do { - EpidStatus sts; - EcGroup* G1 = NULL; - EcGroup* G2 = NULL; - FiniteField* GT = NULL; - FiniteField* Fp = NULL; - BigNumStr t_str = {0}; - - sts = CreateEpid2Params(¶ms); - if (kEpidNoErr != sts) { - result = false; - break; - } - - G1 = params->G1; - G2 = params->G2; - GT = params->GT; - Fp = params->Fp; - - sts = WriteBigNum(params->t, sizeof(t_str), &t_str); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewPairingState(G1, G2, GT, &t_str, params->neg, &ps); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Load private key - sts = NewEcPoint(G1, &a_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadEcPoint(G1, &priv_key->A, sizeof(priv_key->A), a_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewFfElement(Fp, &x_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadFfElement(Fp, &priv_key->x, sizeof(priv_key->x), x_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewFfElement(Fp, &f_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadFfElement(Fp, &priv_key->f, sizeof(priv_key->f), f_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Load public key - sts = NewEcPoint(G1, &h1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadEcPoint(G1, &pub_key->h1, sizeof(pub_key->h1), h1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewEcPoint(G1, &h2_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadEcPoint(G1, &pub_key->h2, sizeof(pub_key->h2), h2_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewEcPoint(G2, &w_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = ReadEcPoint(G2, &pub_key->w, sizeof(pub_key->w), w_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // local variables - sts = NewEcPoint(G2, &t1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewEcPoint(G1, &t2_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewFfElement(GT, &t3_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = NewFfElement(GT, &t4_el); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 1. The member verifies that the gid in the public key matches the - // gid in the private key. - if (0 != memcmp(&pub_key->gid, &priv_key->gid, sizeof(priv_key->gid))) { - result = false; - break; - } - - // Step 2. The member computes t1 = G2.sscmExp(g2, x). - sts = EcSscmExp(G2, params->g2, (BigNumStr const*)&priv_key->x, t1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 3. The member computes t1 = G2.mul(t1, w). - sts = EcMul(G2, t1_pt, w_pt, t1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 4. The member computes t3 = pairing(A, t1). - sts = Pairing(ps, t3_el, a_pt, t1_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 5. The member computes t2 = G1.sscmExp(h1, f). - sts = EcSscmExp(G1, h1_pt, (BigNumStr const*)&priv_key->f, t2_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 6. The member computes t2 = G1.mul(t2, g1). - sts = EcMul(G1, t2_pt, params->g1, t2_pt); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 7. The member computes t4 = pairing(t2, g2). - sts = WriteBigNum(params->t, sizeof(t_str), &t_str); - if (kEpidNoErr != sts) { - result = false; - break; - } - - sts = Pairing(ps, t4_el, t2_pt, params->g2); - if (kEpidNoErr != sts) { - result = false; - break; - } - - // Step 8. If GT.isEqual(t3, t4) = false, reports bad private key. - sts = FfIsEqual(GT, t3_el, t4_el, &result); - if (kEpidNoErr != sts) { - result = false; - break; - } - } while (0); - - // local variables - DeleteFfElement(&t4_el); - DeleteFfElement(&t3_el); - DeleteEcPoint(&t2_pt); - DeleteEcPoint(&t1_pt); - - // public key - DeleteEcPoint(&w_pt); - DeleteEcPoint(&h2_pt); - DeleteEcPoint(&h1_pt); - - // private key - DeleteFfElement(&f_el); - DeleteFfElement(&x_el); - DeleteEcPoint(&a_pt); - - // Intel(R) EPID Parameters - DeletePairingState(&ps); - DeleteEpid2Params(¶ms); - - return result; -} diff --git a/external/epid-sdk-3.0.0/epid/member/src/signbasic.c b/external/epid-sdk-3.0.0/epid/member/src/signbasic.c deleted file mode 100644 index a8dccb30..00000000 --- a/external/epid-sdk-3.0.0/epid/member/src/signbasic.c +++ /dev/null @@ -1,272 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EpidSignBasic implementation. - */ - -#include // memset - -#include "epid/common/src/stack.h" -#include "epid/member/api.h" -#include "epid/member/src/context.h" - -/// Handle SDK Error with Break -#define BREAK_ON_EPID_ERROR(ret) \ - if (kEpidNoErr != (ret)) { \ - break; \ - } - -EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, - void const* basename, size_t basename_len, - BasicSignature* sig) { - EpidStatus result = kEpidErr; - // Values to be affected by basename - EcPoint* B = NULL; - EcPoint* K = NULL; - EcPoint* R1 = NULL; - // data from presig - EcPoint* T = NULL; - FfElement* a = NULL; - FfElement* b = NULL; - FfElement* rx = NULL; - FfElement* rf = NULL; - FfElement* ra = NULL; - FfElement* rb = NULL; - FfElement* R2 = NULL; - - // final calculatoin data - FfElement* sx = NULL; - FfElement* sf = NULL; - FfElement* sa = NULL; - FfElement* sb = NULL; - FfElement* c_hash = NULL; - // priv key data, need to clear after use - BigNumStr f_str = {0}; - if (!ctx || !sig) { - return kEpidBadArgErr; - } - if (!msg && (0 != msg_len)) { - // if message is non-empty it must have both length and content - return kEpidBadArgErr; - } - if (!basename && (0 != basename_len)) { - // if basename is non-empty it must have both length and content - return kEpidBadArgErr; - } - if (!ctx->epid2_params || !ctx->priv_key || !ctx->epid2_params->G1 || - !ctx->epid2_params->GT || !ctx->epid2_params->Fp || !ctx->priv_key->f) { - return kEpidBadArgErr; - } - - do { - PreComputedSignature curr_presig; - G1ElemStr B_str = {0}; - G1ElemStr K_str = {0}; - CommitValues commit_values = ctx->commit_values; - - // create all required elemnts - result = NewEcPoint(ctx->epid2_params->G1, &B); - BREAK_ON_EPID_ERROR(result); - result = NewEcPoint(ctx->epid2_params->G1, &K); - BREAK_ON_EPID_ERROR(result); - result = NewEcPoint(ctx->epid2_params->G1, &R1); - BREAK_ON_EPID_ERROR(result); - - result = NewEcPoint(ctx->epid2_params->G1, &T); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->GT, &R2); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &sx); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &sf); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &sa); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &sb); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &c_hash); - BREAK_ON_EPID_ERROR(result); - - result = NewFfElement(ctx->epid2_params->Fp, &a); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &b); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &rx); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &rf); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &ra); - BREAK_ON_EPID_ERROR(result); - result = NewFfElement(ctx->epid2_params->Fp, &rb); - BREAK_ON_EPID_ERROR(result); - - if (StackGetSize(ctx->presigs)) { - // Use existing pre-computed signature - if (!StackPopN(ctx->presigs, 1, &curr_presig)) { - result = kEpidErr; - break; - } - } else { - // generate a new pre-computed signature - result = EpidComputePreSig(ctx, &curr_presig); - BREAK_ON_EPID_ERROR(result); - } - // 3. If the pre-computed signature pre-sigma exists, the member - // loads (B, K, T, a, b, rx, rf, ra, rb, R1, R2) from - // pre-sigma. Refer to Section 4.4 for the computation of - // these values. - result = ReadEcPoint(ctx->epid2_params->G1, &curr_presig.B, - sizeof(curr_presig.B), B); - BREAK_ON_EPID_ERROR(result); - result = ReadEcPoint(ctx->epid2_params->G1, &curr_presig.K, - sizeof(curr_presig.K), K); - BREAK_ON_EPID_ERROR(result); - result = ReadEcPoint(ctx->epid2_params->G1, &curr_presig.T, - sizeof(curr_presig.T), T); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.a, - sizeof(curr_presig.a), a); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.b, - sizeof(curr_presig.b), b); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.rx, - sizeof(curr_presig.rx), rx); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.rf, - sizeof(curr_presig.rf), rf); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.ra, - sizeof(curr_presig.ra), ra); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->Fp, &curr_presig.rb, - sizeof(curr_presig.rb), rb); - BREAK_ON_EPID_ERROR(result); - result = ReadEcPoint(ctx->epid2_params->G1, &curr_presig.R1, - sizeof(curr_presig.R1), R1); - BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(ctx->epid2_params->GT, &curr_presig.R2, - sizeof(curr_presig.R2), R2); - BREAK_ON_EPID_ERROR(result); - - if (basename) { - // If basename is provided, the member does the following: - // make sure basename is registered/allowed - if (!ContainsBasename(ctx->allowed_basenames, basename, basename_len)) { - result = kEpidBadArgErr; - break; - } else { - // basename valid, can modify parameters - // a. The member computes B = G1.hash(bsn). - result = EcHash(ctx->epid2_params->G1, basename, basename_len, - ctx->hash_alg, B); - BREAK_ON_EPID_ERROR(result); - // b. The member computes K = G1.sscmExp(B, f), where B comes - // from step a. - result = WriteFfElement(ctx->epid2_params->Fp, ctx->priv_key->f, &f_str, - sizeof(f_str)); - BREAK_ON_EPID_ERROR(result); - result = EcSscmExp(ctx->epid2_params->G1, B, &f_str, K); - BREAK_ON_EPID_ERROR(result); - // c. The member computes R1 = G1.sscmExp(B, rf), where B comes - // from step a. - result = EcSscmExp(ctx->epid2_params->G1, B, - (const BigNumStr*)&curr_presig.rf, R1); - BREAK_ON_EPID_ERROR(result); - // d. The member over-writes the B, K, and R1 values. - } - } - // 5. The member computes t3 = Fp.hash(p || g1 || g2 || h1 || h2 - // || w || B || K || T || R1 || R2). Refer to Section 7.1 for - // hash operation over a prime field. - // 6. The member computes c = Fp.hash(t3 || m). - result = WriteEcPoint(ctx->epid2_params->G1, B, &B_str, sizeof(B_str)); - BREAK_ON_EPID_ERROR(result); - result = WriteEcPoint(ctx->epid2_params->G1, K, &K_str, sizeof(K_str)); - BREAK_ON_EPID_ERROR(result); - result = SetCalculatedCommitValues(&B_str, &K_str, &curr_presig.T, R1, - ctx->epid2_params->G1, R2, - ctx->epid2_params->GT, &commit_values); - BREAK_ON_EPID_ERROR(result); - result = CalculateCommitmentHash(&commit_values, ctx->epid2_params->Fp, - ctx->hash_alg, msg, msg_len, c_hash); - BREAK_ON_EPID_ERROR(result); - // 7. The member computes sx = (rx + c * x) mod p. - result = FfMul(ctx->epid2_params->Fp, c_hash, ctx->priv_key->x, sx); - BREAK_ON_EPID_ERROR(result); - result = FfAdd(ctx->epid2_params->Fp, rx, sx, sx); - // 8. The member computes sf = (rf + c * f) mod p. - result = FfMul(ctx->epid2_params->Fp, c_hash, ctx->priv_key->f, sf); - BREAK_ON_EPID_ERROR(result); - result = FfAdd(ctx->epid2_params->Fp, rf, sf, sf); - BREAK_ON_EPID_ERROR(result); - // 9. The member computes sa = (ra + c * a) mod p. - result = FfMul(ctx->epid2_params->Fp, c_hash, a, sa); - BREAK_ON_EPID_ERROR(result); - result = FfAdd(ctx->epid2_params->Fp, ra, sa, sa); - BREAK_ON_EPID_ERROR(result); - // 10. The member computes sb = (rb + c * b) mod p. - result = FfMul(ctx->epid2_params->Fp, c_hash, b, sb); - BREAK_ON_EPID_ERROR(result); - result = FfAdd(ctx->epid2_params->Fp, rb, sb, sb); - BREAK_ON_EPID_ERROR(result); - // 11. The member sets sigma0 = (B, K, T, c, sx, sf, sa, sb). - result = WriteEcPoint(ctx->epid2_params->G1, B, &sig->B, sizeof(sig->B)); - BREAK_ON_EPID_ERROR(result); - result = WriteEcPoint(ctx->epid2_params->G1, K, &sig->K, sizeof(sig->K)); - BREAK_ON_EPID_ERROR(result); - result = WriteEcPoint(ctx->epid2_params->G1, T, &sig->T, sizeof(sig->T)); - BREAK_ON_EPID_ERROR(result); - result = - WriteFfElement(ctx->epid2_params->Fp, c_hash, &sig->c, sizeof(sig->c)); - BREAK_ON_EPID_ERROR(result); - result = - WriteFfElement(ctx->epid2_params->Fp, sx, &sig->sx, sizeof(sig->sx)); - BREAK_ON_EPID_ERROR(result); - result = - WriteFfElement(ctx->epid2_params->Fp, sf, &sig->sf, sizeof(sig->sf)); - BREAK_ON_EPID_ERROR(result); - result = - WriteFfElement(ctx->epid2_params->Fp, sa, &sig->sa, sizeof(sig->sa)); - BREAK_ON_EPID_ERROR(result); - result = - WriteFfElement(ctx->epid2_params->Fp, sb, &sig->sb, sizeof(sig->sb)); - BREAK_ON_EPID_ERROR(result); - result = kEpidNoErr; - } while (0); - // remove all data - DeleteEcPoint(&B); - DeleteEcPoint(&K); - DeleteEcPoint(&R1); - - DeleteEcPoint(&T); - DeleteFfElement(&R2); - DeleteFfElement(&sx); - DeleteFfElement(&sf); - DeleteFfElement(&sa); - DeleteFfElement(&sb); - DeleteFfElement(&c_hash); - DeleteFfElement(&a); - DeleteFfElement(&b); - DeleteFfElement(&rx); - DeleteFfElement(&rf); - DeleteFfElement(&ra); - DeleteFfElement(&rb); - - return result; -} diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/compute_presig-test.cc b/external/epid-sdk-3.0.0/epid/member/unittests/compute_presig-test.cc deleted file mode 100644 index 87b524bf..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/compute_presig-test.cc +++ /dev/null @@ -1,93 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief ComputePreSig unit tests. - */ - -#include "gtest/gtest.h" - -extern "C" { -#include "epid/member/api.h" -#include "epid/member/src/context.h" -} - -#include "epid/member/unittests/member-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" -#include "epid/common-testhelper/epid_params-testhelper.h" - -namespace { - -TEST_F(EpidMemberTest, ComputePreSigFailsGivenNullPointer) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig; - EXPECT_EQ(kEpidBadArgErr, EpidComputePreSig(nullptr, &presig)); - EXPECT_EQ(kEpidBadArgErr, EpidComputePreSig(member, nullptr)); -} - -TEST_F(EpidMemberTest, - ComputePreSigGeneratedPreComputedSignatureCanBeDeserialized) { - const BigNumStr p_str = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; - - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig; - EXPECT_EQ(kEpidNoErr, EpidComputePreSig(member, &presig)); - - Epid20Params params; - FiniteFieldObj Fp(p_str); - FfElementObj Fp_element(&Fp); - - FfElementObj GT_element(¶ms.GT); - EcPointObj G1_pt(¶ms.G1); - - EXPECT_EQ(kEpidNoErr, - ReadEcPoint(params.G1, &presig.B, sizeof(presig.B), G1_pt)); - EXPECT_EQ(kEpidNoErr, - ReadEcPoint(params.G1, &presig.K, sizeof(presig.K), G1_pt)); - EXPECT_EQ(kEpidNoErr, - ReadEcPoint(params.G1, &presig.T, sizeof(presig.T), G1_pt)); - EXPECT_EQ(kEpidNoErr, - ReadEcPoint(params.G1, &presig.R1, sizeof(presig.R1), G1_pt)); - EXPECT_EQ(kEpidNoErr, ReadFfElement(params.GT, &presig.R2, sizeof(presig.R2), - GT_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.a, sizeof(presig.a), Fp_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.b, sizeof(presig.b), Fp_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.rx, sizeof(presig.rx), Fp_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.rf, sizeof(presig.rf), Fp_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.ra, sizeof(presig.ra), Fp_element)); - EXPECT_EQ(kEpidNoErr, - ReadFfElement(Fp, &presig.rb, sizeof(presig.rb), Fp_element)); -} - -} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/context-test.cc b/external/epid-sdk-3.0.0/epid/member/unittests/context-test.cc deleted file mode 100644 index de4d27f4..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/context-test.cc +++ /dev/null @@ -1,264 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Member unit tests. - */ -#include -#include -#include "gtest/gtest.h" - -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/member/unittests/member-testhelper.h" - -extern "C" { -#include "epid/member/api.h" -#include "epid/member/src/context.h" -} -bool operator==(MemberPrecomp const& lhs, MemberPrecomp const& rhs) { - return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); -} -namespace { -////////////////////////////////////////////////////////////////////////// -// EpidMemberDelete Tests -TEST_F(EpidMemberTest, DeleteWorksGivenNullMemberCtx) { - EpidMemberDelete(nullptr); - MemberCtx* member_ctx = nullptr; - EpidMemberDelete(&member_ctx); -} -TEST_F(EpidMemberTest, DeleteNullsMemberCtx) { - MemberCtx* ctx = nullptr; - Prng my_prng; - EpidMemberCreate(nullptr, &this->kMemberPrivateKey, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &ctx); - EpidMemberDelete(&ctx); - EXPECT_EQ(nullptr, ctx); -} -////////////////////////////////////////////////////////////////////////// -// EpidMemberCreate Tests -// test that create fails if any mandatory parameters are NULL -TEST_F(EpidMemberTest, CreateFailsGivenNullParameters) { - MemberCtx* member_ctx = nullptr; - Prng my_prng; - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(nullptr, &this->kMemberPrivateKey, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&this->kGroupPublicKey, nullptr, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&this->kGroupPublicKey, &this->kMemberPrivateKey, - &this->kMemberPrecomp, nullptr, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - - EXPECT_EQ(kEpidBadArgErr, - EpidMemberCreate(&this->kGroupPublicKey, &this->kMemberPrivateKey, - &this->kMemberPrecomp, &Prng::Generate, &my_prng, - nullptr)); - EpidMemberDelete(nullptr); -} - -// test that create succeeds with valid parameters -TEST_F(EpidMemberTest, CreateSucceedsGivenValidParameters) { - MemberCtx* member_ctx = nullptr; - Prng my_prng; - - // pass the whole list of parameters - EXPECT_EQ(kEpidNoErr, - EpidMemberCreate(&this->kGroupPublicKey, &this->kMemberPrivateKey, - &this->kMemberPrecomp, &Prng::Generate, &my_prng, - &member_ctx)); - EpidMemberDelete(&member_ctx); - - // pass the whole list of parameters but member_precomp - EXPECT_EQ(kEpidNoErr, - EpidMemberCreate(&this->kGroupPublicKey, &this->kMemberPrivateKey, - nullptr, &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); -} -// test that create succeeds with valid IKGF given parameters -TEST_F(EpidMemberTest, CreateSucceedsGivenValidParametersUsingIKGFData) { - const GroupPubKey grp_public_key = { -#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" - }; - const PrivKey mbr_private_key = { -#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" - }; - - const MemberPrecomp mbr_precomp = { -#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc" - }; - - MemberCtx* member_ctx = nullptr; - Prng my_prng; - - // pass the whole list of parameters - EXPECT_EQ(kEpidNoErr, - EpidMemberCreate(&grp_public_key, &mbr_private_key, &mbr_precomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - - // pass the whole list of parameters but member_precomp - EXPECT_EQ(kEpidNoErr, - EpidMemberCreate(&grp_public_key, &mbr_private_key, nullptr, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); -} - -TEST_F(EpidMemberTest, CreateFailsForInvalidGroupPubKey) { - MemberCtx* member_ctx = nullptr; - Prng my_prng; - GroupPubKey gpk_h1 = this->kGroupPublicKey; - gpk_h1.h1.x.data.data[0]++; - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&gpk_h1, &this->kMemberPrivateKey, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - GroupPubKey gpk_h2 = this->kGroupPublicKey; - gpk_h2.h2.x.data.data[0]++; - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&gpk_h2, &this->kMemberPrivateKey, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); - GroupPubKey gpk_w = this->kGroupPublicKey; - gpk_w.w.x[0].data.data[0]++; - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&gpk_w, &this->kMemberPrivateKey, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); -} -TEST_F(EpidMemberTest, CreateFailsForInvalidPrivateKey) { - MemberCtx* member_ctx = nullptr; - Prng my_prng; - PrivKey pk_A = this->kMemberPrivateKey; - pk_A.A.x.data.data[0]++; - EXPECT_EQ( - kEpidBadArgErr, - EpidMemberCreate(&this->kGroupPublicKey, &pk_A, &this->kMemberPrecomp, - &Prng::Generate, &my_prng, &member_ctx)); - EpidMemberDelete(&member_ctx); -} - -////////////////////////////////////////////////////////////////////////// -// EpidMemberSetHashAlg -TEST_F(EpidMemberTest, SetHashAlgFailsGivenNullPtr) { - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(nullptr, kSha256)); -} -TEST_F(EpidMemberTest, SetHashAlgCanSetValidAlgorithm) { - Prng my_prng; - MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, - &Prng::Generate, &my_prng); - EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha256)); - EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha384)); - EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha512)); -} -TEST_F(EpidMemberTest, SetHashAlgFailsForNonSupportedAlgorithm) { - Prng my_prng; - MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, - &Prng::Generate, &my_prng); - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha512_256)); - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_256)); - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_384)); - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_512)); - EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, (HashAlg)-1)); -} -////////////////////////////////////////////////////////////////////////// -// EpidRegisterBaseName -TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenNullPtr) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - std::vector basename = {'_', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; - EXPECT_EQ(kEpidBadArgErr, - EpidRegisterBaseName(member, nullptr, basename.size())); - EXPECT_EQ(kEpidBadArgErr, - EpidRegisterBaseName(nullptr, basename.data(), basename.size())); -} -TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenDuplicateBaseName) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - std::vector basename = {'d', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; - EXPECT_EQ(kEpidNoErr, - EpidRegisterBaseName(member, basename.data(), basename.size())); - EXPECT_EQ(kEpidDuplicateErr, - EpidRegisterBaseName(member, basename.data(), basename.size())); -} -TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenInvalidBaseName) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - std::vector basename = {}; - std::vector basename2 = {'b', 's', 'n'}; - EXPECT_EQ(kEpidBadArgErr, - EpidRegisterBaseName(member, basename.data(), basename.size())); - EXPECT_EQ(kEpidBadArgErr, EpidRegisterBaseName(member, basename2.data(), 0)); -} -TEST_F(EpidMemberTest, RegisterBaseNameSucceedsGivenUniqueBaseName) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - std::vector basename = {'b', 's', 'n', '0', '1'}; - EXPECT_EQ(kEpidNoErr, - EpidRegisterBaseName(member, basename.data(), basename.size())); -} -////////////////////////////////////////////////////////////////////////// -// EpidMemberWritePrecomp -TEST_F(EpidMemberTest, MemberWritePrecompFailsGivenNullPointer) { - MemberPrecomp precomp; - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - MemberCtx* ctx = member; - EXPECT_EQ(kEpidBadArgErr, EpidMemberWritePrecomp(nullptr, &precomp)); - EXPECT_EQ(kEpidBadArgErr, EpidMemberWritePrecomp(ctx, nullptr)); -} -TEST_F(EpidMemberTest, MemberWritePrecompSucceedGivenValidArgument) { - MemberPrecomp precomp; - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - MemberCtx* ctx = member; - EXPECT_EQ(kEpidNoErr, EpidMemberWritePrecomp(ctx, &precomp)); - MemberPrecomp expected_precomp = this->kMemberPrecomp; - EXPECT_EQ(expected_precomp, precomp); - - MemberCtxObj member2(this->kGroupPublicKey, this->kMemberPrivateKey, - &Prng::Generate, &my_prng); - MemberCtx* ctx2 = member2; - EXPECT_EQ(kEpidNoErr, EpidMemberWritePrecomp(ctx2, &precomp)); - EXPECT_EQ(expected_precomp, precomp); -} -TEST_F(EpidMemberTest, DefaultHashAlgIsSha512) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - MemberCtx* ctx = member; - EXPECT_EQ(kSha512, ctx->hash_alg); -} - -} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.cc b/external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.cc deleted file mode 100644 index c06b9cb6..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.cc +++ /dev/null @@ -1,522 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Member C++ wrapper implementation. - */ - -#include "epid/member/unittests/member-testhelper.h" - -#include -#include - -MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, - BitSupplier rnd_func, void* rnd_param) - : ctx_(nullptr) { - auto sts = EpidMemberCreate(&pub_key, &priv_key, nullptr, rnd_func, rnd_param, - &ctx_); - if (kEpidNoErr != sts) { - printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); - throw std::logic_error(std::string("Failed to call: ") + - "EpidMemberCreate()"); - } -} - -MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, - MemberPrecomp const& precomp, BitSupplier rnd_func, - void* rnd_param) - : ctx_(nullptr) { - auto sts = EpidMemberCreate(&pub_key, &priv_key, &precomp, rnd_func, - rnd_param, &ctx_); - if (kEpidNoErr != sts) { - printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); - throw std::logic_error(std::string("Failed to call: ") + - "EpidMemberCreate()"); - } -} - -MemberCtxObj::~MemberCtxObj() { EpidMemberDelete(&ctx_); } - -MemberCtx* MemberCtxObj::ctx() const { return ctx_; } - -MemberCtxObj::operator MemberCtx*() const { return ctx_; } - -MemberCtxObj::operator const MemberCtx*() const { return ctx_; } - -/// Arbitrary test data were generated based on Intel(R) EPID 2.0 parameters -const GroupPubKey EpidMemberTest::kGroupPublicKey = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01}, // group id - {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, 0x61, - 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, 0xe3, 0xce, - 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, - {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, 0x9d, - 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, 0x7e, 0x7f, - 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 - {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, 0x1c, - 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, 0xa7, 0x04, - 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, - {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, 0xa6, - 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, 0xea, 0xcb, - 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 - {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, 0x51, - 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, 0xca, 0xc6, - 0x8d, 0xcd, 0x36, 0x88, 0x7, 0x28, 0xe8, 0x96}}}, - {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, 0x68, - 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, 0x56, 0xf5, - 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, - {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, 0x30, - 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, 0x39, 0x9c, - 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, - {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, 0xdb, - 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, 0xc6, 0xad, - 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w -}; - -const PrivKey EpidMemberTest::kMemberPrivateKey = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01}, // group id - {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, 0x77, - 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, 0x96, 0xec, - 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, - {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, 0xad, - 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, 0x4b, 0xa8, - 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A - {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, 0xd8, - 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, 0xb7, 0x1b, - 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x - {0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, 0x56, - 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, 0x87, 0x9b, - 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7} // f -}; - -const MemberPrecomp EpidMemberTest::kMemberPrecomp = { - {0xd8, 0x14, 0xba, 0x4b, 0x44, 0x03, 0x55, 0x6c, 0xf6, 0x42, 0xe8, 0xf0, - 0x4c, 0xb5, 0xe7, 0xd4, 0xa2, 0xa3, 0x69, 0x47, 0xf5, 0xd4, 0xc8, 0xe9, - 0xc5, 0x5a, 0x39, 0xb5, 0x55, 0xa5, 0xd3, 0xfb, 0xf3, 0x85, 0x5a, 0x0d, - 0xd5, 0xee, 0xde, 0xf4, 0xa8, 0xb1, 0x8b, 0xcf, 0xa9, 0x0d, 0x29, 0xbf, - 0x86, 0x27, 0x9c, 0x1f, 0x96, 0xed, 0xd8, 0x44, 0x01, 0x35, 0x1a, 0xce, - 0xfd, 0x4e, 0x6f, 0xa1, 0x66, 0x0d, 0x59, 0x08, 0x6d, 0xa2, 0xe4, 0x99, - 0x83, 0xdc, 0x39, 0x28, 0xb7, 0x1c, 0x1a, 0x33, 0xad, 0xca, 0x5c, 0x35, - 0x26, 0x1f, 0xab, 0xba, 0x0d, 0x53, 0xaf, 0xe0, 0x72, 0x14, 0xc5, 0xa7, - 0x2e, 0x58, 0x26, 0xc9, 0x8e, 0xfa, 0x6f, 0x62, 0xfc, 0xf0, 0x08, 0x3e, - 0xa3, 0x11, 0x3a, 0xf0, 0xb8, 0x3b, 0x2d, 0x3e, 0xec, 0xd5, 0xbc, 0xf2, - 0x05, 0x68, 0xf4, 0x40, 0xce, 0x2c, 0x8f, 0xdd, 0xa4, 0xe5, 0xe1, 0xb5, - 0xbe, 0xbd, 0x3e, 0xd4, 0xf6, 0x9a, 0xb3, 0x37, 0x24, 0x0d, 0xea, 0x13, - 0xd7, 0x1f, 0xa2, 0x75, 0x68, 0xa1, 0xbe, 0x2c, 0x01, 0x42, 0x2a, 0xae, - 0x6f, 0xae, 0x7a, 0x72, 0x3a, 0x11, 0x03, 0x58, 0x02, 0x0d, 0xf0, 0xb0, - 0xd9, 0x6f, 0xb1, 0xe4, 0xf2, 0x70, 0xb8, 0xff, 0x22, 0x56, 0x7c, 0xb3, - 0x80, 0xfd, 0xdf, 0xe5, 0xab, 0xcc, 0x18, 0x7a, 0xfd, 0x91, 0xd0, 0xb0, - 0x63, 0x40, 0xd4, 0x71, 0xfa, 0x03, 0xf5, 0xf1, 0x26, 0xe1, 0xa5, 0x5a, - 0xd9, 0x6d, 0xf5, 0x5a, 0x7b, 0x2a, 0x3a, 0xfe, 0x94, 0x9e, 0x74, 0x41, - 0x79, 0x49, 0x7e, 0x48, 0x1d, 0x58, 0x5e, 0xf6, 0x98, 0xa3, 0x6e, 0x61, - 0x8e, 0x9f, 0x1f, 0xcd, 0x15, 0x01, 0x16, 0xa5, 0xe0, 0xab, 0xd6, 0xd6, - 0x1f, 0x1c, 0xf5, 0x81, 0x76, 0xc1, 0xec, 0x10, 0xc2, 0xcc, 0x68, 0x59, - 0x4d, 0x47, 0xef, 0x4b, 0x7f, 0xd8, 0x78, 0x9c, 0xfe, 0x9a, 0x86, 0x7e, - 0x0c, 0xfd, 0x3e, 0x0a, 0x7a, 0x72, 0x8b, 0x14, 0x5f, 0xe6, 0x5f, 0x19, - 0xa3, 0x0a, 0x1b, 0x71, 0xdc, 0xd2, 0xae, 0x35, 0xc3, 0x11, 0xa5, 0xd3, - 0xea, 0xe1, 0xa9, 0xe7, 0x70, 0x0c, 0x7a, 0x39, 0x56, 0x3c, 0xe4, 0xe7, - 0xf9, 0xb6, 0xf1, 0x15, 0x40, 0xab, 0xb6, 0xc4, 0xad, 0xbd, 0xf4, 0xcc, - 0x13, 0xb7, 0xa8, 0xb6, 0x92, 0x1e, 0x72, 0x27, 0xa7, 0xff, 0xd9, 0xea, - 0x2f, 0x91, 0x96, 0x22, 0xd2, 0xc4, 0x4d, 0x80, 0xdc, 0x47, 0x66, 0x87, - 0xcc, 0xcf, 0xc5, 0x64, 0xf7, 0xb2, 0x34, 0xed, 0xd5, 0x44, 0x44, 0xcc, - 0x57, 0x41, 0xc7, 0x92, 0xb7, 0x5c, 0x12, 0xf7, 0x81, 0xf2, 0x92, 0x35, - 0x3e, 0x4b, 0xdf, 0xf8, 0xda, 0x68, 0xac, 0x30, 0xe3, 0xdd, 0x9e, 0x22, - 0xaa, 0x6d, 0x77, 0xdd, 0xac, 0xd9, 0x11, 0x6e, 0xfb, 0x1a, 0x88, - 0xb3}, // e12 - { - 0x07, 0x3f, 0x9d, 0x47, 0x82, 0xb8, 0x3d, 0x6a, 0xe0, 0x36, 0xab, 0xa6, - 0xfa, 0xe6, 0xd2, 0x1c, 0xc8, 0xb2, 0xd0, 0x01, 0xd4, 0x96, 0xdc, 0x2e, - 0xf8, 0x19, 0xdc, 0x70, 0x1b, 0xf9, 0x73, 0x0c, 0x2b, 0xc2, 0xe2, 0x1d, - 0x85, 0x53, 0x81, 0x51, 0xfb, 0xca, 0x16, 0x86, 0xd4, 0x4e, 0xfd, 0x1a, - 0x59, 0xe3, 0x97, 0xc4, 0x7f, 0x99, 0xd8, 0x66, 0x08, 0xa1, 0xe4, 0x9f, - 0xbb, 0x3a, 0xce, 0xa5, 0x23, 0x9c, 0x83, 0x13, 0xc5, 0xc8, 0xf2, 0x16, - 0x1e, 0xe8, 0xe6, 0xc5, 0x36, 0x57, 0x2c, 0xdf, 0x73, 0xb4, 0xe2, 0xb2, - 0xcb, 0xeb, 0xbb, 0xf7, 0x45, 0xd1, 0x44, 0xbd, 0x6e, 0x92, 0x95, 0x00, - 0xe5, 0x89, 0xb5, 0x91, 0x78, 0xc7, 0x44, 0xb1, 0x2f, 0x37, 0xdf, 0xfb, - 0xe7, 0x8a, 0x44, 0x3f, 0x3d, 0x06, 0x5f, 0x5b, 0x1c, 0x5f, 0xce, 0x11, - 0x05, 0x35, 0x3c, 0xad, 0x92, 0x7e, 0x79, 0xb8, 0xff, 0x28, 0x05, 0xe4, - 0x04, 0x2c, 0xb6, 0x1d, 0x22, 0xab, 0x36, 0x00, 0x5f, 0x74, 0xf1, 0xe3, - 0xf6, 0xa6, 0x68, 0xe6, 0x7b, 0x25, 0xb8, 0xcf, 0x19, 0xb0, 0x1a, 0xdd, - 0x0f, 0xad, 0x63, 0x73, 0x62, 0x1b, 0xe7, 0x94, 0x5d, 0xbf, 0x3d, 0xf1, - 0xf9, 0x8e, 0xab, 0x59, 0xe5, 0xd1, 0x7c, 0x62, 0xdd, 0xbc, 0x40, 0x07, - 0x70, 0x5b, 0x13, 0xf6, 0x12, 0x09, 0xb4, 0x0d, 0x3e, 0xab, 0x8b, 0x70, - 0x60, 0x1d, 0xd4, 0x61, 0x37, 0x28, 0x98, 0x3e, 0x7e, 0xdc, 0xfd, 0xd2, - 0xc0, 0x2f, 0x4b, 0x71, 0x31, 0x34, 0xd7, 0x69, 0x41, 0x5e, 0xaa, 0x72, - 0xe4, 0xdf, 0xeb, 0xfe, 0x8d, 0xcd, 0x68, 0xfc, 0x68, 0x55, 0xbe, 0x32, - 0x7d, 0x24, 0xc5, 0x07, 0x0f, 0xa8, 0xbd, 0x5a, 0xfe, 0xe7, 0xec, 0xdb, - 0xfd, 0x19, 0xc8, 0xa9, 0x20, 0xa2, 0x7f, 0x6c, 0xa6, 0x62, 0xec, 0xed, - 0x9b, 0x79, 0xbf, 0x9c, 0x0e, 0x31, 0x0b, 0x25, 0x2f, 0xd3, 0xcc, 0xa0, - 0xdd, 0xb2, 0xf2, 0x69, 0x26, 0x85, 0x21, 0x06, 0x94, 0x56, 0x5f, 0x59, - 0x5c, 0xf5, 0xb7, 0x82, 0xce, 0x0f, 0xdd, 0x40, 0xdb, 0x83, 0xac, 0x3c, - 0x41, 0xa0, 0x1b, 0xb1, 0xaf, 0xda, 0x55, 0xbf, 0x6b, 0x1a, 0xef, 0xe6, - 0x90, 0xe7, 0xaa, 0x0f, 0x04, 0x3c, 0x9f, 0x5b, 0xb7, 0xcd, 0x98, 0xa8, - 0x9e, 0xff, 0x54, 0x26, 0xc8, 0xd5, 0x5c, 0x30, 0x5e, 0xa2, 0x99, 0x8e, - 0x34, 0xd5, 0x98, 0x9f, 0xcd, 0x57, 0xd1, 0x4d, 0x1d, 0xee, 0x01, 0x5d, - 0x5a, 0x6d, 0xb2, 0xf1, 0xcf, 0x4b, 0xc0, 0x21, 0x23, 0x96, 0x05, 0xf9, - 0xc9, 0x66, 0xe5, 0x25, 0x9d, 0xa3, 0x8e, 0x78, 0x43, 0x19, 0xc1, 0x7f, - 0x7b, 0xef, 0xf5, 0xed, 0x00, 0xb7, 0x45, 0x1f, 0x4e, 0xa9, 0xfa, 0xe3, - 0xff, 0x54, 0xf2, 0x21, 0x73, 0xf8, 0x6b, 0xa1, 0xc7, 0x31, 0x4d, 0x6a, - }, // e22 - { - 0x49, 0x0d, 0x0f, 0x2a, 0x5c, 0x6a, 0x3b, 0xad, 0x71, 0xc9, 0x22, 0x49, - 0xe8, 0x08, 0xdd, 0xba, 0x79, 0x57, 0xb7, 0xc7, 0x61, 0xe4, 0xdb, 0x84, - 0x68, 0x57, 0xb9, 0x30, 0x83, 0xa4, 0xdc, 0xef, 0x70, 0x93, 0x28, 0xe2, - 0x6f, 0xb9, 0xbc, 0x15, 0x28, 0x3a, 0x30, 0xbd, 0x96, 0x83, 0xdb, 0xf2, - 0x9d, 0x1e, 0xc7, 0x64, 0x6d, 0x2e, 0x7c, 0xa2, 0xf3, 0xaa, 0x2f, 0x4b, - 0x6d, 0x86, 0x9e, 0x48, 0x20, 0x29, 0x4b, 0x1f, 0x8d, 0xc2, 0x93, 0xc3, - 0x55, 0x25, 0x8e, 0xb0, 0x8a, 0x7e, 0x64, 0x45, 0x3f, 0xf4, 0x1d, 0x16, - 0x4c, 0x88, 0x2d, 0x54, 0xbe, 0xa8, 0x67, 0x70, 0x81, 0xc5, 0xb9, 0x5c, - 0x16, 0x00, 0xef, 0x78, 0xf6, 0x4d, 0x6a, 0xeb, 0xfd, 0xa2, 0x0d, 0x52, - 0x86, 0xf3, 0x04, 0x4b, 0xd8, 0xf0, 0x7d, 0x50, 0x8b, 0xad, 0xc0, 0x37, - 0xdb, 0x38, 0xf2, 0x7d, 0x1f, 0x8b, 0x13, 0x83, 0x7b, 0xcc, 0xe8, 0x25, - 0xfe, 0xfa, 0x0c, 0x02, 0x05, 0x2e, 0x75, 0x12, 0xa1, 0x0a, 0x89, 0xab, - 0xf1, 0xb2, 0x08, 0x47, 0x9a, 0xea, 0xef, 0x1d, 0xa4, 0x9f, 0xde, 0x89, - 0x47, 0x3e, 0x7c, 0x5e, 0x4a, 0x40, 0xdc, 0xec, 0xc5, 0x1b, 0x7e, 0x33, - 0x0a, 0x19, 0x69, 0x27, 0xa6, 0xcc, 0x25, 0xfc, 0xf9, 0xeb, 0xbd, 0xb7, - 0x8a, 0xdb, 0x45, 0x5f, 0x9d, 0x9e, 0x01, 0xde, 0x3d, 0x91, 0x10, 0x99, - 0x13, 0xbf, 0xc0, 0xfa, 0x9d, 0xd4, 0x0f, 0xb3, 0x09, 0xf3, 0xa1, 0xae, - 0x68, 0xe1, 0x1b, 0x48, 0x85, 0x9f, 0x81, 0x66, 0x91, 0xe2, 0xf0, 0x7b, - 0x29, 0xdb, 0x8f, 0x5d, 0x99, 0xa9, 0xd3, 0x39, 0x30, 0xd9, 0x1b, 0x94, - 0x2a, 0x1c, 0x5c, 0xe9, 0xc0, 0x3f, 0x6e, 0xb2, 0x27, 0xbe, 0x74, 0x7a, - 0xca, 0xe1, 0x0f, 0x6a, 0x43, 0x2e, 0x98, 0x65, 0xaf, 0x7f, 0x6e, 0x5a, - 0x55, 0x98, 0xc1, 0x58, 0x29, 0xb3, 0x86, 0x54, 0x0f, 0x57, 0x91, 0x89, - 0x29, 0xb1, 0x98, 0x79, 0xcc, 0x95, 0x39, 0xd0, 0xab, 0xe0, 0x9f, 0xf3, - 0xda, 0xf9, 0x5e, 0xd9, 0x34, 0xbb, 0x72, 0xda, 0xe5, 0x72, 0xd3, 0xf8, - 0x9b, 0xf9, 0x14, 0x84, 0x48, 0x81, 0x54, 0x4f, 0xe6, 0x2b, 0x80, 0xc8, - 0xc1, 0x79, 0xfe, 0x83, 0xff, 0x76, 0xa3, 0x6d, 0xfe, 0x37, 0x78, 0xc5, - 0x30, 0x7a, 0x50, 0xe2, 0x5d, 0x12, 0xdc, 0x72, 0xe9, 0x58, 0x7c, 0x07, - 0x4f, 0xff, 0x15, 0x8a, 0x97, 0x3b, 0xcb, 0x60, 0xfa, 0x4e, 0xde, 0x8c, - 0x80, 0x3a, 0x8b, 0x0b, 0xc6, 0x1d, 0xa3, 0xce, 0x6a, 0xb3, 0x50, 0x69, - 0x03, 0x96, 0xca, 0xc0, 0xb6, 0x94, 0x6f, 0x8f, 0xab, 0x6f, 0x5b, 0x00, - 0x2a, 0x1d, 0x90, 0xa7, 0x81, 0xc6, 0x15, 0x77, 0x79, 0xf3, 0x36, 0x23, - 0xd1, 0x46, 0x25, 0x58, 0x6f, 0x7b, 0x22, 0xac, 0x4c, 0x7a, 0xf3, 0x9f, - }, // e2w - { - 0x8d, 0x71, 0xe2, 0xb0, 0x73, 0x2f, 0x4a, 0xba, 0x64, 0xe8, 0x7a, 0x12, - 0xaf, 0xe4, 0x4f, 0xdb, 0x6b, 0x3e, 0x38, 0x07, 0x0c, 0x79, 0x22, 0x48, - 0x1b, 0x9d, 0x33, 0x53, 0x5c, 0x75, 0x3b, 0x40, 0x5e, 0x18, 0xd1, 0x92, - 0x4a, 0xd1, 0x82, 0x1c, 0xc7, 0x3a, 0xf7, 0x7e, 0x32, 0x19, 0x99, 0x5d, - 0x01, 0x0e, 0xb0, 0xf2, 0x8f, 0x80, 0xc6, 0xb9, 0xeb, 0x1f, 0x9e, 0xae, - 0x9e, 0xe0, 0x99, 0xfd, 0xe8, 0x93, 0x11, 0x61, 0x7d, 0xc2, 0x49, 0xdb, - 0xa8, 0x73, 0xa4, 0xa9, 0x33, 0xe2, 0x04, 0xd1, 0x7d, 0x8b, 0xe1, 0xd6, - 0x2b, 0x10, 0x6c, 0x79, 0x02, 0xbf, 0xfc, 0x53, 0x03, 0xa9, 0xbc, 0x30, - 0x4d, 0x4d, 0xf4, 0x32, 0xce, 0x9a, 0x4a, 0xfa, 0xd6, 0x7f, 0x26, 0x17, - 0xc5, 0xf6, 0xed, 0xe4, 0xcc, 0xb9, 0x79, 0xe2, 0xa8, 0x86, 0xbb, 0xd7, - 0xfb, 0x05, 0xd2, 0x81, 0xbe, 0x07, 0x1c, 0x47, 0x48, 0x4f, 0x6d, 0x6b, - 0x52, 0x42, 0xe4, 0xc6, 0x20, 0x46, 0xa3, 0xae, 0x5b, 0x55, 0x55, 0xfe, - 0x4a, 0xad, 0xf2, 0x32, 0x07, 0x0f, 0x91, 0xa9, 0xe5, 0xd3, 0x86, 0x08, - 0x73, 0x93, 0xc7, 0x1e, 0x6b, 0xcd, 0x69, 0xd0, 0xfb, 0xc1, 0x74, 0xc2, - 0xb8, 0x90, 0xc8, 0xf8, 0x93, 0xbf, 0x08, 0x0f, 0x15, 0x19, 0x26, 0x71, - 0x4a, 0x9e, 0xdf, 0xdf, 0xca, 0x6f, 0xca, 0xfd, 0x67, 0xec, 0x4d, 0x21, - 0x5b, 0x99, 0xbd, 0x4b, 0x79, 0x22, 0x2d, 0xe4, 0x24, 0x72, 0x88, 0x93, - 0xce, 0xe6, 0x7f, 0xef, 0x35, 0x83, 0x67, 0x39, 0xb9, 0x34, 0x80, 0x64, - 0x0a, 0xf4, 0xff, 0x42, 0x9d, 0xee, 0xda, 0xb8, 0xd3, 0xdc, 0x1d, 0x0d, - 0x9f, 0x45, 0xe9, 0xbe, 0xf4, 0x3e, 0xa6, 0x58, 0x8b, 0xf0, 0xfd, 0x01, - 0x73, 0x63, 0xd0, 0xc6, 0x9d, 0xb9, 0x32, 0xd1, 0x91, 0xfe, 0xb1, 0xf5, - 0x4b, 0x48, 0xb4, 0x46, 0xae, 0x61, 0xd7, 0x90, 0xfe, 0x86, 0x74, 0x68, - 0xee, 0x78, 0x86, 0x65, 0x99, 0x6d, 0x7b, 0xf0, 0x17, 0x1a, 0x4c, 0xb0, - 0x37, 0x73, 0xdc, 0x38, 0x41, 0xfa, 0x02, 0xd2, 0x13, 0x8f, 0x71, 0xb4, - 0x0a, 0x72, 0x70, 0x0f, 0xe1, 0x2c, 0x9a, 0xa9, 0x51, 0xfa, 0xb2, 0xbf, - 0x84, 0xf2, 0xa6, 0xfb, 0xc3, 0x83, 0x16, 0x7e, 0x27, 0xec, 0x06, 0x5d, - 0x64, 0x79, 0xe7, 0x42, 0x30, 0xf8, 0x2d, 0xbc, 0x0f, 0x07, 0x8b, 0xf2, - 0x99, 0xda, 0x91, 0x4c, 0x65, 0xcf, 0x7f, 0x57, 0x2d, 0x2f, 0x67, 0xe7, - 0xfb, 0x75, 0xe9, 0xb2, 0xa3, 0x72, 0x60, 0x88, 0x2b, 0x14, 0x31, 0x62, - 0xbc, 0x45, 0x59, 0x5c, 0x58, 0x39, 0xb3, 0x4a, 0xeb, 0xb9, 0x18, 0x24, - 0x05, 0xcb, 0xda, 0xd3, 0x5e, 0x54, 0xba, 0xda, 0xfd, 0xfc, 0xa0, 0x02, - 0xb3, 0xde, 0x52, 0x3e, 0xc0, 0xd0, 0xb8, 0x19, 0x85, 0x1b, 0x7b, 0xe3, - } // ea2 -}; -const PreComputedSignature EpidMemberTest::kPrecomputedSignatures[2] = { - { - {{{{0x5c, 0x1b, 0x75, 0x1c, 0xc7, 0x2c, 0xf7, 0x4a, 0x97, 0x43, 0xf2, - 0x1a, 0x70, 0x80, 0x90, 0x61, 0xf5, 0x9e, 0x9b, 0x43, 0x92, 0x2f, - 0x05, 0x28, 0xcc, 0x4c, 0xb4, 0xb2, 0x80, 0x15, 0x58, 0x14}}}, - {{{ - 0x3f, 0x7f, 0xd0, 0x95, 0x08, 0x98, 0x0b, 0xae, 0x88, 0xf8, 0x2c, - 0x18, 0x8b, 0x72, 0x50, 0x95, 0x78, 0x41, 0xae, 0x4e, 0x6e, 0xea, - 0x3d, 0xa6, 0x23, 0x91, 0x4a, 0x02, 0x5d, 0x3f, 0x97, 0xd9, - }}}}, // B - {{{{0xb0, 0xdb, 0x88, 0x23, 0x18, 0x95, 0xba, 0x60, 0x72, 0x43, 0xb4, - 0x57, 0xbd, 0x20, 0xd2, 0x28, 0x97, 0xf7, 0x3a, 0x50, 0x06, 0xc5, - 0x89, 0xc9, 0x9f, 0x7a, 0x2a, 0x80, 0x91, 0xee, 0x7a, 0xf8}}}, - {{{0x70, 0xf3, 0x95, 0x12, 0xe4, 0x95, 0xca, 0x19, 0x43, 0x1a, 0x5d, - 0x47, 0x33, 0x71, 0x69, 0xfb, 0x14, 0x5f, 0xbd, 0x3f, 0xb2, 0x72, - 0x22, 0x3f, 0x63, 0xc3, 0xe9, 0x7c, 0x18, 0x82, 0x88, - 0x03}}}}, // K - {{{{0x75, 0x39, 0x21, 0x47, 0x04, 0xfd, 0xb7, 0x71, 0xb2, 0xf5, 0xa9, - 0x83, 0x7f, 0x27, 0x1d, 0x8f, 0xff, 0x07, 0x3c, 0xfb, 0xe9, 0x0d, - 0x14, 0x9c, 0xa6, 0xee, 0x06, 0x1e, 0x3d, 0xd3, 0xfb, 0x92}}}, - {{{0x51, 0x64, 0x11, 0x6d, 0x22, 0xc7, 0xed, 0x67, 0x21, 0xfe, 0x76, - 0x27, 0xf9, 0x43, 0x43, 0x64, 0x11, 0x01, 0x63, 0xc8, 0xda, 0x42, - 0x4e, 0x02, 0xe7, 0xf2, 0xb8, 0xa4, 0x16, 0x5b, 0x39, - 0xc2}}}}, // T - {{{{0x60, 0x25, 0xeb, 0xe8, 0x51, 0xd5, 0xe0, 0xf3, 0xcc, 0xb2, 0xc2, - 0xe3, 0xd7, 0x5c, 0x84, 0x41, 0x57, 0x2b, 0x5b, 0x00, 0xac, 0x1d, - 0x14, 0x89, 0xba, 0xb3, 0x34, 0xf0, 0x8a, 0xd4, 0x72, 0x5e}}}, - {{{0x93, 0xb7, 0xed, 0x03, 0xdd, 0xc7, 0xc9, 0xfa, 0x2c, 0x32, 0x84, - 0x40, 0xd4, 0xa2, 0x74, 0x76, 0x02, 0xef, 0x0c, 0xc6, 0xe4, 0xc2, - 0x9f, 0xd7, 0x18, 0x96, 0xdc, 0x97, 0x22, 0x4e, 0xbf, - 0xfc}}}}, // R1 - { - 0xe4, 0x5f, 0x6c, 0x74, 0x0b, 0xb7, 0x26, 0x59, 0x62, 0x5e, 0x69, - 0x71, 0x01, 0xa8, 0x32, 0xc1, 0xa7, 0xae, 0x32, 0x9e, 0xc2, 0xaf, - 0x9a, 0x55, 0x6c, 0x71, 0x37, 0x80, 0xc7, 0xe1, 0x8b, 0x1c, 0xa1, - 0x0c, 0xce, 0x60, 0x10, 0x18, 0x14, 0xe9, 0x66, 0x84, 0xe0, 0x52, - 0x9d, 0xee, 0x42, 0x0f, 0x47, 0xba, 0xcc, 0xc1, 0xea, 0xeb, 0x93, - 0x18, 0x04, 0x39, 0x7e, 0x36, 0x59, 0x73, 0xd3, 0xf8, 0xa4, 0x67, - 0x64, 0x6a, 0x24, 0x00, 0xd3, 0x4b, 0x0b, 0x17, 0x7f, 0xc6, 0xca, - 0x1a, 0xe3, 0x29, 0x4a, 0x4d, 0x23, 0x7d, 0x02, 0xa4, 0xd3, 0x26, - 0xed, 0xe6, 0x4d, 0xb7, 0xc6, 0x2d, 0x70, 0x85, 0xf0, 0xa4, 0x54, - 0x7f, 0xe9, 0x6e, 0x17, 0xb3, 0x36, 0xa4, 0x30, 0xfc, 0xca, 0x80, - 0x8c, 0x8b, 0x17, 0x6f, 0xe8, 0x22, 0x76, 0x27, 0xd7, 0x42, 0xd5, - 0x14, 0x27, 0x9a, 0x8d, 0x0c, 0x9c, 0x43, 0x7e, 0x41, 0x7a, 0x73, - 0xd9, 0xee, 0xef, 0xc7, 0x42, 0x77, 0xbe, 0x27, 0xa3, 0x8f, 0xa1, - 0x77, 0xaf, 0xdc, 0xa2, 0xfc, 0xf1, 0x3d, 0xd6, 0x00, 0xf3, 0x9c, - 0x43, 0xe9, 0xff, 0xc7, 0x9f, 0x5f, 0x6c, 0xa9, 0x16, 0x47, 0x73, - 0xbb, 0x31, 0x45, 0xb1, 0xcf, 0x7f, 0x39, 0xdd, 0x27, 0x78, 0x03, - 0x45, 0x24, 0x67, 0x08, 0x04, 0xf1, 0xbf, 0xfa, 0x7f, 0xe2, 0x2f, - 0x1f, 0x2c, 0x68, 0xfe, 0x4e, 0x0a, 0xcf, 0xd7, 0xf5, 0x0b, 0xd2, - 0xe2, 0x55, 0x54, 0x15, 0xa6, 0x3d, 0x0c, 0xc3, 0x49, 0xcd, 0x86, - 0xa7, 0x51, 0x12, 0x08, 0x4c, 0xf6, 0x05, 0xbc, 0xdc, 0xb1, 0x22, - 0xe4, 0x92, 0x33, 0x92, 0x8f, 0x6b, 0xee, 0x74, 0x96, 0xaf, 0x7c, - 0x47, 0x65, 0xb6, 0x4d, 0xd8, 0xd4, 0x21, 0xa8, 0xfa, 0xf9, 0x03, - 0xc7, 0xf4, 0x82, 0xde, 0x0a, 0xd9, 0x4c, 0x92, 0xfc, 0x48, 0x65, - 0x1a, 0x4c, 0xb9, 0xf9, 0x91, 0x9e, 0xf4, 0x88, 0x9e, 0x83, 0xa9, - 0x3a, 0x2e, 0x50, 0x94, 0xde, 0xb0, 0x24, 0xf3, 0x9b, 0xa0, 0x9e, - 0x0c, 0x49, 0xb2, 0xe2, 0x53, 0xfc, 0x52, 0x9b, 0x4b, 0x3b, 0x53, - 0xdf, 0xfe, 0x76, 0x99, 0x19, 0x90, 0xb8, 0xf2, 0x8c, 0xda, 0x57, - 0xfc, 0x35, 0xf6, 0xeb, 0xb4, 0x3c, 0xde, 0xff, 0x75, 0xf2, 0x50, - 0x27, 0x20, 0x42, 0x33, 0xd8, 0x6c, 0x5f, 0xba, 0x3d, 0xed, 0x90, - 0x77, 0xbc, 0x97, 0x10, 0xe0, 0x37, 0x21, 0x9e, 0x37, 0xf4, 0x89, - 0x34, 0x7c, 0x4a, 0x27, 0x8b, 0x58, 0x99, 0x83, 0x0a, 0xa7, 0x80, - 0x11, 0xc4, 0x88, 0xf2, 0xbb, 0xc0, 0x99, 0x9f, 0x6f, 0x60, 0x12, - 0x2d, 0x52, 0x20, 0x3a, 0xc0, 0x50, 0x75, 0x97, 0xc9, 0xdb, 0x01, - 0x3d, 0x05, 0x21, 0x3a, 0x16, 0x67, 0x0f, 0x7b, 0x51, 0x4a, 0x33, - 0x93, 0x53, 0x78, 0xd0, 0xb4, 0x91, 0xfc, 0x32, 0x49, 0x5e, - }, // R2 - {0x02, 0x5c, 0x15, 0x7e, 0x0f, 0x00, 0x82, 0x32, 0x45, 0xcf, 0x91, 0xd3, - 0x64, 0x5f, 0xf6, 0x0a, 0x83, 0x83, 0xc6, 0x3c, 0x0a, 0x68, 0x2c, 0x1e, - 0x96, 0x4b, 0xfa, 0xde, 0x06, 0xfe, 0x1a, 0x73}, // a - {0xea, 0x9d, 0xe1, 0x57, 0x32, 0x2e, 0x74, 0xd5, 0xbe, 0x49, 0xc4, 0xc8, - 0x23, 0x7d, 0x93, 0x74, 0x05, 0xee, 0xc2, 0x3d, 0xec, 0xd5, 0xbd, 0x4c, - 0x2f, 0x1d, 0x77, 0x88, 0x2b, 0x81, 0x5e, 0xc4}, // b - {0x98, 0x43, 0xdc, 0x08, 0x7b, 0x99, 0xff, 0x4a, 0x38, 0xbd, 0x5f, 0xe9, - 0xfc, 0xb9, 0x40, 0x3c, 0x31, 0x9b, 0x57, 0x7e, 0xff, 0x1c, 0x80, 0x92, - 0x79, 0x97, 0x3d, 0xa9, 0xbb, 0x70, 0xe7, 0x4b}, // rx - {0x85, 0x09, 0xac, 0xad, 0xcb, 0x5f, 0x24, 0x36, 0x21, 0x9e, 0xc7, 0x3a, - 0x2b, 0xf6, 0x63, 0xe7, 0x0d, 0xef, 0x3f, 0x4d, 0x40, 0x94, 0x49, 0x7b, - 0x2c, 0x89, 0xfe, 0xdc, 0xe7, 0x5b, 0xc5, 0x72}, // rf - {0x0d, 0x6b, 0x41, 0x78, 0x87, 0xb7, 0x90, 0x17, 0x5c, 0xe1, 0x9d, 0xcb, - 0x5d, 0x87, 0x69, 0xe6, 0xdd, 0xc0, 0xef, 0xbb, 0x3f, 0x4d, 0xaf, 0xec, - 0x3a, 0x66, 0x66, 0xb3, 0x51, 0x49, 0xb8, 0xae}, // ra - {0xaa, 0x42, 0x63, 0x36, 0x47, 0xe3, 0x9d, 0x5e, 0x7f, 0xcd, 0x07, 0xee, - 0x26, 0xdc, 0xaf, 0x88, 0xf1, 0x9b, 0xae, 0xa4, 0x7c, 0xff, 0x2e, 0x4f, - 0x7b, 0x6d, 0xb1, 0x42, 0x50, 0x9d, 0x89, 0x39} // rb - }, - { - {{{{0x10, 0x11, 0x7a, 0x7a, 0xbd, 0xe9, 0x4f, 0x96, 0xd7, 0x1e, 0x53, - 0x05, 0x8d, 0x69, 0xb1, 0xdb, 0x3e, 0xf1, 0x3c, 0x24, 0xe2, 0x83, - 0x06, 0x4b, 0xd6, 0xd9, 0xc6, 0x24, 0xf4, 0x7f, 0x67, 0x2c}}}, - {{{0x1a, 0xaf, 0x95, 0xfa, 0x7e, 0x59, 0xd2, 0x93, 0x39, 0x09, 0xae, - 0x0b, 0xc3, 0xe8, 0xe5, 0xf7, 0x36, 0xe7, 0x06, 0xbf, 0xe3, 0xd2, - 0x20, 0xbf, 0xd2, 0x31, 0x3f, 0xc1, 0x15, 0x61, 0x61, - 0x03}}}}, // B - {{{{0xcc, 0x9e, 0x80, 0x5e, 0x0c, 0x32, 0x44, 0x70, 0xe0, 0x44, 0x27, - 0x7a, 0x01, 0xee, 0x51, 0x19, 0xa1, 0x4d, 0x0a, 0x24, 0x8b, 0xa2, - 0xf8, 0xa3, 0x26, 0x56, 0x8c, 0x70, 0xe1, 0xa1, 0x83, 0x70}}}, - {{{0x4d, 0xf0, 0x73, 0x6f, 0xf4, 0x62, 0xc4, 0x30, 0x3e, 0xde, 0xff, - 0xc0, 0x93, 0x92, 0xa4, 0x03, 0x6f, 0x84, 0x3a, 0x3c, 0x34, 0x25, - 0x83, 0xb5, 0x2b, 0x90, 0x95, 0x6b, 0x24, 0x82, 0x6e, - 0xe6}}}}, // K - {{{{0xc6, 0x4c, 0xc8, 0x9d, 0xdc, 0x63, 0x46, 0x5b, 0xab, 0x79, 0xea, - 0x49, 0x76, 0x47, 0x68, 0xe6, 0x2e, 0x7d, 0x0b, 0x49, 0xc0, 0x29, - 0xe4, 0xc8, 0x84, 0xb5, 0x04, 0x2d, 0x15, 0xaa, 0x0d, 0xd4}}}, - {{{0x71, 0x43, 0xd0, 0x24, 0x3e, 0x00, 0xf4, 0x94, 0xad, 0x1e, 0x1e, - 0x32, 0xea, 0x21, 0x4d, 0x83, 0xae, 0x63, 0x3c, 0x5a, 0xd4, 0xa5, - 0x79, 0x9b, 0x2c, 0xad, 0x03, 0x50, 0xb6, 0x57, 0x0a, - 0xbf}}}}, // T - {{{{0xdd, 0x13, 0x14, 0x5a, 0x7d, 0x23, 0xc5, 0xf0, 0xcb, 0xa7, 0xd1, - 0x79, 0x7a, 0x59, 0x91, 0xf3, 0x8f, 0xb3, 0xff, 0x27, 0x52, 0x0e, - 0xe4, 0xc8, 0xb2, 0xe1, 0xc5, 0x29, 0x16, 0x2e, 0x0f, 0xcf}}}, - {{{0xcd, 0xb1, 0xed, 0x9a, 0xf3, 0x8a, 0xdd, 0x97, 0xe3, 0x58, 0xd8, - 0x66, 0xc0, 0xb9, 0xe6, 0x5e, 0x86, 0x6b, 0xfc, 0xde, 0x25, 0x2b, - 0x3c, 0x97, 0x4e, 0xc9, 0x26, 0x12, 0xf7, 0xde, 0xa6, - 0x88}}}}, // R1 - {0x75, 0x5e, 0x75, 0xe8, 0x80, 0xa3, 0x3b, 0x5d, 0xb7, 0xf1, 0x93, 0x4e, - 0x55, 0x6a, 0x14, 0x24, 0x8c, 0x74, 0xcd, 0x58, 0x25, 0xf8, 0x26, 0x6f, - 0x21, 0xc1, 0x1f, 0xb1, 0x7a, 0xc5, 0x48, 0x6b, 0x01, 0x4e, 0xa0, 0xa7, - 0xac, 0x55, 0x5b, 0x68, 0xba, 0x69, 0x17, 0xb0, 0x1e, 0x4a, 0x88, 0x70, - 0xbc, 0xb8, 0x12, 0xd7, 0x3d, 0x1b, 0xb4, 0xee, 0x79, 0xdb, 0xa1, 0x31, - 0xfb, 0x09, 0x3e, 0x89, 0xf6, 0x92, 0x0a, 0x81, 0x6a, 0xde, 0xe6, 0xb9, - 0x26, 0x9e, 0x5f, 0x2a, 0x52, 0xa2, 0x2e, 0x44, 0x0c, 0x15, 0xce, 0xbf, - 0x1f, 0xcf, 0x95, 0xe5, 0x17, 0x1c, 0xf3, 0xd2, 0x90, 0x04, 0xa4, 0xfa, - 0x0e, 0x92, 0x8b, 0xa4, 0xcd, 0x2b, 0xdf, 0x78, 0x71, 0x98, 0xd7, 0x9f, - 0xcd, 0xd1, 0x5e, 0x06, 0xdb, 0x6b, 0xdb, 0xff, 0x8d, 0xb4, 0x10, 0x73, - 0xc8, 0xf6, 0xb9, 0x42, 0x54, 0xc4, 0x6a, 0xc3, 0xbb, 0xdc, 0xec, 0x6d, - 0x2f, 0xec, 0xda, 0xb7, 0x74, 0x02, 0x59, 0xb9, 0xe0, 0x4c, 0xc5, 0x41, - 0x8a, 0x00, 0x2b, 0x10, 0x45, 0x9a, 0xc3, 0x77, 0x98, 0x66, 0xcf, 0xcb, - 0x44, 0xe7, 0x9a, 0x56, 0x40, 0xde, 0x74, 0x9b, 0x9f, 0x34, 0x9f, 0xc0, - 0x59, 0x28, 0x27, 0x3f, 0x90, 0xe0, 0xaa, 0xba, 0x0d, 0x13, 0x8a, 0xec, - 0x97, 0x2a, 0xef, 0xe7, 0xc9, 0x8f, 0xfa, 0xef, 0x14, 0x3a, 0xc2, 0x39, - 0xf6, 0x54, 0xab, 0x28, 0x15, 0x9f, 0x8d, 0x91, 0x49, 0x94, 0x27, 0x72, - 0x47, 0x97, 0x2a, 0x88, 0xb4, 0x95, 0xf4, 0xb7, 0xf3, 0x4d, 0xe3, 0xf0, - 0x53, 0x69, 0x58, 0xaf, 0xb7, 0x22, 0x52, 0x05, 0x9c, 0xac, 0x52, 0xbb, - 0x39, 0xc6, 0x6b, 0xfd, 0xfd, 0xdb, 0x1c, 0xf8, 0xa6, 0xce, 0xd6, 0xe6, - 0x4a, 0xd5, 0xb4, 0xcf, 0x68, 0x24, 0x79, 0xf6, 0xb0, 0xb8, 0x62, 0x37, - 0xc6, 0xa9, 0x14, 0x25, 0x07, 0xec, 0xde, 0x3a, 0x18, 0x13, 0xf9, 0x35, - 0x8d, 0xd7, 0x40, 0x34, 0x8c, 0xe9, 0x3f, 0x97, 0xe1, 0x6e, 0xcf, 0x9e, - 0xb0, 0x5d, 0x15, 0x5f, 0xd7, 0xd4, 0x92, 0x26, 0xa4, 0x87, 0x77, 0x47, - 0x95, 0x53, 0x78, 0x4b, 0x77, 0xd4, 0xb4, 0xd4, 0xad, 0xd2, 0xeb, 0xfb, - 0x70, 0x7b, 0xea, 0x6d, 0x88, 0x9b, 0xb6, 0xf9, 0x95, 0xa2, 0xae, 0x77, - 0xd3, 0x29, 0x43, 0xeb, 0x25, 0x09, 0x3c, 0x68, 0xc5, 0xba, 0x6f, 0x6e, - 0x19, 0x6a, 0x41, 0xb5, 0x02, 0x3f, 0x2e, 0xbe, 0x8e, 0xc4, 0x72, 0x47, - 0x65, 0x7d, 0x2a, 0xbb, 0x55, 0xea, 0x01, 0x2c, 0x24, 0x28, 0x1d, 0x90, - 0x63, 0xe5, 0x8e, 0x4f, 0xb7, 0x0e, 0x86, 0x09, 0x18, 0x5f, 0x1d, 0x69, - 0x72, 0x1a, 0xff, 0x25, 0xb2, 0x82, 0x19, 0x66, 0xbc, 0x68, 0x02, 0x07, - 0x02, 0x05, 0x07, 0x80, 0x88, 0xc9, 0x85, 0xf7, 0xa9, 0x32, 0x0a, - 0x48}, // R2 - {0xb2, 0x9f, 0x28, 0x17, 0xa9, 0x3b, 0x93, 0x5d, 0x84, 0xaa, 0xb9, 0xd2, - 0x61, 0x4c, 0xe4, 0x64, 0x79, 0x2b, 0xc2, 0x87, 0xe4, 0x7f, 0xe2, 0xd6, - 0xe7, 0x20, 0x7f, 0x3f, 0x65, 0x3d, 0x03, 0xa5}, // a - {0xf2, 0xfa, 0x9f, 0x28, 0x8f, 0x1f, 0xd0, 0x6b, 0xa2, 0xe3, 0x37, 0xce, - 0x1c, 0x43, 0x82, 0x81, 0x18, 0x01, 0x75, 0x04, 0xf0, 0x2b, 0xb5, 0xb0, - 0x46, 0x5d, 0x44, 0x7f, 0xaa, 0xb3, 0x8a, 0xd2}, // b - {0xf3, 0xe0, 0xab, 0x75, 0x37, 0x41, 0x61, 0x0d, 0xf5, 0x4a, 0x1f, 0xa6, - 0xee, 0xa5, 0xc6, 0x55, 0xd2, 0xa6, 0xce, 0x1c, 0x08, 0x64, 0x75, 0x22, - 0x15, 0x81, 0x45, 0x76, 0x21, 0x2c, 0x32, 0xca}, // rx - {0x6e, 0xfc, 0x5c, 0x0a, 0x79, 0x3a, 0x5d, 0xca, 0xe6, 0xdc, 0x30, 0x12, - 0x96, 0x5a, 0x95, 0x3f, 0x8b, 0xa6, 0x86, 0x6d, 0x43, 0xf4, 0x4e, 0xfd, - 0x4f, 0xf2, 0x7a, 0x80, 0xa5, 0xcc, 0x05, 0x56}, // rf - {0xcb, 0x58, 0xde, 0x49, 0xd7, 0x19, 0xfa, 0xbf, 0x5f, 0x82, 0x19, 0x0e, - 0x60, 0xb5, 0x0d, 0xde, 0xda, 0xb5, 0xf2, 0xb0, 0xcc, 0x2f, 0x65, 0x5e, - 0x71, 0x08, 0xd6, 0xb5, 0xd5, 0xbc, 0x67, 0xc1}, // ra - {0xe0, 0x3a, 0x71, 0xa7, 0x86, 0x56, 0xea, 0xd0, 0x19, 0xce, 0xa9, 0x65, - 0xe8, 0x26, 0x11, 0x56, 0x5c, 0xcb, 0x04, 0x65, 0x36, 0xfd, 0xd9, 0x39, - 0x35, 0xfa, 0x78, 0xa5, 0xc2, 0x3c, 0x2e, 0x17} // rb - }}; -const std::vector EpidMemberTest::kGroupPublicKeyDataIkgf = { -#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" -}; -const std::vector EpidMemberTest::kMemberPrivateKeyDataIkgf = { -#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" -}; - -const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha256 = { -#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc" -}; -const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha384 = { -#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc" -}; -const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha512 = { -#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc" -}; -const std::vector EpidMemberTest::kTest1Msg = {'t', 'e', 's', 't', - '1'}; -std::vector EpidMemberTest::kSigRlData = { -#include "epid/common-testhelper/testdata/grp01/sigrl.inc" -}; -std::vector EpidMemberTest::kSigRl5EntryData = { - // gid - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - // version - 0x00, 0x00, 0x00, 0x00, - // n2 - 0x00, 0x00, 0x00, 0x05, - // bk's - 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, 0x8, - 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, 0x2e, - 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, 0x67, - 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, 0x9d, 0xc7, - 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, 0x7d, 0xfe, - 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, 0x89, 0xb2, - 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, 0xcf, 0xd, 0x40, - 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, 0x4f, 0x7a, 0xb5, - 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, 0x33, 0xad, 0xf6, - 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, 0xce, 0xec, 0xd1, - 0xa8, 0xc, 0x8b, - - 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10, 0xfe, - 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60, 0x3e, 0xc0, - 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82, 0xc4, 0x49, - 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5, 0x77, 0x16, 0x4, - 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8, 0x40, 0xbd, 0x69, - 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9, 0xdd, 0x97, 0x6c, - 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2, 0xca, 0x5, 0x44, 0x9b, - 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa, 0xcf, 0xa4, 0x4, 0xe9, 0xf3, - 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3, 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, - 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60, 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, - 0x11, - - 0x6e, 0x22, 0xaa, 0x10, 0x84, 0x58, 0x8b, 0xff, 0xd8, 0x37, 0x8, 0xa9, 0xe9, - 0xdb, 0xf6, 0x1f, 0x69, 0x10, 0x95, 0x6c, 0xbf, 0xd, 0x11, 0x48, 0x6f, 0x1b, - 0x3c, 0x62, 0x46, 0x13, 0x89, 0x13, 0x5f, 0xa1, 0x3, 0x62, 0xed, 0x62, 0xdf, - 0x3d, 0xbf, 0xcd, 0xb7, 0x41, 0x48, 0x81, 0x3, 0x9f, 0x54, 0xa, 0xe, 0xb3, - 0x35, 0xf9, 0xde, 0x24, 0xba, 0x6d, 0x4c, 0x7f, 0xfc, 0xc1, 0xb4, 0xce, - 0x6d, 0xa1, 0x73, 0x7c, 0xaa, 0xb, 0xad, 0x2, 0xd6, 0x37, 0x85, 0xe, 0xbb, - 0x48, 0x11, 0x38, 0xc4, 0xaa, 0x1b, 0xf, 0xcf, 0xc1, 0x9c, 0x26, 0xcc, 0x95, - 0xc2, 0x5b, 0x49, 0x9, 0x3d, 0xe9, 0x7d, 0xce, 0xc7, 0xa6, 0x4, 0x3e, 0x7c, - 0x9e, 0x28, 0xde, 0x8, 0x11, 0xe, 0x61, 0x3b, 0xc0, 0x9c, 0x6b, 0x58, 0x23, - 0xe6, 0x40, 0x7b, 0xbd, 0xb8, 0x72, 0xf, 0xe0, 0xee, 0xcf, 0xba, 0xb4, - - 0xc4, 0xff, 0xaf, 0x48, 0x15, 0xda, 0x60, 0x40, 0xcc, 0xd7, 0xf2, 0x68, - 0xf7, 0xe2, 0x70, 0x12, 0x8d, 0x15, 0xa5, 0xb7, 0xe6, 0x4c, 0x23, 0xea, - 0x4d, 0x8a, 0x51, 0x6, 0x67, 0x3, 0x4c, 0x83, 0x6f, 0x28, 0x67, 0xcf, 0x63, - 0x46, 0x3e, 0x8a, 0x45, 0x9f, 0xed, 0x1a, 0xde, 0xa7, 0xad, 0xb2, 0x2b, 0xf, - 0x8b, 0xab, 0x7c, 0x70, 0xff, 0xc3, 0xa8, 0x6e, 0x8c, 0xaa, 0xb1, 0xf6, - 0x20, 0xe3, 0xb9, 0xf1, 0xc3, 0x3d, 0x5, 0x6a, 0x1e, 0x26, 0x2d, 0xf4, 0xd, - 0xe4, 0x53, 0x63, 0x67, 0x23, 0x48, 0xa8, 0x1, 0xa8, 0xee, 0xe1, 0x5f, 0x64, - 0xe3, 0x2c, 0x71, 0xe2, 0x10, 0x82, 0x0, 0x52, 0xd7, 0x74, 0x87, 0xff, 0x1c, - 0x0, 0x19, 0xe6, 0x4d, 0x15, 0x91, 0x6d, 0xf3, 0x38, 0x3b, 0xee, 0xf3, 0xd5, - 0xd1, 0xc7, 0x6d, 0xd9, 0x8e, 0x55, 0x70, 0x90, 0xb0, 0xb, 0x3c, 0x4a, 0x67, - 0x19, - - 0x4f, 0x98, 0x92, 0xf9, 0x18, 0x38, 0xf5, 0xb4, 0xf7, 0x2f, 0xa7, 0x21, - 0x71, 0x52, 0x27, 0xd0, 0x57, 0x4f, 0x9c, 0x30, 0xe, 0xb2, 0x27, 0xce, 0xd7, - 0xb2, 0x9f, 0xc0, 0xf6, 0xc3, 0xb0, 0x7c, 0x40, 0x18, 0x75, 0x4a, 0xde, - 0xb0, 0x9f, 0x46, 0x8a, 0x5a, 0xeb, 0x4f, 0xcb, 0x5e, 0x60, 0xf5, 0xca, - 0xf4, 0x98, 0xaf, 0x62, 0x9b, 0x7e, 0x10, 0xda, 0xba, 0x2f, 0x47, 0x64, - 0xf2, 0xc0, 0x84, 0x19, 0x75, 0xe0, 0xe4, 0xff, 0x20, 0xda, 0x7d, 0xe5, 0xd, - 0xc8, 0xf8, 0xe3, 0x83, 0x61, 0x19, 0x17, 0xf1, 0xa9, 0x1b, 0xff, 0x39, - 0x79, 0x88, 0x1, 0xfb, 0xe7, 0x23, 0xd2, 0xac, 0xe0, 0x49, 0x12, 0x2a, 0x38, - 0xb4, 0x7c, 0xc2, 0x1b, 0x88, 0x5f, 0x68, 0x32, 0x11, 0xd9, 0xfd, 0xdc, - 0x65, 0x2, 0xb3, 0x74, 0x2c, 0x13, 0xf2, 0xd8, 0xf1, 0x45, 0xc5, 0xd1, 0xf4, - 0xa3, 0x38, 0x81, 0x92}; -const std::vector EpidMemberTest::kMsg0 = {'m', 's', 'g', '0'}; -const std::vector EpidMemberTest::kBsn0 = {'b', 's', 'n', '0'}; -const std::vector EpidMemberTest::kMsg1 = {'m', 's', 'g', '1'}; -const std::vector EpidMemberTest::kBsn1 = {'b', 's', 'n', '1'}; - -const GroupPubKey EpidMemberTest::kGrpXKey = { -#include "epid/common-testhelper/testdata/grp_x/pubkey.inc" -}; - -const CompressedPrivKey EpidMemberTest::kGrpXMember9CompressedKey = { -#include "epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc" -}; -const PrivKey EpidMemberTest::kGrpXMember9PrivKey = { -#include "epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc" -}; - -const GroupPubKey EpidMemberTest::kGrpYKey = { -#include "epid/common-testhelper/testdata/grp_y/pubkey.inc" -}; - -const CompressedPrivKey EpidMemberTest::kGrpYMember9CompressedKey = { -#include "epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc" -}; diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/nr_prove-test.cc b/external/epid-sdk-3.0.0/epid/member/unittests/nr_prove-test.cc deleted file mode 100644 index ebc4a597..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/nr_prove-test.cc +++ /dev/null @@ -1,290 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief NrProve unit tests. - */ - -#include "gtest/gtest.h" - -extern "C" { -#include "epid/member/api.h" -#include "epid/verifier/api.h" -} - -#include "epid/member/unittests/member-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" - -namespace { - -TEST_F(EpidMemberTest, NrProveFailsGivenNullParameters) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature const* basic_sig = - &reinterpret_cast( - this->kGrp01Member0SigTest1Sha256.data()) - ->sigma0; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - EXPECT_EQ(kEpidBadArgErr, EpidNrProve(nullptr, msg.data(), msg.size(), - basic_sig, &sig_rl->bk[0], &proof)); - EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, nullptr, msg.size(), basic_sig, - &sig_rl->bk[0], &proof)); - EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), nullptr, - &sig_rl->bk[0], &proof)); - EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), - basic_sig, nullptr, &proof)); - EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), - basic_sig, &sig_rl->bk[0], nullptr)); -} - -TEST_F(EpidMemberTest, NrProveFailsGivenInvalidSigRlEntry) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature const* basic_sig = - &reinterpret_cast( - this->kGrp01Member0SigTest1Sha256.data()) - ->sigma0; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - SigRlEntry sig_rl_enty_invalid_k = sig_rl->bk[0]; - sig_rl_enty_invalid_k.k.x.data.data[31]++; // make it not in EC group - EXPECT_EQ(kEpidBadArgErr, - EpidNrProve(member, msg.data(), msg.size(), basic_sig, - &sig_rl_enty_invalid_k, &proof)); - - SigRlEntry sig_rl_enty_invalid_b = sig_rl->bk[0]; - sig_rl_enty_invalid_b.b.x.data.data[31]++; // make it not in EC group - EXPECT_EQ(kEpidBadArgErr, - EpidNrProve(member, msg.data(), msg.size(), basic_sig, - &sig_rl_enty_invalid_b, &proof)); -} - -TEST_F(EpidMemberTest, NrProveFailsGivenInvalidBasicSig) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature const* basic_sig = - &reinterpret_cast( - this->kGrp01Member0SigTest1Sha256.data()) - ->sigma0; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - // invalid basic sig in this case is invalid B or K value only!! - BasicSignature basic_sig_invalid_B = *basic_sig; - basic_sig_invalid_B.B.x.data.data[31]++; // make it not in EC group; - EXPECT_EQ(kEpidBadArgErr, - EpidNrProve(member, msg.data(), msg.size(), &basic_sig_invalid_B, - &sig_rl->bk[0], &proof)); - - BasicSignature basic_sig_invalid_K = *basic_sig; - basic_sig_invalid_K.K.x.data.data[31]++; // make it not in EC group - EXPECT_EQ(kEpidBadArgErr, - EpidNrProve(member, msg.data(), msg.size(), &basic_sig_invalid_K, - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofForEmptyMessage) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); - ASSERT_EQ(kEpidNoErr, - EpidSignBasic(member, nullptr, 0, nullptr, 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, nullptr, 0, &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); - EXPECT_EQ(kEpidNoErr, - EpidNrVerify(ctx, &basic_sig, nullptr, 0, &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofUsingDefaultHashAlg) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofUsingDefaultHashAlgUsingIKGFData) { - Prng my_prng; - GroupPubKey grp_public_key = *reinterpret_cast( - this->kGroupPublicKeyDataIkgf.data()); - PrivKey mbr_private_key = - *reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); - const std::vector sigrl_bin = { -#include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc" - }; - - MemberCtxObj member(grp_public_key, mbr_private_key, &Prng::Generate, - &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(sigrl_bin.data()); - - NrProof proof; - - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(grp_public_key); - - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofUsingSha256HashAlg) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofUsingSha384HashAlg) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha384)); - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, GeneratesNrProofUsingSha512HashAlg) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -TEST_F(EpidMemberTest, DISABLED_GeneratesNrProofUsingSha512256HashAlg) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - BasicSignature basic_sig; - auto msg = this->kTest1Msg; - SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); - - NrProof proof; - - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512_256)); - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); - EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), &basic_sig, - &sig_rl->bk[0], &proof)); - - // Check proof by doing an NrVerify - VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256)); - EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), - &sig_rl->bk[0], &proof)); -} - -} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/presig-test.cc b/external/epid-sdk-3.0.0/epid/member/unittests/presig-test.cc deleted file mode 100644 index 95538acb..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/presig-test.cc +++ /dev/null @@ -1,246 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief ComputePreSig unit tests. - */ -#include -#include -#include -#include - -#include "gtest/gtest.h" - -extern "C" { -#include "epid/member/api.h" -} - -#include "epid/member/unittests/member-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/common-testhelper/errors-testhelper.h" - -/// Count of elements in array -#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) - -bool operator==(PreComputedSignature const& lhs, - PreComputedSignature const& rhs) { - return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); -} - -bool operator!=(PreComputedSignature const& lhs, - PreComputedSignature const& rhs) { - return !(lhs == rhs); -} - -namespace { - -/////////////////////////////////////////////////////////////////////// -// EpidAddPreSigs -TEST_F(EpidMemberTest, AddPreSigsFailsGivenNullPointer) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig = this->kPrecomputedSignatures[0]; - - EXPECT_EQ(kEpidBadArgErr, EpidAddPreSigs(nullptr, 1, &presig)); -} - -TEST_F(EpidMemberTest, AddPreSigsFailsGivenHugeNumberOfPreSigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig = this->kPrecomputedSignatures[0]; - - // number_presigs = 0x80..01 of size equal to sizeof(size_t) - EXPECT_EQ(kEpidBadArgErr, - EpidAddPreSigs(member, (SIZE_MAX >> 1) + 2, &presig)); -} - -TEST_F(EpidMemberTest, - AddPreSigsComputesSpecifiedNumberOfPresigsIfInputPresigsNull) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 2, nullptr)); - ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 1, nullptr)); - // request to generate 0 pre-computed signatures do nothing - ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0, nullptr)); - EXPECT_EQ((size_t)3, EpidGetNumPreSigs(member)); -} - -TEST_F(EpidMemberTest, AddPreSigsClearsInputPresigBuffer) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - // For a test purposes allocate an array of precomputed signatures with - // all elements initialized to the same precomputed signature. - // Warning: Do not use precomputed signatures twice in production code! - std::vector presigs(2, this->kPrecomputedSignatures[0]); - - ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs.size(), presigs.data())); - EXPECT_TRUE(std::all_of((uint8_t*)presigs.data(), - (uint8_t*)(presigs.data() + presigs.size()), - [](uint8_t a) { return 0 == a; })); -} - -TEST_F(EpidMemberTest, AddPreSigsAddsCorrectNumberOfPresigsGivenValidInput) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - // For a test purposes allocate an arrays of precomputed signatures with - // all elements initialized to the same precomputed signature. - // Warning: Do not use precomputed signatures twice in production code! - std::vector presigs1(2, - this->kPrecomputedSignatures[0]); - std::vector presigs2 = presigs1; - - // add - ASSERT_EQ(kEpidNoErr, - EpidAddPreSigs(member, presigs1.size(), presigs1.data())); - // extend - ASSERT_EQ(kEpidNoErr, - EpidAddPreSigs(member, presigs2.size(), presigs2.data())); - // add empty pre-computed signatures array does not affect internal pool - ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0, presigs2.data())); - EXPECT_EQ(presigs1.size() + presigs2.size(), EpidGetNumPreSigs(member)); -} - -/////////////////////////////////////////////////////////////////////// -// EpidGetNumPreSigs -TEST_F(EpidMemberTest, GetNumPreSigsReturnsZeroGivenNullptr) { - EXPECT_EQ((size_t)0, EpidGetNumPreSigs(nullptr)); -} - -TEST_F(EpidMemberTest, NumPreSigsForNewleyCreatedContextIsZero) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - EXPECT_EQ((size_t)0, EpidGetNumPreSigs(member)); -} - -TEST_F(EpidMemberTest, GetNumPreSigsReturnsNumberOfAddedPresigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - // For a test purposes allocate an array of precomputed signatures with - // all elements initialized to the same precomputed signature. - // Warning: Do not use precomputed signatures twice in production code! - std::vector presigs(5, this->kPrecomputedSignatures[0]); - - THROW_ON_EPIDERR(EpidAddPreSigs(member, presigs.size(), presigs.data())); - EXPECT_EQ(presigs.size(), EpidGetNumPreSigs(member)); -} -/////////////////////////////////////////////////////////////////////// -// EpidWritePreSigs -TEST_F(EpidMemberTest, WritePreSigsFailsGivenNullPointer) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - PreComputedSignature presig; - - EXPECT_EQ(kEpidBadArgErr, EpidWritePreSigs(nullptr, &presig, 0)); -} - -TEST_F(EpidMemberTest, WritePreSigsFailsGivenWrongNumberOfPresigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig = this->kPrecomputedSignatures[0]; - - // add one pre-computed signature - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, &presig)); - // export more pre-computed signatures than available - EXPECT_EQ(kEpidBadArgErr, EpidWritePreSigs(member, &presig, 2)); -} - -TEST_F(EpidMemberTest, WritePreSigsClearsPresigsOnSuccess) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - std::vector presigs( - COUNT_OF(this->kPrecomputedSignatures)); - presigs.assign(std::begin(this->kPrecomputedSignatures), - std::end(this->kPrecomputedSignatures)); - - THROW_ON_EPIDERR(EpidAddPreSigs(member, presigs.size(), presigs.data())); - - // can export some but not all - EXPECT_EQ(kEpidNoErr, EpidWritePreSigs(member, presigs.data(), 1)); - EXPECT_EQ(presigs.size() - 1, EpidGetNumPreSigs(member)); - // can export all the rest - EXPECT_EQ(kEpidNoErr, - EpidWritePreSigs(member, presigs.data() + 1, presigs.size() - 1)); - // check that all exported - EXPECT_EQ((size_t)0, EpidGetNumPreSigs(member)); - // check that both write operations export (and leave) correct values. - EXPECT_EQ(presigs.end(), std::unique(presigs.begin(), presigs.end())); -} - -TEST_F(EpidMemberTest, CanWriteAddedPresigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig0 = this->kPrecomputedSignatures[0]; - PreComputedSignature presig1 = this->kPrecomputedSignatures[1]; - PreComputedSignature presigs[2] = {presig0, presig1}; - - THROW_ON_EPIDERR(EpidAddPreSigs(member, COUNT_OF(presigs), presigs)); - - EXPECT_EQ(kEpidNoErr, EpidWritePreSigs(member, presigs, COUNT_OF(presigs))); - // compare ignoring order - EXPECT_TRUE((presig0 == presigs[0] && presig1 == presigs[1]) || - (presig0 == presigs[1] && presig1 == presigs[0])); -} - -TEST_F(EpidMemberTest, CanWriteGeneratedPresigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature zero_buffer; - memset(&zero_buffer, 0, sizeof(zero_buffer)); - PreComputedSignature presigs[2] = {zero_buffer, zero_buffer}; - - THROW_ON_EPIDERR(EpidAddPreSigs(member, COUNT_OF(presigs), nullptr)); - - EXPECT_EQ(kEpidNoErr, EpidWritePreSigs(member, presigs, COUNT_OF(presigs))); - // check pre-computed signature were written - EXPECT_NE(zero_buffer, presigs[0]); - EXPECT_NE(zero_buffer, presigs[1]); -} - -TEST_F(EpidMemberTest, WritePreSigsCanWriteZeroPresigs) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - - PreComputedSignature presig; - - EXPECT_EQ(kEpidNoErr, EpidWritePreSigs(member, &presig, 0)); -} - -} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/request_join-test.cc b/external/epid-sdk-3.0.0/epid/member/unittests/request_join-test.cc deleted file mode 100644 index d444974b..00000000 --- a/external/epid-sdk-3.0.0/epid/member/unittests/request_join-test.cc +++ /dev/null @@ -1,320 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief RequestJoin unit tests. - */ - -#include -#include "gtest/gtest.h" - -extern "C" { -#include "epid/member/api.h" -#include "epid/common/math/ecgroup.h" -#include "epid/common/math/finitefield.h" -#include "epid/common/src/epid2params.h" -} - -#include "epid/member/unittests/member-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" -#include "epid/common-testhelper/epid_params-testhelper.h" -#include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" -#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" - -namespace { - -// local constant for RequestJoin tests. This can be hoisted later if needed -// avoids cpplint warning about multiple includes. -const GroupPubKey kPubKey = { -#include "epid/common-testhelper/testdata/grp01/gpubkey.inc" -}; - -TEST_F(EpidMemberTest, RequestJoinFailsGivenNullParameters) { - GroupPubKey pub_key = kPubKey; - IssuerNonce ni; - FpElemStr f; - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request; - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(nullptr, &ni, &f, rnd_func, - rnd_param, kSha256, &join_request)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, nullptr, &f, rnd_func, - rnd_param, kSha256, &join_request)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, &ni, nullptr, rnd_func, - rnd_param, kSha256, &join_request)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, - rnd_param, kSha256, nullptr)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, &ni, &f, nullptr, - rnd_param, kSha256, &join_request)); -} - -TEST_F(EpidMemberTest, RequestJoinFailsGivenInvalidGroupKey) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request; - GroupPubKey pub_key = kPubKey; - FpElemStr f = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - pub_key.h1.x.data.data[15] = 0xff; - Epid20Params params; - EcPointObj pt(¶ms.G1); - ASSERT_NE(kEpidNoErr, ReadEcPoint(params.G1, (uint8_t*)&pub_key.h1, - sizeof(pub_key.h1), pt)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, - rnd_param, kSha256, &join_request)); -} - -TEST_F(EpidMemberTest, RequestJoinFailsGivenInvalidFValue) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request; - GroupPubKey pub_key = kPubKey; - FpElemStr f = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - - const BigNumStr p = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; - FiniteFieldObj Fp(p); - FfElementObj el(&Fp); - ASSERT_NE(kEpidNoErr, ReadFfElement(Fp, (uint8_t*)&f, sizeof(f), el)); - EXPECT_EQ(kEpidBadArgErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, - rnd_param, kSha256, &join_request)); -} - -TEST_F(EpidMemberTest, - GeneratesValidJoinRequestGivenValidParametersUsingIKGFData) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request; - FpElemStr f = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - const GroupPubKey* grp_public_key = reinterpret_cast( - this->kGroupPublicKeyDataIkgf.data()); - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(grp_public_key, &ni, &f, rnd_func, - rnd_param, kSha256, &join_request)); -} - -TEST_F(EpidMemberTest, GeneratesValidJoinRequestGivenValidParameters) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request; - GroupPubKey pub_key = kPubKey; - FpElemStr f = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, rnd_param, - kSha256, &join_request)); -} - -TEST_F(EpidMemberTest, GeneratesDiffJoinRequestsOnMultipleCalls) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request1; - JoinRequest join_request2; - GroupPubKey pub_key = kPubKey; - FpElemStr f = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - prng.set_seed(0x1234); - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, rnd_param, - kSha256, &join_request1)); - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, rnd_param, - kSha256, &join_request2)); - EXPECT_NE(0, memcmp(&join_request1, &join_request2, sizeof(join_request1))); -} - -TEST_F(EpidMemberTest, GeneratesDiffJoinRequestsGivenDiffHashAlgs) { - Prng prng; - BitSupplier rnd_func = Prng::Generate; - void* rnd_param = &prng; - JoinRequest join_request1; - JoinRequest join_request2; - GroupPubKey pub_key = kPubKey; - FpElemStr f = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - }; - IssuerNonce ni = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - }; - prng.set_seed(0x1234); - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, rnd_param, - kSha256, &join_request1)); - prng.set_seed(0x1234); - EXPECT_EQ(kEpidNoErr, EpidRequestJoin(&pub_key, &ni, &f, rnd_func, rnd_param, - kSha512, &join_request2)); - EXPECT_NE(0, memcmp(&join_request1, &join_request2, sizeof(join_request1))); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationFailsGivenNullParameters) { - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, nullptr)); - EXPECT_FALSE(EpidIsPrivKeyInGroup(nullptr, &this->kGrpXMember9PrivKey)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationFailsGivenGroupIDMissmatch) { - // Check wrong gid for GroupPubKey - GroupPubKey group_pub_key = this->kGrpXKey; - group_pub_key.gid.data[0] = group_pub_key.gid.data[0] ^ 0xFF; - EXPECT_FALSE( - EpidIsPrivKeyInGroup(&group_pub_key, &this->kGrpXMember9PrivKey)); - // Check wrong gid for PrivKey - PrivKey priv_key = this->kGrpXMember9PrivKey; - priv_key.gid.data[sizeof(priv_key.gid.data) - 1] = - priv_key.gid.data[sizeof(priv_key.gid.data) - 1] ^ 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, &priv_key)); - // Check wrong gid for both GroupPubKey and PrivKey - EXPECT_FALSE(EpidIsPrivKeyInGroup(&group_pub_key, &priv_key)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationRejectsInvalidPrivKey) { - // test for invalid key components values (eg. out of range, not in EC group) - PrivKey priv_key = this->kGrpXMember9PrivKey; - priv_key.A.x.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, &priv_key)); - - priv_key = this->kGrpXMember9PrivKey; - priv_key.A.y.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, &priv_key)); - - priv_key = this->kGrpXMember9PrivKey; - FpElemStr inv_f = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, - }; - priv_key.f = inv_f; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, &priv_key)); - - priv_key = this->kGrpXMember9PrivKey; - priv_key.x.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&this->kGrpXKey, &priv_key)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationRejectsInvalidGroupKey) { - // test for invalid key components values (eg. out of range, not in EC group) - GroupPubKey pub_key = this->kGrpXKey; - pub_key.h1.x.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.h1.y.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.h2.x.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.h2.y.data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.w.x[0].data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.w.x[1].data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.w.y[0].data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); - - pub_key = this->kGrpXKey; - pub_key.w.y[1].data.data[0] = 0xFF; - EXPECT_FALSE(EpidIsPrivKeyInGroup(&pub_key, &this->kGrpXMember9PrivKey)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationRejectsKeyNotInGroup) { - EXPECT_FALSE( - EpidIsPrivKeyInGroup(&this->kGrpYKey, &this->kGrpXMember9PrivKey)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationRejectsKeyNotInGroupUsingIKGFData) { - const GroupPubKey* grp_public_key = reinterpret_cast( - this->kGroupPublicKeyDataIkgf.data()); - const PrivKey mbr_private_key = { -#include "epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc" - }; - EXPECT_FALSE(EpidIsPrivKeyInGroup(grp_public_key, &mbr_private_key)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationAcceptsKeyInGroup) { - EXPECT_TRUE( - EpidIsPrivKeyInGroup(&this->kGrpXKey, &this->kGrpXMember9PrivKey)); -} - -TEST_F(EpidMemberTest, PrivateKeyValidationAcceptsKeyInGroupUsingIKGFData) { - const GroupPubKey* grp_public_key = reinterpret_cast( - this->kGroupPublicKeyDataIkgf.data()); - const PrivKey* mbr_private_key = - reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); - EXPECT_TRUE(EpidIsPrivKeyInGroup(grp_public_key, mbr_private_key)); -} - -} // namespace diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupb/member0/mprivkey.dat b/external/epid-sdk-3.0.0/example/compressed_data/groupb/member0/mprivkey.dat deleted file mode 100644 index e2ba729339d823e6c61b1d158ea00558909ce7d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 80 zcmZQzVgLa~FbSml!#3%g_;PrZR2gJwooGuxuTlueD)oxVv`ef{&Li+tiO=ub$r?S3tOg4V+gf7 f*46f5@^~=G?flJg;?;Ba=!>?x+r<~ZI+U-<7Pl_SE6Flg%`0Pt lnT7Qn>H8%ol~4Ng>!?h2ue+U}I(g{v&V<_KWKy!-K1zOJQFpXHm#xhm125#UkcQt2>{Qaqu9r)1-5AIEa;@rV4r2eEvQtN75pnf%#d8cm!DyiK%$OSh diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrevokedmember0/mprivkey.dat b/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrevokedmember0/mprivkey.dat deleted file mode 100644 index 1100871caeb97f0de64b2ab7f13408976638397f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 80 zcmZQzVgLa~FbSk<`+0gkY)k7rCaL?0&+fz%jk610KRCOo|9!rH2|uUyvJf%1-Cifs ft3R?fo<8Swds)n)<2h2Xb7hp5FL^GuW954QFNq-n diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl.bin b/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl.bin deleted file mode 100644 index 949692ae0a95d3bc559efff2287b88f9d51ecf51..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 476 zcmZQ#VBlk5VgLa~FbSbSBFv?hJ~vJ{?muzQ^v_qLwvAsn{vFD_efihS9NUSV*}F9# zd~-c1VS1(c##HZ5xxzg$SNk}#C%#Qi6o0AKE8wTRnXlV+?$i56wo1Hto#d!2f6((- zp69JgQ#uM+1ti`Cy!tll@Pv-<#YgYhud~a4P%3e`GNyW;O+Y|JR7la&+ovRtWHH(N zsxFH2JG*dmf|&E!r|-5;k6iGTvG35uZHA90^4+`I;Yj<&EkFSS56cieb#u|VfW#M zmtRe=^{xCX5q8$3yz<6(?wxa%ylrfp*zJ}0c{-)`pL%Dye^2X40sRIB%N%x_ZQ@BQk}7TWvw&VEtqwczyo=O_LYER)PKy}Gn1rR@3g??;4wdC5Qbbz86B QcJlePEo@HjkDpNh07C}t)&Kwi diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl_empty.bin b/external/epid-sdk-3.0.0/example/compressed_data/groupb/sigrl_empty.bin deleted file mode 100644 index 70762dae2cd469b4cae5590373af28fa082dfdb4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 92 zcmZQ#VBlk5VgLa~FbSc-Z0%pW*G==kry@#^@ z9UlFWYUdU|KWBU0)H&C>l_&pu$aC#K5HK(>Faj|gfW(jiPy(0ypQvM|H&$6qe!ltj z-q5lcZF^E>**2UB-tf)(oQ<9Or3CM6@r$1x>NvUo*z@dZ@)Czn<;=B>y048Fd|7De zdSk|+Y5tF$9{rQ5pWXNTwO0-QJTdKa#^Kq9apz8NbI35?ANUpI4v@oO?%DI~*V^Uc z^IAUdJay<#vT9)bv^$GZB3jd#_7$4@K5Ix>6Fz&5N~=fG9t){AeJ)Ig4_;H-CB12n e@|E9SJ_?1xac5bibGz=E9xr&c*gQ(b^#%YXL#J^7 diff --git a/external/epid-sdk-3.0.0/example/data/data.parts b/external/epid-sdk-3.0.0/example/data/data.parts deleted file mode 100644 index 28a6b110..00000000 --- a/external/epid-sdk-3.0.0/example/data/data.parts +++ /dev/null @@ -1,72 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -# Normal stuff that all Parts should have -env.PartName("sample_data") - -#files -data_files = Pattern(src_dir='.', - includes=[ - 'grprl_empty.bin', - 'README.md', - 'groupa/privrl.bin', - 'groupa/pubkey.bin', - 'groupa/sigrl.bin', - 'groupa/privrl_empty.bin', - 'groupa/sigrl_empty.bin', - 'groupa/member0/mprivkey.dat', - 'groupa/member1/mprivkey.dat', - 'groupa/privrevokedmember0/mprivkey.dat', - 'groupa/privrevokedmember1/mprivkey.dat', - 'groupa/privrevokedmember2/mprivkey.dat', - 'groupa/sigrevokedmember0/mprivkey.dat', - 'groupa/sigrevokedmember1/mprivkey.dat', - 'groupa/sigrevokedmember2/mprivkey.dat', - 'groupb/privrl.bin', - 'groupb/pubkey.bin', - 'groupb/sigrl.bin', - 'groupb/privrl_empty.bin', - 'groupb/sigrl_empty.bin', - 'groupb/member0/mprivkey.dat', - 'groupb/privrevokedmember0/mprivkey.dat', - 'groupb/sigrevokedmember0/mprivkey.dat', - ], - recursive=True) - -sample_default_files = Pattern(src_dir='.', - includes=[ - 'mprivkey.dat', - 'pubkey.bin', - 'cacert.bin', - 'grprl.bin', - 'privrl.bin', - 'sigrl.bin', - ], - recursive=True) - -part_file = ['data.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(data_files, sub_dir='example/data') - env.InstallTopLevel(part_file, sub_dir='example/data') - env.InstallTopLevel(sample_default_files, sub_dir='example/data') -else: - env.InstallData(data_files, - sub_dir='data', - no_pkg=False) - env.InstallTopLevel(sample_default_files, sub_dir='example') diff --git a/external/epid-sdk-3.0.0/example/data/groupa/member0/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/member0/mprivkey.dat deleted file mode 100644 index 8bf5d47249e204357c3df079f46c0ada2bc7c35f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKn15%Jk#4|{A0b8cC_Y_!?w5nWe0X}B+UwQD`RxHvH0N*{pOU8nWrvm-wgO& z(!JDZ$2r66VcvJ|%J9YQGRa8Wvu)0#5BiJL!w$Z;QjD9$DxA!xFSKUrPPJUwN9R+# pIPdz4&gICSynkw^;0{B%OT>GM&p1bT8&o!%V;1-ZO1_0@WI_&@e diff --git a/external/epid-sdk-3.0.0/example/data/groupa/member1/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/member1/mprivkey.dat deleted file mode 100644 index c11c0cafbb20c8842a2d19fa1ef755f9913009e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKm`pe&!h*OS;d>0q~cm!bJW;3^HoCX%Ci|7y{Wmk_bk}>UV`Io_JQEQoxhxy zZu4S&v-q~ho%y_#7{@32~8z#{w45+5flpX31BJ74@P?V*hWw=l=6aebdUr rMK|w;2Pqb6N6nvm(#279!41omYdupkELOZ*fIfw+TZf diff --git a/external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember1/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember1/mprivkey.dat deleted file mode 100644 index b2694cdb4c5728e9bc7ca90ec61b11063db23fd2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKn1@~AOE28@Yt8Y1CeTdo-EJi+kX%HH}Ox=NiF`s!h+DrGau(!q{@GoyN!>v zq~TuG6V|%2n&qimEc@!VKRxpKLa^M9X?I;Xum67a@`TjYYZVevvX(n!_o%G#-Xhb$ q&)w;4c6KW7qVj2-6Hk3(I;HTx*nIj%x1RMW+ju;d+3lTF_yYh!h(c}v diff --git a/external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember2/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/privrevokedmember2/mprivkey.dat deleted file mode 100644 index 38a2eacced562f6cff1c9d480b5f1757b0e2e921..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKn2%kOiRqXoU=e+Q{EOfrvh)?*aJ2`Ge4RB=-=gf;PU5u*|Q589hbfiepcsM z7QG-u`l@*F)ff62QQ`YGSPK_M3h~X_vGU~4t@S?kC7#NU&Rac>x3pcF+`Q={|F=C# pY>TvID@ETO;ub%0<+QU+%-Req=G^KePY< diff --git a/external/epid-sdk-3.0.0/example/data/groupa/privrl.bin b/external/epid-sdk-3.0.0/example/data/groupa/privrl.bin deleted file mode 100644 index e3bca59da808a97e2ceea4a73360a702cfc9708c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 188 zcmZQ#VBlrI1dKo-X4y*7cZayek6bzJY!kCK!-_fg{;LY7S%?3eoP4*?W!Gu5vr~B& zl~3!OcO2^{h|X#^bTfZttYRA3=(R+EMf8o^){(U2wy4mhs=a@T)06|k$3D0`D*RJf%W&b=k!|lcq)%hkzw~b1 fiHfwZOfLt diff --git a/external/epid-sdk-3.0.0/example/data/groupa/privrl_empty.bin b/external/epid-sdk-3.0.0/example/data/groupa/privrl_empty.bin deleted file mode 100644 index 27bdd70497210f90049e46b6d76561d9395236c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 92 zcmZQ#VBlrI1dJe|Qi-ZBcRsG4F!QjL;N~v5iUm2pBKLKO>f73=y|%mO-?HzPk>-(` g{>>bRMQp9vWmZoUb9ncUb#JTx3qHZ;$7eSK00tHwyZ`_I diff --git a/external/epid-sdk-3.0.0/example/data/groupa/pubkey.bin b/external/epid-sdk-3.0.0/example/data/groupa/pubkey.bin deleted file mode 100644 index 5f766c81efb2a11a7add183fa2d86e9c7d8c2f49..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 340 zcmV-a0jvH3000aC0000000000000000000*%LW9q_am~=(G5>gd%KTu71#0H6*tJZ zJ!lFTr8E=_+}Ra=x>m*IVft!@psZ?vHf;f4hQI`i9{)+%HVW162j|l`?70?$h}vY`#GPtfvK)w)>aVHuJ_qWyD%E=JGTA+l*SV1h1)k#~bp|!% z#CNSyxqJjIeu45`T~dA59Vz>2r@XbP8m9dq>hhT4XEP{gU%n%tL+Ej;tM>3}D^jRo zQ6fYDk=OBl1xVac4DX=xa?M%PdMaR}VpOQMkL{4(K9uOBi888ET9>X&hV;7Z#x@g& zLR}U~5@yBVSd#A9gBStt>T4}En p-yu(r=mpHLyeql4zLjds-Soool=Q{}-vyoQRbGWMHTep9007iVJu3hJ diff --git a/external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember1/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember1/mprivkey.dat deleted file mode 100644 index cdc7911d0a634610de1d9e713fd8287ec6ea5c80..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKn1QZ?UcVCHCZsXW}SA!x&=S%KM8z#`MUP4g@Dv~_aA>eZKmp)DP?&fr&dk!?s5dSyq;h*me&hRP0rwRT%@;PlZsOL?9T>T4(xhDN pDyy_k4U?HKQ-k>?&U*9B`kauA{+22hqa|Mg@@2kqCbrl92LNk$J}CeI diff --git a/external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember2/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupa/sigrevokedmember2/mprivkey.dat deleted file mode 100644 index b5b9edee9ffc26d1c22e2f5785629e582ce911ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKm~8MfBW%~MLbkz(f&=+%O$5v_Z{YHG5maM> zs!K^gqerWlzeRBCbW!nemRcEybF~W}l&+GDPI?}!_Gg{;T*X?xABP%_r6{~&G1@Wh zW>HwqtGh2e7rct!$JMPX&V2I$m&&1KU#8dc|9!`qw97Cs+g5Jk<2_d?wf|PVL#jHD zyJg(zJ*SRE-|=`*RTv_w_{w32=e+E!yVDPrpLY&TnXW4`Cq-$K=7L8Pq!~7yjre|f zf`A-<;@Y)^lPR^|cG2FWqUix0OkC!R%ini?k=9aRIiX{}wP|kX#f{z)zPlA;IXzr- zF8iO*JgxV0|51}oQ~abqESqEGAI6c^?rO~?~A%Xwm$&z|IQu& diff --git a/external/epid-sdk-3.0.0/example/data/groupa/sigrl_empty.bin b/external/epid-sdk-3.0.0/example/data/groupa/sigrl_empty.bin deleted file mode 100644 index 27978221e6bdc49f8595a9fc5d2904645884501a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 92 zcmZQ#VBllG1dJe|goM3wV~bWMm`$Jelk-RHVb|wcQ`EEt*hKx fS~8yd;!{itLvCbFo@=Mx5Vuw5Pzihg$4L$V_{ts= diff --git a/external/epid-sdk-3.0.0/example/data/groupb/member0/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupb/member0/mprivkey.dat deleted file mode 100644 index faa4a6f31cf93bb87fb19c28ff06d1e9fd0e5988..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKmm+#`y#d;z5Ons>bCggAEG;W-pszx!yjAte~F) zM{1o5kH0U7i`jC|#(KYcPrjhhYlD{BF$sX~PS diff --git a/external/epid-sdk-3.0.0/example/data/groupb/privrevokedmember0/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/groupb/privrevokedmember0/mprivkey.dat deleted file mode 100644 index 0e5990a7366ab99b0487d69bd4926879c83aef32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKmm+R+&-JCU0QtV+&CwPKjD@9o*eJUpJ1{n{@dYCGem!QCN-S0DSReSXrl4A z_1^N&NoSRUpKVG%z+^6N_dk6m=PRqeY!};#m=X_}GNYFcTaVwIsmhzMD|Y7_%d*WU pWzHO2A?YkJv8bS$IV5b_`D>QCl9S5r$(?`O$$$5Ykim}5835BnJQDx_ diff --git a/external/epid-sdk-3.0.0/example/data/groupb/privrl.bin b/external/epid-sdk-3.0.0/example/data/groupb/privrl.bin deleted file mode 100644 index 5ff658f3c0434d0c0bed6d4f7b6ffc3f366d0496..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 188 zcmZQ#VBlpy1&ly02s68f@jnQ5G}v-><(-7}A2|iJb%K{|>1H}HTQls><5joT1YSR; zdpvZ~B^Cb}>-3L247d8S@%78ik6$|QNM#n+1U9dbbe5P{R8Y+v5;pDpHA`K|NoDus z&cE&CzxzeVU`OW+qx0c!s+nsQl&>9%YY=~&y=dZVR`=6K{{+08xkPYkx?FUH?s3+S guOGW+xj*tu_A?NBZx%IMGpIRy`qfPj)-Qht03GR2M*si- diff --git a/external/epid-sdk-3.0.0/example/data/groupb/privrl_empty.bin b/external/epid-sdk-3.0.0/example/data/groupb/privrl_empty.bin deleted file mode 100644 index 3638c8180768b3868be6a55a1b168c388c69dd41..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 92 zcmZQ#VBlpy1&ly02s0f1Wu&)S<`I*V)c!|bwTk^;%8BPk%WXGxV#(?BpBCqHj%l{6 i?4c_G?gw^o7XI$}GL!qq++5Wb`IF!Nxy-+{`8NQpARkEp diff --git a/external/epid-sdk-3.0.0/example/data/groupb/pubkey.bin b/external/epid-sdk-3.0.0/example/data/groupb/pubkey.bin deleted file mode 100644 index 0d0ba5210b5bb160ba8cf73a7459fbc8a64158fb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 340 zcmV-a0jvH3000aC0000000000000000004ainb4$_2kj#Icj-qwb7x2?4bev=yJ}^ z1)5K#7aQ#`#Q?yx+g_&PBqOW!3GzyQa{9x+Gm|4oiPD$|;Q_jxspUaNF1wy;{V0W$ z)oxn)LUC@~e%sOVgb@f&4~pMD0g9$#n=teF#nCvLvDC>lQz|bjmgOWkjcY@j@PfxW@DClj=+U|NGbM9TlQ}8tKIUl z>a+EcjY0E2Fq^Ba)YmIEex&Wxe$g%RO7PRepJF$(UyHe0+@TuB)YLS!>el`6ZHq#Z rb~B3J_P({EzIodX108?fo%@oeNgls3gKK-!0o6OJgd;DvG)DjclT|~r diff --git a/external/epid-sdk-3.0.0/example/data/groupb/sigrl.bin b/external/epid-sdk-3.0.0/example/data/groupb/sigrl.bin deleted file mode 100644 index b55ea33cffd011814842f99dc1f9d3604cb628d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 476 zcmZQ#VBljw1&ly02s1}%#z)9;aEjWqUc2_tI^*+(;O3qR4Z|-YKit)4=n8IP*FU4% z$joJNG+Oah;v}b;Y7^Xqiq+*q9vkM|zgfuZ;FV(Cbi-HRW|(=;j@ZW8Axq|KR5N~m zyo76VTD(m2EJYKQ*bMc|nG7o2a_zBVuc8Agy6U$?mcMmi7kXO#h4U4q_A@Ns8J4{F z(%sdp9w(#)CKMK2bemsja3*#0Zgvaf`3E~WM4eXJ@0e*7^+J5^vEZxI{f;EVxcOVvgqZi+DxC{^sPcG2nrXqhS(g|# jP5S-wtM{SYo9aiN-mz}}&66Lq_{s7c@0Wex_udHrS7IY| diff --git a/external/epid-sdk-3.0.0/example/data/grprl.bin b/external/epid-sdk-3.0.0/example/data/grprl.bin deleted file mode 100644 index 2774f2b253aa6f7a3db62425383be8f78ce5f386..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 876 zcmZQ#VBlw9VBiE|BOpcwjK~}yn+c82jK*g{U0Xna02KFHt5KmeHoWDBD4h0yrIXnYYgz9<@B42>_2#+N|jOQP|m(D>45d>J&p zEE-=9jW3VJS3u({qVbi`_{wN}6*Rso8ea{Kua3soK;vto@wL$S+Gu!aUEL# diff --git a/external/epid-sdk-3.0.0/example/data/mprivkey.dat b/external/epid-sdk-3.0.0/example/data/mprivkey.dat deleted file mode 100644 index 8bf5d47249e204357c3df079f46c0ada2bc7c35f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 144 zcmZQzKn15%Jk#4|{A0b8cC_Y_!?w5nWe0X}B+UwQD`RxHvH0N*{pOU8nWrvm-wgO& z(!JDZ$2r66VcvJ|%J9YQGRa8Wvu)0#5BiJL!w$Z;QjD9$DxA!xFSKUrPPJUwN9R+# pIPdz4&gICSynkw^;0{B%OT>GM&p1bT8&o!%V;1-ZO1_0@WI_&@e diff --git a/external/epid-sdk-3.0.0/example/data/privrl.bin b/external/epid-sdk-3.0.0/example/data/privrl.bin deleted file mode 100644 index 27bdd70497210f90049e46b6d76561d9395236c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 92 zcmZQ#VBlrI1dJe|Qi-ZBcRsG4F!QjL;N~v5iUm2pBKLKO>f73=y|%mO-?HzPk>-(` g{>>bRMQp9vWmZoUb9ncUb#JTx3qHZ;$7eSK00tHwyZ`_I diff --git a/external/epid-sdk-3.0.0/example/data/pubkey.bin b/external/epid-sdk-3.0.0/example/data/pubkey.bin deleted file mode 100644 index 5f766c81efb2a11a7add183fa2d86e9c7d8c2f49..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 340 zcmV-a0jvH3000aC0000000000000000000*%LW9q_am~=(G5>gd%KTu71#0H6*tJZ zJ!lFTr8E=_+}Ra=x>m*IVft!@psZ?vHf;f4hQI`i9{)+%HVW162j|l`?70?$h}vY`#GPtfvK)w)>aVHuJ_qWyD%E=JGTA+l*SV1h1)k#~bp|!% z#CNSyxqJjIeu45`T~dA59Vz>2r@XbP8m9dq>hhT4XEP{gU%n%tL+Ej;tM>3}D^jRo zQ6fYDk=OBl1xVac4DX=xa?M%PdMaR}VpOQMkL{4(K9uOBi888ET9>X&hV;7Z#x@g& zLR}U~5@yBV`EEt*hKx fS~8yd;!{itLvCbFo@=Mx5Vuw5Pzihg$4L$V_{ts= diff --git a/external/epid-sdk-3.0.0/example/signmsg/signmsg.parts b/external/epid-sdk-3.0.0/example/signmsg/signmsg.parts deleted file mode 100644 index 1246cb94..00000000 --- a/external/epid-sdk-3.0.0/example/signmsg/signmsg.parts +++ /dev/null @@ -1,52 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -# Normal stuff that all Parts should have -env.PartName("signmsg") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() -inc_files = Pattern(src_dir='src/', - includes=['*.h'], - recursive=True).files() -parts_file = ['signmsg.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(inc_files + src_files, - sub_dir='example/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='example/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('member'), - Component('util'), - Component('dropt') - ]) - - env.Append(CPPPATH='#/example/signmsg') - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_SAMPLE_BIN}') diff --git a/external/epid-sdk-3.0.0/example/signmsg/src/main.c b/external/epid-sdk-3.0.0/example/signmsg/src/main.c deleted file mode 100644 index 8bd9000f..00000000 --- a/external/epid-sdk-3.0.0/example/signmsg/src/main.c +++ /dev/null @@ -1,410 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Signmsg example implementation. - * - */ - -#include -#include -#include - -#include -#include "util/buffutil.h" -#include "util/convutil.h" -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "src/signmsg.h" - -// Defaults -#define PROGRAM_NAME "signmsg" -#define MPRIVKEYFILE_DEFAULT "mprivkey.dat" -#define PUBKEYFILE_DEFAULT "pubkey.bin" -#define SIG_DEFAULT "sig.dat" -#define CACERT_DEFAULT "cacert.bin" -#define HASHALG_DEFAULT "SHA-512" - -/// parses string to a hashalg type -static dropt_error HandleHashalg(dropt_context* context, - const char* option_argument, - void* handler_data) { - dropt_error err = dropt_error_none; - HashAlg* hashalg = handler_data; - (void)context; - if (option_argument == NULL) { - *hashalg = kSha512; - } else if (option_argument[0] == '\0') { - err = dropt_error_insufficient_arguments; - } else if (StringToHashAlg(option_argument, hashalg)) { - err = dropt_error_none; - } else { - /* Reject the value as being inappropriate for this handler. */ - err = dropt_error_mismatch; - } - return err; -} - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_SUCCESS; - - // intermediate return value for EPID functions - EpidStatus result = kEpidErr; - - // User Settings - - // Signature file name parameter - static char* sig_file = NULL; - - // Message string parameter - static char* msg_str = NULL; - size_t msg_size = 0; - - // Basename string parameter - static char* basename_str = NULL; - size_t basename_size = 0; - - // SigRl file name parameter - static char* sigrl_file = NULL; - - // Group public key file name parameter - static char* pubkey_file = NULL; - - // Member private key file name parameter - static char* mprivkey_file = NULL; - - // Member pre-computed settings input file name parameter - static char* mprecmpi_file = NULL; - - // Member pre-computed settings output file name parameter - static char* mprecmpo_file = NULL; - - // CA certificate file name parameter - static char* cacert_file = NULL; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - // Buffers and computed values - - // Signature buffer - EpidSignature* sig = NULL; - size_t sig_size = 0; - - // SigRl file - unsigned char* signed_sig_rl = NULL; - size_t signed_sig_rl_size = 0; - - // Group public key file - unsigned char* signed_pubkey = NULL; - size_t signed_pubkey_size = 0; - - // CA certificate - EpidCaCertificate cacert = {0}; - - // Member private key buffer - unsigned char* mprivkey = NULL; - size_t mprivkey_size = 0; - - // Member pre-computed settings - MemberPrecomp member_precmp = {0}; - - // Flag that Member pre-computed settings input is valid - bool use_precmp_in; - - // Hash algorithm - static HashAlg hashalg = kSha512; - - dropt_option options[] = { - {'\0', "sig", "write signature to FILE (default: " SIG_DEFAULT ")", - "FILE", dropt_handle_string, &sig_file}, - {'\0', "msg", "MESSAGE to sign", "MESSAGE", dropt_handle_string, - &msg_str}, - {'\0', "bsn", "BASENAME to sign with (default: random)", "BASENAME", - dropt_handle_string, &basename_str}, - - {'\0', "sigrl", "load signature based revocation list from FILE", "FILE", - dropt_handle_string, &sigrl_file}, - {'\0', "gpubkey", - "load group public key from FILE (default: " PUBKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &pubkey_file}, - {'\0', "mprivkey", - "load member private key from FILE " - "(default:" MPRIVKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &mprivkey_file}, - {'\0', "mprecmpi", "load pre-computed member data from FILE", "FILE", - dropt_handle_string, &mprecmpi_file}, - {'\0', "mprecmpo", "write pre-computed member data to FILE", "FILE", - dropt_handle_string, &mprecmpo_file}, - {'\0', "capubkey", - "load IoT Issuing CA public key from FILE (default: " CACERT_DEFAULT ")", - "FILE", dropt_handle_string, &cacert_file}, - - {'\0', "hashalg", - "use specified hash algorithm (default: " HASHALG_DEFAULT ")", - "{SHA-256 | SHA-384 | SHA-512}", HandleHashalg, &hashalg}, - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - // set program name for logging - set_prog_name(PROGRAM_NAME); - do { - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - ret_value = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]...\n" - "Create Intel(R) EPID signature of message\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else if (*rest) { - // we have unparsed (positional) arguments - log_error("invalid argument: %s", *rest); - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } else { - if (verbose) { - verbose = ToggleVerbosity(); - } - if (!sig_file) { - sig_file = SIG_DEFAULT; - } - if (!pubkey_file) { - pubkey_file = PUBKEYFILE_DEFAULT; - } - if (!mprivkey_file) { - mprivkey_file = MPRIVKEYFILE_DEFAULT; - } - if (!cacert_file) { - cacert_file = CACERT_DEFAULT; - } - - if (msg_str) { - msg_size = strlen(msg_str); - } - if (basename_str) { - basename_size = strlen(basename_str); - } - if (verbose) { - log_msg("\nOption values:"); - log_msg(" sig_file : %s", sig_file); - log_msg(" msg_str : %s", msg_str); - log_msg(" basename_str : %s", basename_str); - log_msg(" pubkey_file : %s", pubkey_file); - log_msg(" mprivkey_file : %s", mprivkey_file); - log_msg(" mprecmpi_file : %s", mprecmpi_file); - log_msg(" mprecmpo_file : %s", mprecmpo_file); - log_msg(" hashalg : %s", HashAlgToString(hashalg)); - log_msg(" cacert_file : %s", cacert_file); - log_msg(""); - } - } - } - // convert command line args to usable formats - - // CA certificate - if (0 != ReadLoud(cacert_file, &cacert, sizeof(cacert))) { - ret_value = EXIT_FAILURE; - break; - } - // Security note: - // Application must confirm that IoT EPID Issuing CA certificate is - // authorized by IoT EPID Root CA, e.g., signed by IoT EPID Root CA. - if (!IsCaCertAuthorizedByRootCa(&cacert, sizeof(cacert))) { - log_error("CA certificate is not authorized"); - ret_value = EXIT_FAILURE; - break; - } - // SigRl - if (sigrl_file) { - if (FileExists(sigrl_file)) { - signed_sig_rl = NewBufferFromFile(sigrl_file, &signed_sig_rl_size); - if (!signed_sig_rl) { - ret_value = EXIT_FAILURE; - break; - } - - if (0 != ReadLoud(sigrl_file, signed_sig_rl, signed_sig_rl_size)) { - ret_value = EXIT_FAILURE; - break; - } - } else { - log_error("SigRL file %s does not exist", sigrl_file); - ret_value = EXIT_FAILURE; - break; - } - } - // Group public key file - signed_pubkey = NewBufferFromFile(pubkey_file, &signed_pubkey_size); - if (!signed_pubkey) { - ret_value = EXIT_FAILURE; - break; - } - if (0 != ReadLoud(pubkey_file, signed_pubkey, signed_pubkey_size)) { - ret_value = EXIT_FAILURE; - break; - } - // Member private key - mprivkey = NewBufferFromFile(mprivkey_file, &mprivkey_size); - if (!mprivkey) { - ret_value = EXIT_FAILURE; - break; - } - if (mprivkey_size != sizeof(PrivKey) && - mprivkey_size != sizeof(CompressedPrivKey)) { - log_error("Private Key file size is inconsistent"); - ret_value = EXIT_FAILURE; - break; - } - if (0 != ReadLoud(mprivkey_file, mprivkey, mprivkey_size)) { - ret_value = EXIT_FAILURE; - break; - } - // Load Member pre-computed settings - use_precmp_in = false; - if (mprecmpi_file) { - if (sizeof(MemberPrecomp) != GetFileSize(mprecmpi_file)) { - log_error("incorrect input precomp size"); - ret_value = EXIT_FAILURE; - break; - } - use_precmp_in = true; - - if (0 != ReadLoud(mprecmpi_file, &member_precmp, sizeof(MemberPrecomp))) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Signing Message:"); - log_msg(""); - log_msg(" [in] Message Len: %d", (int)msg_size); - log_msg(" [in] Message: "); - PrintBuffer(msg_str, msg_size); - log_msg(""); - log_msg(" [in] BaseName Len: %d", (int)basename_size); - log_msg(" [in] BaseName: "); - PrintBuffer(basename_str, basename_size); - log_msg(""); - log_msg(" [in] SigRl Len: %d", (int)signed_sig_rl_size); - log_msg(" [in] SigRl: "); - PrintBuffer(signed_sig_rl, signed_sig_rl_size); - log_msg(""); - log_msg(" [in] Group Public Key: "); - PrintBuffer(signed_pubkey, signed_pubkey_size); - log_msg(""); - log_msg(" [in] Member Private Key: "); - PrintBuffer(&mprivkey, sizeof(mprivkey)); - log_msg(""); - log_msg(" [in] Hash Algorithm: %s", HashAlgToString(hashalg)); - log_msg(""); - log_msg(" [in] IoT EPID Issuing CA Certificate: "); - PrintBuffer(&cacert, sizeof(cacert)); - if (use_precmp_in) { - log_msg(""); - log_msg(" [in] Member PreComp: "); - PrintBuffer(&member_precmp, sizeof(member_precmp)); - } - log_msg("=============================================="); - } - - // Sign - result = SignMsg(msg_str, msg_size, basename_str, basename_size, - signed_sig_rl, signed_sig_rl_size, signed_pubkey, - signed_pubkey_size, mprivkey, mprivkey_size, hashalg, - &member_precmp, use_precmp_in, &sig, &sig_size, &cacert); - - // Report Result - if (kEpidNoErr != result) { - if (kEpidSigRevokedInSigRl == result) { - log_error("signature revoked in SigRL"); - } else { - log_error("function SignMsg returned %s", EpidStatusToString(result)); - ret_value = EXIT_FAILURE; - break; - } - } - - if (sig && sig_size != 0) { - // Store signature - if (0 != WriteLoud(sig, sig_size, sig_file)) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Store Member pre-computed settings - if (mprecmpo_file) { - if (0 != - WriteLoud(&member_precmp, sizeof(member_precmp), mprecmpo_file)) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Success - ret_value = EXIT_SUCCESS; - } while (0); - - // Free allocated buffers - if (sig) free(sig); - if (signed_sig_rl) free(signed_sig_rl); - if (signed_pubkey) free(signed_pubkey); - if (mprivkey) free(mprivkey); - - dropt_free_context(dropt_ctx); - - return ret_value; -} diff --git a/external/epid-sdk-3.0.0/example/signmsg/src/prng.c b/external/epid-sdk-3.0.0/example/signmsg/src/prng.c deleted file mode 100644 index e1da167f..00000000 --- a/external/epid-sdk-3.0.0/example/signmsg/src/prng.c +++ /dev/null @@ -1,98 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Pseudo random number generator implementation. - */ -#include -#include -#include - -#include "src/prng.h" - -EpidStatus PrngCreate(void** prng) { - // Security note: - // Random number generator used in the samples not claimed to be a - // cryptographically secure pseudo-random number generator. - EpidStatus sts = kEpidErr; - int prng_ctx_size = 0; - IppsPRNGState* prng_ctx = NULL; - int seed_ctx_size = 0; - IppsBigNumState* seed_ctx = NULL; - time_t seed_value; - - if (!prng) return kEpidBadArgErr; - - if (ippStsNoErr != ippsPRNGGetSize(&prng_ctx_size)) return kEpidErr; - if (ippStsNoErr != - ippsBigNumGetSize((sizeof(seed_value) + 3) / 4, &seed_ctx_size)) - return kEpidErr; - - do { - prng_ctx = (IppsPRNGState*)calloc(1, prng_ctx_size); - - if (!prng_ctx) { - sts = kEpidNoMemErr; - break; - } - if (ippStsNoErr != ippsPRNGInit(sizeof(seed_value) * 8, prng_ctx)) { - sts = kEpidErr; - break; - } - - // seed PRNG - seed_ctx = (IppsBigNumState*)calloc(1, seed_ctx_size); - if (!seed_ctx) { - sts = kEpidNoMemErr; - break; - } - if (ippStsNoErr != ippsBigNumInit((sizeof(seed_value) + 3) / 4, seed_ctx)) { - sts = kEpidErr; - break; - } - time(&seed_value); - if (ippStsNoErr != - ippsSetOctString_BN((void*)&seed_value, sizeof(seed_value), seed_ctx)) { - sts = kEpidErr; - break; - } - if (ippStsNoErr != ippsPRNGSetSeed(seed_ctx, prng_ctx)) { - sts = kEpidErr; - break; - } - - *prng = prng_ctx; - prng_ctx = NULL; - sts = kEpidNoErr; - } while (0); - - if (seed_ctx) free(seed_ctx); - if (prng_ctx) free(prng_ctx); - return sts; -} - -void PrngDelete(void** prng) { - if (prng && *prng) { - free(*prng); - *prng = NULL; - } -} - -// simple wrapper to hide IPP implementation. -int __STDCALL PrngGen(unsigned int* rand_data, int num_bits, void* user_data) { - return ippsPRNGen(rand_data, num_bits, (IppsPRNGState*)user_data); -} diff --git a/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.c b/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.c deleted file mode 100644 index 7b95d0de..00000000 --- a/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.c +++ /dev/null @@ -1,176 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ -/// Message signing implementation. -/*! - * \file - * - * This file has a corresponding walk-through in the SDK documentation. - * - * Review the walk-through for correctness after making changes to this - * file. - */ -#include -#include -#include "src/signmsg.h" -#include "src/prng.h" -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "util/buffutil.h" -#include "epid/member/api.h" -#include "epid/common/file_parser.h" - -bool IsCaCertAuthorizedByRootCa(void const* data, size_t size) { - // Implementation of this function is out of scope of the sample. - // In an actual implementation Issuing CA certificate must be validated - // with CA Root certificate before using it in parse functions. - (void)data; - (void)size; - return true; -} - -EpidStatus SignMsg(void const* msg, size_t msg_len, void const* basename, - size_t basename_len, unsigned char const* signed_sig_rl, - size_t signed_sig_rl_size, - unsigned char const* signed_pubkey, - size_t signed_pubkey_size, unsigned char const* priv_key_ptr, - size_t privkey_size, HashAlg hash_alg, - MemberPrecomp* member_precomp, bool member_precomp_is_input, - EpidSignature** sig, size_t* sig_len, - EpidCaCertificate const* cacert) { - EpidStatus sts = kEpidErr; - void* prng = NULL; - MemberCtx* member = NULL; - SigRl* sig_rl = NULL; - - do { - GroupPubKey pub_key = {0}; - PrivKey priv_key = {0}; - size_t sig_rl_size = 0; - - if (!sig) { - sts = kEpidBadArgErr; - break; - } - - // authenticate and extract group public key - sts = EpidParseGroupPubKeyFile(signed_pubkey, signed_pubkey_size, cacert, - &pub_key); - if (kEpidNoErr != sts) { - break; - } - - if (signed_sig_rl) { - // authenticate and determine space needed for SigRl - sts = EpidParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, NULL, - &sig_rl_size); - if (kEpidSigInvalid == sts) { - // authentication failure - break; - } - if (kEpidNoErr != sts) { - break; - } - sig_rl = AllocBuffer(sig_rl_size); - if (!sig_rl) { - sts = kEpidMemAllocErr; - break; - } - - // fill the SigRl - sts = EpidParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, - sig_rl, &sig_rl_size); - if (kEpidSigInvalid == sts) { - // authentication failure - break; - } - if (kEpidNoErr != sts) { - break; - } - } // if (signed_sig_rl) - - // decompress private key - if (privkey_size == sizeof(PrivKey)) { - priv_key = *(PrivKey*)priv_key_ptr; - } else if (privkey_size == sizeof(CompressedPrivKey)) { - sts = EpidDecompressPrivKey(&pub_key, (CompressedPrivKey*)priv_key_ptr, - &priv_key); - if (kEpidNoErr != sts) { - break; - } - } else { - sts = kEpidErr; - break; - } // if (privkey_size == sizeof(PrivKey)) - - // acquire PRNG - sts = PrngCreate(&prng); - if (kEpidNoErr != sts) { - break; - } - - // create member - sts = EpidMemberCreate(&pub_key, &priv_key, - member_precomp_is_input ? member_precomp : NULL, - PrngGen, prng, &member); - if (kEpidNoErr != sts) { - break; - } - - // return member pre-computation blob if requested - sts = EpidMemberWritePrecomp(member, member_precomp); - if (kEpidNoErr != sts) { - break; - } - - // register any provided basename as allowed - if (0 != basename_len) { - sts = EpidRegisterBaseName(member, basename, basename_len); - if (kEpidNoErr != sts) { - break; - } - } - - sts = EpidMemberSetHashAlg(member, hash_alg); - if (kEpidNoErr != sts) { - break; - } - - // Signature - // Note: Signature size must be computed after sig_rl is loaded. - *sig_len = EpidGetSigSize(sig_rl); - - *sig = AllocBuffer(*sig_len); - if (!*sig) { - sts = kEpidMemAllocErr; - break; - } - - // sign message - sts = EpidSign(member, msg, msg_len, basename, basename_len, sig_rl, - sig_rl_size, *sig, *sig_len); - if (kEpidNoErr != sts) { - break; - } - sts = kEpidNoErr; - } while (0); - - PrngDelete(&prng); - EpidMemberDelete(&member); - - if (sig_rl) free(sig_rl); - - return sts; -} diff --git a/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.h b/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.h deleted file mode 100644 index 4426ea93..00000000 --- a/external/epid-sdk-3.0.0/example/signmsg/src/signmsg.h +++ /dev/null @@ -1,42 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Message signing interface. - */ - -#ifndef EXAMPLE_SIGNMSG_SRC_SIGNMSG_H_ -#define EXAMPLE_SIGNMSG_SRC_SIGNMSG_H_ - -#include "epid/member/api.h" -#include "epid/common/file_parser.h" - -/// Check if opaque data blob containing CA certificate is authorized -bool IsCaCertAuthorizedByRootCa(void const* data, size_t size); - -/// Create Intel(R) EPID signature of message -EpidStatus SignMsg(void const* msg, size_t msg_len, void const* basename, - size_t basename_len, unsigned char const* signed_sig_rl, - size_t signed_sig_rl_size, - unsigned char const* signed_pubkey, - size_t signed_pubkey_size, unsigned char const* priv_key, - size_t privkey_size, HashAlg hash_alg, - MemberPrecomp* member_precomp, bool member_precomp_is_input, - EpidSignature** sig, size_t* sig_len, - EpidCaCertificate const* cacert); - -#endif // EXAMPLE_SIGNMSG_SRC_SIGNMSG_H_ diff --git a/external/epid-sdk-3.0.0/example/util/Makefile b/external/epid-sdk-3.0.0/example/util/Makefile deleted file mode 100644 index f55643ae..00000000 --- a/external/epid-sdk-3.0.0/example/util/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/make -f - -#define variables -COMMON_INCLUDE_DIR = ../../ -UTIL_INCLUDE_DIR = ../ - -UTIL_SRC = $(wildcard ./src/*.c) -UTIL_OBJ = $(sort $(UTIL_SRC:.c=.o)) -UTIL_LIB = ./src/libutil.a - -#set additional compiler flag -CFLAGS += -D_CRT_SECURE_NO_WARNINGS - -#target part -$(UTIL_OBJ): %.o: %.c - $(CC) $(CFLAGS) -I$(COMMON_INCLUDE_DIR) \ - -I$(UTIL_INCLUDE_DIR) \ - -c $^ -o $@ - -$(UTIL_LIB): $(UTIL_OBJ) - $(AR) rc $(UTIL_LIB) $(UTIL_OBJ) - ranlib $(UTIL_LIB) - -build: all - -all: $(UTIL_LIB) - -install: - -clean: - rm -f $(UTIL_OBJ) $(UTIL_LIB) - diff --git a/external/epid-sdk-3.0.0/example/util/buffutil.h b/external/epid-sdk-3.0.0/example/util/buffutil.h deleted file mode 100644 index 6c50eb6c..00000000 --- a/external/epid-sdk-3.0.0/example/util/buffutil.h +++ /dev/null @@ -1,159 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Buffer handling utilities interface. - */ -#ifndef EXAMPLE_UTIL_BUFFUTIL_H_ -#define EXAMPLE_UTIL_BUFFUTIL_H_ - -#include -#include "util/stdtypes.h" - -/// Options controlling how a buffer should be printed. -typedef struct BufferPrintOptions { - bool show_header; - bool show_offset; - bool show_hex; - bool show_ascii; - size_t bytes_per_group; - size_t groups_per_line; -} BufferPrintOptions; - -/// Toggle verbose logging -bool ToggleVerbosity(); - -/// Test if file exists -/*! - \param[in] filename - The file path. - - \returns bool -*/ -bool FileExists(char const* filename); - -/// Get file size -/*! - \param[in] filename - - The file path. - \returns size of the file in bytes -*/ -size_t GetFileSize(char const* filename); - -/// Get file size -/*! - checks the size against an expected maximum size. - \param[in] filename - - The file path. - \param[in] max_size - - the maximum expected size of the file. - \returns size of the file in bytes -*/ -size_t GetFileSize_S(char const* filename, size_t max_size); - -/// Allocate a buffer of a fixed size -/*! - Logs an error message on failure. - - \param[out] buffer - A pointer to the buffer to allocate. - \param[in] size - the requested size of the buffer in bytes. - - \returns - A pointer to the allocated buffer or NULL if the allocation failed. - -*/ -void* AllocBuffer(size_t size); - -/// Allocate a buffer to hold the content of a file and load -/*! - Logs an error message on failure. - - \param[in] filename - The file path. - \param[out] size - The allocated size of the buffer in bytes (same as file size). - - \returns - A pointer to the allocated buffer or NULL if the allocation failed. - - \see ToggleVerbosity() -*/ -void* NewBufferFromFile(const char* filename, size_t* size); - -/// Read a buffer from a file with logging -/*! - - Verbosity of logging controlled by verbosity state - - - \param[in] filename - The file path. - \param[in,out] buf - The buffer. - \param[in] size - The size of the buffer in bytes. - - \returns 0 on success, non-zero failure - - \see ToggleVerbosity() -*/ -int ReadLoud(char const* filename, void* buf, size_t size); - -/// write a buffer from a file with logging -/*! - - Verbosity of logging controlled by verbosity state - - \param[in] buf - The buffer. - \param[in] size - The size of the buffer in bytes. - \param[in] filename - The file path. - - \returns 0 on success, non-zero failure - - \see ToggleVerbosity() -*/ -int WriteLoud(void* buf, size_t size, char const* filename); - -/// print a buffer to standard out using user provided options -/*! - \param[in] buf - The buffer. - \param[in] size - The size of the buffer in bytes. - \param[in] opts - The formatting options. -*/ -void PrintBufferOpt(const void* buffer, size_t size, BufferPrintOptions opts); - -/// print a buffer to standard out using default options -/*! - \param[in] buf - The buffer. - \param[in] size - The size of the buffer in bytes. -*/ -void PrintBuffer(const void* buffer, size_t size); - -#endif // EXAMPLE_UTIL_BUFFUTIL_H_ diff --git a/external/epid-sdk-3.0.0/example/util/convutil.h b/external/epid-sdk-3.0.0/example/util/convutil.h deleted file mode 100644 index 83aeb9ab..00000000 --- a/external/epid-sdk-3.0.0/example/util/convutil.h +++ /dev/null @@ -1,77 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Conversion utilities interface. - */ -#ifndef EXAMPLE_UTIL_CONVUTIL_H_ -#define EXAMPLE_UTIL_CONVUTIL_H_ - -#include -#include "epid/common/types.h" -#include "epid/common/file_parser.h" -#include "util/stdtypes.h" - -/// convert a hash algorithm to a string -/*! - \param[in] alg a hash algorithm - \returns string representing the algorithm -*/ -char const* HashAlgToString(HashAlg alg); - -/// convert a string to a hash algorithm -/*! - \param[in] str a string - \param[out] alg a hash algorithm - \retval true string represents a hash algorithm - \retval false string does not represent a hash algorithm -*/ -bool StringToHashAlg(char const* str, HashAlg* alg); - -/// convert an EPID version to a string -/*! -\param[in] version an EPID version -\returns string representing the version -*/ -char const* EpidVersionToString(EpidVersion version); - -/// convert a string to an EPID version -/*! -\param[in] str a string -\param[out] version an EPID version -\retval true string represents an EPID version -\retval false string does not represent an EPID version -*/ -bool StringToEpidVersion(char const* str, EpidVersion* version); - -/// convert an EPID file type to a string -/*! -\param[in] type an EPID file type -\returns string representing the algorithm -*/ -char const* EpidFileTypeToString(EpidFileType type); - -/// convert a string to an EPID file type -/*! -\param[in] str a string -\param[out] type an EPID file type -\retval true string represents an EPID file type -\retval false string does not represent an EPID file type -*/ -bool StringToEpidFileType(char const* str, EpidFileType* type); - -#endif // EXAMPLE_UTIL_CONVUTIL_H_ diff --git a/external/epid-sdk-3.0.0/example/util/envutil.h b/external/epid-sdk-3.0.0/example/util/envutil.h deleted file mode 100644 index 794f2298..00000000 --- a/external/epid-sdk-3.0.0/example/util/envutil.h +++ /dev/null @@ -1,54 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Environment utilities interface. - */ -#ifndef EXAMPLE_UTIL_ENVUTIL_H_ -#define EXAMPLE_UTIL_ENVUTIL_H_ - -/// set the program name -void set_prog_name(char const* name); - -/// get the program name -char const* get_prog_name(); - -/// log an error -/*! -This function may add or format the message before writing it out - -output is written to the error stream -*/ -int log_error(char const* msg, ...); - -/// log a message -/*! -This function may add or format the message before writing it out - -output is written to the standard output stream -*/ -int log_msg(char const* msg, ...); - -/// log a formatted message -/*! -This function will not add or format the message before writing it out - -output is written to the standard output stream -*/ -int log_fmt(char const* msg, ...); - -#endif // EXAMPLE_UTIL_ENVUTIL_H_ diff --git a/external/epid-sdk-3.0.0/example/util/src/bufutil.c b/external/epid-sdk-3.0.0/example/util/src/bufutil.c deleted file mode 100644 index adfb337b..00000000 --- a/external/epid-sdk-3.0.0/example/util/src/bufutil.c +++ /dev/null @@ -1,364 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Buffer handling utilities implementation. - */ - -#include - -#include -#include -#include -#include "util/envutil.h" - -/// file static variable that indicates verbose logging -static bool g_bufutil_verbose = false; - -bool ToggleVerbosity() { - g_bufutil_verbose = (g_bufutil_verbose) ? false : true; - return g_bufutil_verbose; -} - -bool FileExists(char const* filename) { - FILE* fp = NULL; - if (!filename || !filename[0]) { - return false; - } - fp = fopen(filename, "rb"); - if (fp) { - fclose(fp); - return true; - } - return false; -} - -size_t GetFileSize(char const* filename) { - size_t file_length = 0; - FILE* fp = fopen(filename, "rb"); - if (fp) { - fseek(fp, 0, SEEK_END); - file_length = ftell(fp); - fclose(fp); - } - return file_length; -} - -size_t GetFileSize_S(char const* filename, size_t max_size) { - size_t size = GetFileSize(filename); - if (size > max_size) { - return 0; - } else { - return size; - } -} - -void* AllocBuffer(size_t size) { - void* buffer = NULL; - if (size) { - buffer = malloc(size); - } - if (!buffer) { - log_error("failed to allocate memory"); - } - return buffer; -} - -void* NewBufferFromFile(const char* filename, size_t* size) { - void* buffer = NULL; - - do { - size_t len = 0; - - if (!FileExists(filename)) { - log_error("cannot access '%s'", filename); - break; - } - - len = GetFileSize_S(filename, SIZE_MAX); - if (len == 0) { - log_error("cannot load empty file '%s'", filename); - break; - } - - buffer = AllocBuffer(len); - - if (buffer) { - if (0 != ReadLoud(filename, buffer, len)) { - free(buffer); - buffer = NULL; - break; - } - } - - if (size) { - *size = len; - } - } while (0); - return buffer; -} - -int ReadBufferFromFile(const char* filename, void* buffer, size_t size) { - int result = 0; - FILE* file = NULL; - do { - size_t bytes_read = 0; - size_t file_size = 0; - file = fopen(filename, "rb"); - if (!file) { - result = -1; - break; - } - fseek(file, 0, SEEK_END); - file_size = ftell(file); - fseek(file, 0, SEEK_SET); - if ((size_t)file_size != size) { - result = -1; - break; - } - - if (buffer && (0 != size)) { - bytes_read = fread(buffer, 1, size, file); - if (bytes_read != size) { - result = -1; - break; - } - } - } while (0); - - if (file) { - fclose(file); - } - - return result; -} - -int WriteBufferToFile(const void* buffer, size_t size, const char* filename) { - int result = 0; - FILE* file = NULL; - do { - size_t bytes_written = 0; - - file = fopen(filename, "wb"); - if (!file) { - result = -1; - break; - } - bytes_written = fwrite(buffer, 1, size, file); - if (bytes_written != size) { - result = -1; - break; - } - } while (0); - - if (file) { - fclose(file); - } - - return result; -} - -int ReadLoud(char const* filename, void* buf, size_t size) { - int result; - - if (!buf || 0 == size) { - log_error("internal error: invalid buffer to ReadLoud"); - return -1; - } - - if (g_bufutil_verbose) { - log_msg("reading %s", filename); - } - - if (!FileExists(filename)) { - log_error("cannot access '%s' for reading", filename); - return -1; - } - - if (size != GetFileSize(filename)) { - log_error("unexpected file size for '%s'. Expected: %d; got: %d", filename, - (int)size, (int)GetFileSize(filename)); - return -1; - } - - result = ReadBufferFromFile(filename, buf, size); - if (0 != result) { - log_error("failed to read from `%s`", filename); - return result; - } - - if (g_bufutil_verbose) { - PrintBuffer(buf, size); - } - - return result; -} - -int WriteLoud(void* buf, size_t size, char const* filename) { - int result = -1; - - if (!buf || 0 == size) { - log_error("internal error: invalid buffer to WriteLoud"); - return -1; - } - - if (g_bufutil_verbose) { - log_msg("writing %s", filename); - } - - result = WriteBufferToFile(buf, size, filename); - - if (0 != result) { - log_error("failed to write to `%s`", filename); - return result; - } - - if (g_bufutil_verbose) { - PrintBuffer(buf, size); - } - - return result; -} - -void PrintBuffer(const void* buffer, size_t size) { - BufferPrintOptions opts; - opts.show_header = true; - opts.show_offset = true; - opts.show_hex = true; - opts.show_ascii = true; - opts.bytes_per_group = 2; - opts.groups_per_line = 8; - PrintBufferOpt(buffer, size, opts); -} - -void PrintBufferOpt(const void* buffer, size_t size, BufferPrintOptions opts) { - unsigned char* bytes = (unsigned char*)buffer; - size_t bytes_per_line = opts.bytes_per_group * opts.groups_per_line; - size_t line_offset = 0; - size_t byte_offset = 0; - size_t byte_col = 0; - if (opts.show_header) { - if (opts.show_offset) { - log_fmt(" offset"); - log_fmt(": "); - } - - if (opts.show_hex) { - byte_col = 0; - while (byte_col < bytes_per_line) { - log_fmt("%x%x", (int)byte_col, (int)byte_col); - if (0 == (byte_col + 1) % opts.bytes_per_group) { - log_fmt(" "); - } - byte_col += 1; - } - } - - if (opts.show_hex && opts.show_ascii) { - log_fmt("| "); - } - - if (opts.show_ascii) { - byte_col = 0; - while (byte_col < bytes_per_line) { - log_fmt("%x", (int)byte_col); - byte_col += 1; - } - } - - log_fmt("\n"); - - if (opts.show_offset) { - log_fmt("--------"); - log_fmt(": "); - } - - if (opts.show_hex) { - byte_col = 0; - while (byte_col < bytes_per_line) { - log_fmt("--"); - if (0 == (byte_col + 1) % opts.bytes_per_group) { - log_fmt("-"); - } - byte_col += 1; - } - } - - if (opts.show_hex && opts.show_ascii) { - log_fmt("|-"); - } - - if (opts.show_ascii) { - byte_col = 0; - while (byte_col < bytes_per_line) { - log_fmt("-"); - byte_col += 1; - } - } - log_fmt("\n"); - } - - line_offset = 0; - - while (line_offset < size) { - if (opts.show_offset) { - log_fmt("%08x", (int)line_offset); - log_fmt(": "); - } - - if (opts.show_hex) { - byte_col = 0; - while (byte_col < bytes_per_line) { - byte_offset = line_offset + byte_col; - if (byte_offset < size) { - log_fmt("%02x", (int)bytes[byte_offset]); - } else { - log_fmt(" "); - } - if (0 == (byte_col + 1) % opts.bytes_per_group) { - log_fmt(" "); - } - byte_col += 1; - } - } - - if (opts.show_hex && opts.show_ascii) { - log_fmt("| "); - } - - if (opts.show_ascii) { - byte_col = 0; - while (byte_col < bytes_per_line) { - byte_offset = line_offset + byte_col; - if (byte_offset < size) { - unsigned char ch = bytes[byte_offset]; - if (isprint(ch)) { - log_fmt("%c", ch); - } else { - log_fmt("."); - } - } else { - log_fmt(" "); - } - byte_col += 1; - } - } - - log_fmt("\n"); - line_offset += bytes_per_line; - } -} diff --git a/external/epid-sdk-3.0.0/example/util/src/convutil.c b/external/epid-sdk-3.0.0/example/util/src/convutil.c deleted file mode 100644 index 4a57c68a..00000000 --- a/external/epid-sdk-3.0.0/example/util/src/convutil.c +++ /dev/null @@ -1,95 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Conversion utilities implementation. - * - */ - -#include -#include -#include -#include "util/convutil.h" -#include "util/envutil.h" - -const char* hash_alg_to_string[] = {"SHA-256", "SHA-384", "SHA-512", - "SHA-512/256", "SHA3/256", "SHA3/384", - "SHA3/512"}; - -#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) - -char const* HashAlgToString(HashAlg alg) { - if ((int)alg < 0 || (size_t)alg >= COUNT_OF(hash_alg_to_string)) - return "unknown"; - return hash_alg_to_string[alg]; -} - -bool StringToHashAlg(char const* str, HashAlg* alg) { - size_t i; - if (!alg || !str) return false; - for (i = 0; i < COUNT_OF(hash_alg_to_string); i++) { - if (0 == strcmp(str, hash_alg_to_string[i])) { - *alg = (HashAlg)i; - return true; - } - } - return false; -} - -const char* epid_version_to_string[kNumEpidVersions] = {"1", "2"}; - -char const* EpidVersionToString(EpidVersion version) { - if ((int)version < 0 || (size_t)version >= COUNT_OF(epid_version_to_string)) - return "unknown"; - return epid_version_to_string[version]; -} - -bool StringToEpidVersion(char const* str, EpidVersion* version) { - size_t i; - if (!version || !str) return false; - for (i = 0; i < COUNT_OF(epid_version_to_string); i++) { - if (0 == strcmp(str, epid_version_to_string[i])) { - *version = (EpidVersion)i; - return true; - } - } - log_error("epid version \"%s\" is unknown", str); - return false; -} - -const char* epid_file_type_to_string[kNumFileTypes] = { - "IssuingCaPubKey", "GroupPubKey", "PrivRl", "SigRl", "GroupRl"}; - -char const* EpidFileTypeToString(EpidFileType type) { - if ((int)type < 0 || (size_t)type >= COUNT_OF(epid_file_type_to_string)) - return "unknown"; - return epid_file_type_to_string[type]; -} - -bool StringToEpidFileType(char const* str, EpidFileType* type) { - size_t i; - if (!type || !str) return false; - for (i = 0; i < COUNT_OF(epid_file_type_to_string); i++) { - if (0 == strcmp(str, epid_file_type_to_string[i])) { - *type = (EpidFileType)i; - return true; - } - } - log_error("epid file type \"%s\" is unknown", str); - return false; -} diff --git a/external/epid-sdk-3.0.0/example/util/src/envutil.c b/external/epid-sdk-3.0.0/example/util/src/envutil.c deleted file mode 100644 index dbec1788..00000000 --- a/external/epid-sdk-3.0.0/example/util/src/envutil.c +++ /dev/null @@ -1,91 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Environment utilities implementation. - */ - -#include -#include -#include "util/envutil.h" - -static char const* prog_name = NULL; - -void set_prog_name(char const* name) { prog_name = name; } - -char const* get_prog_name() { return prog_name; } - -int log_error(char const* msg, ...) { - int result = 0; - int local_result = 0; - va_list args; - va_start(args, msg); - do { - local_result = fprintf(stderr, "%s: ", prog_name); - if (local_result < 0) { - result = local_result; - break; - } - result += local_result; - local_result = vfprintf(stderr, msg, args); - if (local_result < 0) { - result = local_result; - break; - } - result += local_result; - local_result = fprintf(stderr, "\n"); - if (local_result < 0) { - result = local_result; - break; - } - result += local_result; - } while (0); - va_end(args); - return result; -} - -int log_msg(char const* msg, ...) { - int result = 0; - int local_result = 0; - va_list args; - va_start(args, msg); - do { - local_result = vfprintf(stdout, msg, args); - if (local_result < 0) { - result = local_result; - break; - } - result += local_result; - local_result = fprintf(stdout, "\n"); - if (local_result < 0) { - result = local_result; - break; - } - result += local_result; - } while (0); - va_end(args); - return result; -} - -int log_fmt(char const* msg, ...) { - int result = 0; - va_list args; - va_start(args, msg); - result = vfprintf(stdout, msg, args); - va_end(args); - return result; -} diff --git a/external/epid-sdk-3.0.0/example/util/src/strutil.c b/external/epid-sdk-3.0.0/example/util/src/strutil.c deleted file mode 100644 index 2080fc17..00000000 --- a/external/epid-sdk-3.0.0/example/util/src/strutil.c +++ /dev/null @@ -1,53 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Buffer handling utilities implementation. - */ - -#include -#include - -#include -#if defined(_MSC_VER) && _MSC_VER < 1900 -int vsnprintf(char* outBuf, size_t size, const char* format, va_list ap) { - int count = -1; - - if (0 != size) { - count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); - } - if (-1 == count) { - // vsnprintf returns "The number of characters that would have been - // written if n had been sufficiently large" however _vsnprintf_s - // returns -1 if the content was truncated. - // _vscprintf calculates that value - count = _vscprintf(format, ap); - } - return count; -} - -int snprintf(char* outBuf, size_t size, const char* format, ...) { - int count; - va_list ap; - - va_start(ap, format); - count = vsnprintf(outBuf, size, format, ap); - va_end(ap); - - return count; -} -#endif diff --git a/external/epid-sdk-3.0.0/example/util/util.parts b/external/epid-sdk-3.0.0/example/util/util.parts deleted file mode 100644 index 881dfe32..00000000 --- a/external/epid-sdk-3.0.0/example/util/util.parts +++ /dev/null @@ -1,61 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("util") - -src_files = Pattern(src_dir='src', - includes=['*.c'], - recursive=True).files() - -api_headers = Pattern(src_dir='.', - includes=['*.h'], - recursive=False).files() -parts_file = ['util.parts'] - -makefile = ['Makefile'] -#unit tests -utest_files = Pattern(src_dir='.', - includes=['*-test.cc', '*-testhelper.cc'], - excludes=[], - recursive=True).files() - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='example/${PART_SHORT_NAME}/src') - env.InstallTopLevel(api_headers, sub_dir='example/${PART_SHORT_NAME}') - env.InstallTopLevel(utest_files, sub_dir='example/${PART_SHORT_NAME}/utest') - env.InstallTopLevel(parts_file, sub_dir='example/${PART_SHORT_NAME}') - env.InstallTopLevel(makefile, sub_dir='example/${PART_SHORT_NAME}') -else: - env.DependsOn([Component('common', requires=REQ.HEADERS)]) - - env.Append(CPPPATH='#/example') - - testenv = env.Clone() - - env.SdkInclude(api_headers, sub_dir='${PART_SHORT_NAME}') - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - #env.Append(CPPDEFINES = 'ENABLE_UTIL_DEBUG_PRINT_') - env.Append(CPPDEFINES='_CRT_SECURE_NO_WARNINGS') - - outputs = env.Library('${PART_NAME}', src_files) - - env.Sdk(outputs) diff --git a/external/epid-sdk-3.0.0/example/verifysig/src/main.c b/external/epid-sdk-3.0.0/example/verifysig/src/main.c deleted file mode 100644 index 951f9232..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/src/main.c +++ /dev/null @@ -1,501 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Verifysig example implementation. - */ - -#include -#include -#include - -#include -#include "epid/common/errors.h" -#include "epid/common/types.h" -#include "epid/common/file_parser.h" -#include "epid/verifier/api.h" -#include "epid/verifier/1.1/api.h" - -#include "util/buffutil.h" -#include "util/convutil.h" -#include "util/envutil.h" -#include "src/verifysig.h" -#include "src/verifysig11.h" - -// Defaults -#define PROGRAM_NAME "verifysig" -#define PUBKEYFILE_DEFAULT "pubkey.bin" -#define PRIVRL_DEFAULT NULL -#define SIGRL_DEFAULT NULL -#define GRPRL_DEFAULT "grprl.bin" -#define VERIFIERRL_DEFAULT NULL -#define SIG_DEFAULT "sig.dat" -#define CACERT_DEFAULT "cacert.bin" -#define HASHALG_DEFAULT "SHA-512" -#define UNPARSED_HASHALG (kInvalidHashAlg) -#define VPRECMPI_DEFAULT NULL -#define VPRECMPO_DEFAULT NULL - -/// parses string to a hashalg type -static dropt_error HandleHashalg(dropt_context* context, - const char* option_argument, - void* handler_data) { - dropt_error err = dropt_error_none; - HashAlg* hashalg = handler_data; - (void)context; - if (option_argument == NULL) { - *hashalg = UNPARSED_HASHALG; - } else if (option_argument[0] == '\0') { - err = dropt_error_insufficient_arguments; - } else if (StringToHashAlg(option_argument, hashalg)) { - err = dropt_error_none; - } else { - /* Reject the value as being inappropriate for this handler. */ - err = dropt_error_mismatch; - } - return err; -} - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_SUCCESS; - // intermediate return value for EPID functions - EpidStatus result = kEpidErr; - - // User Settings - - // Signature file name parameter - static char* sig_file = SIG_DEFAULT; - - // Message string parameter - static char* msg_str = NULL; - size_t msg_size = 0; - - // Basename string parameter - static char* basename_str = NULL; - size_t basename_size = 0; - - // PrivRl file name parameter - static char* privrl_file = NULL; - - // SigRl file name parameter - static char* sigrl_file = NULL; - - // GrpRl file name parameter - static char* grprl_file = NULL; - - // VerRl file name parameter - static char* verrl_file = NULL; - - // Group public key file name parameter - static char* pubkey_file = NULL; - - // Verifier pre-computed settings input file name parameter - static char* vprecmpi_file = NULL; - - // Verifier pre-computed settings output file name parameter - static char* vprecmpo_file = NULL; - - // CA certificate file name parameter - static char* cacert_file_name = NULL; - - // Verbose flag parameter - static bool verbose = false; - - // help flag parameter - static bool show_help = false; - - // Buffers and computed values - - // Signature buffer - void* sig = NULL; - size_t sig_size = 0; - - // PrivRl buffer - void* signed_priv_rl = NULL; - size_t signed_priv_rl_size = 0; - - // SigRl buffer - void* signed_sig_rl = NULL; - size_t signed_sig_rl_size = 0; - - // GrpRl buffer - void* signed_grp_rl = NULL; - size_t signed_grp_rl_size = 0; - - // VerRl buffer - VerifierRl* ver_rl = NULL; - size_t ver_rl_size = 0; - - // Group public key buffer - void* signed_pubkey = NULL; - size_t signed_pubkey_size = 0; - - // Verifier pre-computed settings - void* verifier_precmp = NULL; - size_t verifier_precmp_size = 0; - size_t vprecmpi_file_size = 0; - - // Flag that Verifier pre-computed settings input is valid - bool use_precmp_in; - - // CA certificate - EpidCaCertificate cacert = {0}; - // Hash algorithm - static HashAlg hashalg = UNPARSED_HASHALG; - - dropt_option options[] = { - {'\0', "sig", "load signature from FILE (default: " SIG_DEFAULT ")", - "FILE", dropt_handle_string, &sig_file}, - {'\0', "msg", "MESSAGE that was signed (default: empty)", "MESSAGE", - dropt_handle_string, &msg_str}, - {'\0', "bsn", "BASENAME used in signature (default: random)", "BASENAME", - dropt_handle_string, &basename_str}, - {'\0', "privrl", "load private key revocation list from FILE", "FILE", - dropt_handle_string, &privrl_file}, - {'\0', "sigrl", "load signature based revocation list from FILE", "FILE", - dropt_handle_string, &sigrl_file}, - {'\0', "grprl", - "load group revocation list from FILE\n (default: " GRPRL_DEFAULT ")", - "FILE", dropt_handle_string, &grprl_file}, - {'\0', "verifierrl", "load verifier revocation list from FILE", "FILE", - dropt_handle_string, &verrl_file}, - {'\0', "gpubkey", - "load group public key from FILE (default: " PUBKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &pubkey_file}, - {'\0', "vprecmpi", "load pre-computed verifier data from FILE", "FILE", - dropt_handle_string, &vprecmpi_file}, - {'\0', "vprecmpo", "write pre-computed verifier data to FILE", "FILE", - dropt_handle_string, &vprecmpo_file}, - {'\0', "capubkey", - "load IoT Issuing CA public key from FILE\n (default: " CACERT_DEFAULT - ")", - "FILE", dropt_handle_string, &cacert_file_name}, - {'\0', "hashalg", - "use specified hash algorithm for 2.0 groups " - "(default: " HASHALG_DEFAULT ")", - "{SHA-256 | SHA-384 | SHA-512}", HandleHashalg, &hashalg}, - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - - // set program name for logging - set_prog_name(PROGRAM_NAME); - do { - EpidVersion epid_version = kNumEpidVersions; - // Read command line args - - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - ret_value = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]...\n" - "Verify signature was created by group member in good standing\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else if (*rest) { - // we have unparsed (positional) arguments - log_error("invalid argument: %s", *rest); - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } else { - if (verbose) { - verbose = ToggleVerbosity(); - } - if (!sig_file) sig_file = SIG_DEFAULT; - if (!grprl_file) grprl_file = GRPRL_DEFAULT; - if (!pubkey_file) pubkey_file = PUBKEYFILE_DEFAULT; - if (!cacert_file_name) cacert_file_name = CACERT_DEFAULT; - if (msg_str) msg_size = strlen(msg_str); - if (basename_str) basename_size = strlen(basename_str); - - if (verbose) { - log_msg("\nOption values:"); - log_msg(" sig_file : %s", sig_file); - log_msg(" msg_str : %s", msg_str); - log_msg(" basename_str : %s", basename_str); - log_msg(" privrl_file : %s", privrl_file); - log_msg(" sigrl_file : %s", sigrl_file); - log_msg(" grprl_file : %s", grprl_file); - log_msg(" verrl_file : %s", verrl_file); - log_msg(" vprecmpi_file : %s", vprecmpi_file); - log_msg(" vprecmpo_file : %s", vprecmpo_file); - log_msg(" hashalg : %s", (UNPARSED_HASHALG == hashalg) - ? "(default)" - : HashAlgToString(hashalg)); - log_msg(" cacert_file_name : %s", cacert_file_name); - log_msg(""); - } - } - } - // convert command line args to usable formats - - // Signature - sig = NewBufferFromFile(sig_file, &sig_size); - if (!sig) { - ret_value = EXIT_FAILURE; - break; - } - - // PrivRl - if (privrl_file) { - signed_priv_rl = NewBufferFromFile(privrl_file, &signed_priv_rl_size); - if (!signed_priv_rl) { - ret_value = EXIT_FAILURE; - break; - } - } - - // SigRl - if (sigrl_file) { - signed_sig_rl = NewBufferFromFile(sigrl_file, &signed_sig_rl_size); - if (!signed_sig_rl) { - ret_value = EXIT_FAILURE; - break; - } - } - - // GrpRl - signed_grp_rl = NewBufferFromFile(grprl_file, &signed_grp_rl_size); - if (!signed_grp_rl) { - ret_value = EXIT_FAILURE; - break; - } - // VerRl - if (verrl_file) { - ver_rl = (VerifierRl*)NewBufferFromFile(verrl_file, &ver_rl_size); - if (!ver_rl) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Group public key - signed_pubkey = NewBufferFromFile(pubkey_file, &signed_pubkey_size); - if (!signed_pubkey) { - ret_value = EXIT_FAILURE; - break; - } - - // CA certificate - if (0 != ReadLoud(cacert_file_name, &cacert, sizeof(cacert))) { - ret_value = EXIT_FAILURE; - break; - } - - // Security note: - // Application must confirm that IoT EPID Issuing CA certificate is - // authorized by IoT EPID Root CA, e.g., signed by IoT EPID Root CA. - if (!IsCaCertAuthorizedByRootCa(&cacert, sizeof(cacert))) { - log_error("CA certificate is not authorized"); - ret_value = EXIT_FAILURE; - break; - } - - // Detect EPID version - result = EpidParseFileHeader(signed_pubkey, signed_pubkey_size, - &epid_version, NULL); - if (kEpidNoErr != result || kNumEpidVersions <= epid_version) { - log_error("EPID version can not be detected"); - ret_value = EXIT_FAILURE; - break; - } - - // Configure hashalg based on group - if (kEpid1x == epid_version) { - if (!(kSha256 == hashalg || UNPARSED_HASHALG == hashalg)) { - log_error( - "unsupported hash algorithm: %s only supported for 2.0 groups", - HashAlgToString(hashalg)); - ret_value = EXIT_FAILURE; - break; - } - } else { - if (UNPARSED_HASHALG == hashalg) { - hashalg = kSha512; - } - } - - // Load Verifier pre-computed settings - if (kEpid1x == epid_version) { - verifier_precmp_size = sizeof(Epid11VerifierPrecomp); - } else if (kEpid2x == epid_version) { - verifier_precmp_size = sizeof(VerifierPrecomp); - } else { - log_error("EPID version %s is not supported", - EpidVersionToString(epid_version)); - ret_value = EXIT_FAILURE; - break; - } - verifier_precmp = AllocBuffer(verifier_precmp_size); - use_precmp_in = false; - if (vprecmpi_file) { - vprecmpi_file_size = GetFileSize(vprecmpi_file); - if (verifier_precmp_size != vprecmpi_file_size) { - if (kEpid2x == epid_version && - vprecmpi_file_size == verifier_precmp_size - sizeof(GroupId)) { - log_error( - "incorrect input precomp size: precomp format may have changed, " - "try regenerating it"); - } else { - log_error("incorrect input precomp size"); - } - ret_value = EXIT_FAILURE; - break; - } - use_precmp_in = true; - - if (0 != ReadLoud(vprecmpi_file, verifier_precmp, verifier_precmp_size)) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Verifying Message:"); - log_msg(""); - log_msg(" [in] EPID version: %s", EpidVersionToString(epid_version)); - log_msg(""); - log_msg(" [in] Signature Len: %d", (int)sig_size); - log_msg(" [in] Signature: "); - PrintBuffer(sig, sig_size); - log_msg(""); - log_msg(" [in] Message Len: %d", (int)msg_size); - log_msg(" [in] Message: "); - PrintBuffer(msg_str, msg_size); - log_msg(""); - log_msg(" [in] BaseName Len: %d", (int)basename_size); - log_msg(" [in] BaseName: "); - PrintBuffer(basename_str, basename_size); - log_msg(""); - log_msg(" [in] PrivRl Len: %d", (int)signed_priv_rl_size); - log_msg(" [in] PrivRl: "); - PrintBuffer(signed_priv_rl, signed_priv_rl_size); - log_msg(""); - log_msg(" [in] SigRl Len: %d", (int)signed_sig_rl_size); - log_msg(" [in] SigRl: "); - PrintBuffer(signed_sig_rl, signed_sig_rl_size); - log_msg(""); - log_msg(" [in] GrpRl Len: %d", (int)signed_grp_rl_size); - log_msg(" [in] GrpRl: "); - PrintBuffer(signed_grp_rl, signed_grp_rl_size); - log_msg(""); - log_msg(" [in] VerRl Len: %d", (int)ver_rl_size); - log_msg(" [in] VerRl: "); - PrintBuffer(ver_rl, ver_rl_size); - log_msg(""); - log_msg(" [in] Group Public Key: "); - PrintBuffer(signed_pubkey, sizeof(signed_pubkey_size)); - log_msg(""); - log_msg(" [in] Hash Algorithm: %s", HashAlgToString(hashalg)); - if (use_precmp_in) { - log_msg(""); - log_msg(" [in] Verifier PreComp: "); - PrintBuffer(verifier_precmp, verifier_precmp_size); - } - log_msg("=============================================="); - } - - // Verify - if (kEpid2x == epid_version) { - result = - Verify(sig, sig_size, msg_str, msg_size, basename_str, basename_size, - signed_priv_rl, signed_priv_rl_size, signed_sig_rl, - signed_sig_rl_size, signed_grp_rl, signed_grp_rl_size, ver_rl, - ver_rl_size, signed_pubkey, signed_pubkey_size, &cacert, - hashalg, (VerifierPrecomp*)verifier_precmp, use_precmp_in); - } else if (kEpid1x == epid_version) { - result = Verify11(sig, sig_size, msg_str, msg_size, basename_str, - basename_size, signed_priv_rl, signed_priv_rl_size, - signed_sig_rl, signed_sig_rl_size, signed_grp_rl, - signed_grp_rl_size, signed_pubkey, signed_pubkey_size, - &cacert, (Epid11VerifierPrecomp*)verifier_precmp, - use_precmp_in); - } else { - log_error("EPID version %s is not supported", - EpidVersionToString(epid_version)); - ret_value = EXIT_FAILURE; - break; - } - // Report Result - if (kEpidNoErr == result) { - log_msg("signature verified successfully"); - } else { - log_error("signature verification failed: %s", - EpidStatusToString(result)); - ret_value = result; - break; - } - - // Store Verifier pre-computed settings - if (vprecmpo_file) { - if (0 != - WriteLoud(verifier_precmp, verifier_precmp_size, vprecmpo_file)) { - ret_value = EXIT_FAILURE; - break; - } - } - - // Success - ret_value = EXIT_SUCCESS; - } while (0); - - // Free allocated buffers - if (sig) free(sig); - if (signed_priv_rl) free(signed_priv_rl); - if (signed_sig_rl) free(signed_sig_rl); - if (signed_grp_rl) free(signed_grp_rl); - if (ver_rl) free(ver_rl); - if (signed_pubkey) free(signed_pubkey); - if (verifier_precmp) free(verifier_precmp); - - dropt_free_context(dropt_ctx); - - return ret_value; -} diff --git a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.c b/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.c deleted file mode 100644 index 722231d5..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.c +++ /dev/null @@ -1,211 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Signature verification implementation. - */ - -#include "src/verifysig.h" - -#include - -#include "util/buffutil.h" -#include "util/envutil.h" -#include "epid/verifier/api.h" -#include "epid/common/file_parser.h" - -bool IsCaCertAuthorizedByRootCa(void const* data, size_t size) { - // Implementation of this function is out of scope of the sample. - // In an actual implementation Issuing CA certificate must be validated - // with CA Root certificate before using it in parse functions. - (void)data; - (void)size; - return true; -} - -EpidStatus Verify(EpidSignature const* sig, size_t sig_len, void const* msg, - size_t msg_len, void const* basename, size_t basename_len, - void const* signed_priv_rl, size_t signed_priv_rl_size, - void const* signed_sig_rl, size_t signed_sig_rl_size, - void const* signed_grp_rl, size_t signed_grp_rl_size, - VerifierRl const* ver_rl, size_t ver_rl_size, - void const* signed_pub_key, size_t signed_pub_key_size, - EpidCaCertificate const* cacert, HashAlg hash_alg, - VerifierPrecomp* verifier_precomp, - bool verifier_precomp_is_input) { - EpidStatus result = kEpidErr; - VerifierCtx* ctx = NULL; - PrivRl* priv_rl = NULL; - SigRl* sig_rl = NULL; - GroupRl* grp_rl = NULL; - - do { - GroupPubKey pub_key = {0}; - // authenticate and extract group public key - result = EpidParseGroupPubKeyFile(signed_pub_key, signed_pub_key_size, - cacert, &pub_key); - if (kEpidNoErr != result) { - break; - } - - // create verifier - result = EpidVerifierCreate( - &pub_key, verifier_precomp_is_input ? verifier_precomp : NULL, &ctx); - if (kEpidNoErr != result) { - break; - } - - // serialize verifier pre-computation blob - result = EpidVerifierWritePrecomp(ctx, verifier_precomp); - if (kEpidNoErr != result) { - break; - } - - // set hash algorithm used for signing - result = EpidVerifierSetHashAlg(ctx, hash_alg); - if (kEpidNoErr != result) { - break; - } - - // set the basename used for signing - result = EpidVerifierSetBasename(ctx, basename, basename_len); - if (kEpidNoErr != result) { - break; - } - - if (signed_priv_rl) { - // authenticate and determine space needed for RL - size_t priv_rl_size = 0; - result = EpidParsePrivRlFile(signed_priv_rl, signed_priv_rl_size, cacert, - NULL, &priv_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - priv_rl = AllocBuffer(priv_rl_size); - if (!priv_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = EpidParsePrivRlFile(signed_priv_rl, signed_priv_rl_size, cacert, - priv_rl, &priv_rl_size); - if (kEpidNoErr != result) { - break; - } - - // set private key based revocation list - result = EpidVerifierSetPrivRl(ctx, priv_rl, priv_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_priv_rl) - - if (signed_sig_rl) { - // authenticate and determine space needed for RL - size_t sig_rl_size = 0; - result = EpidParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, - NULL, &sig_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - sig_rl = AllocBuffer(sig_rl_size); - if (!sig_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = EpidParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, - sig_rl, &sig_rl_size); - if (kEpidNoErr != result) { - break; - } - - // set signature based revocation list - result = EpidVerifierSetSigRl(ctx, sig_rl, sig_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_sig_rl) - - if (signed_grp_rl) { - // authenticate and determine space needed for RL - size_t grp_rl_size = 0; - result = EpidParseGroupRlFile(signed_grp_rl, signed_grp_rl_size, cacert, - NULL, &grp_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - grp_rl = AllocBuffer(grp_rl_size); - if (!grp_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = EpidParseGroupRlFile(signed_grp_rl, signed_grp_rl_size, cacert, - grp_rl, &grp_rl_size); - if (kEpidNoErr != result) { - break; - } - // set group revocation list - result = EpidVerifierSetGroupRl(ctx, grp_rl, grp_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_grp_rl) - - if (ver_rl) { - // set verifier based revocation list - result = EpidVerifierSetVerifierRl(ctx, ver_rl, ver_rl_size); - if (kEpidNoErr != result) { - break; - } - } - - // verify signature - result = EpidVerify(ctx, sig, sig_len, msg, msg_len); - if (kEpidNoErr != result) { - break; - } - } while (0); - - // delete verifier - EpidVerifierDelete(&ctx); - - if (priv_rl) free(priv_rl); - if (sig_rl) free(sig_rl); - if (grp_rl) free(grp_rl); - - return result; -} diff --git a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.h b/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.h deleted file mode 100644 index f566e862..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig.h +++ /dev/null @@ -1,42 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief Signature verification interface. - */ -#ifndef EXAMPLE_VERIFYSIG_SRC_VERIFYSIG_H_ -#define EXAMPLE_VERIFYSIG_SRC_VERIFYSIG_H_ - -#include "epid/verifier/api.h" -#include "epid/common/file_parser.h" - -/// Check if opaque data blob containing CA certificate is authorized -bool IsCaCertAuthorizedByRootCa(void const* data, size_t size); - -/// verify EPID 2.x signature -EpidStatus Verify(EpidSignature const* sig, size_t sig_len, void const* msg, - size_t msg_len, void const* basename, size_t basename_len, - void const* signed_priv_rl, size_t signed_priv_rl_size, - void const* signed_sig_rl, size_t signed_sig_rl_size, - void const* signed_grp_rl, size_t signed_grp_rl_size, - VerifierRl const* ver_rl, size_t ver_rl_size, - void const* signed_pub_key, size_t signed_pub_key_size, - EpidCaCertificate const* cacert, HashAlg hash_alg, - VerifierPrecomp* verifier_precomp, - bool verifier_precomp_is_input); - -#endif // EXAMPLE_VERIFYSIG_SRC_VERIFYSIG_H_ diff --git a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.c b/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.c deleted file mode 100644 index bf440009..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.c +++ /dev/null @@ -1,187 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EPID 1.1 signature verification implementation. - */ - -#include "src/verifysig11.h" - -#include - -#include "util/buffutil.h" -#include "util/envutil.h" -#include "epid/verifier/1.1/api.h" -#include "epid/common/1.1/file_parser.h" - -EpidStatus Verify11(Epid11Signature const* sig, size_t sig_len, void const* msg, - size_t msg_len, void const* basename, size_t basename_len, - void const* signed_priv_rl, size_t signed_priv_rl_size, - void const* signed_sig_rl, size_t signed_sig_rl_size, - void const* signed_grp_rl, size_t signed_grp_rl_size, - void const* signed_pub_key, size_t signed_pub_key_size, - EpidCaCertificate const* cacert, - Epid11VerifierPrecomp* verifier_precomp, - bool verifier_precomp_is_input) { - EpidStatus result = kEpidErr; - Epid11VerifierCtx* ctx = NULL; - Epid11PrivRl* priv_rl = NULL; - Epid11SigRl* sig_rl = NULL; - Epid11GroupRl* grp_rl = NULL; - - do { - Epid11GroupPubKey pub_key = {0}; - // authenticate and extract group public key - result = Epid11ParseGroupPubKeyFile(signed_pub_key, signed_pub_key_size, - cacert, &pub_key); - if (kEpidNoErr != result) { - break; - } - - // create verifier - result = Epid11VerifierCreate( - &pub_key, verifier_precomp_is_input ? verifier_precomp : NULL, &ctx); - if (kEpidNoErr != result) { - break; - } - - // serialize verifier pre-computation blob - result = Epid11VerifierWritePrecomp(ctx, verifier_precomp); - if (kEpidNoErr != result) { - break; - } - - // set the basename used for signing - result = Epid11VerifierSetBasename(ctx, basename, basename_len); - if (kEpidNoErr != result) { - break; - } - - if (signed_priv_rl) { - // authenticate and determine space needed for RL - size_t priv_rl_size = 0; - result = Epid11ParsePrivRlFile(signed_priv_rl, signed_priv_rl_size, - cacert, NULL, &priv_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - priv_rl = AllocBuffer(priv_rl_size); - if (!priv_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = Epid11ParsePrivRlFile(signed_priv_rl, signed_priv_rl_size, - cacert, priv_rl, &priv_rl_size); - if (kEpidNoErr != result) { - break; - } - - // set private key based revocation list - result = Epid11VerifierSetPrivRl(ctx, priv_rl, priv_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_priv_rl) - - if (signed_sig_rl) { - // authenticate and determine space needed for RL - size_t sig_rl_size = 0; - result = Epid11ParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, - NULL, &sig_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - sig_rl = AllocBuffer(sig_rl_size); - if (!sig_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = Epid11ParseSigRlFile(signed_sig_rl, signed_sig_rl_size, cacert, - sig_rl, &sig_rl_size); - if (kEpidNoErr != result) { - break; - } - - // set signature based revocation list - result = Epid11VerifierSetSigRl(ctx, sig_rl, sig_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_sig_rl) - - if (signed_grp_rl) { - // authenticate and determine space needed for RL - size_t grp_rl_size = 0; - result = Epid11ParseGroupRlFile(signed_grp_rl, signed_grp_rl_size, cacert, - NULL, &grp_rl_size); - if (kEpidSigInvalid == result) { - // authentication failure - break; - } - if (kEpidNoErr != result) { - break; - } - - grp_rl = AllocBuffer(grp_rl_size); - if (!grp_rl) { - result = kEpidMemAllocErr; - break; - } - - // fill the rl - result = Epid11ParseGroupRlFile(signed_grp_rl, signed_grp_rl_size, cacert, - grp_rl, &grp_rl_size); - if (kEpidNoErr != result) { - break; - } - // set group revocation list - result = Epid11VerifierSetGroupRl(ctx, grp_rl, grp_rl_size); - if (kEpidNoErr != result) { - break; - } - } // if (signed_grp_rl) - - // verify signature - result = Epid11Verify(ctx, sig, sig_len, msg, msg_len); - if (kEpidNoErr != result) { - break; - } - } while (0); - - // delete verifier - Epid11VerifierDelete(&ctx); - - if (priv_rl) free(priv_rl); - if (sig_rl) free(sig_rl); - if (grp_rl) free(grp_rl); - - return result; -} diff --git a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.h b/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.h deleted file mode 100644 index a3463882..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/src/verifysig11.h +++ /dev/null @@ -1,38 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * \brief EPID 1.1 signature verification interface. - */ -#ifndef EXAMPLE_VERIFYSIG_SRC_VERIFYSIG11_H_ -#define EXAMPLE_VERIFYSIG_SRC_VERIFYSIG11_H_ - -#include "epid/verifier/1.1/api.h" -#include "epid/common/1.1/file_parser.h" - -/// verify EPID 1.x signature -EpidStatus Verify11(Epid11Signature const* sig, size_t sig_len, void const* msg, - size_t msg_len, void const* basename, size_t basename_len, - void const* signed_priv_rl, size_t signed_priv_rl_size, - void const* signed_sig_rl, size_t signed_sig_rl_size, - void const* signed_grp_rl, size_t signed_grp_rl_size, - void const* signed_pub_key, size_t signed_pub_key_size, - EpidCaCertificate const* cacert, - Epid11VerifierPrecomp* verifier_precomp, - bool verifier_precomp_is_input); - -#endif // EXAMPLE_VERIFYSIG_SRC_VERIFYSIG11_H_ diff --git a/external/epid-sdk-3.0.0/example/verifysig/verifysig.parts b/external/epid-sdk-3.0.0/example/verifysig/verifysig.parts deleted file mode 100644 index 68b62dfb..00000000 --- a/external/epid-sdk-3.0.0/example/verifysig/verifysig.parts +++ /dev/null @@ -1,53 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("verifysig") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() - -inc_files = Pattern(src_dir='src/', - includes=['*.h'], - recursive=True).files() - -parts_file = ['verifysig.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files + inc_files, sub_dir='example/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='example/${PART_SHORT_NAME}') - -else: - env.DependsOn([ - Component('verifier'), - Component('util'), - Component('dropt') - ]) - - env.Append(CPPPATH='#/example/verifysig') - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_SAMPLE_BIN}') diff --git a/external/epid-sdk-3.0.0/ext/dropt/LICENSE b/external/epid-sdk-3.0.0/ext/dropt/LICENSE deleted file mode 100644 index aa487e17..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -dropt -Copyright (c) 2006-2012 James D. Lin - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - -3. This notice may not be removed or altered from any source distribution. - - diff --git a/external/epid-sdk-3.0.0/ext/dropt/Makefile b/external/epid-sdk-3.0.0/ext/dropt/Makefile deleted file mode 100644 index c284c3cb..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/make -f - -DROPT_INCLUDE_DIR = ./include -DROPT_SRC = $(wildcard ./src/*.c) -DROPT_OBJ = $(sort $(DROPT_SRC:.c=.o)) - -DROPT_LIB = ./src/libdropt.a - -$(DROPT_OBJ): %.o: %.c - $(CC) -o $@ -c $(CFLAGS) -I$(DROPT_INCLUDE_DIR) $< - -$(DROPT_LIB): $(DROPT_OBJ) - $(AR) rc $@ $^ - ranlib $@ - -build: all - -all: $(DROPT_LIB) - -install: - -clean: - rm -f $(DROPT_OBJ) $(DROPT_LIB) diff --git a/external/epid-sdk-3.0.0/ext/dropt/include/dropt.h b/external/epid-sdk-3.0.0/ext/dropt/include/dropt.h deleted file mode 100644 index 2cd66b17..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/include/dropt.h +++ /dev/null @@ -1,249 +0,0 @@ -/** dropt.h - * - * A deliberately rudimentary command-line option parser. - * - * Version 1.1.1 - * - * Copyright (c) 2006-2012 James D. Lin - * - * The latest version of this file can be downloaded from: - * - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef DROPT_H -#define DROPT_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifndef DROPT_USE_WCHAR -#if defined _UNICODE && (defined _MSC_VER || defined DROPT_NO_STRING_BUFFERS) -#define DROPT_USE_WCHAR 1 -#endif -#endif - -#ifdef DROPT_USE_WCHAR - /* This may be used for both char and string literals. */ - #define DROPT_TEXT_LITERAL(s) L ## s - - typedef wchar_t dropt_char; -#else - #define DROPT_TEXT_LITERAL(s) s - - typedef char dropt_char; -#endif - - -enum -{ - /* Errors in the range [0x00, 0x7F] are reserved for dropt. */ - dropt_error_none, - dropt_error_unknown, - dropt_error_bad_configuration, - dropt_error_insufficient_memory, - dropt_error_invalid_option, - dropt_error_insufficient_arguments, - dropt_error_mismatch, - dropt_error_overflow, - dropt_error_underflow, - - /* Errors in the range [0x80, 0xFFFF] are free for clients to use. */ - dropt_error_custom_start = 0x80, - dropt_error_custom_last = 0xFFFF -}; -typedef unsigned int dropt_error; - -typedef unsigned char dropt_bool; - -/* Opaque. */ -typedef struct dropt_context dropt_context; - - -/** dropt_option_handler_func callbacks are responsible for parsing - * individual options. - * - * dropt_option_handler_decl may be used for declaring the callback - * functions; dropt_option_handler_func is the actual function pointer - * type. - * - * optionArgument will be NULL if no argument is specified for an option. - * It will be the empty string if the user explicitly passed an empty - * string as the argument (e.g. --option=""). - * - * An option that doesn't expect an argument still can receive a non-NULL - * value for optionArgument if the user explicitly specified one (e.g. - * --option=arg). - * - * If the option's argument is optional, the handler might be called - * twice: once with a candidate argument, and if that argument is rejected - * by the handler, again with no argument. Handlers should be aware of - * this if they have side-effects. - * - * handlerData is the client-specified value specified in the dropt_option - * table. - */ -typedef dropt_error dropt_option_handler_decl(dropt_context* context, - const dropt_char* optionArgument, - void* handlerData); -typedef dropt_option_handler_decl* dropt_option_handler_func; - -/** dropt_error_handler_func callbacks are responsible for generating error - * messages. The returned string must be allocated on the heap and must - * be freeable with free(). - */ -typedef dropt_char* (*dropt_error_handler_func)(dropt_error error, - const dropt_char* optionName, - const dropt_char* optionArgument, - void* handlerData); - -/** dropt_strncmp_func callbacks allow callers to provide their own (possibly - * case-insensitive) string comparison function. - */ -typedef int (*dropt_strncmp_func)(const dropt_char* s, const dropt_char* t, size_t n); - - -/** Properties defining each option: - * - * short_name: - * The option's short name (e.g. the 'h' in -h). - * Use '\0' if the option has no short name. - * - * long_name: - * The option's long name (e.g. "help" in --help). - * Use NULL if the option has no long name. - * - * description: - * The description shown when generating help. - * May be NULL for undocumented options. - * - * arg_description: - * The description for the option's argument (e.g. --option=argument - * or --option argument), printed when generating help. If NULL, the - * option does not take an argument. - * - * handler: - * The handler callback and data invoked in response to encountering - * the option. - * - * handler_data: - * Callback data for the handler. For typical handlers, this is - * usually the address of a variable for the handler to modify. - * - * attr: - * Miscellaneous attributes. See below. - */ -typedef struct dropt_option -{ - dropt_char short_name; - const dropt_char* long_name; - const dropt_char* description; - const dropt_char* arg_description; - dropt_option_handler_func handler; - void* handler_data; - unsigned int attr; -} dropt_option; - - -/** Bitwise flags for option attributes: - * - * dropt_attr_halt: - * Stop processing when this option is encountered. - * - * dropt_attr_hidden: - * Don't list the option when generating help. Use this for - * undocumented options. - * - * dropt_attr_optional_val: - * The option's argument is optional. If an option has this - * attribute, the handler callback may be invoked twice (once with a - * potential argument, and if that fails, again with a NULL argument). - */ -enum -{ - dropt_attr_halt = (1 << 0), - dropt_attr_hidden = (1 << 1), - dropt_attr_optional_val = (1 << 2) -}; - - -typedef struct dropt_help_params -{ - unsigned int indent; - unsigned int description_start_column; - dropt_bool blank_lines_between_options; -} dropt_help_params; - - -dropt_context* dropt_new_context(const dropt_option* options); -void dropt_free_context(dropt_context* context); - -const dropt_option* dropt_get_options(const dropt_context* context); - -void dropt_set_error_handler(dropt_context* context, - dropt_error_handler_func handler, void* handlerData); -void dropt_set_strncmp(dropt_context* context, dropt_strncmp_func cmp); - -/* Use this only for backward compatibility purposes. */ -void dropt_allow_concatenated_arguments(dropt_context* context, dropt_bool allow); - -dropt_char** dropt_parse(dropt_context* context, int argc, dropt_char** argv); - -dropt_error dropt_get_error(const dropt_context* context); -void dropt_get_error_details(const dropt_context* context, - dropt_char** optionName, - dropt_char** optionArgument); -const dropt_char* dropt_get_error_message(dropt_context* context); -void dropt_clear_error(dropt_context* context); - -#ifndef DROPT_NO_STRING_BUFFERS -dropt_char* dropt_default_error_handler(dropt_error error, - const dropt_char* optionName, - const dropt_char* optionArgument); - -void dropt_init_help_params(dropt_help_params* helpParams); -dropt_char* dropt_get_help(const dropt_context* context, - const dropt_help_params* helpParams); -void dropt_print_help(FILE* f, const dropt_context* context, - const dropt_help_params* helpParams); -#endif - - -/* Stock option handlers for common types. */ -dropt_option_handler_decl dropt_handle_bool; -dropt_option_handler_decl dropt_handle_verbose_bool; -dropt_option_handler_decl dropt_handle_int; -dropt_option_handler_decl dropt_handle_uint; -dropt_option_handler_decl dropt_handle_double; -dropt_option_handler_decl dropt_handle_string; - -#define DROPT_MISUSE(message) dropt_misuse(message, __FILE__, __LINE__) -void dropt_misuse(const char* message, const char* filename, int line); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* DROPT_H */ diff --git a/external/epid-sdk-3.0.0/ext/dropt/include/dropt_string.h b/external/epid-sdk-3.0.0/ext/dropt/include/dropt_string.h deleted file mode 100644 index e890c5a9..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/include/dropt_string.h +++ /dev/null @@ -1,94 +0,0 @@ -/** dropt_string.h - * - * String routines for dropt. - * - * Copyright (c) 2006-2010 James D. Lin - * - * The latest version of this file can be downloaded from: - * - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef DROPT_STRING_H -#define DROPT_STRING_H - -#include -#include "dropt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef DROPT_USE_WCHAR - #define dropt_strlen wcslen - #define dropt_strcmp wcscmp - #define dropt_strncmp wcsncmp - #define dropt_strchr wcschr - #define dropt_strtol wcstol - #define dropt_strtoul wcstoul - #define dropt_strtod wcstod - #define dropt_tolower towlower - #define dropt_fputs fputws -#else - #define dropt_strlen strlen - #define dropt_strcmp strcmp - #define dropt_strncmp strncmp - #define dropt_strchr strchr - #define dropt_strtol strtol - #define dropt_strtoul strtoul - #define dropt_strtod strtod - #define dropt_tolower tolower - #define dropt_fputs fputs -#endif - -void* dropt_safe_malloc(size_t numElements, size_t elementSize); -void* dropt_safe_realloc(void* p, size_t numElements, size_t elementSize); - -dropt_char* dropt_strdup(const dropt_char* s); -dropt_char* dropt_strndup(const dropt_char* s, size_t n); -int dropt_stricmp(const dropt_char* s, const dropt_char* t); -int dropt_strnicmp(const dropt_char* s, const dropt_char* t, size_t n); - - -#ifndef DROPT_NO_STRING_BUFFERS -typedef struct dropt_stringstream dropt_stringstream; - -int dropt_vsnprintf(dropt_char* s, size_t n, const dropt_char* format, va_list args); -int dropt_snprintf(dropt_char* s, size_t n, const dropt_char* format, ...); - -dropt_char* dropt_vasprintf(const dropt_char* format, va_list args); -dropt_char* dropt_asprintf(const dropt_char* format, ...); - -dropt_stringstream* dropt_ssopen(void); -void dropt_ssclose(dropt_stringstream* ss); - -void dropt_ssclear(dropt_stringstream* ss); -dropt_char* dropt_ssfinalize(dropt_stringstream* ss); -const dropt_char* dropt_ssgetstring(const dropt_stringstream* ss); - -int dropt_vssprintf(dropt_stringstream* ss, const dropt_char* format, va_list args); -int dropt_ssprintf(dropt_stringstream* ss, const dropt_char* format, ...); -#endif /* DROPT_NO_STRING_BUFFERS */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* DROPT_STRING_H */ diff --git a/external/epid-sdk-3.0.0/ext/dropt/src/dropt.c b/external/epid-sdk-3.0.0/ext/dropt/src/dropt.c deleted file mode 100644 index 917e8fd0..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/src/dropt.c +++ /dev/null @@ -1,1562 +0,0 @@ -/** dropt.c - * - * A deliberately rudimentary command-line option parser. - * - * Copyright (c) 2006-2012 James D. Lin - * - * The latest version of this file can be downloaded from: - * - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ -// THIS FILE HAS BEEN ALTERED from original version to: -// * fix warnings -// * modify error messages -// * resolve bool type conflict -// * fix issues found by static code analisys: -// * possible leak in dropt_get_help -// * null pointer dereference in dropt_parse -#include -#include -#include -#include -#include - -#include "dropt.h" -#include "dropt_string.h" - -#if __STDC_VERSION__ >= 199901L - #include - #include -#else - /* Compatibility junk for things that don't yet support ISO C99. */ - #ifndef SIZE_MAX - #define SIZE_MAX ((size_t) -1) - #endif - - #ifndef __cplusplus - #ifndef _Bool - /// C99 standard name for bool - #define _Bool char - /// Boolean type - typedef char bool; - /// integer constant 1 - #define true 1 - /// integer constant 0 - #define false 0 - #endif - #endif // ifndef __cplusplus -#endif -#ifndef MIN -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#ifndef ARRAY_LENGTH -#define ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0]) -#endif - -#define IMPLIES(p, q) (!(p) || q) - -#define OPTION_TAKES_ARG(option) ((option)->arg_description != NULL) - -enum -{ - default_help_indent = 2, - default_description_start_column = 6, -}; - - -/** A string that might not be NUL-terminated. */ -typedef struct -{ - const dropt_char* s; - - /* The length of s, excluding any NUL terminator. */ - size_t len; -} char_array; - - -/** A proxy for a dropt_option used for qsort and bsearch. Instead of - * sorting the dropt_option table directly, we sort arrays of option_proxy - * structures. This allows us to have separate arrays sorted by different - * keys and allows passing along additional data. - */ -typedef struct -{ - const dropt_option* option; - - /* The qsort and bsearch comparison callbacks don't pass along any - * client-supplied contextual data, so we have to embed it alongside - * the regular data. - */ - const dropt_context* context; -} option_proxy; - - -struct dropt_context -{ - const dropt_option* options; - size_t numOptions; - - /* These may be NULL. */ - option_proxy* sortedByLong; - option_proxy* sortedByShort; - - bool allowConcatenatedArgs; - - dropt_error_handler_func errorHandler; - void* errorHandlerData; - - struct - { - dropt_error err; - dropt_char* optionName; - dropt_char* optionArgument; - dropt_char* message; - } errorDetails; - - /* This isn't named strncmp because platforms might provide a macro - * version of strncmp, and we want to avoid a potential naming - * conflict. - */ - dropt_strncmp_func ncmpstr; -}; - - -typedef struct -{ - const dropt_option* option; - const dropt_char* optionArgument; - dropt_char** argNext; - int argsLeft; -} parse_state; - - -/** make_char_array - * - * PARAMETERS: - * IN s : A string. Might not be NUL-terminated. - * May be NULL. - * len : The length of s, excluding any NUL terminator. - * - * RETURNS: - * The constructed char_array structure. - */ -static char_array -make_char_array(const dropt_char* s, size_t len) -{ - char_array a; - - assert(IMPLIES(s == NULL, len == 0)); - - a.s = s; - a.len = len; - return a; -} - - -/** cmp_key_option_proxy_long - * - * Comparison callback for bsearch. Compares a char_array structure - * against an option_proxy structure based on long option names. - * - * PARAMETERS: - * IN key : A pointer to the char_array structure to search for. - * IN item : A pointer to the option_proxy structure being searched - * against. - * - * RETURNS: - * 0 if key and item are equivalent, - * < 0 if key should precede item, - * > 0 if key should follow item. - */ -static int -cmp_key_option_proxy_long(const void* key, const void* item) -{ - const char_array* longName = key; - const option_proxy* op = item; - - size_t optionLen; - int ret; - - assert(longName != NULL); - assert(op != NULL); - assert(op->option != NULL); - assert(op->context != NULL); - assert(op->context->ncmpstr != NULL); - - if (longName->s == op->option->long_name) - { - return 0; - } - else if (longName->s == NULL) - { - return -1; - } - else if (op->option->long_name == NULL) - { - return +1; - } - - /* Although the longName key might not be NUL-terminated, the - * option_proxy item we're searching against must be. - */ - optionLen = dropt_strlen(op->option->long_name); - ret = op->context->ncmpstr(longName->s, - op->option->long_name, - MIN(longName->len, optionLen)); - if (ret != 0) - { - return ret; - } - - if (longName->len < optionLen) - { - return -1; - } - else if (longName->len > optionLen) - { - return +1; - } - - return 0; -} - - -/** cmp_option_proxies_long - * - * Comparison callback for qsort. Compares two option_proxy - * structures based on long option names. - * - * PARAMETERS: - * IN p1, p2 : Pointers to the option_proxy structures to compare. - * - * RETURNS: - * 0 if p1 and p2 are equivalent, - * < 0 if p1 should precede p2, - * > 0 if p1 should follow p2. - */ -static int -cmp_option_proxies_long(const void* p1, const void* p2) -{ - const option_proxy* o1 = p1; - const option_proxy* o2 = p2; - - char_array ca1; - - assert(o1 != NULL); - assert(o2 != NULL); - assert(o1->option != NULL); - assert(o1->context == o2->context); - - ca1 = make_char_array(o1->option->long_name, - (o1->option->long_name == NULL) - ? 0 - : dropt_strlen(o1->option->long_name)); - return cmp_key_option_proxy_long(&ca1, o2); -} - - -/** cmp_key_option_proxy_short - * - * Comparison callback for bsearch. Compares a dropt_char against an - * option_proxy structure based on short option names. - * - * PARAMETERS: - * IN key : A pointer to the dropt_char to search for. - * IN item : A pointer to the option_proxy structure being searched - * against. - * - * RETURNS: - * 0 if key and item are equivalent, - * < 0 if key should precede item, - * > 0 if key should follow item. - */ -static int -cmp_key_option_proxy_short(const void* key, const void* item) -{ - const dropt_char* shortName = key; - const option_proxy* op = item; - - assert(shortName != NULL); - assert(op != NULL); - assert(op->option != NULL); - assert(op->context != NULL); - assert(op->context->ncmpstr != NULL); - - return op->context->ncmpstr(shortName, - &op->option->short_name, - 1); -} - - -/** cmp_option_proxies_short - * - * Comparison callback for qsort. Compares two option_proxy - * structures based on short option names. - * - * PARAMETERS: - * IN p1, p2 : Pointers to the option_proxy structures to compare. - * - * RETURNS: - * 0 if p1 and p2 are equivalent, - * < 0 if p1 should precede p2, - * > 0 if p1 should follow p2. - */ -static int -cmp_option_proxies_short(const void* p1, const void* p2) -{ - const option_proxy* o1 = p1; - const option_proxy* o2 = p2; - - assert(o1 != NULL); - assert(o2 != NULL); - assert(o1->option != NULL); - assert(o1->context == o2->context); - - return cmp_key_option_proxy_short(&o1->option->short_name, o2); -} - - -/** init_lookup_tables - * - * Initializes the sorted lookup tables in a dropt context if not - * already initialized. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * Must not be NULL. - */ -static void -init_lookup_tables(dropt_context* context) -{ - const dropt_option* options; - size_t n; - - assert(context != NULL); - - options = context->options; - n = context->numOptions; - - if (context->sortedByLong == NULL) - { - context->sortedByLong = dropt_safe_malloc(n, sizeof *(context->sortedByLong)); - if (context->sortedByLong != NULL) - { - size_t i; - for (i = 0; i < n; i++) - { - context->sortedByLong[i].option = &options[i]; - context->sortedByLong[i].context = context; - } - - qsort(context->sortedByLong, - n, sizeof *(context->sortedByLong), - cmp_option_proxies_long); - } - } - - if (context->sortedByShort == NULL) - { - context->sortedByShort = dropt_safe_malloc(n, sizeof *(context->sortedByShort)); - if (context->sortedByShort != NULL) - { - size_t i; - for (i = 0; i < n; i++) - { - context->sortedByShort[i].option = &options[i]; - context->sortedByShort[i].context = context; - } - - qsort(context->sortedByShort, - n, sizeof *(context->sortedByShort), - cmp_option_proxies_short); - } - } -} - - -/** free_lookup_tables - * - * Frees the sorted lookup tables in a dropt context. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * May be NULL. - */ -static void -free_lookup_tables(dropt_context* context) -{ - if (context != NULL) - { - free(context->sortedByLong); - context->sortedByLong = NULL; - - free(context->sortedByShort); - context->sortedByShort = NULL; - } -} - - -/** is_valid_option - * - * PARAMETERS: - * IN option : Specification for an individual option. - * - * RETURNS: - * true if the specified option is valid, false if it's a sentinel - * value. - */ -static bool -is_valid_option(const dropt_option* option) -{ - return option != NULL - && !( option->long_name == NULL - && option->short_name == DROPT_TEXT_LITERAL('\0') - && option->description == NULL - && option->arg_description == NULL - && option->handler == NULL - && option->handler_data == NULL - && option->attr == 0); -} - - -/** find_option_long - * - * Finds the option specification for a long option name (i.e., an - * option of the form "--option"). - * - * PARAMETERS: - * IN context : The dropt context. - * IN longName : The long option name to search for (excluding - * leading dashes). - * longName.s must not be NULL. - * - * RETURNS: - * A pointer to the corresponding option specification or NULL if not - * found. - */ -static const dropt_option* -find_option_long(const dropt_context* context, - char_array longName) -{ - assert(context != NULL); - assert(longName.s != NULL); - - if (context->sortedByLong != NULL) - { - option_proxy* found = bsearch(&longName, context->sortedByLong, - context->numOptions, sizeof *(context->sortedByLong), - cmp_key_option_proxy_long); - return (found == NULL) ? NULL : found->option; - } - - /* Fall back to a linear search. */ - { - option_proxy item = { 0 }; - item.context = context; - for (item.option = context->options; is_valid_option(item.option); item.option++) - { - if (cmp_key_option_proxy_long(&longName, &item) == 0) - { - return item.option; - } - } - } - return NULL; -} - - -/** find_option_short - * - * Finds the option specification for a short option name (i.e., an - * option of the form "-o"). - * - * PARAMETERS: - * IN context : The dropt context. - * IN shortName : The short option name to search for. - * - * RETURNS: - * A pointer to the corresponding option specification or NULL if not - * found. - */ -static const dropt_option* -find_option_short(const dropt_context* context, dropt_char shortName) -{ - assert(context != NULL); - assert(shortName != DROPT_TEXT_LITERAL('\0')); - assert(context->ncmpstr != NULL); - - if (context->sortedByShort != NULL) - { - option_proxy* found = bsearch(&shortName, context->sortedByShort, - context->numOptions, sizeof *(context->sortedByShort), - cmp_key_option_proxy_short); - return (found == NULL) ? NULL : found->option; - } - - /* Fall back to a linear search. */ - { - const dropt_option* option; - for (option = context->options; is_valid_option(option); option++) - { - if (context->ncmpstr(&shortName, &option->short_name, 1) == 0) - { - return option; - } - } - } - return NULL; -} - - -/** set_error_details - * - * Generates error details in the dropt context. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * Must not be NULL. - * IN err : The error code. - * IN optionName : The name of the option we failed on. - * optionName.s must not be NULL. - * IN optionArgument : The value of the option we failed on. - * Pass NULL if unwanted. - */ -static void -set_error_details(dropt_context* context, dropt_error err, - char_array optionName, - const dropt_char* optionArgument) -{ - assert(context != NULL); - assert(optionName.s != NULL); - - context->errorDetails.err = err; - - free(context->errorDetails.optionName); - free(context->errorDetails.optionArgument); - - context->errorDetails.optionName = dropt_strndup(optionName.s, optionName.len); - context->errorDetails.optionArgument = (optionArgument == NULL) - ? NULL - : dropt_strdup(optionArgument); - - /* The message will be generated lazily on retrieval. */ - free(context->errorDetails.message); - context->errorDetails.message = NULL; -} - - -/** set_short_option_error_details - * - * Generates error details in the dropt context. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * IN err : The error code. - * IN shortName : the "short" name of the option we failed on. - * IN optionArgument : The value of the option we failed on. - * Pass NULL if unwanted. - */ -static void -set_short_option_error_details(dropt_context* context, dropt_error err, - dropt_char shortName, const dropt_char* optionArgument) -{ - /* "-?" is just a placeholder. */ - dropt_char shortNameBuf[] = DROPT_TEXT_LITERAL("-?"); - - assert(context != NULL); - assert(shortName != DROPT_TEXT_LITERAL('\0')); - - shortNameBuf[1] = shortName; - - set_error_details(context, err, - make_char_array(shortNameBuf, ARRAY_LENGTH(shortNameBuf) - 1), - optionArgument); -} - - -/** dropt_get_error - * - * PARAMETERS: - * IN context : The dropt context. - * Must not be NULL. - * - * RETURNS: - * The current error code waiting in the dropt context. - */ -dropt_error -dropt_get_error(const dropt_context* context) -{ - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return dropt_error_bad_configuration; - } - return context->errorDetails.err; -} - - -/** dropt_get_error_details - * - * Retrieves details about the current error. - * - * PARAMETERS: - * IN context : The dropt context. - * OUT optionName : On output, the name of the option we failed - * on. Do not free this string. - * Pass NULL if unwanted. - * OUT optionArgument : On output, the value (possibly NULL) of the - * option we failed on. Do not free this - * string. - * Pass NULL if unwanted. - */ -void -dropt_get_error_details(const dropt_context* context, - dropt_char** optionName, dropt_char** optionArgument) -{ - if (optionName != NULL) { *optionName = context->errorDetails.optionName; } - if (optionArgument != NULL) { *optionArgument = context->errorDetails.optionArgument; } -} - - -/** dropt_get_error_message - * - * PARAMETERS: - * IN context : The dropt context. - * Must not be NULL. - * - * RETURNS: - * The current error message waiting in the dropt context or the empty - * string if there are no errors. Note that calling any dropt - * function other than dropt_get_error, dropt_get_error_details, and - * dropt_get_error_message may invalidate a previously-returned - * string. - */ -const dropt_char* -dropt_get_error_message(dropt_context* context) -{ - if (context == NULL) - { - DROPT_MISUSE("no dropt context specified."); - return DROPT_TEXT_LITERAL(""); - } - - if (context->errorDetails.err == dropt_error_none) - { - return DROPT_TEXT_LITERAL(""); - } - - if (context->errorDetails.message == NULL) - { - if (context->errorHandler != NULL) - { - context->errorDetails.message - = context->errorHandler(context->errorDetails.err, - context->errorDetails.optionName, - context->errorDetails.optionArgument, - context->errorHandlerData); - } - else - { -#ifndef DROPT_NO_STRING_BUFFERS - context->errorDetails.message - = dropt_default_error_handler(context->errorDetails.err, - context->errorDetails.optionName, - context->errorDetails.optionArgument); -#endif - } - } - - return (context->errorDetails.message == NULL) - ? DROPT_TEXT_LITERAL("unknown error") - : context->errorDetails.message; -} - - -/** dropt_clear_error - * - * Clears the error waiting in the dropt context. - * - * PARAMETERS: - * IN/OUT context : The dropt context to free. - * May be NULL. - */ -void -dropt_clear_error(dropt_context* context) -{ - if (context != NULL) - { - context->errorDetails.err = dropt_error_none; - - free(context->errorDetails.optionName); - context->errorDetails.optionName = NULL; - - free(context->errorDetails.optionArgument); - context->errorDetails.optionArgument = NULL; - - free(context->errorDetails.message); - context->errorDetails.message = NULL; - } -} - - -#ifndef DROPT_NO_STRING_BUFFERS -/** dropt_default_error_handler - * - * Default error handler. - * - * PARAMETERS: - * IN error : The error code. - * IN optionName : The name of the option we failed on. - * IN optionArgument : The value of the option we failed on. - * Pass NULL if unwanted. - * - * RETURNS: - * An allocated string for the given error. The caller is responsible - * for calling free() on it when no longer needed. - * May return NULL. - */ -dropt_char* -dropt_default_error_handler(dropt_error error, - const dropt_char* optionName, - const dropt_char* optionArgument) -{ - dropt_char* s = NULL; - - const dropt_char* separator = DROPT_TEXT_LITERAL(": "); - - if (optionArgument == NULL) - { - separator = optionArgument = DROPT_TEXT_LITERAL(""); - } - - switch (error) - { - case dropt_error_none: - /* This shouldn't happen (unless client code invokes this - * directly with dropt_error_none), but it's here for - * completeness. - */ - break; - - case dropt_error_bad_configuration: - s = dropt_strdup(DROPT_TEXT_LITERAL("invalid option configuration")); - break; - - case dropt_error_invalid_option: - s = dropt_asprintf(DROPT_TEXT_LITERAL("invalid option: %s"), - optionName); - break; - case dropt_error_insufficient_arguments: - s = dropt_asprintf(DROPT_TEXT_LITERAL("value required after option %s"), - optionName); - break; - case dropt_error_mismatch: - s = dropt_asprintf(DROPT_TEXT_LITERAL("invalid value for option %s%s%s"), - optionName, separator, optionArgument); - break; - case dropt_error_overflow: - s = dropt_asprintf(DROPT_TEXT_LITERAL("value too large for option %s%s%s"), - optionName, separator, optionArgument); - break; - case dropt_error_underflow: - s = dropt_asprintf(DROPT_TEXT_LITERAL("value too small for option %s%s%s"), - optionName, separator, optionArgument); - break; - case dropt_error_insufficient_memory: - s = dropt_strdup(DROPT_TEXT_LITERAL("insufficient memory")); - break; - case dropt_error_unknown: - default: - s = dropt_asprintf(DROPT_TEXT_LITERAL("unknown error handling option %s"), - optionName); - break; - } - - return s; -} - - -/** dropt_get_help - * - * PARAMETERS: - * IN context : The dropt context. - * Must not be NULL. - * IN helpParams : The help parameters. - * Pass NULL to use the default help parameters. - * - * RETURNS: - * An allocated help string for the available options. The caller is - * responsible for calling free() on it when no longer needed. - * Returns NULL on error. - */ -dropt_char* -dropt_get_help(const dropt_context* context, const dropt_help_params* helpParams) -{ - dropt_char* helpText = NULL; - dropt_stringstream* ss = NULL; - - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return NULL; - } - - ss = dropt_ssopen(); - - if (ss != NULL) - { - const dropt_option* option; - dropt_help_params hp; - - if (helpParams == NULL) - { - dropt_init_help_params(&hp); - } - else - { - hp = *helpParams; - } - - for (option = context->options; is_valid_option(option); option++) - { - bool hasLongName = option->long_name != NULL - && option->long_name[0] != DROPT_TEXT_LITERAL('\0'); - bool hasShortName = option->short_name != DROPT_TEXT_LITERAL('\0'); - - /* The number of characters printed on the current line so far. */ - int n; - - if (option->description == NULL || (option->attr & dropt_attr_hidden)) - { - /* Undocumented option. Ignore it and move on. */ - continue; - } - else if (hasLongName && hasShortName) - { - n = dropt_ssprintf(ss, DROPT_TEXT_LITERAL("%*s-%c, --%s"), - hp.indent, DROPT_TEXT_LITERAL(""), - option->short_name, option->long_name); - } - else if (hasLongName) - { - n = dropt_ssprintf(ss, DROPT_TEXT_LITERAL("%*s--%s"), - hp.indent, DROPT_TEXT_LITERAL(""), - option->long_name); - } - else if (hasShortName) - { - n = dropt_ssprintf(ss, DROPT_TEXT_LITERAL("%*s-%c"), - hp.indent, DROPT_TEXT_LITERAL(""), - option->short_name); - } - else - { - /* Comment text. Don't bother with indentation. */ - assert(option->description != NULL); - dropt_ssprintf(ss, DROPT_TEXT_LITERAL("%s\n"), option->description); - goto next; - } - - if (n < 0) { n = 0; } - - if (option->arg_description != NULL) - { - int m = dropt_ssprintf(ss, - (option->attr & dropt_attr_optional_val) - ? DROPT_TEXT_LITERAL("[=%s]") - : DROPT_TEXT_LITERAL("=%s"), - option->arg_description); - if (m > 0) { n += m; } - } - - /* Check for equality to make sure that there's at least one - * space between the option name and its description. - */ - if ((unsigned int) n >= hp.description_start_column) - { - dropt_ssprintf(ss, DROPT_TEXT_LITERAL("\n")); - n = 0; - } - - { - const dropt_char* line = option->description; - while (line != NULL) - { - size_t lineLen; - const dropt_char* nextLine; - const dropt_char* newline = dropt_strchr(line, DROPT_TEXT_LITERAL('\n')); - - if (newline == NULL) - { - lineLen = (int)dropt_strlen(line); - nextLine = NULL; - } - else - { - lineLen = (int)(newline - line); - nextLine = newline + 1; - } - - dropt_ssprintf(ss, DROPT_TEXT_LITERAL("%*s%.*s\n"), - hp.description_start_column - n, DROPT_TEXT_LITERAL(""), - lineLen, line); - n = 0; - - line = nextLine; - } - } - - next: - if (hp.blank_lines_between_options) - { - dropt_ssprintf(ss, DROPT_TEXT_LITERAL("\n")); - } - } - helpText = dropt_ssfinalize(ss); - } - - return helpText; -} - - -/** dropt_print_help - * - * Prints help for the available options. - * - * PARAMETERS: - * IN/OUT f : The file stream to print to. - * IN context : The dropt context. - * Must not be NULL. - * IN helpParams : The help parameters. - * Pass NULL to use the default help parameters. - */ -void -dropt_print_help(FILE* f, const dropt_context* context, - const dropt_help_params* helpParams) -{ - dropt_char* helpText = dropt_get_help(context, helpParams); - if (helpText != NULL) - { - dropt_fputs(helpText, f); - free(helpText); - } -} -#endif /* DROPT_NO_STRING_BUFFERS */ - - -/** set_option_value - * - * Sets the value for a specified option by invoking the option's - * handler callback. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * IN option : The option. - * IN optionArgument : The option's value. May be NULL. - * - * RETURNS: - * An error code. - */ -static dropt_error -set_option_value(dropt_context* context, - const dropt_option* option, const dropt_char* optionArgument) -{ - assert(option != NULL); - - if (option->handler == NULL) - { - DROPT_MISUSE("No option handler specified."); - return dropt_error_bad_configuration; - } - - return option->handler(context, optionArgument, option->handler_data); -} - - -/** parse_option_arg - * - * Helper function to dropt_parse to deal with consuming possibly - * optional arguments. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * IN/OUT ps : The current parse state. - * - * RETURNS: - * An error code. - */ -static dropt_error -parse_option_arg(dropt_context* context, parse_state* ps) -{ - dropt_error err; - - bool consumeNextArg = false; - - if (OPTION_TAKES_ARG(ps->option) && ps->optionArgument == NULL) - { - /* The option expects an argument, but none was specified with '='. - * Try using the next item from the command-line. - */ - if (ps->argsLeft > 0 && *(ps->argNext) != NULL) - { - consumeNextArg = true; - ps->optionArgument = *(ps->argNext); - } - else if (!(ps->option->attr & dropt_attr_optional_val)) - { - err = dropt_error_insufficient_arguments; - goto exit; - } - } - - /* Even for options that don't ask for arguments, always parse and - * consume an argument that was specified with '='. - */ - err = set_option_value(context, ps->option, ps->optionArgument); - - if ( err != dropt_error_none - && (ps->option->attr & dropt_attr_optional_val) - && consumeNextArg - && ps->optionArgument != NULL) - { - /* The option's handler didn't like the argument we fed it. If the - * argument was optional, try again without it. - */ - consumeNextArg = false; - ps->optionArgument = NULL; - err = set_option_value(context, ps->option, NULL); - } - -exit: - if (err == dropt_error_none && consumeNextArg) - { - ps->argNext++; - ps->argsLeft--; - } - return err; -} - - -/** dropt_parse - * - * Parses command-line options. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * Must not be NULL. - * IN argc : The maximum number of arguments to parse from - * argv. - * Pass -1 to parse all arguments up to a NULL - * sentinel value. - * IN argv : The list of command-line arguments, not including - * the initial program name. - * - * RETURNS: - * A pointer to the first unprocessed element in argv. - */ -dropt_char** -dropt_parse(dropt_context* context, - int argc, dropt_char** argv) -{ - dropt_error err = dropt_error_none; - - dropt_char* arg; - parse_state ps; - - ps.option = NULL; - ps.optionArgument = NULL; - ps.argNext = argv; - - if (argv == NULL) - { - /* Nothing to do. */ - goto exit; - } - - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - goto exit; - } - -#ifdef DROPT_NO_STRING_BUFFERS - if (context->errorHandler == NULL) - { - DROPT_MISUSE("No error handler specified."); - set_error_details(context, dropt_error_bad_configuration, - make_char_array(DROPT_TEXT_LITERAL(""), 0), - NULL); - goto exit; - } -#endif - - if (argc == -1) - { - argc = 0; - while (argv[argc] != NULL) { argc++; } - } - - if (argc == 0) - { - /* Nothing to do. */ - goto exit; - } - - init_lookup_tables(context); - - ps.argsLeft = argc; - - while ( ps.argsLeft-- > 0 - && (arg = *ps.argNext) != NULL - && arg[0] == DROPT_TEXT_LITERAL('-')) - { - assert(err == dropt_error_none); - - if (arg[1] == DROPT_TEXT_LITERAL('\0')) - { - /* - */ - - /* This intentionally leaves "-" unprocessed for the caller to - * deal with. This allows construction of programs that treat - * "-" to mean "stdin". - */ - goto exit; - } - - ps.argNext++; - - if (arg[1] == DROPT_TEXT_LITERAL('-')) - { - const dropt_char* longName = arg + 2; - if (longName[0] == DROPT_TEXT_LITERAL('\0')) - { - /* -- */ - - /* This is used to mark the end of the option processing - * to prevent some arguments with leading '-' characters - * from being treated as options. - * - * Don't pass this back to the caller. - */ - goto exit; - } - else if (longName[0] == DROPT_TEXT_LITERAL('=')) - { - /* Deal with the pathological case of a user supplying - * "--=". - */ - err = dropt_error_invalid_option; - set_error_details(context, err, - make_char_array(arg, dropt_strlen(arg)), - NULL); - goto exit; - } - else - { - /* --longName */ - const dropt_char* p = dropt_strchr(longName, DROPT_TEXT_LITERAL('=')); - const dropt_char* longNameEnd; - if (p != NULL) - { - /* --longName=arg */ - longNameEnd = p; - ps.optionArgument = p + 1; - } - else - { - longNameEnd = longName + dropt_strlen(longName); - assert(ps.optionArgument == NULL); - } - - /* Pass the length of the option name so that we don't need - * to mutate the original string by inserting a - * NUL-terminator. - */ - ps.option = find_option_long(context, - make_char_array(longName, - longNameEnd - longName)); - if (ps.option == NULL) - { - err = dropt_error_invalid_option; - set_error_details(context, err, - make_char_array(arg, longNameEnd - arg), - NULL); - } - else - { - err = parse_option_arg(context, &ps); - if (err != dropt_error_none) - { - set_error_details(context, err, - make_char_array(arg, longNameEnd - arg), - ps.optionArgument); - } - } - - if ( err != dropt_error_none - || ps.option->attr & dropt_attr_halt) - { - goto exit; - } - } - } - else - { - /* Short name. (-x) */ - size_t len; - size_t j; - - if (arg[1] == DROPT_TEXT_LITERAL('=')) - { - /* Deal with the pathological case of a user supplying - * "-=". - */ - err = dropt_error_invalid_option; - set_error_details(context, err, - make_char_array(arg, dropt_strlen(arg)), - NULL); - goto exit; - } - else - { - const dropt_char* p = dropt_strchr(arg, DROPT_TEXT_LITERAL('=')); - if (p != NULL) - { - /* -x=arg */ - len = p - arg; - ps.optionArgument = p + 1; - } - else - { - len = dropt_strlen(arg); - assert(ps.optionArgument == NULL); - } - } - - for (j = 1; j < len; j++) - { - ps.option = find_option_short(context, arg[j]); - if (ps.option == NULL) - { - err = dropt_error_invalid_option; - set_short_option_error_details(context, err, arg[j], NULL); - goto exit; - } - else if (j + 1 == len) - { - /* The last short option in a condensed list gets - * to use an argument. - */ - err = parse_option_arg(context, &ps); - if (err != dropt_error_none) - { - set_short_option_error_details(context, err, arg[j], - ps.optionArgument); - goto exit; - } - } - else if ( context->allowConcatenatedArgs - && OPTION_TAKES_ARG(ps.option) - && j == 1) - { - err = set_option_value(context, ps.option, &arg[j + 1]); - - if ( err != dropt_error_none - && (ps.option->attr & dropt_attr_optional_val)) - { - err = set_option_value(context, ps.option, NULL); - } - - if (err != dropt_error_none) - { - set_short_option_error_details(context, err, arg[j], &arg[j + 1]); - goto exit; - } - - /* Skip to the next argument. */ - break; - } - else if ( OPTION_TAKES_ARG(ps.option) - && !(ps.option->attr & dropt_attr_optional_val)) - { - /* Short options with required arguments can't be used - * in condensed lists except in the last position. - * - * e.g. -abcd arg - * ^ - */ - err = dropt_error_insufficient_arguments; - set_short_option_error_details(context, err, arg[j], NULL); - goto exit; - } - else - { - err = set_option_value(context, ps.option, NULL); - if (err != dropt_error_none) - { - set_short_option_error_details(context, err, arg[j], NULL); - goto exit; - } - } - - if (ps.option->attr & dropt_attr_halt) { goto exit; } - } - } - - ps.option = NULL; - ps.optionArgument = NULL; - } - -exit: - return ps.argNext; -} - - -/** dropt_new_context - * - * Creates a new dropt context. - * - * PARAMETERS: - * IN options : The list of option specifications. - * Must not be NULL. - * - * RETURNS: - * An allocated dropt context. The caller is responsible for freeing - * it with dropt_free_context when no longer needed. - * Returns NULL on error. - */ -dropt_context* -dropt_new_context(const dropt_option* options) -{ - dropt_context* context = NULL; - size_t n; - - if (options == NULL) - { - DROPT_MISUSE("No option list specified."); - goto exit; - } - - /* Sanity-check the options. */ - for (n = 0; is_valid_option(&options[n]); n++) - { - if ( options[n].short_name == DROPT_TEXT_LITERAL('=') - || ( options[n].long_name != NULL - && dropt_strchr(options[n].long_name, DROPT_TEXT_LITERAL('=')) != NULL)) - { - DROPT_MISUSE("Invalid option list. '=' may not be used in an option name."); - goto exit; - } - } - - context = malloc(sizeof *context); - if (context == NULL) - { - goto exit; - } - else - { - dropt_context emptyContext = { 0 }; - *context = emptyContext; - - context->options = options; - context->numOptions = n; - dropt_set_strncmp(context, NULL); - } - -exit: - return context; -} - - -/** dropt_free_context - * - * Frees a dropt context. - * - * PARAMETERS: - * IN/OUT context : The dropt context to free. - * May be NULL. - */ -void -dropt_free_context(dropt_context* context) -{ - dropt_clear_error(context); - free_lookup_tables(context); - free(context); -} - - -/** dropt_get_options - * - * PARAMETERS: - * IN context : The dropt context. - * Must not be NULL. - * - * RETURNS: - * The context's list of option specifications. - */ -const dropt_option* -dropt_get_options(const dropt_context* context) -{ - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return NULL; - } - - return context->options; -} - - -/** dropt_init_help_params - * - * Initializes a dropt_help_params structure with the default - * values. - * - * PARAMETERS: - * OUT helpParams : On output, set to the default help parameters. - * Must not be NULL. - */ -void -dropt_init_help_params(dropt_help_params* helpParams) -{ - if (helpParams == NULL) - { - DROPT_MISUSE("No dropt help parameters specified."); - return; - } - - helpParams->indent = default_help_indent; - helpParams->description_start_column = default_description_start_column; - helpParams->blank_lines_between_options = true; -} - - -/** dropt_set_error_handler - * - * Sets the callback function used to generate error strings from - * error codes. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * Must not be NULL. - * IN handler : The error handler callback. - * Pass NULL to use the default error handler. - * IN handlerData : Caller-defined callback data. - */ -void -dropt_set_error_handler(dropt_context* context, dropt_error_handler_func handler, void* handlerData) -{ - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return; - } - - context->errorHandler = handler; - context->errorHandlerData = handlerData; -} - - -/** dropt_set_strncmp - * - * Sets the callback function used to compare strings. - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * Must not be NULL. - * IN cmp : The string comparison function. - * Pass NULL to use the default string comparison - * function. - */ -void -dropt_set_strncmp(dropt_context* context, dropt_strncmp_func cmp) -{ - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return; - } - - if (cmp == NULL) { cmp = dropt_strncmp; } - context->ncmpstr = cmp; - - /* Changing the sort method invalidates our existing lookup tables. */ - free_lookup_tables(context); -} - - -/** dropt_allow_concatenated_arguments - * - * Specifies whether "short" options are allowed to have concatenated - * arguments (i.e. without space or '=' separators, such as -oARGUMENT). - * - * (Concatenated arguments are disallowed by default.) - * - * PARAMETERS: - * IN/OUT context : The dropt context. - * IN allow : Pass 1 if concatenated arguments should be allowed, - * 0 otherwise. - */ -void -dropt_allow_concatenated_arguments(dropt_context* context, dropt_bool allow) -{ - if (context == NULL) - { - DROPT_MISUSE("No dropt context specified."); - return; - } - - context->allowConcatenatedArgs = (allow != 0); -} - - -/** dropt_misuse - * - * Prints a diagnostic for logical errors caused by external clients - * calling into dropt improperly. - * - * In debug builds, terminates the program and prints the filename and - * line number of the failure. - * - * For logical errors entirely internal to dropt, use assert() - * instead. - * - * PARAMETERS: - * IN message : The error message. - * Must not be NULL. - * IN filename : The name of the file where the logical error - * occurred. - * Must not be NULL. - * IN line : The line number where the logical error occurred. - */ -void -dropt_misuse(const char* message, const char* filename, int line) -{ -#ifdef NDEBUG - (void)filename; - (void)line; - fprintf(stderr, "dropt: %s\n", message); -#else - fprintf(stderr, "dropt: %s (%s: %d)\n", message, filename, line); - abort(); -#endif -} diff --git a/external/epid-sdk-3.0.0/ext/dropt/src/dropt_handlers.c b/external/epid-sdk-3.0.0/ext/dropt/src/dropt_handlers.c deleted file mode 100644 index 412d571c..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/src/dropt_handlers.c +++ /dev/null @@ -1,438 +0,0 @@ -/** dropt_handlers.c - * - * Default type handlers for dropt. - * - * Copyright (c) 2006-2012 James D. Lin - * - * The latest version of this file can be downloaded from: - * - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ -// THIS FILE HAS BEEN ALTERED from original version to fix warnings -#include -#include -#include -#include -#include -#include - -#include "dropt.h" -#include "dropt_string.h" - -#define ABS(x) (((x) < 0) ? -(x) : (x)) - -typedef enum { false, true } bool; - -/** dropt_handle_bool - * - * Parses a boolean value from the given string if possible. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string representing a boolean value (0 or 1). - * If NULL, the boolean value is assumed to be - * true. - * OUT handlerData : A dropt_bool*. - * On success, set to the interpreted boolean - * value. - * On error, left untouched. - * - * RETURNS: - * dropt_error_none - * dropt_error_unknown - * dropt_error_bad_configuration - * dropt_error_mismatch - */ -dropt_error -dropt_handle_bool(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_error_none; - bool val = false; - dropt_bool* out = handlerData; - - if (out == NULL) - { - DROPT_MISUSE("No handler data specified."); - err = dropt_error_bad_configuration; - } - else if (optionArgument == NULL) - { - /* No explicit argument implies that the option is being turned on. */ - val = true; - } - else if (optionArgument[0] == DROPT_TEXT_LITERAL('\0')) - { - err = dropt_error_mismatch; - } - else - { - unsigned int i = 0; - err = dropt_handle_uint(context, optionArgument, &i); - if (err == dropt_error_none) - { - switch (i) - { - case 0: - val = false; - break; - case 1: - val = true; - break; - default: - err = dropt_error_mismatch; - break; - } - } - else if (err == dropt_error_overflow) - { - err = dropt_error_mismatch; - } - } - - if (err == dropt_error_none) { *out = val; } - return err; -} - - -/** dropt_handle_verbose_bool - * - * Like dropt_handle_bool but accepts "true" and "false" string - * values. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string representing a boolean value. - * If NULL, the boolean value is assumed to be - * true. - * OUT handlerData : A dropt_bool*. - * On success, set to the interpreted boolean - * value. - * On error, left untouched. - * - * RETURNS: - * See dropt_handle_bool. - */ -dropt_error -dropt_handle_verbose_bool(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_handle_bool(context, optionArgument, handlerData); - if (err == dropt_error_mismatch) - { - bool val = false; - dropt_bool* out = handlerData; - - /* dropt_handle_bool already checks for this. */ - assert(out != NULL); - - if (dropt_stricmp(optionArgument, DROPT_TEXT_LITERAL("false")) == 0) - { - val = false; - err = dropt_error_none; - } - else if (dropt_stricmp(optionArgument, DROPT_TEXT_LITERAL("true")) == 0) - { - val = true; - err = dropt_error_none; - } - - if (err == dropt_error_none) { *out = val; } - } - return err; -} - - -/** dropt_handle_int - * - * Parses an integer from the given string. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string representing a base-10 integer. - * If NULL, returns dropt_error_insufficient_arguments. - * OUT handlerData : An int*. - * On success, set to the interpreted integer. - * On error, left untouched. - * - * RETURNS: - * dropt_error_none - * dropt_error_unknown - * dropt_error_bad_configuration - * dropt_error_insufficient_arguments - * dropt_error_mismatch - * dropt_error_overflow - */ -dropt_error -dropt_handle_int(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_error_none; - int val = 0; - int* out = handlerData; - (void)context; - - if (out == NULL) - { - DROPT_MISUSE("No handler data specified."); - err = dropt_error_bad_configuration; - } - else if (optionArgument == NULL || optionArgument[0] == DROPT_TEXT_LITERAL('\0')) - { - err = dropt_error_insufficient_arguments; - } - else - { - dropt_char* end; - long n; - errno = 0; - n = dropt_strtol(optionArgument, &end, 10); - - /* Check that we matched at least one digit. - * (strtol/strtoul will return 0 if fed a string with no digits.) - */ - if (*end == DROPT_TEXT_LITERAL('\0') && end > optionArgument) - { - if (errno == ERANGE || n < INT_MIN || n > INT_MAX) - { - err = dropt_error_overflow; - val = (n < 0) ? INT_MIN : INT_MAX; - } - else if (errno == 0) - { - val = (int) n; - } - else - { - err = dropt_error_unknown; - } - } - else - { - err = dropt_error_mismatch; - } - } - - if (err == dropt_error_none) { *out = val; } - return err; -} - - -/** dropt_handle_uint - * - * Parses an unsigned integer from the given string. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string representing an unsigned base-10 - * integer. - * If NULL, returns dropt_error_insufficient_arguments. - * OUT handlerData : An unsigned int*. - * On success, set to the interpreted integer. - * On error, left untouched. - * - * RETURNS: - * dropt_error_none - * dropt_error_unknown - * dropt_error_bad_configuration - * dropt_error_insufficient_arguments - * dropt_error_mismatch - * dropt_error_overflow - */ -dropt_error -dropt_handle_uint(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_error_none; - int val = 0; - unsigned int* out = handlerData; - (void)context; - - if (out == NULL) - { - DROPT_MISUSE("No handler data specified."); - err = dropt_error_bad_configuration; - } - else if ( optionArgument == NULL - || optionArgument[0] == DROPT_TEXT_LITERAL('\0')) - { - err = dropt_error_insufficient_arguments; - } - else if (optionArgument[0] == DROPT_TEXT_LITERAL('-')) - { - err = dropt_error_mismatch; - } - else - { - dropt_char* end; - unsigned long n; - errno = 0; - n = dropt_strtoul(optionArgument, &end, 10); - - /* Check that we matched at least one digit. - * (strtol/strtoul will return 0 if fed a string with no digits.) - */ - if (*end == DROPT_TEXT_LITERAL('\0') && end > optionArgument) - { - if (errno == ERANGE || n > UINT_MAX) - { - err = dropt_error_overflow; - val = UINT_MAX; - } - else if (errno == 0) - { - val = (unsigned int) n; - } - else - { - err = dropt_error_unknown; - } - } - else - { - err = dropt_error_mismatch; - } - } - - if (err == dropt_error_none) { *out = val; } - return err; -} - - -/** dropt_handle_double - * - * Parses a double from the given string. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string representing a base-10 floating-point - * number. - * If NULL, returns dropt_error_insufficient_arguments. - * OUT handlerData : A double*. - * On success, set to the interpreted double. - * On error, left untouched. - * - * RETURNS: - * dropt_error_none - * dropt_error_unknown - * dropt_error_bad_configuration - * dropt_error_insufficient_arguments - * dropt_error_mismatch - * dropt_error_overflow - * dropt_error_underflow - */ -dropt_error -dropt_handle_double(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_error_none; - double val = 0.0; - double* out = handlerData; - (void)context; - - if (out == NULL) - { - DROPT_MISUSE("No handler data specified."); - err = dropt_error_bad_configuration; - } - else if ( optionArgument == NULL - || optionArgument[0] == DROPT_TEXT_LITERAL('\0')) - { - err = dropt_error_insufficient_arguments; - } - else - { - dropt_char* end; - errno = 0; - val = dropt_strtod(optionArgument, &end); - - /* Check that we matched at least one digit. - * (strtod will return 0 if fed a string with no digits.) - */ - if (*end == DROPT_TEXT_LITERAL('\0') && end > optionArgument) - { - if (errno == ERANGE) - { - /* Note that setting errno to ERANGE for underflow errors - * is implementation-defined behavior, but glibc, BSD's - * libc, and Microsoft's CRT all have implementations of - * strtod documented to return 0 and to set errno to ERANGE - * for such cases. - */ - err = (ABS(val) <= DBL_MIN) - ? dropt_error_underflow - : dropt_error_overflow; - } - else if (errno != 0) - { - err = dropt_error_unknown; - } - } - else - { - err = dropt_error_mismatch; - } - } - - if (err == dropt_error_none) { *out = val; } - return err; -} - - -/** dropt_handle_string - * - * Obtains a string. - * - * PARAMETERS: - * IN/OUT context : The options context. - * IN optionArgument : A string. - * If NULL, returns dropt_error_insufficient_arguments. - * OUT handlerData : A dropt_char**. - * On success, set to the input string. The - * string is NOT copied from the original argv - * array, so do not free it. - * On error, left untouched. - * - * RETURNS: - * dropt_error_none - * dropt_error_bad_configuration - * dropt_error_insufficient_arguments - */ -dropt_error -dropt_handle_string(dropt_context* context, const dropt_char* optionArgument, - void* handlerData) -{ - dropt_error err = dropt_error_none; - const dropt_char** out = handlerData; - (void)context; - - if (out == NULL) - { - DROPT_MISUSE("No handler data specified."); - err = dropt_error_bad_configuration; - } - else if (optionArgument == NULL) - { - err = dropt_error_insufficient_arguments; - } - - if (err == dropt_error_none) { *out = optionArgument; } - return err; -} diff --git a/external/epid-sdk-3.0.0/ext/dropt/src/dropt_string.c b/external/epid-sdk-3.0.0/ext/dropt/src/dropt_string.c deleted file mode 100644 index 6505bd1b..00000000 --- a/external/epid-sdk-3.0.0/ext/dropt/src/dropt_string.c +++ /dev/null @@ -1,686 +0,0 @@ -/** dropt_string.c - * - * String routines for dropt. - * - * Copyright (c) 2006-2012 James D. Lin - * - * The latest version of this file can be downloaded from: - * - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifdef _MSC_VER - #include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#if __STDC_VERSION__ >= 199901L - #include -#else - /* Compatibility junk for things that don't yet support ISO C99. */ - #if defined _MSC_VER || defined __BORLANDC__ - #ifndef va_copy - #define va_copy(dest, src) (dest = (src)) - #endif - #else - #ifndef va_copy - #error Unsupported platform. va_copy is not defined. - #endif - #endif - - #ifndef SIZE_MAX - #define SIZE_MAX ((size_t) -1) - #endif -#endif - -#include "dropt_string.h" - -#ifndef MAX -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#endif - -#ifndef MIN -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#ifdef DROPT_DEBUG_STRING_BUFFERS - enum { default_stringstream_buffer_size = 1 }; - #define GROWN_STRINGSTREAM_BUFFER_SIZE(oldSize, minAmount) \ - ((oldSize) + (minAmount)) -#else - enum { default_stringstream_buffer_size = 256 }; - #define GROWN_STRINGSTREAM_BUFFER_SIZE(oldSize, minAmount) \ - MAX((oldSize) * 2, (oldSize) + (minAmount)) -#endif - - -#ifndef DROPT_NO_STRING_BUFFERS -struct dropt_stringstream -{ - dropt_char* string; /* The string buffer. */ - size_t maxSize; /* Size of the string buffer, in dropt_char-s, including space for NUL. */ - size_t used; /* Number of elements used in the string buffer, excluding NUL. */ -}; -#endif - - -/** dropt_safe_malloc - * - * A version of malloc that checks for integer overflow. - * - * PARAMETERS: - * IN numElements : The number of elements to allocate. - * IN elementSize : The size of each element, in bytes. - * - * RETURNS: - * A pointer to the allocated memory. - * Returns NULL if numElements is 0. - * Returns NULL on error. - */ -void* -dropt_safe_malloc(size_t numElements, size_t elementSize) -{ - return dropt_safe_realloc(NULL, numElements, elementSize); -} - - -/** dropt_safe_realloc - * - * Wrapper around realloc to check for integer overflow. - * - * PARAMETERS: - * IN/OUT p : A pointer to the memory block to resize. - * If NULL, a new memory block of the specified size - * will be allocated. - * IN numElements : The number of elements to allocate. - * If 0, frees p. - * IN elementSize : The size of each element, in bytes. - * - * RETURNS: - * A pointer to the allocated memory. - * Returns NULL if numElements is 0. - * Returns NULL on error. - */ -void* -dropt_safe_realloc(void* p, size_t numElements, size_t elementSize) -{ - size_t numBytes; - - /* elementSize shouldn't legally be 0, but we check for it in case a - * caller got the argument order wrong. - */ - if (numElements == 0 || elementSize == 0) - { - /* The behavior of realloc(p, 0) is implementation-defined. Let's - * enforce a particular behavior. - */ - free(p); - - assert(elementSize != 0); - return NULL; - } - - numBytes = numElements * elementSize; - if (numBytes / elementSize != numElements) - { - /* Overflow. */ - return NULL; - } - - return realloc(p, numBytes); -} - - -/** dropt_strdup - * - * Duplicates a string. - * - * PARAMETERS: - * IN s : A NUL-terminated string to duplicate. - * - * RETURNS: - * The duplicated string. The caller is responsible for calling - * free() on it when no longer needed. - * Returns NULL on error. - */ -dropt_char* -dropt_strdup(const dropt_char* s) -{ - return dropt_strndup(s, SIZE_MAX); -} - - -/** dropt_strndup - * - * Duplicates the first n characters of a string. - * - * PARAMETERS: - * IN s : The string to duplicate. - * IN n : The maximum number of dropt_char-s to copy, excluding the - * NUL-terminator. - * - * RETURNS: - * The duplicated string, which is always NUL-terminated. The caller - * is responsible for calling free() on it when no longer needed. - * Returns NULL on error. - */ -dropt_char* -dropt_strndup(const dropt_char* s, size_t n) -{ - dropt_char* copy; - size_t len = 0; - - assert(s != NULL); - - while (len < n && s[len] != DROPT_TEXT_LITERAL('\0')) - { - len++; - } - - if (len + 1 < len) - { - /* This overflow check shouldn't be strictly necessary. len can be - * at most SIZE_MAX, so SIZE_MAX + 1 can wrap around to 0, but - * dropt_safe_malloc will return NULL for a 0-sized allocation. - * However, favor defensive paranoia. - */ - return NULL; - } - - copy = dropt_safe_malloc(len + 1 /* NUL */, sizeof *copy); - if (copy != NULL) - { - memcpy(copy, s, len * sizeof *copy); - copy[len] = DROPT_TEXT_LITERAL('\0'); - } - - return copy; -} - - -/** dropt_stricmp - * - * Compares two NUL-terminated strings ignoring case differences. Not - * recommended for non-ASCII strings. - * - * PARAMETERS: - * IN s, t : The strings to compare. - * - * RETURNS: - * 0 if the strings are equivalent, - * < 0 if s is lexically less than t, - * > 0 if s is lexically greater than t. - */ -int -dropt_stricmp(const dropt_char* s, const dropt_char* t) -{ - assert(s != NULL); - assert(t != NULL); - return dropt_strnicmp(s, t, SIZE_MAX); -} - - -/** dropt_strnicmp - * - * Compares the first n characters of two strings, ignoring case - * differences. Not recommended for non-ASCII strings. - * - * PARAMETERS: - * IN s, t : The strings to compare. - * IN n : The maximum number of dropt_char-s to compare. - * - * RETURNS: - * 0 if the strings are equivalent, - * < 0 if s is lexically less than t, - * > 0 if s is lexically greater than t. - */ -int -dropt_strnicmp(const dropt_char* s, const dropt_char* t, size_t n) -{ - assert(s != NULL); - assert(t != NULL); - - if (s == t) { return 0; } - - while (n--) - { - if (*s == DROPT_TEXT_LITERAL('\0') && *t == DROPT_TEXT_LITERAL('\0')) - { - break; - } - else if (*s == *t || dropt_tolower(*s) == dropt_tolower(*t)) - { - s++; - t++; - } - else - { - return (dropt_tolower(*s) < dropt_tolower(*t)) - ? -1 - : +1; - } - } - - return 0; -} - - -#ifndef DROPT_NO_STRING_BUFFERS -/** dropt_vsnprintf - * - * vsnprintf wrapper to provide ISO C99-compliant behavior. - * - * PARAMETERS: - * OUT s : The destination buffer. May be NULL if n is 0. - * If non-NULL, always NUL-terminated. - * IN n : The size of the destination buffer, measured in - * dropt_char-s. - * IN format : printf-style format specifier. Must not be NULL. - * IN args : Arguments to insert into the formatted string. - * - * RETURNS: - * The number of characters that would be written to the destination - * buffer if it's sufficiently large, excluding the NUL-terminator. - * Returns -1 on error. - */ -int -dropt_vsnprintf(dropt_char* s, size_t n, const dropt_char* format, va_list args) -{ -#if __STDC_VERSION__ >= 199901L || __GNUC__ - /* ISO C99-compliant. - * - * As far as I can tell, gcc's implementation of vsnprintf has always - * matched the behavior required by the C99 standard (which is to - * return the necessary buffer size). - * - * Note that this won't work with wchar_t because there is no true, - * standard wchar_t equivalent of snprintf. swprintf comes close but - * doesn't return the necessary buffer size (and the standard does not - * provide a guaranteed way to test if truncation occurred), and its - * format string can't be used interchangeably with snprintf. - * - * It's simpler not to support wchar_t on non-Windows platforms. - */ - assert(format != NULL); - return vsnprintf(s, n, format, args); -#elif defined __BORLANDC__ - /* Borland's compiler neglects to NUL-terminate. */ - int ret; - assert(format != NULL); - ret = vsnprintf(s, n, format, args); - if (n != 0) { s[n - 1] = DROPT_TEXT_LITERAL('\0'); } - return ret; -#elif defined _MSC_VER - /* _vsntprintf and _vsnprintf_s on Windows don't have C99 semantics; - * they return -1 if truncation occurs. - */ - va_list argsCopy; - int ret; - - assert(format != NULL); - - va_copy(argsCopy, args); - ret = _vsctprintf(format, argsCopy); - va_end(argsCopy); - - if (n != 0) - { - assert(s != NULL); - - #if _MSC_VER >= 1400 - (void) _vsntprintf_s(s, n, _TRUNCATE, format, args); - #else - /* This version doesn't necessarily NUL-terminate. Sigh. */ - (void) _vsnprintf(s, n, format, args); - s[n - 1] = DROPT_TEXT_LITERAL('\0'); - #endif - } - - return ret; - -#else - #error Unsupported platform. dropt_vsnprintf unimplemented. - return -1; -#endif -} - - -/** See dropt_vsnprintf. */ -int -dropt_snprintf(dropt_char* s, size_t n, const dropt_char* format, ...) -{ - int ret; - va_list args; - va_start(args, format); - ret = dropt_vsnprintf(s, n, format, args); - va_end(args); - return ret; -} - - -/** dropt_vasprintf - * - * Allocates a formatted string with vprintf semantics. - * - * PARAMETERS: - * IN format : printf-style format specifier. Must not be NULL. - * IN args : Arguments to insert into the formatted string. - * - * RETURNS: - * The formatted string, which is always NUL-terminated. The caller - * is responsible for calling free() on it when no longer needed. - * Returns NULL on error. - */ -dropt_char* -dropt_vasprintf(const dropt_char* format, va_list args) -{ - dropt_char* s = NULL; - int len; - va_list argsCopy; - assert(format != NULL); - - va_copy(argsCopy, args); - len = dropt_vsnprintf(NULL, 0, format, argsCopy); - va_end(argsCopy); - - if (len >= 0) - { - size_t n = len + 1 /* NUL */; - s = dropt_safe_malloc(n, sizeof *s); - if (s != NULL) - { - dropt_vsnprintf(s, n, format, args); - } - } - - return s; -} - - -/** See dropt_vasprintf. */ -dropt_char* -dropt_asprintf(const dropt_char* format, ...) -{ - dropt_char* s; - - va_list args; - va_start(args, format); - s = dropt_vasprintf(format, args); - va_end(args); - - return s; -} - - -/** dropt_ssopen - * - * Constructs a new dropt_stringstream. - * - * RETURNS: - * An initialized dropt_stringstream. The caller is responsible for - * calling either dropt_ssclose() or dropt_ssfinalize() on it when - * no longer needed. - * Returns NULL on error. - */ -dropt_stringstream* -dropt_ssopen(void) -{ - dropt_stringstream* ss = malloc(sizeof *ss); - if (ss != NULL) - { - ss->used = 0; - ss->maxSize = default_stringstream_buffer_size; - ss->string = dropt_safe_malloc(ss->maxSize, sizeof *ss->string); - if (ss->string == NULL) - { - free(ss); - ss = NULL; - } - else - { - ss->string[0] = DROPT_TEXT_LITERAL('\0'); - } - } - return ss; -} - - -/** dropt_ssclose - * - * Destroys a dropt_stringstream. - * - * PARAMETERS: - * IN/OUT ss : The dropt_stringstream. - */ -void -dropt_ssclose(dropt_stringstream* ss) -{ - if (ss != NULL) - { - free(ss->string); - free(ss); - } -} - - -/** dropt_ssgetfreespace - * - * RETURNS: - * The amount of free space in the dropt_stringstream's internal - * buffer, measured in dropt_char-s. Space used for the - * NUL-terminator is considered free. (The amount of free space - * therefore is always positive.) - */ -static size_t -dropt_ssgetfreespace(const dropt_stringstream* ss) -{ - assert(ss != NULL); - assert(ss->maxSize > 0); - assert(ss->maxSize > ss->used); - return ss->maxSize - ss->used; -} - - -/** dropt_ssresize - * - * Resizes a dropt_stringstream's internal buffer. If the requested - * size is less than the amount of buffer already in use, the buffer - * will be shrunk to the minimum size necessary. - * - * PARAMETERS: - * IN/OUT ss : The dropt_stringstream. - * IN n : The desired buffer size, in dropt_char-s. - * - * RETURNS: - * The new size of the dropt_stringstream's buffer in dropt_char-s, - * including space for a terminating NUL. - */ -static size_t -dropt_ssresize(dropt_stringstream* ss, size_t n) -{ - assert(ss != NULL); - - /* Don't allow shrinking if it will truncate the string. */ - if (n < ss->maxSize) { n = MAX(n, ss->used + 1 /* NUL */); } - - /* There should always be a buffer to point to. */ - assert(n > 0); - - if (n != ss->maxSize) - { - dropt_char* p = dropt_safe_realloc(ss->string, n, sizeof *ss->string); - if (p != NULL) - { - ss->string = p; - ss->maxSize = n; - assert(ss->maxSize > 0); - } - } - return ss->maxSize; -} - - -/** dropt_ssclear - * - * Clears and re-initializes a dropt_stringstream. - * - * PARAMETERS: - * IN/OUT ss : The dropt_stringstream - */ -void -dropt_ssclear(dropt_stringstream* ss) -{ - assert(ss != NULL); - - ss->string[0] = DROPT_TEXT_LITERAL('\0'); - ss->used = 0; - - dropt_ssresize(ss, default_stringstream_buffer_size); -} - - -/** dropt_ssfinalize - * - * Finalizes a dropt_stringstream; returns the contained string and - * destroys the dropt_stringstream. - * - * PARAMETERS: - * IN/OUT ss : The dropt_stringstream. - * - * RETURNS: - * The dropt_stringstream's string, which is always NUL-terminated. - * Note that the caller assumes ownership of the returned string and - * is responsible for calling free() on it when no longer needed. - */ -dropt_char* -dropt_ssfinalize(dropt_stringstream* ss) -{ - dropt_char* s; - assert(ss != NULL); - - /* Shrink to fit. */ - dropt_ssresize(ss, 0); - - s = ss->string; - ss->string = NULL; - - dropt_ssclose(ss); - - return s; -} - - -/** dropt_ssgetstring - * - * PARAMETERS: - * IN ss : The dropt_stringstream. - * - * RETURNS: - * The dropt_stringstream's string, which is always NUL-terminated. - * The returned string will no longer be valid if further operations - * are performed on the dropt_stringstream or if the - * dropt_stringstream is closed. - */ -const dropt_char* -dropt_ssgetstring(const dropt_stringstream* ss) -{ - assert(ss != NULL); - return ss->string; -} - - -/** dropt_vssprintf - * - * Appends a formatted string with vprintf semantics to a - * dropt_stringstream. - * - * PARAMETERS: - * IN/OUT ss : The dropt_stringstream. - * IN format : printf-style format specifier. Must not be NULL. - * IN args : Arguments to insert into the formatted string. - * - * RETURNS: - * The number of characters written to the dropt_stringstream, - * excluding the NUL-terminator. - * Returns a negative value on error. - */ -int -dropt_vssprintf(dropt_stringstream* ss, const dropt_char* format, va_list args) -{ - int n; - va_list argsCopy; - assert(ss != NULL); - assert(format != NULL); - - va_copy(argsCopy, args); - n = dropt_vsnprintf(NULL, 0, format, argsCopy); - va_end(argsCopy); - - if (n > 0) - { - size_t available = dropt_ssgetfreespace(ss); - if ((unsigned int) n >= available) - { - /* It's possible that newSize < ss->maxSize if - * GROWN_STRINGSTREAM_BUFFER_SIZE overflows, but it should be - * safe since we'll recompute the available space. - */ - size_t newSize = GROWN_STRINGSTREAM_BUFFER_SIZE(ss->maxSize, n); - dropt_ssresize(ss, newSize); - available = dropt_ssgetfreespace(ss); - } - assert(available > 0); /* Space always is reserved for NUL. */ - - /* snprintf's family of functions return the number of characters - * that would be output with a sufficiently large buffer, excluding - * NUL. - */ - n = dropt_vsnprintf(ss->string + ss->used, available, format, args); - - /* We couldn't allocate enough space. */ - if ((unsigned int) n >= available) { n = -1; } - - if (n > 0) { ss->used += n; } - } - return n; -} - - -/** See dropt_vssprintf. */ -int -dropt_ssprintf(dropt_stringstream* ss, const dropt_char* format, ...) -{ - int n; - - va_list args; - va_start(args, format); - n = dropt_vssprintf(ss, format, args); - va_end(args); - - return n; -} -#endif /* DROPT_NO_STRING_BUFFERS */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ippcpdefs.h b/external/epid-sdk-3.0.0/ext/ipp/include/ippcpdefs.h deleted file mode 100644 index aa306221..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ippcpdefs.h +++ /dev/null @@ -1,371 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippCP) definitions. -// -// -*/ - - -#ifndef __IPPCPDEFS_H__ -#define __IPPCPDEFS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined( _OWN_BLDPCS ) - -typedef Ipp32u IppAlgId; - -/* -// ========================================================= -// Symmetric Ciphers -// ========================================================= -*/ -typedef enum { - ippPaddingNONE = 0, /*NONE = 0,*/ IppsCPPaddingNONE = 0, - ippPaddingPKCS7 = 1, /*PKCS7 = 1,*/ IppsCPPaddingPKCS7 = 1, - ippPaddingZEROS = 2, /*ZEROS = 2,*/ IppsCPPaddingZEROS = 2 -} IppsPadding, IppsCPPadding; - -typedef struct _cpDES IppsDESSpec; -typedef struct _cpRijndael128 IppsAESSpec; -typedef struct _cpRijndael128 IppsRijndael128Spec; -typedef struct _cpSMS4 IppsSMS4Spec; - -/* TDES */ -#define DES_BLOCKSIZE (64) /* cipher blocksize (bits) */ -#define TDES_BLOCKSIZE DES_BLOCKSIZE - -#define DES_KEYSIZE (64) /* cipher keysize (bits) */ -#define TDES_KEYSIZE DES_KEYSIZE - -/* AES */ -#define IPP_AES_BLOCK_BITSIZE (128) /* cipher blocksizes (bits) */ - -/* Rijndael */ -typedef enum { - ippRijndaelKey128 = 128, IppsRijndaelKey128 = 128, /* 128-bit key */ - ippRijndaelKey192 = 192, IppsRijndaelKey192 = 192, /* 192-bit key */ - ippRijndaelKey256 = 256, IppsRijndaelKey256 = 256 /* 256-bit key */ -} IppsRijndaelKeyLength; - -/* AES based authentication & confidence */ -typedef struct _cpRijndael128GCM IppsRijndael128GCMState; -typedef struct _cpAES_CCM IppsAES_CCMState; -typedef struct _cpRijndael128GCM IppsAES_GCMState; - -/* -// ========================================================= -// ARCFOUR Stream Cipher -// ========================================================= -*/ -typedef struct _cpARCfour IppsARCFourState; - -#define IPP_ARCFOUR_KEYMAX_SIZE (256) /* max key length (bytes) */ -#define MAX_ARCFOUR_KEY_LEN IPP_ARCFOUR_KEYMAX_SIZE /* obsolete */ - -/* -// ========================================================= -// One-Way Hash Functions -// ========================================================= -*/ -typedef enum { - ippHashAlg_Unknown, - ippHashAlg_SHA1, - ippHashAlg_SHA256, - ippHashAlg_SHA224, - ippHashAlg_SHA512, - ippHashAlg_SHA384, - ippHashAlg_MD5, - ippHashAlg_SM3, - ippHashAlg_SHA512_224, - ippHashAlg_SHA512_256, - ippHashAlg_MaxNo -} IppHashAlgId; - -#define IPP_ALG_HASH_UNKNOWN (ippHashAlg_Unknown) /* unknown */ -#define IPP_ALG_HASH_SHA1 (ippHashAlg_SHA1) /* SHA1 */ -#define IPP_ALG_HASH_SHA256 (ippHashAlg_SHA256) /* SHA256 */ -#define IPP_ALG_HASH_SHA224 (ippHashAlg_SHA224) /* SHA224 or SHA256/224 */ -#define IPP_ALG_HASH_SHA512 (ippHashAlg_SHA512) /* SHA512 */ -#define IPP_ALG_HASH_SHA384 (ippHashAlg_SHA384) /* SHA384 or SHA512/384 */ -#define IPP_ALG_HASH_MD5 (ippHashAlg_MD5) /* MD5 */ -#define IPP_ALG_HASH_SM3 (ippHashAlg_SM3) /* SM3 */ -#define IPP_ALG_HASH_SHA512_224 (ippHashAlg_SHA512_224) /* SHA512/224 */ -#define IPP_ALG_HASH_SHA512_256 (ippHashAlg_SHA512_256) /* SHA512/256 */ -#define IPP_ALG_HASH_LIMIT (ippHashAlg_MaxNo) /* hash alg limiter*/ - -typedef struct _cpSHA1 IppsSHA1State; -typedef struct _cpSHA256 IppsSHA256State; -typedef struct _cpSHA256 IppsSHA224State; -typedef struct _cpSHA512 IppsSHA512State; -typedef struct _cpSHA512 IppsSHA384State; -typedef struct _cpMD5 IppsMD5State; -typedef struct _cpSM3 IppsSM3State; -typedef struct _cpHashCtx IppsHashState; - - -/* MGF */ -typedef IppStatus (__STDCALL *IppMGF)(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen); -/* HASH function */ -typedef IppStatus (__STDCALL *IppHASH)(const Ipp8u* pMsg, int len, Ipp8u* pMD); - -#define IPP_SHA1_DIGEST_BITSIZE 160 /* digest size (bits) */ -#define IPP_SHA256_DIGEST_BITSIZE 256 -#define IPP_SHA224_DIGEST_BITSIZE 224 -#define IPP_SHA384_DIGEST_BITSIZE 384 -#define IPP_SHA512_DIGEST_BITSIZE 512 -#define IPP_MD5_DIGEST_BITSIZE 128 -#define IPP_SM3_DIGEST_BITSIZE 256 -#define IPP_SHA512_224_DIGEST_BITSIZE 224 -#define IPP_SHA512_256_DIGEST_BITSIZE 256 - -/* -// ========================================================= -// Keyed-Hash Message Authentication Codes -// ========================================================= -*/ -typedef struct _cpHMAC IppsHMACState; -typedef struct _cpHMAC IppsHMACSHA1State; -typedef struct _cpHMAC IppsHMACSHA256State; -typedef struct _cpHMAC IppsHMACSHA224State; -typedef struct _cpHMAC IppsHMACSHA384State; -typedef struct _cpHMAC IppsHMACSHA512State; -typedef struct _cpHMAC IppsHMACMD5State; - -/* -// ========================================================= -// Data Authentication Codes -// ========================================================= -*/ -typedef struct _cpAES_CMAC IppsAES_CMACState; - -/* -// ========================================================= -// Big Number Integer Arithmetic -// ========================================================= -*/ -typedef enum { - ippBigNumNEG = 0, IppsBigNumNEG = 0, - ippBigNumPOS = 1, IppsBigNumPOS = 1 -} IppsBigNumSGN; - -typedef enum { - ippBinaryMethod = 0, IppsBinaryMethod = 0, - ippSlidingWindows = 1, IppsSlidingWindows = 1 -} IppsExpMethod; - -typedef struct _cpBigNum IppsBigNumState; -typedef struct _cpMontgomery IppsMontState; -typedef struct _cpPRNG IppsPRNGState; -typedef struct _cpPrime IppsPrimeState; - -/* External Bit Supplier */ -typedef IppStatus (__STDCALL *IppBitSupplier)(Ipp32u* pRand, int nBits, void* pEbsParams); - -#define IPP_IS_EQ (0) -#define IPP_IS_GT (1) -#define IPP_IS_LT (2) -#define IPP_IS_NE (3) -#define IPP_IS_NA (4) - -#define IPP_IS_PRIME (5) -#define IPP_IS_COMPOSITE (6) - -#define IPP_IS_VALID (7) -#define IPP_IS_INVALID (8) -#define IPP_IS_INCOMPLETE (9) -#define IPP_IS_ATINFINITY (10) - -#define IS_ZERO IPP_IS_EQ -#define GREATER_THAN_ZERO IPP_IS_GT -#define LESS_THAN_ZERO IPP_IS_LT -#define IS_PRIME IPP_IS_PRIME -#define IS_COMPOSITE IPP_IS_COMPOSITE -#define IS_VALID_KEY IPP_IS_VALID -#define IS_INVALID_KEY IPP_IS_INVALID -#define IS_INCOMPLETED_KEY IPP_IS_INCOMPLETE - -/* -// ========================================================= -// RSA Cryptography -// ========================================================= -*/ -typedef struct _cpRSA IppsRSAState; - -/* key types */ -typedef enum { - ippRSApublic = 0x20000000, IppRSApublic = 0x20000000, - ippRSAprivate = 0x40000000, IppRSAprivate = 0x40000000 -} IppRSAKeyType; - -/* key component's tag */ -typedef enum { - ippRSAkeyN = 0x01, IppRSAkeyN = 0x01, - ippRSAkeyE = 0x02, IppRSAkeyE = 0x02, - ippRSAkeyD = 0x04, IppRSAkeyD = 0x04, - ippRSAkeyP = 0x08, IppRSAkeyP = 0x08, - ippRSAkeyQ = 0x10, IppRSAkeyQ = 0x10, - ippRSAkeyDp = 0x20, IppRSAkeyDp = 0x20, - ippRSAkeyDq = 0x40, IppRSAkeyDq = 0x40, - ippRSAkeyQinv = 0x80, IppRSAkeyQinv = 0x80 -} IppRSAKeyTag; - -typedef struct _cpRSA_public_key IppsRSAPublicKeyState; -typedef struct _cpRSA_private_key IppsRSAPrivateKeyState; - -#define MIN_RSA_SIZE (8) -#define MAX_RSA_SIZE (4096) - -/* -// ========================================================= -// DL Cryptography -// ========================================================= -*/ -typedef struct _cpDLP IppsDLPState; - -/* domain parameter tags */ -typedef enum { - ippDLPkeyP = 0x01, IppDLPkeyP = 0x01, - ippDLPkeyR = 0x02, IppDLPkeyR = 0x02, - ippDLPkeyG = 0x04, IppDLPkeyG = 0x04 -} IppDLPKeyTag; - -typedef enum { - ippDLValid, /* validation pass successfully */ - - ippDLBaseIsEven, /* !(P is odd) */ - ippDLOrderIsEven, /* !(R is odd) */ - ippDLInvalidBaseRange, /* !(2^(L-1) < P < 2^L) */ - ippDLInvalidOrderRange, /* !(2^(M-1) < R < 2^M) */ - ippDLCompositeBase, - ippDLCompositeOrder, - ippDLInvalidCofactor, /* !( R|(P-1) ) */ - ippDLInvalidGenerator, /* !( G^R == 1 (mod P) ) */ - /* !(1 < G < (P-1)) */ - ippDLInvalidPrivateKey, /* !(1 < private < (R-1)) */ - ippDLInvalidPublicKey, /* !(1 < public <=(P-1)) */ - ippDLInvalidKeyPair, /* !(G^private == public */ - - ippDLInvalidSignature /* invalid signature */ -} IppDLResult; - -#define MIN_DLP_BITSIZE (512) -#define MIN_DLP_BITSIZER (160) - -#define MIN_DLPDH_BITSIZE (512) -#define MIN_DLPDH_BITSIZER (160) -#define DEF_DLPDH_BITSIZER (160) - -#define MIN_DLPDSA_BITSIZE (512) -#define MAX_DLPDSA_BITSIZE (1024) -#define MIN_DLPDSA_BITSIZER (160) -#define DEF_DLPDSA_BITSIZER (160) -#define MAX_DLPDSA_BITSIZER (160) -#define MIN_DLPDSA_SEEDSIZE (160) - -/* -// ========================================================= -// EC Cryptography -// ========================================================= -*/ -typedef struct _cpECCP IppsECCPState; -typedef struct _cpECCB IppsECCBState; -typedef struct _cpECCPPoint IppsECCPPointState; -typedef struct _cpECCBPoint IppsECCBPointState; - -/* operation result */ -typedef enum { - ippECValid, /* validation pass successfully */ - - ippECCompositeBase, /* field based on composite */ - ippECComplicatedBase, /* number of non-zero terms in the polynomial (> PRIME_ARR_MAX) */ - ippECIsZeroDiscriminant,/* zero discriminant */ - ippECCompositeOrder, /* composite order of base point */ - ippECInvalidOrder, /* invalid base point order */ - ippECIsWeakMOV, /* weak Meneze-Okamoto-Vanstone reduction attack */ - ippECIsWeakSSSA, /* weak Semaev-Smart,Satoh-Araki reduction attack */ - ippECIsSupersingular, /* supersingular curve */ - - ippECInvalidPrivateKey, /* !(0 < Private < order) */ - ippECInvalidPublicKey, /* (order*PublicKey != Infinity) */ - ippECInvalidKeyPair, /* (Private*BasePoint != PublicKey) */ - - ippECPointOutOfGroup, /* out of group (order*P != Infinity) */ - ippECPointIsAtInfinite, /* point (P=(Px,Py)) at Infinity */ - ippECPointIsNotValid, /* point (P=(Px,Py)) out-of EC */ - - ippECPointIsEqual, /* compared points are equal */ - ippECPointIsNotEqual, /* compared points are different */ - - ippECInvalidSignature /* invalid signature */ -} IppECResult; - -/* domain parameter set/get flags */ -typedef enum { - ippECarbitrary =0x00000, IppECCArbitrary = 0x00000, /* arbitrary ECC */ - - ippECPstd = 0x10000, IppECCPStd = 0x10000, /* random (recommended) EC over FG(p): */ - ippECPstd112r1 = ippECPstd, IppECCPStd112r1 = IppECCPStd, /* secp112r1 curve */ - ippECPstd112r2 = ippECPstd+1, IppECCPStd112r2 = IppECCPStd+1, /* secp112r2 curve */ - ippECPstd128r1 = ippECPstd+2, IppECCPStd128r1 = IppECCPStd+2, /* secp128r1 curve */ - ippECPstd128r2 = ippECPstd+3, IppECCPStd128r2 = IppECCPStd+3, /* secp128r2 curve */ - ippECPstd160r1 = ippECPstd+4, IppECCPStd160r1 = IppECCPStd+4, /* secp160r1 curve */ - ippECPstd160r2 = ippECPstd+5, IppECCPStd160r2 = IppECCPStd+5, /* secp160r2 curve */ - ippECPstd192r1 = ippECPstd+6, IppECCPStd192r1 = IppECCPStd+6, /* secp192r1 curve */ - ippECPstd224r1 = ippECPstd+7, IppECCPStd224r1 = IppECCPStd+7, /* secp224r1 curve */ - ippECPstd256r1 = ippECPstd+8, IppECCPStd256r1 = IppECCPStd+8, /* secp256r1 curve */ - ippECPstd384r1 = ippECPstd+9, IppECCPStd384r1 = IppECCPStd+9, /* secp384r1 curve */ - ippECPstd521r1 = ippECPstd+10, IppECCPStd521r1 = IppECCPStd+10, /* secp521r1 curve */ - ippECPstdSM2 = ippECPstd+11, IppECCPStdSM2 = IppECCPStd+11, /* TMP SM2 curve */ - ippEC_TPM_SM2_P256= ippECPstd+11, - ippEC_TPM_BN_P256 = ippECPstd+12, /* TPM BN_P256 curve */ - - /* curves over binary finit fields are not supported in IPP 9.0 */ - IppECCBStd = 0x20000, /* random (recommended) EC over FG(2^m): */ - IppECCBStd113r1 = IppECCBStd, /* sect113r1 curve */ - IppECCBStd113r2 = IppECCBStd+1, /* sect113r2 curve */ - IppECCBStd131r1 = IppECCBStd+2, /* sect131r1 curve */ - IppECCBStd131r2 = IppECCBStd+3, /* sect131r2 curve */ - IppECCBStd163r1 = IppECCBStd+4, /* sect163r1 curve */ - IppECCBStd163r2 = IppECCBStd+5, /* sect163r2 curve */ - IppECCBStd193r1 = IppECCBStd+6, /* sect193r1 curve */ - IppECCBStd193r2 = IppECCBStd+7, /* sect193r2 curve */ - IppECCBStd233r1 = IppECCBStd+8, /* sect233r1 curve */ - IppECCBStd283r1 = IppECCBStd+9, /* sect283r1 curve */ - IppECCBStd409r1 = IppECCBStd+10, /* sect409r1 curve */ - IppECCBStd571r1 = IppECCBStd+11, /* sect571r1 curve */ - - IppECCKStd = 0x40000, /* Koblitz (recommended) EC over FG(2^m): */ - IppECCBStd163k1 = IppECCKStd, /* Koblitz 163 curve */ - IppECCBStd233k1 = IppECCKStd+1, /* Koblitz 233 curve */ - IppECCBStd239k1 = IppECCKStd+2, /* Koblitz 239 curve */ - IppECCBStd283k1 = IppECCKStd+3, /* Koblitz 283 curve */ - IppECCBStd409k1 = IppECCKStd+4, /* Koblitz 409 curve */ - IppECCBStd571k1 = IppECCKStd+5 /* Koblitz 571 curve */ -} IppsECType, IppECCType; - -#endif /* _OWN_BLDPCS */ - -#ifdef __cplusplus -} -#endif - -#endif /* __IPPCPDEFS_H__ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ippcpepid.h b/external/epid-sdk-3.0.0/ext/ipp/include/ippcpepid.h deleted file mode 100644 index d36661bf..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ippcpepid.h +++ /dev/null @@ -1,218 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// ippCP Intel(R) EPID functionality -// -// -*/ - - -#if !defined( __IPPCPEPID_H__ ) || defined( _OWN_BLDPCS ) -#define __IPPCPEPID_H__ - - -#if defined (_WIN32_WCE) && defined (_M_IX86) && defined (__stdcall) - #define _IPP_STDCALL_CDECL - #undef __stdcall -#endif - - -#ifndef __IPPDEFS_H__ - #include "ippdefs.h" -#endif - -#ifndef __IPPCPDEFS_H__ - #include "ippcpdefs.h" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined( _IPP_NO_DEFAULT_LIB ) - #if defined( _IPP_PARALLEL_DYNAMIC ) || defined( _IPP_SEQUENTIAL_DYNAMIC ) - #pragma comment( lib, "ippcpepid" ) - #pragma comment( lib, "ippcp" ) - #pragma comment( lib, "ippcore" ) - #elif defined( _IPP_PARALLEL_STATIC ) || defined( _IPP_SEQUENTIAL_STATIC ) - #pragma comment( lib, "ippcpepidmt" ) - #pragma comment( lib, "ippcpmt" ) - #pragma comment( lib, "ippcoremt" ) - #endif -#endif - - -/* ///////////////////////////////////////////////////////////////////////////// -// Name: ippcpepidGetLibVersion -// Purpose: getting of the library version -// Returns: the structure of information about version of ippCP EPID library -// Parameters: -// -// Notes: not necessary to release the returned structure -*/ -IPPAPI( const IppLibraryVersion*, ippcpepidGetLibVersion, (void) ) - - -/* -// Finite Field Low Level Math -*/ -#define IPP_MIN_GF_BITSIZE (2) /* min bitsize for GF element */ -#define IPP_MAX_GF_BITSIZE (4096) /* max bitsize for GF element */ - -//#define IPP_IS_EQ IS_ZERO //(0) -//#define IPP_IS_NE (1) -//#define IPP_IS_GT GREATER_THAN_ZERO //(2) -//#define IPP_IS_LT LESS_THAN_ZERO // (3) -//#define IPP_IS_NA (4) - -#if !defined( _OWN_BLDPCS ) -typedef struct _cpGFp IppsGFpState; -typedef struct _cpElementGFp IppsGFpElement; - -typedef struct { - const IppsGFpState* pBasicGF; - const IppsGFpState* pGroundGF; - int basicGFdegree; - int groundGFdegree; - int elementLen; -} IppsGFpInfo; -#endif - -#if !defined( _OWN_BLDPCS ) -typedef enum { - ippMD5 = 0x00, - ippSHA1 = 0x01, - ippSHA256 = 0x02, ippSHA224 = 0x12, - ippSHA512 = 0x03, ippSHA384 = 0x13 -} IppHashID; -#endif /* _OWN_BLDPCS */ - - -IPPAPI(IppStatus, ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) -IPPAPI(IppStatus, ippsGFpInit, (const Ipp32u* pPime, int bitSize, IppsGFpState* pGFp)) - -IPPAPI(IppStatus, ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) -IPPAPI(IppStatus, ippsGFpxInit, (const IppsGFpState* pGroundGF, const Ipp32u* pIrrPolynomial, int degree, IppsGFpState* pGFpx)) -IPPAPI(IppStatus, ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, const IppsGFpElement* pGroundElm, int degree, IppsGFpState* pGFpx)) - -IPPAPI(IppStatus, ippsGFpGetInfo,(const IppsGFpState* pGFp, IppsGFpInfo* pInfo)) -IPPAPI(IppStatus, ippsGFpGetModulus,(const IppsGFpState* pGFp, Ipp32u* pModulus)) - -IPPAPI(IppStatus, ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) - -//IPPAPI(IppStatus, ippsBasicGFpRef,(const IppsGFpState* pGFp, IppsGFpState** ppBasicGF)) -//IPPAPI(IppStatus, ippsGroundGFpRef,(const IppsGFpState* pGFp, IppsGFpState** ppGroundGF)) -//IPPAPI(IppStatus, ippsGFpGetDegree,(const IppsGFpState* pGFp, int* pDegree)) -//IPPAPI(IppStatus, ippsGFpGetElementLen,(const IppsGFpState* pGFp, int* pElmLen)) -//IPPAPI(IppStatus, ippsGFpCmp, (const IppsGFpState* pGFp1, const IppsGFpState* pGFp2, IppGFpResult* pCmpResult)) - -IPPAPI(IppStatus, ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) -IPPAPI(IppStatus, ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) - -IPPAPI(IppStatus, ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSetElementRandom,(IppBitSupplier rndFunc, void* pRndParam, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppHashID hashID, IppsGFpElement* pElm, IppsGFpState* pGF)) -IPPAPI(IppStatus, ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) - -IPPAPI(IppStatus, ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) - -//IPPAPI(IppStatus, ippsGFpSetPolyTerm, (const Ipp32u* pTerm, int nsT, int termDegree, IppsGFpElement* pElm, IppsGFpState* pGF)) -//IPPAPI(IppStatus, ippsGFpGetPolyTerm, (const IppsGFpElement* pElm, int termDegree, Ipp32u* pTerm, int nsT, IppsGFpState* pGF)) - -IPPAPI(IppStatus, ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) - -IPPAPI(IppStatus, ippsGFpAdd_GFpE,(const IppsGFpElement* pA, const IppsGFpElement* pGroundB, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpSub_GFpE,(const IppsGFpElement* pA, const IppsGFpElement* pGroundB, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, ippsGFpMul_GFpE,(const IppsGFpElement* pA, const IppsGFpElement* pGroundB, IppsGFpElement* pR, IppsGFpState* pGFp)) - - -#if !defined( _OWN_BLDPCS ) -typedef struct _cpGFpEC IppsGFpECState; -typedef struct _cpGFpECPoint IppsGFpECPoint; -#endif - -IPPAPI(IppStatus, ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) -IPPAPI(IppStatus, ippsGFpECInit, (const IppsGFpElement* pA, const IppsGFpElement* pB, - const IppsGFpElement* pX, const IppsGFpElement* pY, - const Ipp32u* pOrder, int orderLen, - const Ipp32u* pCofactor, int cofactorLen, - IppsGFpState* pGF, IppsGFpECState* pEC)) - -IPPAPI(IppStatus, ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) - -IPPAPI(IppStatus, ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, - const IppsGFpElement* pX, const IppsGFpElement* pY, - const Ipp32u* pOrder, int orderLen, - const Ipp32u* pCofactor, int cofactorLen, - IppsGFpECState* pEC)) - -IPPAPI(IppStatus, ippsGFpECGet,(const IppsGFpECState* pEC, - const IppsGFpState** ppGF, - IppsGFpElement* pA, IppsGFpElement* pB, - IppsGFpElement* pX, IppsGFpElement* pY, - const Ipp32u** ppOrder, int* pOrderLen, - const Ipp32u** ppCofactor, int* pCoFactorLen)) - -IPPAPI(IppStatus, ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPAPI(IppStatus, ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) -IPPAPI(IppStatus, ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) - -IPPAPI(IppStatus, ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECSetPointRandom,(IppBitSupplier rndFunc, void* pRndParam, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppHashID hashID, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPAPI(IppStatus, ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) - -IPPAPI(IppStatus, ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) - -IPPAPI(IppStatus, ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPAPI(IppStatus, ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -#ifdef __cplusplus -} -#endif - - -#if defined (_IPP_STDCALL_CDECL) - #undef _IPP_STDCALL_CDECL - #define __stdcall __cdecl -#endif - - -#endif /* __IPPCPEPID_H__ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/ippcommon.parts b/external/epid-sdk-3.0.0/ext/ipp/ippcommon.parts deleted file mode 100644 index 62b601cf..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/ippcommon.parts +++ /dev/null @@ -1,56 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ -Import('*') - -env.PartVersion("9.0.1") -env.PartName("ippcommon") -env.DependsOn([]) - -#prebuild installs prebuild headers instead of src headers. -#internal ipp includes src/primitives/ipp/ -env.Append(CPPPATH=[AbsDir('sources/include/')]) - -# env.Append(CPPDEFINES = '_IPP_BE') #only for BE targets - -#includes to install -install_headers = Pattern(src_dir='include/', - includes=['ippdefs.h', - 'ippversion.h', - 'ippcore.h', - 'ippbase.h', - 'ipptypes.h' - ], - excludes=[], - recursive=True) - -source_headers = Pattern(src_dir='sources/include/', - includes=['*'], - excludes=[], - recursive=True) -parts_file = Pattern(src_dir='.', - includes=['ippcommon.parts'], - excludes=[], - recursive=True) - -env.ExportCPPPATH([AbsDir('sources/include/')]) - -if 'install_package' in env['MODE']: - # All files at /ext/ipp/include - env.InstallTopLevel(install_headers, sub_dir='ext/ipp/include') - env.InstallTopLevel(source_headers, sub_dir='ext/ipp/sources/include') - env.InstallTopLevel(parts_file, sub_dir='ext/ipp/') -#else - env.SdkInclude(install_headers) diff --git a/external/epid-sdk-3.0.0/ext/ipp/ippcp.parts b/external/epid-sdk-3.0.0/ext/ipp/ippcp.parts deleted file mode 100644 index a559908e..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/ippcp.parts +++ /dev/null @@ -1,115 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ -Import('*') - -import os - -env.PartVersion("9.0.1") -env.PartName("ippcp") -env.DependsOn([Component('ippcommon')]) -ipp_libname = '${PART_SHORT_NAME}' - -ipp_src_install_loc = 'epid/src/primitives/${IPP_DIR}/' - -env.ExportCPPPATH([AbsDir('sources/ippcp/src/')]) #ippcpepid needs this - -#includes to install -install_headers = Pattern(src_dir='include/', - includes=[ - 'ippcp.h', - 'ippcpdefs.h', - ], - excludes=[], - recursive=True) -# common headers, for SdkInclude -common_headers = Pattern(src_dir='include/', - includes=['ippdefs.h', - 'ippversion.h', - 'ippcore.h', - 'ippbase.h', - 'ipptypes.h'], - excludes=[], - recursive=True) -#files -ippcp_files = Pattern(src_dir='sources/ippcp/src/', - includes=[ - 'pcp*.c', - ], - excludes=[], - recursive=True) - -ippdir = '' -#internal ipp includes src/primitives/ipp/ -env.Append(CPPPATH=[AbsDir('include/')]) -env.Append(CPPPATH=[AbsDir('sources/ippcp/src/')]) -#ipp defines -env.Append(CPPDEFINES='_IPP_v50_') #required for all ippcp - -env.Append(CPPDEFINES='_IPP_DEBUG') #enable function sanity checking - -if 'install_package' in env['MODE']: - # All files at /ext/ipp/source/include - env.InstallTopLevel(install_headers, sub_dir='ext/ipp/include') - src_files = Pattern(src_dir='sources/ippcp/src/', - includes=['*'], - excludes=[''], - recursive=True) - env.InstallTopLevel(src_files, sub_dir='ext/ipp/sources/ippcp/src') - this_file = Pattern(src_dir='.', - includes=['ippcp.parts'], - excludes=[], - recursive=True) - env.InstallTopLevel(this_file, sub_dir='ext/ipp/') - makefile = Pattern(src_dir='./sources/ippcp', - includes=['Makefile'], - excludes=[], - recursive=True) - env.InstallTopLevel(makefile, sub_dir='ext/ipp/sources/ippcp') - -else: - all_c_files = ippcp_files.files() - outputs = env.Library(ipp_libname, all_c_files) - - env.SdkInclude(install_headers) - env.SdkInclude(common_headers) - if 'use_commercial_ipp' in env['MODE']: - try: - IPPROOT = os.environ['IPPROOT'] - except KeyError, e: - env.PrintError("Necessary environment variable not set: ", - e, show_stack=False) - if env['TARGET_PLATFORM']['OS'] == 'win32': - libpre = '' - libpost = '.lib' - IPP_TH_SYMBOL = 'mt' - else: - libpre = 'lib' - libpost = '.a' - IPP_TH_SYMBOL = '' - if env['TARGET_PLATFORM']['ARCH'] == 'x86': - archdir = 'ia32/' - else: - archdir = 'intel64/' - - ippcp_libname = libpre + 'ippcp' + IPP_TH_SYMBOL + libpost - ippcore_libname = libpre + 'ippcore' + IPP_TH_SYMBOL + libpost - ipp_dir = IPPROOT + '/lib/' + archdir - env.SdkLib(ipp_dir + ippcp_libname) - env.SdkLib(ipp_dir + ippcore_libname) - else: - env.SdkLib(outputs) - if 'install_lib' in env['MODE']: - env.InstallLib(outputs) diff --git a/external/epid-sdk-3.0.0/ext/ipp/ippcpepid.parts b/external/epid-sdk-3.0.0/ext/ipp/ippcpepid.parts deleted file mode 100644 index 2913a55d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/ippcpepid.parts +++ /dev/null @@ -1,105 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ -Import('*') - -env.PartVersion("9.0.1") -env.PartName("ippcpepid") -env.DependsOn([ - Component('ippcommon'), - Component('ippcp'), -]) - -IPP_LIBNAME = '${PART_SHORT_NAME}' - -env.ExportCPPPATH([AbsDir('sources/ippcp/src/')]) #ippcpepid needs this - -#includes to install -install_headers = Pattern(src_dir='include/', - includes=[ - 'ippcpepid.h', - ], - excludes=[], - recursive=True) -# common headers, for SdkInclude -common_headers = Pattern(src_dir='include/', - includes=['ippdefs.h', - 'ippversion.h', - 'ippcore.h', - 'ippbase.h', - 'ipptypes.h'], - excludes=[], - recursive=True) -#files -ippcp_files = Pattern(src_dir='sources/ippcpepid/src/', - includes=[ - 'pcp*.c', - ], - excludes=['pcpepidmain.c'], - recursive=True) -#Symbols defined in following files are used by ippcpepid library -ippcp_intern_files = Pattern(src_dir='sources/ippcp/src/', - includes=[ - 'pcpmontexpbinca.c', - 'pcpmontred.c', - 'pcpbnuarith.c', - 'pcpbnu32misc.c', - 'pcpbnu32arith.c', - 'pcpbnumisc.c', - ], - recursive=True) - -ippdir = '' -#internal ipp includes src/primitives/ipp/ -env.Append(CPPPATH=[AbsDir('include/')]) -env.Append(CPPPATH=[AbsDir('sources/ippcp/src/')]) -env.Append(CPPPATH=[AbsDir('sources/ippcpepid/src/')]) -#ipp defines -env.Append(CPPDEFINES='_IPP_v50_') #required for all ippcp - -env.Append(CPPDEFINES='_IPP_DEBUG') #enable function sanity checking - -if 'install_package' in env['MODE']: - # All files at /ext/ipp/source/include - env.InstallTopLevel(install_headers, sub_dir='ext/ipp/include') - src_files = Pattern(src_dir='sources/ippcpepid/src/', - includes=['*'], - excludes=['pcpepidmain.c'], - recursive=True) - env.InstallTopLevel(src_files, sub_dir='ext/ipp/sources/ippcpepid/src') - this_file = Pattern(src_dir='.', - includes=['ippcpepid.parts'], - excludes=[], - recursive=True) - env.InstallTopLevel(this_file, sub_dir='ext/ipp/') - makefile = Pattern(src_dir='./sources/ippcpepid', - includes=['Makefile'], - excludes=[], - recursive=True) - env.InstallTopLevel(makefile, sub_dir='ext/ipp/sources/ippcpepid') - -else: - - all_c_files = ippcp_files.files() - if 'use_commercial_ipp' in env['MODE']: - all_c_files = all_c_files + ippcp_intern_files.files() - - outputs = env.Library(IPP_LIBNAME, all_c_files) - - env.SdkLib(outputs) - env.SdkInclude(install_headers) - env.SdkInclude(common_headers) - if 'install_lib' in env['MODE']: - env.InstallLib(outputs) diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/include/owndefs.h b/external/epid-sdk-3.0.0/ext/ipp/sources/include/owndefs.h deleted file mode 100644 index 1cd2e95d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/include/owndefs.h +++ /dev/null @@ -1,934 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Author(s): Alexey Korchuganov -// Anatoly Pluzhnikov -// Igor Astakhov -// Dmitry Kozhaev -// -// Created: 27-Jul-1999 20:27 -// -*/ - -#ifndef __OWNDEFS_H__ -#define __OWNDEFS_H__ - -#if defined( _VXWORKS ) - #include - #undef NONE -#endif - -#include "ippdefs.h" - -#if defined(__INTEL_COMPILER) || defined(_MSC_VER) - #define __INLINE static __inline -#elif defined( __GNUC__ ) - #define __INLINE static __inline__ -#else - #define __INLINE static -#endif - -#if defined(__INTEL_COMPILER) - #define __RESTRICT restrict -#elif !defined( __RESTRICT ) - #define __RESTRICT -#endif - -#if defined( IPP_W32DLL ) - #if defined( _MSC_VER ) || defined( __INTEL_COMPILER ) - #define IPPFUN(type,name,arg) __declspec(dllexport) type __STDCALL name arg - #else - #define IPPFUN(type,name,arg) extern type __STDCALL name arg - #endif -#else - #define IPPFUN(type,name,arg) extern type __STDCALL name arg -#endif - - -/* structure represeting 128 bit unsigned integer type */ - -typedef struct{ - Ipp64u low; - Ipp64u high; -}Ipp128u; - -#define _IPP_PX 0 /* pure C-code ia32 */ -#define _IPP_M5 1 /* Quark (Pentium) - x86+x87 ia32 */ -#define _IPP_M6 2 /* Pentium MMX - MMX ia32 */ -#define _IPP_A6 4 /* Pentium III - SSE ia32 */ -#define _IPP_W7 8 /* Pentium 4 - SSE2 ia32 */ -#define _IPP_T7 16 /* Pentium with x64 support (Nocona) - SSE3 ia32 */ -#define _IPP_V8 32 /* Merom - SSSE3 ia32 */ -#define _IPP_P8 64 /* Penryn - SSE4.1 + tick for SSE4.2 ia32 */ -#define _IPP_G9 128 /* SandyBridge (GSSE) - AVX ia32 */ -#define _IPP_H9 256 /* Haswell (AVX2) ia32 */ -#define _IPP_I0 512 /* KNL (AVX-512) ia32 */ -#define _IPP_S0 1024 /* SkyLake Xeon (AVX-512) ia32 */ - -#define _IPPXSC_PX 0 -#define _IPPXSC_S1 1 -#define _IPPXSC_S2 2 -#define _IPPXSC_C2 4 - -#define _IPPLRB_PX 0 -#define _IPPLRB_B1 1 -#define _IPPLRB_B2 2 - -#define _IPP64_PX _IPP_PX -#define _IPP64_I7 64 - -#define _IPP32E_PX _IPP_PX /* pure C-code x64 */ -#define _IPP32E_M7 32 /* Pentium with x64 support (Nocona) - SSE3 x64 */ -#define _IPP32E_U8 64 /* Merom - SSSE3 x64 */ -#define _IPP32E_Y8 128 /* Penryn - SSE4.1 + tick for SSE4.2 x64 */ -#define _IPP32E_E9 256 /* SandyBridge (GSSE) - AVX x64 */ -#define _IPP32E_L9 512 /* Haswell (AVX2) x64 */ -#define _IPP32E_N0 1024 /* KNL (AVX-512) x64 */ -#define _IPP32E_K0 2048 /* SkyLake Xeon (AVX-512) x64 */ - -#define _IPPLP32_PX _IPP_PX -#define _IPPLP32_S8 1 /* old Atom (SSSE3+movbe) (Silverthorne) ia32 */ - -#define _IPPLP64_PX _IPP_PX -#define _IPPLP64_N8 1 /* old Atom (SSSE3+movbe) (Silverthorne) x64 */ - -#if defined(__INTEL_COMPILER) || (_MSC_VER >= 1300) - #define __ALIGN8 __declspec (align(8)) - #define __ALIGN16 __declspec (align(16)) -#if !defined( OSX32 ) - #define __ALIGN32 __declspec (align(32)) -#else - #define __ALIGN32 __declspec (align(16)) -#endif - #define __ALIGN64 __declspec (align(64)) -#else - #define __ALIGN8 - #define __ALIGN16 - #define __ALIGN32 - #define __ALIGN64 -#endif - -#if defined ( _M5 ) /* Quark (Pentium) - x86+x87 ia32 */ - #define _IPP _IPP_M5 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined ( _M6 ) /* Pentium MMX - MMX ia32 */ - #define _IPP _IPP_M6 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _A6 ) /* Pentium III - SSE ia32 */ - #define _IPP _IPP_A6 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _W7 ) /* Pentium 4 - SSE2 ia32 */ - #define _IPP _IPP_W7 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _T7 ) /* Pentium with x64 support (Nocona) - SSE3 ia32 */ - #define _IPP _IPP_T7 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _V8 ) /* Merom - SSSE3 ia32 */ - #define _IPP _IPP_V8 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _P8 ) /* Penryn - SSE4.1 + tick for SSE4.2 ia32 */ - #define _IPP _IPP_P8 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _G9 ) /* SandyBridge (GSSE) - AVX ia32 */ - #define _IPP _IPP_G9 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _H9 ) /* Haswell (AVX2) ia32 */ - #define _IPP _IPP_H9 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _M7 ) /* Pentium with x64 support (Nocona) - SSE3 x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_M7 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _U8 ) /* Merom - SSSE3 x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_U8 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _Y8 ) /* Penryn - SSE4.1 + tick for SSE4.2 x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_Y8 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _E9 ) /* SandyBridge (GSSE) - AVX x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_E9 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _L9 ) /* Haswell (AVX2) x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_L9 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _N0 ) /* KNL (AVX-512) x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_N0 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _K0 ) /* SkyLake Xeon (AVX-512) x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_K0 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _B2 ) /* KNC (MIC) */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_B2 - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _S8 ) /* old Atom (SSSE3+movbe) (Silverthorne) ia32 */ - #define _IPP _IPP_V8 - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_S8 - #define _IPPLP64 _IPPLP64_PX - -#elif defined( _N8 ) /* old Atom (SSSE3+movbe) (Silverthorne) x64 */ - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_U8 - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_N8 - -#else - #define _IPP _IPP_PX - #define _IPP32E _IPP32E_PX - #define _IPPLRB _IPPLRB_PX - #define _IPPLP32 _IPPLP32_PX - #define _IPPLP64 _IPPLP64_PX - -#endif - - -#define _IPP_ARCH_IA32 1 -#define _IPP_ARCH_IA64 2 -#define _IPP_ARCH_EM64T 4 -#define _IPP_ARCH_XSC 8 -#define _IPP_ARCH_LRB 16 -#define _IPP_ARCH_LP32 32 -#define _IPP_ARCH_LP64 64 -#define _IPP_ARCH_LRB2 128 - -#if defined ( _ARCH_IA32 ) - #define _IPP_ARCH _IPP_ARCH_IA32 - -#elif defined( _ARCH_EM64T ) - #define _IPP_ARCH _IPP_ARCH_EM64T - -#elif defined( _ARCH_LRB2 ) - #define _IPP_ARCH _IPP_ARCH_LRB2 - -#elif defined( _ARCH_LP32 ) - #define _IPP_ARCH _IPP_ARCH_LP32 - -#elif defined( _ARCH_LP64 ) - #define _IPP_ARCH _IPP_ARCH_LP64 - -#else - #if defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) - #define _IPP_ARCH _IPP_ARCH_EM64T - - #else - #define _IPP_ARCH _IPP_ARCH_IA32 - - #endif -#endif - -#if ((_IPP_ARCH == _IPP_ARCH_IA32) || (_IPP_ARCH == _IPP_ARCH_LP32)) -__INLINE -Ipp32s IPP_INT_PTR( const void* ptr ) { - union { - void* Ptr; - Ipp32s Int; - } dd; - dd.Ptr = (void*)ptr; - return dd.Int; -} - -__INLINE -Ipp32u IPP_UINT_PTR( const void* ptr ) { - union { - void* Ptr; - Ipp32u Int; - } dd; - dd.Ptr = (void*)ptr; - return dd.Int; -} -#elif ((_IPP_ARCH == _IPP_ARCH_EM64T) || (_IPP_ARCH == _IPP_ARCH_LRB2) || (_IPP_ARCH == _IPP_ARCH_LP64)) -__INLINE -Ipp64s IPP_INT_PTR( const void* ptr ) { - union { - void* Ptr; - Ipp64s Int; - } dd; - dd.Ptr = (void*)ptr; - return dd.Int; -} - -__INLINE -Ipp64u IPP_UINT_PTR( const void* ptr ) { - union { - void* Ptr; - Ipp64u Int; - } dd; - dd.Ptr = (void*)ptr; - return dd.Int; -} -#else - #define IPP_INT_PTR( ptr ) ( (long)(ptr) ) - #define IPP_UINT_PTR( ptr ) ( (unsigned long)(ptr) ) -#endif - -#define IPP_ALIGN_TYPE(type, align) ((align)/sizeof(type)-1) -#define IPP_BYTES_TO_ALIGN(ptr, align) ((-(IPP_INT_PTR(ptr)&((align)-1)))&((align)-1)) -#define IPP_ALIGNED_PTR(ptr, align) (void*)( (unsigned char*)(ptr) + (IPP_BYTES_TO_ALIGN( ptr, align )) ) - -#define IPP_ALIGNED_SIZE(size, align) (((size)+(align)-1)&~((align)-1)) - -#define IPP_MALLOC_ALIGNED_BYTES 64 -#define IPP_MALLOC_ALIGNED_8BYTES 8 -#define IPP_MALLOC_ALIGNED_16BYTES 16 -#define IPP_MALLOC_ALIGNED_32BYTES 32 - -#define IPP_ALIGNED_ARRAY(align,arrtype,arrname,arrlength)\ - char arrname##AlignedArrBuff[sizeof(arrtype)*(arrlength)+IPP_ALIGN_TYPE(char, align)];\ - arrtype *arrname = (arrtype*)IPP_ALIGNED_PTR(arrname##AlignedArrBuff,align) - -#if defined( __cplusplus ) -extern "C" { -#endif - -/* ///////////////////////////////////////////////////////////////////////////// - - IPP Context Identification - - /////////////////////////////////////////////////////////////////////////// */ - -#define IPP_CONTEXT( a, b, c, d) \ - (int)(((unsigned)(a) << 24) | ((unsigned)(b) << 16) | \ - ((unsigned)(c) << 8) | (unsigned)(d)) - -typedef enum { - idCtxUnknown = 0, - idCtxFFT_C_16sc, - idCtxFFT_C_16s, - idCtxFFT_R_16s, - idCtxFFT_C_32fc, - idCtxFFT_C_32f, - idCtxFFT_R_32f, - idCtxFFT_C_64fc, - idCtxFFT_C_64f, - idCtxFFT_R_64f, - idCtxDFT_C_16sc, - idCtxDFT_C_16s, - idCtxDFT_R_16s, - idCtxDFT_C_32fc, - idCtxDFT_C_32f, - idCtxDFT_R_32f, - idCtxDFT_C_64fc, - idCtxDFT_C_64f, - idCtxDFT_R_64f, - idCtxDCTFwd_16s, - idCtxDCTInv_16s, - idCtxDCTFwd_32f, - idCtxDCTInv_32f, - idCtxDCTFwd_64f, - idCtxDCTInv_64f, - idCtxFFT2D_C_32fc, - idCtxFFT2D_R_32f, - idCtxDFT2D_C_32fc, - idCtxDFT2D_R_32f, - idCtxFFT2D_R_32s, - idCtxDFT2D_R_32s, - idCtxDCT2DFwd_32f, - idCtxDCT2DInv_32f, - idCtxMoment64f, - idCtxMoment64s, - idCtxRandUni_8u, - idCtxRandUni_16s, - idCtxRandUni_32f, - idCtxRandUni_64f, - idCtxRandGauss_8u, - idCtxRandGauss_16s, - idCtxRandGauss_32f, - idCtxRandGauss_64f, - idCtxWTFwd_32f, - idCtxWTFwd_8u32f, - idCtxWTFwd_8s32f, - idCtxWTFwd_16u32f, - idCtxWTFwd_16s32f, - idCtxWTFwd2D_32f_C1R, - idCtxWTInv2D_32f_C1R, - idCtxWTFwd2D_32f_C3R, - idCtxWTInv2D_32f_C3R, - idCtxWTInv_32f, - idCtxWTInv_32f8u, - idCtxWTInv_32f8s, - idCtxWTInv_32f16u, - idCtxWTInv_32f16s, - idCtxMDCTFwd_32f, - idCtxMDCTInv_32f, - idCtxMDCTFwd_16s, - idCtxFIRBlock_32f, - idCtxFDP_32f, - idCtxRLMS_32f = IPP_CONTEXT( 'L', 'M', 'S', '1'), - idCtxRLMS32f_16s = IPP_CONTEXT( 'L', 'M', 'S', 0 ), - idCtxIIRAR_32f = IPP_CONTEXT( 'I', 'I', '0', '1'), - idCtxIIRBQ_32f = IPP_CONTEXT( 'I', 'I', '0', '2'), - idCtxIIRAR_32fc = IPP_CONTEXT( 'I', 'I', '0', '3'), - idCtxIIRBQ_32fc = IPP_CONTEXT( 'I', 'I', '0', '4'), - idCtxIIRAR32f_16s = IPP_CONTEXT( 'I', 'I', '0', '5'), - idCtxIIRBQ32f_16s = IPP_CONTEXT( 'I', 'I', '0', '6'), - idCtxIIRAR32fc_16sc = IPP_CONTEXT( 'I', 'I', '0', '7'), - idCtxIIRBQ32fc_16sc = IPP_CONTEXT( 'I', 'I', '0', '8'), - idCtxIIRAR32s_16s = IPP_CONTEXT( 'I', 'I', '0', '9'), - idCtxIIRBQ32s_16s = IPP_CONTEXT( 'I', 'I', '1', '0'), - idCtxIIRAR32sc_16sc = IPP_CONTEXT( 'I', 'I', '1', '1'), - idCtxIIRBQ32sc_16sc = IPP_CONTEXT( 'I', 'I', '1', '2'), - idCtxIIRAR_64f = IPP_CONTEXT( 'I', 'I', '1', '3'), - idCtxIIRBQ_64f = IPP_CONTEXT( 'I', 'I', '1', '4'), - idCtxIIRAR_64fc = IPP_CONTEXT( 'I', 'I', '1', '5'), - idCtxIIRBQ_64fc = IPP_CONTEXT( 'I', 'I', '1', '6'), - idCtxIIRAR64f_32f = IPP_CONTEXT( 'I', 'I', '1', '7'), - idCtxIIRBQ64f_32f = IPP_CONTEXT( 'I', 'I', '1', '8'), - idCtxIIRAR64fc_32fc = IPP_CONTEXT( 'I', 'I', '1', '9'), - idCtxIIRBQ64fc_32fc = IPP_CONTEXT( 'I', 'I', '2', '0'), - idCtxIIRAR64f_32s = IPP_CONTEXT( 'I', 'I', '2', '1'), - idCtxIIRBQ64f_32s = IPP_CONTEXT( 'I', 'I', '2', '2'), - idCtxIIRAR64fc_32sc = IPP_CONTEXT( 'I', 'I', '2', '3'), - idCtxIIRBQ64fc_32sc = IPP_CONTEXT( 'I', 'I', '2', '4'), - idCtxIIRAR64f_16s = IPP_CONTEXT( 'I', 'I', '2', '5'), - idCtxIIRBQ64f_16s = IPP_CONTEXT( 'I', 'I', '2', '6'), - idCtxIIRAR64fc_16sc = IPP_CONTEXT( 'I', 'I', '2', '7'), - idCtxIIRBQ64fc_16sc = IPP_CONTEXT( 'I', 'I', '2', '8'), - idCtxIIRBQDF1_32f = IPP_CONTEXT( 'I', 'I', '2', '9'), - idCtxIIRBQDF164f_32s= IPP_CONTEXT( 'I', 'I', '3', '0'), - idCtxFIRSR_32f = IPP_CONTEXT( 'F', 'I', '0', '1'), - idCtxFIRSR_32fc = IPP_CONTEXT( 'F', 'I', '0', '2'), - idCtxFIRMR_32f = IPP_CONTEXT( 'F', 'I', '0', '3'), - idCtxFIRMR_32fc = IPP_CONTEXT( 'F', 'I', '0', '4'), - idCtxFIRSR32f_16s = IPP_CONTEXT( 'F', 'I', '0', '5'), - idCtxFIRSR32fc_16sc = IPP_CONTEXT( 'F', 'I', '0', '6'), - idCtxFIRMR32f_16s = IPP_CONTEXT( 'F', 'I', '0', '7'), - idCtxFIRMR32fc_16sc = IPP_CONTEXT( 'F', 'I', '0', '8'), - idCtxFIRSR32s_16s = IPP_CONTEXT( 'F', 'I', '0', '9'), - idCtxFIRSR32sc_16sc = IPP_CONTEXT( 'F', 'I', '1', '0'), - idCtxFIRMR32s_16s = IPP_CONTEXT( 'F', 'I', '1', '1'), - idCtxFIRMR32sc_16sc = IPP_CONTEXT( 'F', 'I', '1', '2'), - idCtxFIRSR_64f = IPP_CONTEXT( 'F', 'I', '1', '3'), - idCtxFIRSR_64fc = IPP_CONTEXT( 'F', 'I', '1', '4'), - idCtxFIRMR_64f = IPP_CONTEXT( 'F', 'I', '1', '5'), - idCtxFIRMR_64fc = IPP_CONTEXT( 'F', 'I', '1', '6'), - idCtxFIRSR64f_32f = IPP_CONTEXT( 'F', 'I', '1', '7'), - idCtxFIRSR64fc_32fc = IPP_CONTEXT( 'F', 'I', '1', '8'), - idCtxFIRMR64f_32f = IPP_CONTEXT( 'F', 'I', '1', '9'), - idCtxFIRMR64fc_32fc = IPP_CONTEXT( 'F', 'I', '2', '0'), - idCtxFIRSR64f_32s = IPP_CONTEXT( 'F', 'I', '2', '1'), - idCtxFIRSR64fc_32sc = IPP_CONTEXT( 'F', 'I', '2', '2'), - idCtxFIRMR64f_32s = IPP_CONTEXT( 'F', 'I', '2', '3'), - idCtxFIRMR64fc_32sc = IPP_CONTEXT( 'F', 'I', '2', '4'), - idCtxFIRSR64f_16s = IPP_CONTEXT( 'F', 'I', '2', '5'), - idCtxFIRSR64fc_16sc = IPP_CONTEXT( 'F', 'I', '2', '6'), - idCtxFIRMR64f_16s = IPP_CONTEXT( 'F', 'I', '2', '7'), - idCtxFIRMR64fc_16sc = IPP_CONTEXT( 'F', 'I', '2', '8'), - idCtxFIRSR_16s = IPP_CONTEXT( 'F', 'I', '2', '9'), - idCtxFIRMR_16s = IPP_CONTEXT( 'F', 'I', '3', '0'), - idCtxFIRSRStream_16s= IPP_CONTEXT( 'F', 'I', '3', '1'), - idCtxFIRMRStream_16s= IPP_CONTEXT( 'F', 'I', '3', '2'), - idCtxFIRSRStream_32f= IPP_CONTEXT( 'F', 'I', '3', '3'), - idCtxFIRMRStream_32f= IPP_CONTEXT( 'F', 'I', '3', '4'), - idCtxRLMS32s_16s = IPP_CONTEXT( 'L', 'M', 'S', 'R'), - idCtxCLMS32s_16s = IPP_CONTEXT( 'L', 'M', 'S', 'C'), - idCtxEncode_JPEG2K, - idCtxDES = IPP_CONTEXT( ' ', 'D', 'E', 'S'), - idCtxBlowfish = IPP_CONTEXT( ' ', ' ', 'B', 'F'), - idCtxRijndael = IPP_CONTEXT( ' ', 'R', 'I', 'J'), - idCtxSMS4 = IPP_CONTEXT( 'S', 'M', 'S', '4'), - idCtxTwofish = IPP_CONTEXT( ' ', ' ', 'T', 'F'), - idCtxARCFOUR = IPP_CONTEXT( ' ', 'R', 'C', '4'), - idCtxRC564 = IPP_CONTEXT( 'R', 'C', '5', '1'), - idCtxRC5128 = IPP_CONTEXT( 'R', 'C', '5', '2'), - idCtxSHA1 = IPP_CONTEXT( 'S', 'H', 'S', '1'), - idCtxSHA224 = IPP_CONTEXT( 'S', 'H', 'S', '3'), - idCtxSHA256 = IPP_CONTEXT( 'S', 'H', 'S', '2'), - idCtxSHA384 = IPP_CONTEXT( 'S', 'H', 'S', '4'), - idCtxSHA512 = IPP_CONTEXT( 'S', 'H', 'S', '5'), - idCtxMD5 = IPP_CONTEXT( ' ', 'M', 'D', '5'), - idCtxHMAC = IPP_CONTEXT( 'H', 'M', 'A', 'C'), - idCtxDAA = IPP_CONTEXT( ' ', 'D', 'A', 'A'), - idCtxBigNum = IPP_CONTEXT( 'B', 'I', 'G', 'N'), - idCtxMontgomery = IPP_CONTEXT( 'M', 'O', 'N', 'T'), - idCtxPrimeNumber = IPP_CONTEXT( 'P', 'R', 'I', 'M'), - idCtxPRNG = IPP_CONTEXT( 'P', 'R', 'N', 'G'), - idCtxRSA = IPP_CONTEXT( ' ', 'R', 'S', 'A'), - idCtxRSA_PubKey = IPP_CONTEXT( 'R', 'S', 'A', '0'), - idCtxRSA_PrvKey1 = IPP_CONTEXT( 'R', 'S', 'A', '1'), - idCtxRSA_PrvKey2 = IPP_CONTEXT( 'R', 'S', 'A', '2'), - idCtxDSA = IPP_CONTEXT( ' ', 'D', 'S', 'A'), - idCtxECCP = IPP_CONTEXT( ' ', 'E', 'C', 'P'), - idCtxECCB = IPP_CONTEXT( ' ', 'E', 'C', 'B'), - idCtxECCPPoint = IPP_CONTEXT( 'P', 'E', 'C', 'P'), - idCtxECCBPoint = IPP_CONTEXT( 'P', 'E', 'C', 'B'), - idCtxDH = IPP_CONTEXT( ' ', ' ', 'D', 'H'), - idCtxDLP = IPP_CONTEXT( ' ', 'D', 'L', 'P'), - idCtxCMAC = IPP_CONTEXT( 'C', 'M', 'A', 'C'), - idCtxRFFT2_8u, - idCtxHilbert_32f32fc, - idCtxHilbert_16s32fc, - idCtxHilbert_16s16sc, - idCtxTone_16s, - idCtxTriangle_16s, - idCtxDFTOutOrd_C_32fc, - idCtxDFTOutOrd_C_64fc, - idCtxFFT_C_32sc, - idCtxFFT_C_32s, - idCtxFFT_R_32s, - idCtxFFT_R_16s32s, - idCtxDecodeProgr_JPEG2K, - idCtxWarp_MPEG4, - idCtxQuantInvIntra_MPEG4, - idCtxQuantInvInter_MPEG4, - idCtxQuantIntra_MPEG4, - idCtxQuantInter_MPEG4, - idCtxAnalysisFilter_SBR_C_32f32fc, - idCtxAnalysisFilter_SBR_C_32f, - idCtxAnalysisFilter_SBR_R_32f, - idCtxSynthesisFilter_SBR_C_32fc32f, - idCtxSynthesisFilter_SBR_C_32f, - idCtxSynthesisFilter_SBR_R_32f, - idCtxSynthesisDownFilter_SBR_C_32fc32f, - idCtxSynthesisDownFilter_SBR_C_32f, - idCtxSynthesisDownFilter_SBR_R_32f, - idCtxVLCEncode, - idCtxVLCDecode, - idCtxAnalysisFilter_SBR_C_32s32sc, - idCtxAnalysisFilter_SBR_R_32s, - idCtxSynthesisFilter_SBR_C_32sc32s, - idCtxSynthesisFilter_SBR_R_32s, - idCtxSynthesisDownFilter_SBR_C_32sc32s, - idCtxSynthesisDownFilter_SBR_R_32s, - idCtxSynthesisFilter_PQMF_MP3_32f, - idCtxAnalysisFilter_PQMF_MP3_32f, - idCtxResampleRow, - idCtxAnalysisFilter_SBR_Enc_C_32f32fc, - idCtxSynthesisFilter_DTS_32f, - idCtxFilterBilateralGauss_8u, - idCtxFilterBilateralGaussFast_8u, - idCtxBGF, - idCtxPolyGF, - idCtxRSenc, - idCtxRSdec, - idCtxSnow3g = IPP_CONTEXT( 'S', 'n', 'o', 'w'), - idCtxSnow3gF8, - idCtxSnow3gF9, - idCtxKasumi = IPP_CONTEXT( 'K', 'a', 's', 'u'), - idCtxKasumiF8, - idCtxKasumiF9, - idCtxResizeHannFilter_8u, - idCtxResizeLanczosFilter_8u, - idCtxAESXCBC, - idCtxAESCCM, - idCtxAESGCM, - idCtxMsgCatalog, - idCtxGFP, - idCtxGFPE, - idCtxGFPX, - idCtxGFPXE, - idCtxGFPXQX, - idCtxGFPXQXE, - idCtxGFPEC, - idCtxGFPPoint, - idCtxGFPXEC, - idCtxGFPXECPoint, - idCtxPairing, - idCtxResize_32f, - idCtxResizeYUV420, - idCtxResizeYUV422, - idCtxResize_64f, - idCtxFilterBilateralBorder, - idCtxThresholdAdaptiveGauss, - idCtxHOG, - idCtxFastN, - idCtxHash, - idCtxSM3 -} IppCtxId; - - - - -/* ///////////////////////////////////////////////////////////////////////////// - Helpers - /////////////////////////////////////////////////////////////////////////// */ - -#define IPP_NOERROR_RET() return ippStsNoErr -#define IPP_ERROR_RET( ErrCode ) return (ErrCode) - -#ifdef _IPP_DEBUG - - #define IPP_BADARG_RET( expr, ErrCode )\ - {if (expr) { IPP_ERROR_RET( ErrCode ); }} - -#else - - #define IPP_BADARG_RET( expr, ErrCode ) - -#endif - - - #define IPP_BAD_SIZE_RET( n )\ - IPP_BADARG_RET( (n)<=0, ippStsSizeErr ) - - #define IPP_BAD_STEP_RET( n )\ - IPP_BADARG_RET( (n)<=0, ippStsStepErr ) - - #define IPP_BAD_PTR1_RET( ptr )\ - IPP_BADARG_RET( NULL==(ptr), ippStsNullPtrErr ) - - #define IPP_BAD_PTR2_RET( ptr1, ptr2 )\ - {IPP_BAD_PTR1_RET( ptr1 ); IPP_BAD_PTR1_RET( ptr2 )} - - #define IPP_BAD_PTR3_RET( ptr1, ptr2, ptr3 )\ - {IPP_BAD_PTR2_RET( ptr1, ptr2 ); IPP_BAD_PTR1_RET( ptr3 )} - - #define IPP_BAD_PTR4_RET( ptr1, ptr2, ptr3, ptr4 )\ - {IPP_BAD_PTR2_RET( ptr1, ptr2 ); IPP_BAD_PTR2_RET( ptr3, ptr4 )} - - #define IPP_BAD_ISIZE_RET(roi) \ - IPP_BADARG_RET( ((roi).width<=0 || (roi).height<=0), ippStsSizeErr) - -/* ////////////////////////////////////////////////////////////////////////// */ -/* internal messages */ - -#define MSG_LOAD_DLL_ERR (-9700) /* Error at loading of %s library */ -#define MSG_NO_DLL (-9701) /* No DLLs were found in the Waterfall procedure */ -#define MSG_NO_SHARED (-9702) /* No shared libraries were found in the Waterfall procedure */ - -/* ////////////////////////////////////////////////////////////////////////// */ - - -typedef union { /* double precision */ - Ipp64s hex; - Ipp64f fp; -} IppFP_64f; - -typedef union { /* single precision */ - Ipp32s hex; - Ipp32f fp; -} IppFP_32f; - - -extern const IppFP_32f ippConstantOfNAN_32f; -extern const IppFP_64f ippConstantOfNAN_64f; - -extern const IppFP_32f ippConstantOfINF_32f; -extern const IppFP_64f ippConstantOfINF_64f; -extern const IppFP_32f ippConstantOfINF_NEG_32f; -extern const IppFP_64f ippConstantOfINF_NEG_64f; - -#define NAN_32F (ippConstantOfNAN_32f.fp) -#define NAN_64F (ippConstantOfNAN_64f.fp) -#define INF_32F (ippConstantOfINF_32f.fp) -#define INF_64F (ippConstantOfINF_64f.fp) -#define INF_NEG_32F (ippConstantOfINF_NEG_32f.fp) -#define INF_NEG_64F (ippConstantOfINF_NEG_64f.fp) - -/* ////////////////////////////////////////////////////////////////////////// */ - -typedef enum { - ippunreg=-1, - ippac = 0, - ippcc = 1, - ippch = 2, - ippcp = 3, - ippcv = 4, - ippdc = 5, - ippdi = 6, - ippgen = 7, - ippi = 8, - ippj = 9, - ippm = 10, - ippr = 11, - ipps = 12, - ippsc = 13, - ippsr = 14, - ippvc = 15, - ippvm = 16, - ippmsdk = 17, - ippcpepid = 18, - ippe = 19, - ipprs = 20, - ippsq = 21, - ippnomore -} IppDomain; - -int __CDECL ownGetNumThreads( void ); -int __CDECL ownGetFeature( Ipp64u MaskOfFeature ); /* the main function of tick-tock dispatcher */ - -#ifdef _IPP_DYNAMIC -typedef IppStatus (__STDCALL *DYN_RELOAD)( int ); -void __CDECL ownRegisterLib( IppDomain, DYN_RELOAD ); -void __CDECL ownUnregisterLib( IppDomain ); -#endif - -/* the number of threads available for any ipp function that uses OMP; */ -/* at the ippxx.dll loading time is equal to the number of logical processors, */ -/* and can be changed ONLY externally by library user to any desired number */ -/* by means of ippSetNumThreads() function */ -#define IPP_GET_NUM_THREADS() ( ownGetNumThreads() ) -#define IPP_OMP_NUM_THREADS() num_threads( IPP_GET_NUM_THREADS() ) -#define IPP_OMP_LIMIT_MAX_NUM_THREADS(n) num_threads( IPP_MIN(IPP_GET_NUM_THREADS(),(n))) - - -/* ////////////////////////////////////////////////////////////////////////// */ - -/* Define NULL pointer value */ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define UNREFERENCED_PARAMETER(p) (p)=(p) - -#if defined( _IPP_MARK_LIBRARY ) -static char G[] = {73, 80, 80, 71, 101, 110, 117, 105, 110, 101, 243, 193, 210, 207, 215}; -#endif - - -#define STR2(x) #x -#define STR(x) STR2(x) -#define MESSAGE( desc )\ - message(__FILE__ "(" STR(__LINE__) "):" #desc) - -/* -// endian definition -*/ -#define IPP_LITTLE_ENDIAN (0) -#define IPP_BIG_ENDIAN (1) - -#if defined( _IPP_LE ) - #define IPP_ENDIAN IPP_LITTLE_ENDIAN - -#elif defined( _IPP_BE ) - #define IPP_ENDIAN IPP_BIG_ENDIAN - -#else - #if defined( __ARMEB__ ) - #define IPP_ENDIAN IPP_BIG_ENDIAN - - #else - #define IPP_ENDIAN IPP_LITTLE_ENDIAN - - #endif -#endif - - -/* ////////////////////////////////////////////////////////////////////////// */ - -/* intrinsics */ -#if (_IPP >= _IPP_A6) || (_IPP32E >= _IPP32E_M7) - #if defined(__INTEL_COMPILER) || (_MSC_VER >= 1300) - #if (_IPP == _IPP_A6) - #include "xmmintrin.h" - #elif (_IPP == _IPP_W7) - #if defined(__INTEL_COMPILER) - #include "emmintrin.h" - #else - #undef _W7 - #include "emmintrin.h" - #define _W7 - #endif - #define _mm_loadu _mm_loadu_si128 - #elif (_IPP == _IPP_T7) || (_IPP32E == _IPP32E_M7) - #if defined(__INTEL_COMPILER) - #include "pmmintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER >= 140050110) - #include "intrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER < 140050110) - #include "emmintrin.h" - #define _mm_loadu _mm_loadu_si128 - #endif - #elif (_IPP == _IPP_V8) || (_IPP32E == _IPP32E_U8) - #if defined(__INTEL_COMPILER) - #include "tmmintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER >= 140050110) - #include "intrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER < 140050110) - #include "emmintrin.h" - #define _mm_loadu _mm_loadu_si128 - #endif - #elif (_IPP == _IPP_P8) || (_IPP32E == _IPP32E_Y8) - #if defined(__INTEL_COMPILER) - #include "smmintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER >= 140050110) - #include "intrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER < 140050110) - #include "emmintrin.h" - #define _mm_loadu _mm_loadu_si128 - #endif - #elif (_IPP >= _IPP_G9) || (_IPP32E >= _IPP32E_E9) - #if defined(__INTEL_COMPILER) - #include "immintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER >= 160021003) - #include "immintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #endif - #endif - #endif -#elif (_IPPLP32 >= _IPPLP32_S8) || (_IPPLP64 >= _IPPLP64_N8) - #if defined(__INTEL_COMPILER) - #include "tmmintrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER >= 140050110) - #include "intrin.h" - #define _mm_loadu _mm_lddqu_si128 - #elif (_MSC_FULL_VER < 140050110) - #include "emmintrin.h" - #define _mm_loadu _mm_loadu_si128 - #endif -#elif (_IPPLRB >= _IPPLRB_B2) - #if defined(__INTEL_COMPILER) || defined(_REF_LIB) - #include "immintrin.h" - #endif -#endif - -// **** intrinsics for bit casting **** -#if defined(__INTEL_COMPILER) -extern unsigned int __intel_castf32_u32(float val); -extern float __intel_castu32_f32(unsigned int val); -extern unsigned __int64 __intel_castf64_u64(double val); -extern double __intel_castu64_f64(unsigned __int64 val); - #define __CAST_32f32u(val) __intel_castf32_u32((Ipp32f)val) - #define __CAST_32u32f(val) __intel_castu32_f32((Ipp32u)val) - #define __CAST_64f64u(val) __intel_castf64_u64((Ipp64f)val) - #define __CAST_64u64f(val) __intel_castu64_f64((Ipp64u)val) -#else - #define __CAST_32f32u(val) ( *((Ipp32u*)&val) ) - #define __CAST_32u32f(val) ( *((Ipp32f*)&val) ) - #define __CAST_64f64u(val) ( *((Ipp64u*)&val) ) - #define __CAST_64u64f(val) ( *((Ipp64f*)&val) ) -#endif - - -// short names for vector registers casting -#define _pd2ps _mm_castpd_ps -#define _ps2pd _mm_castps_pd -#define _pd2pi _mm_castpd_si128 -#define _pi2pd _mm_castsi128_pd -#define _ps2pi _mm_castps_si128 -#define _pi2ps _mm_castsi128_ps - -#define _ypd2ypi _mm256_castpd_si256 -#define _ypi2ypd _mm256_castsi256_pd -#define _yps2ypi _mm256_castps_si256 -#define _ypi2yps _mm256_castsi256_ps -#define _ypd2yps _mm256_castpd_ps -#define _yps2ypd _mm256_castps_pd - -#define _yps2ps _mm256_castps256_ps128 -#define _ypi2pi _mm256_castsi256_si128 -#define _ypd2pd _mm256_castpd256_pd128 -#define _ps2yps _mm256_castps128_ps256 -#define _pi2ypi _mm256_castsi128_si256 -#define _pd2ypd _mm256_castpd128_pd256 - - -#if defined(__INTEL_COMPILER) -#define __IVDEP ivdep -#else -#define __IVDEP message("message :: 'ivdep' is not defined") -#endif -//usage: #pragma __IVDEP - -/* ////////////////////////////////////////////////////////////////////////// - _IPP_DATA shoul be defined only: - - if compile not merged library - - only for 1 CPU for merged library to avoid data duplication -*/ -#if defined( _MERGED_BLD ) && ( defined(_G9) || defined(_E9) ) /* compile data only for g9 and e9 CPU */ - #define _IPP_DATA 1 -#elif !defined( _MERGED_BLD ) /* compile data if it isn't merged library */ - #define _IPP_DATA 1 -#endif - - -#if defined( __cplusplus ) -} -#endif - -#endif /* __OWNDEFS_H__ */ - diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/Makefile b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/Makefile deleted file mode 100644 index 3dabff6f..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/make -f - -API_INCLUDE_DIR = ../../include -SRC_INCLUDE_DIR = ../../sources/include -LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/ - -PCP_INCLUDE_DIR = ./src -PCP_SRC = $(wildcard ./src/*.c) -PCP_OBJ = $(sort $(PCP_SRC:.c=.o)) -PCP_LIB = ./src/libippcp.a - - -$(PCP_OBJ): %.o: %.c - $(CC) $(CFLAGS) -I$(API_INCLUDE_DIR) -I$(SRC_INCLUDE_DIR) -I$(PCP_INCLUDE_DIR) -c -o $@ $< - -$(PCP_LIB): $(PCP_OBJ) - $(AR) rc $@ $^ - ranlib $@ - -build: all - -all: $(PCP_LIB) - -install: - mkdir -p '$(LIB_INSTALL_DIR)' - cp $(PCP_LIB) '$(LIB_INSTALL_DIR)' - -clean: - rm -f $(PCP_OBJ) $(PCP_LIB) - - diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/owncp.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/owncp.h deleted file mode 100644 index 6bf81b23..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/owncp.h +++ /dev/null @@ -1,171 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -// -*/ - -#ifndef __OWNCP_H__ -#define __OWNCP_H__ - -#ifndef __OWNDEFS_H__ - #include "owndefs.h" -#endif - -#ifndef __IPPCP_H__ - #include "ippcp.h" -#endif - -#if defined(_TXT_ACM_) - //#pragma message ("cogifuration: TXT ACM") - #include "pcpvariant_txt_acm.h" -#else - //#pragma message ("cogifuration: STANDARD") - #include "pcpvariant.h" -#endif - - -#pragma warning( disable : 4996 4324 4206) - -/* ippCP length */ -typedef int cpSize; - -/* -// Common ippCP Macros -*/ - -/* size of cache line (bytes) */ -#if (_IPP==_IPP_M5) -#define CACHE_LINE_SIZE (16) -#define LOG_CACHE_LINE_SIZE (4) -#else -#define CACHE_LINE_SIZE (64) -#define LOG_CACHE_LINE_SIZE (6) -#endif - -/* swap data & pointers */ -#define SWAP_PTR(ATYPE, pX,pY) { ATYPE* aPtr=(pX); (pX)=(pY); (pY)=aPtr; } -#define SWAP(x,y) {(x)^=(y); (y)^=(x); (x)^=(y);} - -/* alignment value */ -#define ALIGN_VAL ((int)sizeof(void*)) - -/* bitsize */ -#define BYTESIZE (8) -#define BITSIZE(x) ((int)(sizeof(x)*BYTESIZE)) - -/* bit length -> byte/word length conversion */ -#define BITS2WORD8_SIZE(x) (((x)+ 7)>>3) -#define BITS2WORD16_SIZE(x) (((x)+15)>>4) -#define BITS2WORD32_SIZE(x) (((x)+31)>>5) -#define BITS2WORD64_SIZE(x) (((x)+63)>>6) - -/* WORD and DWORD manipulators */ -#define LODWORD(x) ((Ipp32u)(x)) -#define HIDWORD(x) ((Ipp32u)(((Ipp64u)(x) >>32) & 0xFFFFFFFF)) - -#define MAKEHWORD(bLo,bHi) ((Ipp16u)(((Ipp8u)(bLo)) | ((Ipp16u)((Ipp8u)(bHi))) << 8)) -#define MAKEWORD(hLo,hHi) ((Ipp32u)(((Ipp16u)(hLo)) | ((Ipp32u)((Ipp16u)(hHi))) << 16)) -#define MAKEDWORD(wLo,wHi) ((Ipp64u)(((Ipp32u)(wLo)) | ((Ipp64u)((Ipp32u)(wHi))) << 32)) - -/* extract byte */ -#define EBYTE(w,n) ((Ipp8u)((w) >> (8 * (n)))) - -/* hexString <-> Ipp32u conversion */ -#define HSTRING_TO_U32(ptrByte) \ - (((ptrByte)[0]) <<24) \ - +(((ptrByte)[1]) <<16) \ - +(((ptrByte)[2]) <<8) \ - +((ptrByte)[3]) -#define U32_TO_HSTRING(ptrByte, x) \ - (ptrByte)[0] = (Ipp8u)((x)>>24); \ - (ptrByte)[1] = (Ipp8u)((x)>>16); \ - (ptrByte)[2] = (Ipp8u)((x)>>8); \ - (ptrByte)[3] = (Ipp8u)(x) - -/* 32- and 64-bit masks for MSB of nbits-sequence */ -#define MAKEMASK32(nbits) (0xFFFFFFFF >>((32 - ((nbits)&0x1F)) &0x1F)) -#define MAKEMASK64(nbits) (0xFFFFFFFFFFFFFFFF >>((64 - ((nbits)&0x3F)) &0x3F)) - -/* Logical Shifts (right and left) of WORD */ -#define LSR32(x,nBits) ((x)>>(nBits)) -#define LSL32(x,nBits) ((x)<<(nBits)) - -/* Rorate (right and left) of WORD */ -#if defined(_MSC_VER) -# include -# define ROR32(x, nBits) _lrotr((x),(nBits)) -# define ROL32(x, nBits) _lrotl((x),(nBits)) -#else -# define ROR32(x, nBits) (LSR32((x),(nBits)) | LSL32((x),32-(nBits))) -# define ROL32(x, nBits) ROR32((x),(32-(nBits))) -#endif - -/* Logical Shifts (right and left) of DWORD */ -#define LSR64(x,nBits) ((x)>>(nBits)) -#define LSL64(x,nBits) ((x)<<(nBits)) - -/* Rorate (right and left) of DWORD */ -#define ROR64(x, nBits) (LSR64((x),(nBits)) | LSL64((x),64-(nBits))) -#define ROL64(x, nBits) ROR64((x),(64-(nBits))) - -/* change endian */ -#if defined(_MSC_VER) -# define ENDIANNESS(x) _byteswap_ulong((x)) -# define ENDIANNESS32(x) ENDIANNESS((x)) -# define ENDIANNESS64(x) _byteswap_uint64((x)) -#else -# define ENDIANNESS(x) ((ROR32((x), 24) & 0x00ff00ff) | (ROR32((x), 8) & 0xff00ff00)) -# define ENDIANNESS32(x) ENDIANNESS((x)) -# define ENDIANNESS64(x) MAKEDWORD(ENDIANNESS(HIDWORD((x))), ENDIANNESS(LODWORD((x)))) -#endif - -#define IPP_MAKE_MULTIPLE_OF_8(x) ((x) = ((x)+7)&(~7)) -#define IPP_MAKE_MULTIPLE_OF_16(x) ((x) = ((x)+15)&(~15)) - -/* 64-bit constant */ -#if !defined(__GNUC__) - #define CONST_64(x) (x) /*(x##i64)*/ -#else - #define CONST_64(x) (x##LL) -#endif - - -/* crypto NI */ -#define AES_NI_ENABLED (ippCPUID_AES) -#define CLMUL_NI_ENABLED (ippCPUID_CLMUL) -#define AES_CLMUL_NI_ENABLED (ippCPUID_AES|ippCPUID_CLMUL) -#define ADCOX_ENABLED (ippCPUID_ADCOX) -#define SHA_NI_ENABLED (ippCPUID_SHA) -#define RDRAND_NI_ENABLED (ippCPUID_RDRAND) -#define RDSEED_NI_ENABLED (ippCPUID_RDSEED) - -/* test CPU crypto features */ -__INLINE Ipp32u IsFeatureEnabled(Ipp64u niMmask) -{ - return ownGetFeature(niMmask); -} - -/* copy under mask */ -#define MASKED_COPY_BNU(dst, mask, src1, src2, len) { \ - cpSize i; \ - for(i=0; i<(len); i++) (dst)[i] = ((mask) & (src1)[i]) | (~(mask) & (src2)[i]); \ -} - -#endif /* __OWNCP_H__ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbn.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbn.h deleted file mode 100644 index 5912211c..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbn.h +++ /dev/null @@ -1,203 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -// -// -*/ - -#if !defined(_CP_BN_H) -#define _CP_BN_H - -#include "pcpbnuimpl.h" -#include "pcpbnuarith.h" -#include "pcpbnumisc.h" -#include "pcpbnu32arith.h" -#include "pcpbnu32misc.h" - -/* -// Big Number context -*/ -struct _cpBigNum -{ - IppCtxId idCtx; /* BigNum ctx id */ - IppsBigNumSGN sgn; /* sign */ - cpSize size; /* BigNum size (BNU_CHUNK_T) */ - cpSize room; /* BigNum max size (BNU_CHUNK_T) */ - BNU_CHUNK_T* number; /* BigNum value */ - BNU_CHUNK_T* buffer; /* temporary buffer */ -}; - -/* BN accessory macros */ -#define BN_ID(pBN) ((pBN)->idCtx) -#define BN_SIGN(pBN) ((pBN)->sgn) -#define BN_POSITIVE(pBN) (BN_SIGN(pBN)==ippBigNumPOS) -#define BN_NEGATIVE(pBN) (BN_SIGN(pBN)==ippBigNumNEG) -#define BN_NUMBER(pBN) ((pBN)->number) -#define BN_BUFFER(pBN) ((pBN)->buffer) -#define BN_ROOM(pBN) ((pBN)->room) -#define BN_SIZE(pBN) ((pBN)->size) -#define BN_SIZE32(pBN) ((pBN)->size*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)) -//#define BN_SIZE32(pBN) (BITS2WORD32_SIZE( BITSIZE_BNU(BN_NUMBER((pBN)),BN_SIZE((pBN))))) - -#define BN_VALID_ID(pBN) (BN_ID((pBN))==idCtxBigNum) - -#define INVERSE_SIGN(s) (((s)==ippBigNumPOS)? ippBigNumNEG : ippBigNumPOS) - -#define BN_ALIGNMENT ((int)sizeof(void*)) - - -/* pack-unpack context */ -void cpPackBigNumCtx(const IppsBigNumState* pBN, Ipp8u* pBuffer); -void cpUnpackBigNumCtx(const Ipp8u* pBuffer, IppsBigNumState* pBN); - -/* copy BN */ -__INLINE IppsBigNumState* cpBN_copy(IppsBigNumState* pDst, const IppsBigNumState* pSrc) -{ - BN_SIGN(pDst) = BN_SIGN(pSrc); - BN_SIZE(pDst) = BN_SIZE(pSrc); - ZEXPAND_COPY_BNU(BN_NUMBER(pDst), BN_ROOM(pDst), BN_NUMBER(pSrc), BN_SIZE(pSrc)); - return pDst; -} -/* set BN to zero */ -__INLINE IppsBigNumState* cpBN_zero(IppsBigNumState* pBN) -{ - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = 1; - ZEXPAND_BNU(BN_NUMBER(pBN),0, (int)BN_ROOM(pBN)); - return pBN; -} -/* fixup BN */ -__INLINE IppsBigNumState* cpBN_fix(IppsBigNumState* pBN) -{ - cpSize len = BN_SIZE(pBN); - FIX_BNU(BN_NUMBER(pBN), len); - BN_SIZE(pBN) = len; - return pBN; -} -/* set BN to chunk */ -__INLINE IppsBigNumState* cpBN_chunk(IppsBigNumState* pBN, BNU_CHUNK_T a) -{ - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = 1; - ZEXPAND_BNU(BN_NUMBER(pBN),0, (int)BN_ROOM(pBN)); - BN_NUMBER(pBN)[0] = a; - return pBN; -} -/* set BN to 2^m */ -__INLINE IppsBigNumState* cpBN_power2(IppsBigNumState* pBN, int power) -{ - cpSize size = BITS_BNU_CHUNK(power+1); - if(BN_ROOM(pBN) >= size) { - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = size; - ZEXPAND_BNU(BN_NUMBER(pBN),0, BN_ROOM(pBN)); - SET_BIT(BN_NUMBER(pBN), power); - return pBN; - } - else return NULL; -} - -/* bitsize of BN */ -__INLINE int cpBN_bitsize(const IppsBigNumState* pA) -{ - int bitsize = BITSIZE_BNU(BN_NUMBER(pA), BN_SIZE(pA)); - return bitsize; -} - -/* returns -1/0/+1 depemding on A~B comparison */ -__INLINE int cpBN_cmp(const IppsBigNumState* pA, const IppsBigNumState* pB) -{ - IppsBigNumSGN signA = BN_SIGN(pA); - IppsBigNumSGN signB = BN_SIGN(pB); - - if(signA==signB) { - int result = cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pB), BN_SIZE(pB)); - return (ippBigNumPOS==signA)? result : -result; - } - return (ippBigNumPOS==signA)? 1 : -1; -} - -/* returns -1/0/+1 depemding on A comparison 00 */ -__INLINE int cpBN_tst(const IppsBigNumState* pA) -{ - if(1==BN_SIZE(pA) && 0==BN_NUMBER(pA)[0]) - return 0; - else - return BN_POSITIVE(pA)? 1 : -1; -} - - -// some addtition functions -__INLINE int IsZero_BN(const IppsBigNumState* pA) -{ - return ( BN_SIZE(pA)==1 ) && ( BN_NUMBER(pA)[0]==0 ); -} -__INLINE int IsOdd_BN(const IppsBigNumState* pA) -{ - return BN_NUMBER(pA)[0] & 1; -} - -__INLINE IppsBigNumState* BN_Word(IppsBigNumState* pBN, BNU_CHUNK_T w) -{ - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = 1; - ZEXPAND_BNU(BN_NUMBER(pBN),0, BN_ROOM(pBN)); - BN_NUMBER(pBN)[0] = w; - return pBN; -} -__INLINE IppsBigNumState* BN_Set(const BNU_CHUNK_T* pData, cpSize len, IppsBigNumState* pBN) -{ - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = len; - ZEXPAND_COPY_BNU(BN_NUMBER(pBN), BN_ROOM(pBN), pData, len); - return pBN; -} -__INLINE IppsBigNumState* BN_Make(BNU_CHUNK_T* pData, BNU_CHUNK_T* pBuffer, cpSize len, IppsBigNumState* pBN) -{ - BN_ID(pBN) = idCtxBigNum; - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = 1; - BN_ROOM(pBN) = len; - BN_NUMBER(pBN) = pData; - BN_BUFFER(pBN) = pBuffer; - return pBN; -} - - - -/* -// fixed single chunk BN -*/ -typedef struct _ippcpBigNumChunk { - IppsBigNumState bn; - BNU_CHUNK_T value; - BNU_CHUNK_T temporary; -} IppsBigNumStateChunk; - -/* reference to BN(1) and BN(2) */ -IppsBigNumState* cpBN_OneRef(void); -IppsBigNumState* cpBN_TwoRef(void); -IppsBigNumState* cpBN_ThreeRef(void); - -#define BN_ONE_REF() cpBN_OneRef() -#define BN_TWO_REF() cpBN_TwoRef() -#define BN_THREE_REF() cpBN_ThreeRef() - -#endif /* _CP_BN_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnca.c deleted file mode 100644 index 1ccfd573..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnca.c +++ /dev/null @@ -1,1286 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -// Contents: -// ippsBigNumGetSize() -// ippsBigNumInit() -// -// ippsSet_BN() -// ippsGet_BN() -// ippsGetSize_BN() -// ippsExtGet_BN() -// ippsRef_BN() -// -// ippsCmpZero_BN() -// ippsCmp_BN() -// -// ippsAdd_BN() -// ippsSub_BN() -// ippsMul_BN() -// ippsMAC_BN_I() -// ippsDiv_BN() -// ippsMod_BN() -// ippsGcd_BN() -// ippsModInv_BN() -// -// cpPackBigNumCtx(), cpUnpackBigNumCtx() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpbn.h" -#include "pcptool.h" - -/* BN(1) and reference */ -static IppsBigNumStateChunk cpChunk_BN1 = { - { - idCtxBigNum, - ippBigNumPOS, - 1,1, - &cpChunk_BN1.value,&cpChunk_BN1.temporary - }, - 1,0 -}; -IppsBigNumState* cpBN_OneRef(void) -{ return &cpChunk_BN1.bn; }; - -/* BN(2) and reference */ -static IppsBigNumStateChunk cpChunk_BN2 = { - { - idCtxBigNum, - ippBigNumPOS, - 1,1, - &cpChunk_BN2.value,&cpChunk_BN2.temporary - }, - 2,0 -}; -IppsBigNumState* cpBN_TwoRef(void) -{ return &cpChunk_BN2.bn; }; - -/* BN(3) and reference */ -static IppsBigNumStateChunk cpChunk_BN3 = { - { - idCtxBigNum, - ippBigNumPOS, - 1,1, - &cpChunk_BN3.value,&cpChunk_BN3.temporary - }, - 3,0 -}; -IppsBigNumState* cpBN_ThreeRef(void) -{ return &cpChunk_BN3.bn; }; - - - -/*F* -// Name: ippsBigNumGetSize -// -// Purpose: Returns size of BigNum ctx (bytes). -// -// Returns: Reason: -// ippStsNullPtrErr pCtxSize == NULL -// ippStsLengthErr len32 < 1 -// ippStsNoErr no errors -// -// Parameters: -// pCtxSize pointer BigNum ctx size -// -*F*/ -IPPFUN(IppStatus, ippsBigNumGetSize, (cpSize len32, cpSize *pCtxSize)) -{ - IPP_BAD_PTR1_RET(pCtxSize); - IPP_BADARG_RET(len32<1, ippStsLengthErr); - - { - /* convert length to the number of BNU_CHUNK_T */ - cpSize len = INTERNAL_BNU_LENGTH(len32); - /* reserve one BNU_CHUNK_T above for cpDiv_BNU, multiplication, mont exponentiation */ - len++; - - *pCtxSize = sizeof(IppsBigNumState) - + len*sizeof(BNU_CHUNK_T) - + len*sizeof(BNU_CHUNK_T) - + BN_ALIGNMENT-1; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsBigNumInit -// -// Purpose: Init BigNum spec for future usage. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// ippStsLengthErr len32<1 -// ippStsNoErr no errors -// -// Parameters: -// len32 max BN length (32-bits segments) -// pBN BigNum ctx -// -*F*/ -IPPFUN(IppStatus, ippsBigNumInit, (cpSize len32, IppsBigNumState* pBN)) -{ - IPP_BADARG_RET(len32<1, ippStsLengthErr); - IPP_BAD_PTR1_RET(pBN); - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - - { - Ipp8u* ptr = (Ipp8u*)pBN; - - /* convert length to the number of BNU_CHUNK_T */ - cpSize len = INTERNAL_BNU_LENGTH(len32); - - BN_ID(pBN) = idCtxBigNum; - BN_SIGN(pBN) = ippBigNumPOS; - BN_SIZE(pBN) = 1; /* initial valie is zero */ - BN_ROOM(pBN) = len; /* close to what has been passed by user */ - - /* reserve one BNU_CHUNK_T above for cpDiv_BNU, multiplication, mont exponentiation */ - len++; - - /* allocate buffers */ - BN_NUMBER(pBN) = (BNU_CHUNK_T*)(ptr += sizeof(IppsBigNumState)); - BN_BUFFER(pBN) = (BNU_CHUNK_T*)(ptr += len*sizeof(BNU_CHUNK_T)); /* use expanded length here */ - - /* set BN zero */ - ZEXPAND_BNU(BN_NUMBER(pBN), 0, len); - - return ippStsNoErr; - } -} - -/* -// Serialize / Deserialize bigNum context -*/ -void cpPackBigNumCtx(const IppsBigNumState* pBN, Ipp8u* pBuffer) -{ - IppsBigNumState* pAlignedBuffer = (IppsBigNumState*)(IPP_ALIGNED_PTR((pBuffer), BN_ALIGNMENT)); - CopyBlock(pBN, pAlignedBuffer, sizeof(IppsBigNumState)); - BN_NUMBER(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(BN_NUMBER(pBN))-IPP_UINT_PTR(pBN)); - BN_BUFFER(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(BN_BUFFER(pBN))-IPP_UINT_PTR(pBN)); - CopyBlock(BN_NUMBER(pBN), (Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(BN_NUMBER(pAlignedBuffer)), BN_ROOM(pBN)*sizeof(BNU_CHUNK_T)); - CopyBlock(BN_BUFFER(pBN), (Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(BN_BUFFER(pAlignedBuffer)), BN_ROOM(pBN)*sizeof(BNU_CHUNK_T)); -} - -void cpUnpackBigNumCtx(const Ipp8u* pBuffer, IppsBigNumState* pBN) -{ - IppsBigNumState* pAlignedBuffer = (IppsBigNumState*)(IPP_ALIGNED_PTR((pBuffer), BN_ALIGNMENT)); - CopyBlock(pBuffer, pBN, sizeof(IppsBigNumState)); - BN_NUMBER(pBN) = (BNU_CHUNK_T*)((Ipp8u*)pBN + IPP_UINT_PTR(BN_NUMBER(pAlignedBuffer))); - BN_BUFFER(pBN) = (BNU_CHUNK_T*)((Ipp8u*)pBN + IPP_UINT_PTR(BN_BUFFER(pAlignedBuffer))); - CopyBlock((Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(BN_NUMBER(pAlignedBuffer)), BN_NUMBER(pBN), BN_ROOM(pBN)*sizeof(BNU_CHUNK_T)); - CopyBlock((Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(BN_BUFFER(pAlignedBuffer)), BN_BUFFER(pBN), BN_ROOM(pBN)*sizeof(BNU_CHUNK_T)); -} - - -/*F* -// Name: ippsCmpZero_BN -// -// Purpose: Test BigNum value. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// pResult == NULL -// ippStsContextMatchErr BN_VALID_ID() -// ippStsNoErr no errors -// -// Parameters: -// pBN BigNum ctx -// pResult result of comparison -// -*F*/ -IPPFUN(IppStatus, ippsCmpZero_BN, (const IppsBigNumState* pBN, Ipp32u* pResult)) -{ - IPP_BAD_PTR2_RET(pBN, pResult); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - if(BN_SIZE(pBN)==1 && BN_NUMBER(pBN)[0]==0) - *pResult = IS_ZERO; - else if (BN_SIGN(pBN)==ippBigNumPOS) - *pResult = GREATER_THAN_ZERO; - else if (BN_SIGN(pBN)==ippBigNumNEG) - *pResult = LESS_THAN_ZERO; - - return ippStsNoErr; -} - - -/*F* -// Name: ippsCmp_BN -// -// Purpose: Compare two BigNums. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pResult == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// ippStsNoErr no errors -// -// Parameters: -// pA BigNum ctx -// pB BigNum ctx -// pResult result of comparison -// -*F*/ -IPPFUN(IppStatus, ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u *pResult)) -{ - IPP_BAD_PTR3_RET(pA, pB, pResult); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - - { - int res; - if(BN_SIGN(pA)==BN_SIGN(pB)) { - res = cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pB), BN_SIZE(pB)); - if(ippBigNumNEG==BN_SIGN(pA)) - res = -res; - } - else - res = (ippBigNumPOS==BN_SIGN(pA))? 1 :-1; - - *pResult = (1==res)? IPP_IS_GT : (-1==res)? IPP_IS_LT : IPP_IS_EQ; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsGetSize_BN -// -// Purpose: Returns BigNum room. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// pSize == NULL -// ippStsContextMatchErr BN_VALID_ID(pBN) -// ippStsNoErr no errors -// -// Parameters: -// pBN BigNum ctx -// pSize max BigNum length (in Ipp32u chunks) -// -*F*/ -IPPFUN(IppStatus, ippsGetSize_BN, (const IppsBigNumState* pBN, cpSize* pSize)) -{ - IPP_BAD_PTR2_RET(pBN, pSize); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - *pSize = BN_ROOM(pBN)*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsSet_BN -// -// Purpose: Set BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// pData == NULL -// ippStsContextMatchErr BN_VALID_ID(pBN) -// ippStsLengthErr len32 < 1 -// ippStsOutOfRangeErr len32 > BN_ROOM() -// ippStsNoErr no errors -// -// Parameters: -// sgn sign -// len32 data size (in Ipp32u chunks) -// pData source data pointer -// pBn BigNum ctx -// -*F*/ -IPPFUN(IppStatus, ippsSet_BN, (IppsBigNumSGN sgn, cpSize len32, const Ipp32u* pData, - IppsBigNumState* pBN)) -{ - IPP_BAD_PTR2_RET(pData, pBN); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - IPP_BADARG_RET(len32<1, ippStsLengthErr); - - /* compute real size */ - FIX_BNU(pData, len32); - - { - cpSize len = INTERNAL_BNU_LENGTH(len32); - IPP_BADARG_RET(len > BN_ROOM(pBN), ippStsOutOfRangeErr); - - ZEXPAND_COPY_BNU((Ipp32u*)BN_NUMBER(pBN), BN_ROOM(pBN)*(int)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)), pData, len32); - - BN_SIZE(pBN) = len; - - if(len32==1 && pData[0] == 0) - sgn = ippBigNumPOS; /* consider zero value as positive */ - BN_SIGN(pBN) = sgn; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsGet_BN -// -// Purpose: Get BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// pData == NULL -// pSgn == NULL -// pLen32 ==NULL -// ippStsContextMatchErr !BN_VALID_ID(pBN) -// ippStsNoErr no errors -// -// Parameters: -// pSgn pointer to the sign -// pLen32 pointer to the data size (in Ipp32u chunks) -// pData pointer to the data buffer -// pBN BigNum ctx -// -*F*/ -IPPFUN(IppStatus, ippsGet_BN, (IppsBigNumSGN* pSgn, cpSize* pLen32, Ipp32u* pData, - const IppsBigNumState* pBN)) -{ - IPP_BAD_PTR4_RET(pSgn, pLen32, pData, pBN); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - { - cpSize len32 = BN_SIZE(pBN)*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u); - Ipp32u* bnData = (Ipp32u*)BN_NUMBER(pBN); - - FIX_BNU(bnData, len32); - COPY_BNU(pData, bnData, len32); - - *pSgn = BN_SIGN(pBN); - *pLen32 = len32; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsRef_BN -// -// Purpose: Get BigNum info. -// -// Returns: Reason: -// ippStsNullPtrErr pBN == NULL -// ippStsContextMatchErr BN_VALID_ID(pBN) -// ippStsNoErr no errors -// -// Parameters: -// pSgn pointer to the sign -// pBitSize pointer to the data size (in bits) -// ppData pointer to the data buffer -// pBN BigNum ctx -// -*F*/ -IPPFUN(IppStatus, ippsRef_BN, (IppsBigNumSGN* pSgn, cpSize* pBitSize, Ipp32u** const ppData, - const IppsBigNumState *pBN)) -{ - IPP_BAD_PTR1_RET(pBN); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - if(pSgn) - *pSgn = BN_SIGN(pBN); - if(pBitSize) { - cpSize bitLen = BITSIZE_BNU(BN_NUMBER(pBN), BN_SIZE(pBN)); - *pBitSize = bitLen? bitLen : 1; - } - - if(ppData) - *ppData = (Ipp32u*)BN_NUMBER(pBN); - - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsExtGet_BN, (IppsBigNumSGN* pSgn, cpSize* pBitSize, Ipp32u* pData, - const IppsBigNumState* pBN)) -{ - IPP_BAD_PTR1_RET(pBN); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - { - cpSize bitSize = BITSIZE_BNU(BN_NUMBER(pBN), BN_SIZE(pBN)); - if(pData) - COPY_BNU(pData, (Ipp32u*)BN_NUMBER(pBN), BITS2WORD32_SIZE(bitSize)); - if(pSgn) - *pSgn = BN_SIGN(pBN); - if(pBitSize) - *pBitSize = bitSize? bitSize : 1; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsAdd_BN -// -// Purpose: Add BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// BN_VALID_ID(pR) -// ippStsOutOfRangeErr pR can not hold result -// ippStsNoErr no errors -// -// Parameters: -// pA source BigNum -// pB source BigNum -// pR resultant BigNum -// -*F*/ -IPPFUN(IppStatus, ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -{ - IPP_BAD_PTR3_RET(pA, pB, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - { - cpSize nsA = BN_SIZE(pA); - cpSize nsB = BN_SIZE(pB); - cpSize nsR = BN_ROOM(pR); - IPP_BADARG_RET(nsR < IPP_MAX(nsA, nsB), ippStsOutOfRangeErr); - - { - BNU_CHUNK_T* pDataR = BN_NUMBER(pR); - - IppsBigNumSGN sgnA = BN_SIGN(pA); - IppsBigNumSGN sgnB = BN_SIGN(pB); - BNU_CHUNK_T* pDataA = BN_NUMBER(pA); - BNU_CHUNK_T* pDataB = BN_NUMBER(pB); - - BNU_CHUNK_T carry; - - if(sgnA==sgnB) { - if(nsA < nsB) { - SWAP(nsA, nsB); - SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); - } - - carry = cpAdd_BNU(pDataR, pDataA, pDataB, nsB); - if(nsA>nsB) - carry = cpInc_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); - if(carry) { - if(nsR>nsA) - pDataR[nsA++] = carry; - else - IPP_ERROR_RET(ippStsOutOfRangeErr); - } - BN_SIGN(pR) = sgnA; - } - - else { - int cmpRes = cpCmp_BNU(pDataA, nsA, pDataB, nsB); - - if(0==cmpRes) { - pDataR[0] = 0; - BN_SIZE(pR) = 1; - BN_SIGN(pR) = ippBigNumPOS; - return ippStsNoErr; - } - - if(0>cmpRes) { - SWAP(nsA, nsB); - SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); - } - - carry = cpSub_BNU(pDataR, pDataA, pDataB, nsB); - if(nsA>nsB) - cpDec_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); - - BN_SIGN(pR) = cmpRes>0? sgnA : INVERSE_SIGN(sgnA); - } - - FIX_BNU(pDataR, nsA); - BN_SIZE(pR) = nsA; - - return ippStsNoErr; - } - } -} - - -/*F* -// Name: ippsSub_BN -// -// Purpose: Subtcrac BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// BN_VALID_ID(pR) -// ippStsOutOfRangeErr pR can not hold result -// ippStsNoErr no errors -// -// Parameters: -// pA source BigNum -// pB source BigNum -// pR resultant BigNum -// -*F*/ -IPPFUN(IppStatus, ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -{ - IPP_BAD_PTR3_RET(pA, pB, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - { - cpSize nsA = BN_SIZE(pA); - cpSize nsB = BN_SIZE(pB); - cpSize nsR = BN_ROOM(pR); - IPP_BADARG_RET(nsR < IPP_MAX(nsA, nsB), ippStsOutOfRangeErr); - - { - BNU_CHUNK_T* pDataR = BN_NUMBER(pR); - - IppsBigNumSGN sgnA = BN_SIGN(pA); - IppsBigNumSGN sgnB = BN_SIGN(pB); - BNU_CHUNK_T* pDataA = BN_NUMBER(pA); - BNU_CHUNK_T* pDataB = BN_NUMBER(pB); - - BNU_CHUNK_T carry; - - if(sgnA!=sgnB) { - if(nsA < nsB) { - SWAP(nsA, nsB); - SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); - } - - carry = cpAdd_BNU(pDataR, pDataA, pDataB, nsB); - if(nsA>nsB) - carry = cpInc_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); - if(carry) { - if(nsR > nsA) - pDataR[nsA++] = carry; - else - IPP_ERROR_RET(ippStsOutOfRangeErr); - } - BN_SIGN(pR) = sgnA; - } - - else { - int cmpRes= cpCmp_BNU(pDataA, nsA, pDataB, nsB); - - if(0==cmpRes) { - ZEXPAND_BNU(pDataR,0, nsR); - BN_SIZE(pR) = 1; - BN_SIGN(pR) = ippBigNumPOS; - return ippStsNoErr; - } - - if(0>cmpRes) { - SWAP(nsA, nsB); - SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); - } - - carry = cpSub_BNU(pDataR, pDataA, pDataB, nsB); - if(nsA>nsB) - cpDec_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); - - BN_SIGN(pR) = cmpRes>0? sgnA : INVERSE_SIGN(sgnA); - } - - FIX_BNU(pDataR, nsA); - BN_SIZE(pR) = nsA; - - return ippStsNoErr; - } - } -} - - -/*F* -// Name: ippsMul_BN -// -// Purpose: Multiply BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// BN_VALID_ID(pR) -// ippStsOutOfRangeErr pR can not hold result -// ippStsNoErr no errors -// -// Parameters: -// pA source BigNum -// pB source BigNum -// pR resultant BigNum -// -*F*/ -IPPFUN(IppStatus, ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -{ - IPP_BAD_PTR3_RET(pA, pB, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - { - BNU_CHUNK_T* pDataA = BN_NUMBER(pA); - BNU_CHUNK_T* pDataB = BN_NUMBER(pB); - BNU_CHUNK_T* pDataR = BN_NUMBER(pR); - - cpSize nsA = BN_SIZE(pA); - cpSize nsB = BN_SIZE(pB); - cpSize nsR = BN_ROOM(pR); - - cpSize bitSizeA = BITSIZE_BNU(pDataA, nsA); - cpSize bitSizeB = BITSIZE_BNU(pDataB, nsB); - - /* test if multiplicant/multiplier is zero */ - if(!bitSizeA || !bitSizeB) { - BN_SIZE(pR) = 1; - BN_SIGN(pR) = IppsBigNumPOS; - pDataR[0] = 0; - return ippStsNoErr; - } - - /* test if even low estimation of product A*B exceeded */ - IPP_BADARG_RET(nsR*BNU_CHUNK_BITS < (bitSizeA+bitSizeB-1), ippStsOutOfRangeErr); - - { - BNU_CHUNK_T* aData = pDataA; - BNU_CHUNK_T* bData = pDataB; - - if(pA == pR) { - aData = BN_BUFFER(pR); - COPY_BNU(aData, pDataA, nsA); - } - if((pB == pR) && (pA != pB)) { - bData = BN_BUFFER(pR); - COPY_BNU(bData, pDataB, nsB); - } - - /* clear result */ - ZEXPAND_BNU(pDataR, 0, nsR+1); - - if(pA==pB) - cpSqr_BNU_school(pDataR, aData, nsA); - else - cpMul_BNU_school(pDataR, aData, nsA, bData, nsB); - - nsR = (bitSizeA + bitSizeB + BNU_CHUNK_BITS - 1) /BNU_CHUNK_BITS; - FIX_BNU(pDataR, nsR); - IPP_BADARG_RET(nsR>BN_ROOM(pR), ippStsOutOfRangeErr); - - BN_SIZE(pR) = nsR; - BN_SIGN(pR) = (BN_SIGN(pA)==BN_SIGN(pB)? ippBigNumPOS : ippBigNumNEG); - return ippStsNoErr; - } - } -} - - -/*F* -// Name: ippsMAC_BN_I -// -// Purpose: Multiply and Accumulate BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// BN_VALID_ID(pR) -// ippStsOutOfRangeErr pR can not fit result -// ippStsNoErr no errors -// -// Parameters: -// pA source BigNum -// pB source BigNum -// pR resultant BigNum -// -*F*/ -IPPFUN(IppStatus, ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -{ - IPP_BAD_PTR3_RET(pA, pB, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - { - BNU_CHUNK_T* pDataA = BN_NUMBER(pA); - BNU_CHUNK_T* pDataB = BN_NUMBER(pB); - - cpSize nsA = BN_SIZE(pA); - cpSize nsB = BN_SIZE(pB); - - cpSize bitSizeA = BITSIZE_BNU(pDataA, nsA); - cpSize bitSizeB = BITSIZE_BNU(pDataB, nsB); - /* size of temporary pruduct */ - cpSize nsP = BITS_BNU_CHUNK(bitSizeA+bitSizeB); - - /* test if multiplicant/multiplier is zero */ - if(!nsP) return ippStsNoErr; - /* test if product can't fit to the result */ - IPP_BADARG_RET(BN_ROOM(pR)cmpRes) { - SWAP_PTR(BNU_CHUNK_T, pTmp, pDataP); - } - cpSub_BNU(pDataR, pTmp, pDataP, room); - - BN_SIGN(pR) = cmpRes>0? sgnR : INVERSE_SIGN(sgnR); - } - - FIX_BNU(pDataR, room); - BN_SIZE(pR) = room; - - return ippStsNoErr; - } - } -} - - -/*F* -// Name: ippsDiv_BN -// -// Purpose: Divide BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pB == NULL -// pQ == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pB) -// BN_VALID_ID(pQ) -// BN_VALID_ID(pR) -// ippStsOutOfRangeErr pQ and/or pR can not hold result -// ippStsNoErr no errors -// -// Parameters: -// pA source BigNum -// pB source BigNum -// pQ quotient BigNum -// pR reminder BigNum -// -// A = Q*B + R, 0 <= val(R) < val(B), sgn(A)==sgn(R) -// -*F*/ -IPPFUN(IppStatus, ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) -{ - IPP_BAD_PTR4_RET(pA, pB, pQ, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - pQ = (IppsBigNumState*)( IPP_ALIGNED_PTR(pQ, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pQ), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - IPP_BADARG_RET(BN_SIZE(pB)== 1 && BN_NUMBER(pB)[0]==0, ippStsDivByZeroErr); - - IPP_BADARG_RET(BN_ROOM(pR)cmpRes) - SWAP_PTR(IppsBigNumState, x, y); - if(0==cmpRes) { - COPY_BNU(BN_NUMBER(g), BN_NUMBER(x), BN_SIZE(x)); - BN_SIGN(g) = ippBigNumPOS; - BN_SIZE(g) = BN_SIZE(x); - return ippStsNoErr; - } - if(BN_SIZE(x)==1) { - BNU_CHUNK_T gcd = cpGcd_BNU(BN_NUMBER(x)[0], BN_NUMBER(y)[0]); - BN_NUMBER(g)[0] = gcd; - BN_SIZE(g) = 1; - return ippStsNoErr; - } - } - - { - Ipp32u* xBuffer = (Ipp32u*)BN_BUFFER(x); - Ipp32u* yBuffer = (Ipp32u*)BN_BUFFER(y); - Ipp32u* gBuffer = (Ipp32u*)BN_BUFFER(g); - Ipp32u* xData = (Ipp32u*)BN_NUMBER(x); - Ipp32u* yData = (Ipp32u*)BN_NUMBER(y); - Ipp32u* gData = (Ipp32u*)BN_NUMBER(g); - cpSize nsXmax = BN_ROOM(x)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - cpSize nsYmax = BN_ROOM(y)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - cpSize nsGmax = BN_ROOM(g)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - cpSize nsX = BN_SIZE(x)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - cpSize nsY = BN_SIZE(y)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - - Ipp32u* T; - Ipp32u* u; - - FIX_BNU(xData, nsX); - FIX_BNU(yData, nsY); - - /* init buffers */ - ZEXPAND_COPY_BNU(xBuffer, nsX, xData, nsXmax); - ZEXPAND_COPY_BNU(yBuffer, nsY, yData, nsYmax); - - T = gBuffer; - u = gData; - ZEXPAND_BNU(T, 0, nsGmax); - ZEXPAND_BNU(u, 0, nsGmax); - - while(nsX > (cpSize)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u))) { - /* xx and yy is the high-order digits of x and y (yy could be 0) */ - - Ipp64u xx = (Ipp64u)(xBuffer[nsX-1]); - Ipp64u yy = (nsY < nsX)? 0 : (Ipp64u)(yBuffer[nsY-1]); - - Ipp64s AA = 1; - Ipp64s BB = 0; - Ipp64s CC = 0; - Ipp64s DD = 1; - Ipp64s t; - - while((yy+CC)!=0 && (yy+DD)!=0) { - Ipp64u q = ( xx + AA ) / ( yy + CC ); - Ipp64u q1 = ( xx + BB ) / ( yy + DD ); - if(q!=q1) - break; - t = AA - q*CC; - AA = CC; - CC = t; - t = BB - q*DD; - BB = DD; - DD = t; - t = xx - q*yy; - xx = yy; - yy = t; - } - - if(BB == 0) { - /* T = x mod y */ - cpSize nsT = cpMod_BNU32(xBuffer, nsX, yBuffer, nsY); - ZEXPAND_BNU(T, 0, nsGmax); - COPY_BNU(T, xBuffer, nsT); - /* a = b; b = T; */ - ZEXPAND_BNU(xBuffer, 0, nsXmax); - COPY_BNU(xBuffer, yBuffer, nsY); - ZEXPAND_BNU(yBuffer, 0, nsYmax); - COPY_BNU(yBuffer, T, nsY); - } - - else { - Ipp32u carry; - /* - // T = AA*x + BB*y; - // u = CC*x + DD*y; - // b = u; a = T; - */ - if((AA <= 0)&&(BB>=0)) { - Ipp32u a1 = (Ipp32u)(-AA); - carry = cpMulDgt_BNU32(T, yBuffer, nsY, (Ipp32u)BB); - carry = cpMulDgt_BNU32(u, xBuffer, nsY, a1); - /* T = BB*y - AA*x; */ - carry = cpSub_BNU32(T, T, u, nsY); - } - else { - if((AA >= 0)&&(BB<=0)) { - Ipp32u b1 = (Ipp32u)(-BB); - carry = cpMulDgt_BNU32(T, xBuffer, nsY, (Ipp32u)AA); - carry = cpMulDgt_BNU32(u, yBuffer, nsY, b1); - /* T = AA*x - BB*y; */ - carry = cpSub_BNU32(T, T, u, nsY); - } - else { - /*AA*BB>=0 */ - carry = cpMulDgt_BNU32(T, xBuffer, nsY, (Ipp32u)AA); - carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)BB); - /* T = AA*x + BB*y; */ - carry = cpAdd_BNU32(T, T, u, nsY); - } - } - - /* Now T is reserved. We use only u for intermediate results. */ - if((CC <= 0)&&(DD>=0)){ - Ipp32u c1 = (Ipp32u)(-CC); - /* u = x*CC; x = u; */ - carry = cpMulDgt_BNU32(u, xBuffer, nsY, c1); - COPY_BNU(xBuffer, u, nsY); - /* u = y*DD; */ - carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)DD); - /* u = DD*y - CC*x; */ - carry = cpSub_BNU32(u, u, xBuffer, nsY); - } - else { - if((CC >= 0)&&(DD<=0)){ - Ipp32u d1 = (Ipp32u)(-DD); - /* u = y*DD; y = u */ - carry = cpMulDgt_BNU32(u, yBuffer, nsY, d1); - COPY_BNU(yBuffer, u, nsY); - /* u = CC*x; */ - carry = cpMulDgt_BNU32(u, xBuffer, nsY, (Ipp32u)CC); - /* u = CC*x - DD*y; */ - carry = cpSub_BNU32(u, u, yBuffer, nsY); - } - else { - /*CC*DD>=0 */ - /* y = y*DD */ - carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)DD); - COPY_BNU(yBuffer, u, nsY); - /* u = x*CC */ - carry = cpMulDgt_BNU32(u, xBuffer, nsY, (Ipp32u)CC); - /* u = x*CC + y*DD */ - carry = cpAdd_BNU32(u, u, yBuffer, nsY); - } - } - - /* y = u; x = T; */ - COPY_BNU(yBuffer, u, nsY); - COPY_BNU(xBuffer, T, nsY); - } - - FIX_BNU(xBuffer, nsX); - FIX_BNU(yBuffer, nsY); - - if (nsY > nsX) { - SWAP_PTR(IppsBigNumState, x, y); - SWAP(nsX, nsY); - } - - if (nsY==1 && yBuffer[nsY-1]==0) { - /* End evaluation */ - ZEXPAND_BNU(gData, 0, nsGmax); - COPY_BNU(gData, xBuffer, nsX); - BN_SIZE(g) = INTERNAL_BNU_LENGTH(nsX); - BN_SIGN(g) = ippBigNumPOS; - return ippStsNoErr; - } - } - - BN_NUMBER(g)[0] = cpGcd_BNU(((BNU_CHUNK_T*)xBuffer)[0], ((BNU_CHUNK_T*)yBuffer)[0]); - BN_SIZE(g) = 1; - BN_SIGN(g) = ippBigNumPOS; - return ippStsNoErr; - } - } -} - - -/*F* -// Name: ippsModInv_BN -// -// Purpose: Multiplicative Inversion BigNum. -// -// Returns: Reason: -// ippStsNullPtrErr pA == NULL -// pM == NULL -// pR == NULL -// ippStsContextMatchErr BN_VALID_ID(pA) -// BN_VALID_ID(pM) -// BN_VALID_ID(pR) -// ippStsBadArgErr A<=0 -// ippStsBadModulusErr M<=0 -// ippStsScaleRangeErr A>=M -// ippStsOutOfRangeErr pR can not hold result -// ippStsNoErr no errors -// ippStsBadModulusErr inversion not found -// -// Parameters: -// pA source (value) BigNum -// pM source (modulus) BigNum -// pR reminder BigNum -// -*F*/ -IPPFUN(IppStatus, ippsModInv_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR) ) -{ - IPP_BAD_PTR3_RET(pA, pM, pR); - - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - pM = (IppsBigNumState*)( IPP_ALIGNED_PTR(pM, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pM), ippStsContextMatchErr); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - IPP_BADARG_RET(BN_ROOM(pR) < BN_SIZE(pM), ippStsOutOfRangeErr); - IPP_BADARG_RET(BN_NEGATIVE(pA) || (BN_SIZE(pA)==1 && BN_NUMBER(pA)[0]==0), ippStsBadArgErr); - IPP_BADARG_RET(BN_NEGATIVE(pM) || (BN_SIZE(pM)==1 && BN_NUMBER(pM)[0]==0), ippStsBadModulusErr); - IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pM), BN_SIZE(pM)) >= 0, ippStsScaleRangeErr); - - { - cpSize nsR = cpModInv_BNU(BN_NUMBER(pR), - BN_NUMBER(pA), BN_SIZE(pA), - BN_NUMBER(pM), BN_SIZE(pM), - BN_BUFFER(pR), BN_BUFFER(pA), BN_BUFFER(pM)); - if(nsR) { - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = nsR; - return ippStsNoErr; - } - else - return ippStsBadModulusErr; - } -} - diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresourceca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresourceca.c deleted file mode 100644 index 8e475205..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresourceca.c +++ /dev/null @@ -1,87 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal ECC (prime) Resource List Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpbnresource.h" -#include "pcpbn.h" - -/* -// Size of BigNum List Buffer -*/ -int cpBigNumListGetSize(int feBitSize, int nodes) -{ - /* size of buffer per single big number */ - int bnSize; - ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize); - - /* size of buffer for whole list */ - return (ALIGN_VAL-1) + (sizeof(BigNumNode) + bnSize) * nodes; -} - -/* -// Init list -// -// Note: buffer for BN list must have appropriate alignment -*/ -void cpBigNumListInit(int feBitSize, int nodes, BigNumNode* pList) -{ - int itemSize; - /* length of Big Num */ - int bnLen = BITS2WORD32_SIZE(feBitSize); - /* size of buffer per single big number */ - ippsBigNumGetSize(bnLen, &itemSize); - /* size of list item */ - itemSize += sizeof(BigNumNode); - - { - int n; - /* init all nodes */ - BigNumNode* pNode = (BigNumNode*)( (Ipp8u*)pList + (nodes-1)*itemSize ); - BigNumNode* pNext = NULL; - for(n=0; npNext = pNext; - pNode->pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(tbnPtr, ALIGN_VAL) ); - ippsBigNumInit(bnLen, pNode->pBN); - pNext = pNode; - pNode = (BigNumNode*)( (Ipp8u*)pNode - itemSize); - } - } -} - -/* -// Get BigNum reference -*/ -IppsBigNumState* cpBigNumListGet(BigNumNode** ppList) -{ - if(*ppList) { - IppsBigNumState* ret = (*ppList)->pBN; - *ppList = (*ppList)->pNext; - return ret; - } - else - return NULL; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnsetca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnsetca.c deleted file mode 100644 index 0afc468d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnsetca.c +++ /dev/null @@ -1,117 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Big Number Operations -// -// Contents: -// ippsSetOctString_BN() -// ippsGetOctString_BN() -// -// -*/ - -#include "owndefs.h" -#include "owncp.h" -#include "pcpbn.h" - - -/*F* -// Name: ippsSetOctString_BN -// -// Purpose: Convert octet string into the BN value. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pOctStr -// NULL == pBN -// -// ippStsLengthErr 0>strLen -// -// ippStsSizeErr BN_ROOM() is enough for keep actual strLen -// -// ippStsNoErr no errors -// -// Parameters: -// pOctStr pointer to the source octet string -// strLen octet string length -// pBN pointer to the target BN -// -*F*/ -IPPFUN(IppStatus, ippsSetOctString_BN,(const Ipp8u* pOctStr, cpSize strLen, - IppsBigNumState* pBN)) -{ - IPP_BAD_PTR2_RET(pOctStr, pBN); - - pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); - - IPP_BADARG_RET((0>strLen), ippStsLengthErr); - - /* remove leading zeros */ - while(strLen && (0==pOctStr[0])) { - strLen--; - pOctStr++; - } - - /* test BN size */ - IPP_BADARG_RET((int)(sizeof(BNU_CHUNK_T)*BN_ROOM(pBN))strLen), ippStsLengthErr); - - return cpToOctStr_BNU(pOctStr,strLen, BN_NUMBER(pBN),BN_SIZE(pBN))? ippStsNoErr : ippStsLengthErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.c deleted file mode 100644 index 1bf70f0a..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.c +++ /dev/null @@ -1,366 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Internal BNU32 arithmetic. -// -// Contents: -// -// cpAdd_BNU32() -// cpSub_BNU32() -// -// cpMulDgt_BNU32() -// cpSubMulDgt_BNU32() -// -// cpDiv_BNU32() -// -// -*/ - -#include "owncp.h" -#include "pcpbnumisc.h" -#include "pcpbnu32misc.h" -#include "pcpbnu32arith.h" - -/* -// BNU32 addition -*/ -Ipp32u cpAdd_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, cpSize ns) -{ - Ipp32u carry = 0; - cpSize i; - for(i=0; i>(32-1); - } - return borrow; -} - -/* -// BNU32 mul_by_digit -*/ -Ipp32u cpMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, Ipp32u val) -{ - Ipp32u carry = 0; - cpSize i; - for(i=0; i0; nsA--) { - Ipp64u r = (Ipp64u)*pR + (Ipp64u)(*pA++) * val + extension; - *pR++ = LODWORD(r); - extension = HIDWORD(r); - } - return extension; -} -#endif - -/* -// BNU32 mul_by_digit_subtract -*/ -#if !((_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -Ipp32u cpSubMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, Ipp32u val) -{ - Ipp32u carry = 0; - for(; nsA>0; nsA--) { - Ipp64u r = (Ipp64u)*pR - (Ipp64u)(*pA++) * val - carry; - *pR++ = LODWORD(r); - carry = 0-HIDWORD(r); - } - return carry; -} -#endif - -/* -// BNU32 division -*/ -#if !((_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -int cpDiv_BNU32(Ipp32u* pQ, cpSize* sizeQ, - Ipp32u* pX, cpSize sizeX, - Ipp32u* pY, cpSize sizeY) -{ - FIX_BNU(pY,sizeY); - FIX_BNU(pX,sizeX); - - /* special case */ - if(sizeX < sizeY) { - - if(pQ) { - pQ[0] = 0; - *sizeQ = 1; - } - - return sizeX; - } - - /* special case */ - if(1 == sizeY) { - int i; - Ipp32u r = 0; - for(i=(int)sizeX-1; i>=0; i--) { - Ipp64u tmp = MAKEDWORD(pX[i],r); - Ipp32u q = LODWORD(tmp / pY[0]); - r = LODWORD(tmp - q*pY[0]); - if(pQ) pQ[i] = q; - } - - pX[0] = r; - - if(pQ) { - FIX_BNU(pQ,sizeX); - *sizeQ = sizeX; - } - - return 1; - } - - - /* common case */ - { - cpSize qs = sizeX-sizeY+1; - - cpSize nlz = cpNLZ_BNU32(pY[sizeY-1]); - - /* normalization */ - pX[sizeX] = 0; - if(nlz) { - cpSize ni; - - pX[sizeX] = pX[sizeX-1] >> (32-nlz); - for(ni=sizeX-1; ni>0; ni--) - pX[ni] = (pX[ni]<>(32-nlz)); - pX[0] <<= nlz; - - for(ni=sizeY-1; ni>0; ni--) - pY[ni] = (pY[ni]<>(32-nlz)); - pY[0] <<= nlz; - } - - /* - // division - */ - { - Ipp32u yHi = pY[sizeY-1]; - - int i; - for(i=(int)qs-1; i>=0; i--) { - Ipp32u extend; - - /* estimate digit of quotient */ - Ipp64u tmp = MAKEDWORD(pX[i+sizeY-1], pX[i+sizeY]); - Ipp64u q = tmp / yHi; - Ipp64u r = tmp - q*yHi; - - /* tune estimation above */ - //for(; (q>=CONST_64(0x100000000)) || (Ipp64u)q*pY[sizeY-2] > MAKEDWORD(pX[i+sizeY-2],r); ) { - for(; HIDWORD(q) || (Ipp64u)q*pY[sizeY-2] > MAKEDWORD(pX[i+sizeY-2],r); ) { - q -= 1; - r += yHi; - if( HIDWORD(r) ) - break; - } - - /* multiply and subtract */ - extend = cpSubMulDgt_BNU32(pX+i, pY, sizeY, (Ipp32u)q); - extend = (pX[i+sizeY] -= extend); - - if(extend) { /* subtracted too much */ - q -= 1; - extend = cpAdd_BNU32(pX+i, pY, pX+i, sizeY); - pX[i+sizeY] += extend; - } - - /* store quotation digit */ - if(pQ) pQ[i] = LODWORD(q); - } - } - - /* de-normalization */ - if(nlz) { - cpSize ni; - for(ni=0; ni>nlz) | (pX[ni+1]<<(32-nlz)); - for(ni=0; ni>nlz) | (pY[ni+1]<<(32-nlz)); - pY[sizeY-1] >>= nlz; - } - - FIX_BNU(pX,sizeX); - - if(pQ) { - FIX_BNU(pQ,qs); - *sizeQ = qs; - } - - return sizeX; - } -} -#endif - -#define FE_MUL(R,A,B,LEN) { \ - int aidx, bidx; \ - \ - for(aidx=0; aidx<(LEN); aidx++) (R)[aidx] = 0; \ - \ - for(bidx=0; bidx<(LEN); bidx++) { \ - Ipp64u b = (B)[bidx]; \ - Ipp32u c = 0; \ - for(aidx=0; aidx<(LEN); aidx++) { \ - Ipp64u t = (R)[bidx+aidx] + (A)[aidx] * b + c; \ - (R)[bidx+aidx] = LODWORD(t); \ - c = HIDWORD(t); \ - } \ - (R)[bidx+aidx] = c; \ - } \ -} - -#if 0 -#if !((_IPP==_IPP_W7) || \ - (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || \ - (_IPP==_IPP_P8) || \ - (_IPP>=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -void cpMul_BNU8(const Ipp32u* pA, const Ipp32u* pB, Ipp32u* pR) -{ - FE_MUL(pR, pA, pB, 8) -} -#endif -#endif - -#if 0 -#if !((_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -void cpMul_BNU4(const Ipp32u* pA, const Ipp32u* pB, Ipp32u* pR) -{ - FE_MUL(pR, pA, pB, 4) -} -#endif -#endif - -#if 0 -#if !((_IPP==_IPP_W7) || \ - (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || \ - (_IPP==_IPP_P8) || \ - (_IPP>=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -void cpSqr_BNU8(const Ipp32u* pA, Ipp32u* pR) -{ - FE_MUL(pR, pA, pA, 8) -} -#endif -#endif - -#if 0 -#if !((_IPP==_IPP_W7) || \ - (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || \ - (_IPP==_IPP_P8) || \ - (_IPP>=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -void cpSqr_BNU4(const Ipp32u* pA, Ipp32u* pR) -{ - FE_MUL(pR, pA, pA, 4) -} -#endif -#endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.h deleted file mode 100644 index 39ce622d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32arith.h +++ /dev/null @@ -1,50 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. -// Internal BNU32 arithmetic -// -// -*/ - -#if !defined(_CP_BNU32_ARITH_H) -#define _CP_BNU32_ARITH_H - -Ipp32u cpAdd_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, int ns); -Ipp32u cpSub_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, int ns); -Ipp32u cpInc_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u val); -Ipp32u cpDec_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u val); - -Ipp32u cpMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, int ns, Ipp32u val); -Ipp32u cpSubMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, int nsA, Ipp32u val); -#if 0 -Ipp32u cpAddMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, int nsA, Ipp32u val); -#endif - -int cpDiv_BNU32(Ipp32u* pQ, int* nsQ, Ipp32u* pX, int nsX, Ipp32u* pY, int nsY); -#define cpMod_BNU32(pX,sizeX, pM,sizeM) cpDiv_BNU32(NULL,NULL, (pX),(sizeX), (pM),(sizeM)) - -int cpFromOS_BNU32(Ipp32u* pBNU, const Ipp8u* pOctStr, int strLen); -int cpToOS_BNU32(Ipp8u* pStr, int strLen, const Ipp32u* pBNU, int bnuSize); - -void cpMul_BNU8(const Ipp32u* pA, const Ipp32u* pB, Ipp32u* pR); -void cpMul_BNU4(const Ipp32u* pA, const Ipp32u* pB, Ipp32u* pR); -void cpSqr_BNU8(const Ipp32u* pA, Ipp32u* pR); -void cpSqr_BNU4(const Ipp32u* pA, Ipp32u* pR); - -#endif /* _CP_BNU32_ARITH_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.c deleted file mode 100644 index 36e777f2..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.c +++ /dev/null @@ -1,229 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Unsigned internal BNU32 misc functionality -// -// Contents: -// cpNLZ_BNU32() -// cpNTZ_BNU32() -// -// cpLSL_BNU32() -// cpLSR_BNU32() -// -// cpFromOctStr_BNU32() -// cpToOctStr_BNU32() -// -// -*/ - -#include "owncp.h" -#include "pcpbnuimpl.h" -#include "pcpbnumisc.h" -#include "pcpbnu32misc.h" - - -/* -// number of leading zeros -*/ -cpSize cpNLZ_BNU32(Ipp32u x) -{ - cpSize nlz = BITSIZE(Ipp32u); - if(x) { - nlz = 0; - if( 0==(x & 0xFFFF0000) ) { nlz +=16; x<<=16; } - if( 0==(x & 0xFF000000) ) { nlz += 8; x<<= 8; } - if( 0==(x & 0xF0000000) ) { nlz += 4; x<<= 4; } - if( 0==(x & 0xC0000000) ) { nlz += 2; x<<= 2; } - if( 0==(x & 0x80000000) ) { nlz++; } - } - return nlz; -} - -/* -// number of trailing zeros -*/ -#if 0 -cpSize cpNTZ_BNU32(Ipp32u x) -{ - cpSize ntz = BITSIZE(Ipp32u); - if(x) { - ntz = 0; - if( 0==(x & 0x0000FFFF) ) { ntz+=16; x>>=16; } - if( 0==(x & 0x000000FF) ) { ntz+= 8; x>>= 8; } - if( 0==(x & 0x0000000F) ) { ntz+= 4; x>>= 4; } - if( 0==(x & 0x00000003) ) { ntz+= 2; x>>= 2; } - if( 0==(x & 0x00000001) ) { ntz++; } - } - return ntz; -} -#endif - -/* -// Logical shift left (including inplace) -// -// Returns new length -*/ -#if 0 -cpSize cpLSL_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, cpSize nBits) -{ - cpSize nlz = cpNLZ_BNU32(pA[nsA-1]); - cpSize nw = nBits/BNU_CHUNK_32BIT; - cpSize n; - - pR += nw; - - nBits %= BNU_CHUNK_32BIT; - if(nBits) { - Ipp32u hi,lo; - - if(nlz < nBits ) - hi = 0; - else - hi = pA[--nsA]; - - for(n=nsA; n>0; n--) { - lo = pA[n-1]; - pR[n] = (hi<>(BNU_CHUNK_32BIT-nBits)); - hi = lo; - } - pR[0] = (hi<0; n--) - pR[n-1] = pA[n-1]; - } - - pR--; - for(n=0; n>nBits) | (hi<<(BNU_CHUNK_32BIT-nBits)); - lo = hi; - } - if(cnz > nBits) - pR[nsA-1] = (lo>>nBits); - else - nsA--; - } - - else { - for(n=0; n=4; bnuSize++,strLen-=4) { - /* pack 4 bytes into single Ipp32u value*/ - *pBNU++ = ( pOctStr[strLen-4]<<(8*3) ) - +( pOctStr[strLen-3]<<(8*2) ) - +( pOctStr[strLen-2]<<(8*1) ) - + pOctStr[strLen-1]; - } - - /* convert the beginning of the string */ - if(strLen) { - Ipp32u x; - for(x=0; strLen>0; strLen--) { - Ipp32u d = *pOctStr++; - x = x*256 + d; - } - *pBNU++ = x; - bnuSize++; - } - - return bnuSize? bnuSize : 1; -} - - -/* -// Convert BNU into Octet String representation -// -// Returns strLen or 0 if no success -*/ -cpSize cpToOctStr_BNU32(Ipp8u* pStr, cpSize strLen, const Ipp32u* pBNU, cpSize bnuSize) -{ - FIX_BNU(pBNU, bnuSize); - { - int bnuBitSize = BITSIZE_BNU32(pBNU, bnuSize); - if(bnuBitSize <= strLen*BYTESIZE) { - Ipp32u x = pBNU[bnuSize-1]; - - ZEXPAND_BNU(pStr, 0, strLen); - pStr += strLen - BITS2WORD8_SIZE(bnuBitSize); - - if(x) { - int nb; - for(nb=cpNLZ_BNU32(x)/BYTESIZE; nb<4; nb++) - *pStr++ = EBYTE(x,3-nb); - - for(--bnuSize; bnuSize>0; bnuSize--) { - x = pBNU[bnuSize-1]; - *pStr++ = EBYTE(x,3); - *pStr++ = EBYTE(x,2); - *pStr++ = EBYTE(x,1); - *pStr++ = EBYTE(x,0); - } - } - return strLen; - } - else - return 0; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.h deleted file mode 100644 index 228b9652..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnu32misc.h +++ /dev/null @@ -1,71 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Internal Miscellaneous BNU 32 bit Definitions & Function Prototypes -// -// -*/ - -#if !defined(_CP_BNU32_MISC_H) -#define _CP_BNU32_MISC_H - - -/* bit operations */ -#define BITSIZE_BNU32(p,ns) ((ns)*BNU_CHUNK_32BIT-cpNLZ_BNU32((p)[(ns)-1])) - -/* number of leading/trailing zeros */ -cpSize cpNLZ_BNU32(Ipp32u x); -#if 0 -cpSize cpNTZ_BNU32(Ipp32u x); -#endif - -/* most significant BNU bit */ -__INLINE int cpMSBit_BNU32(const Ipp32u* pA, cpSize nsA) -{ - FIX_BNU(pA, nsA); - return nsA*BITSIZE(Ipp32u) - cpNLZ_BNU32(pA[nsA-1]) -1; -} - - -__INLINE int cpCmp_BNU32(const Ipp32u* pA, cpSize nsA, const Ipp32u* pB, cpSize nsB) -{ - if(nsA!=nsB) - return nsA>nsB? 1 : -1; - else { - for(; nsA>0; nsA--) { - if(pA[nsA-1] > pB[nsA-1]) - return 1; - else if(pA[nsA-1] < pB[nsA-1]) - return -1; - } - return 0; - } -} - -/* logical shift left/right */ -#if 0 -cpSize cpLSL_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, cpSize nBits); -cpSize cpLSR_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, cpSize nBits); -#endif - -/* to/from oct string conversion */ -cpSize cpToOctStr_BNU32(Ipp8u* pStr, cpSize strLen, const Ipp32u* pBNU, cpSize bnuSize); -cpSize cpFromOctStr_BNU32(Ipp32u* pBNU, const Ipp8u* pOctStr, cpSize strLen); - -#endif /* _CP_BNU32_MISC_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.c deleted file mode 100644 index d224a562..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.c +++ /dev/null @@ -1,537 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Internal Unsigned arithmetic -// -// Contents: -// cpAdd_BNU() -// cpSub_BNU() -// cpInc_BNU() -// cpDec_BNU() -// -// cpAddAdd_BNU() -// cpAddSub_BNU() -// -// cpMuldgt_BNU() -// cpAddMulDgt_BNU() -// cpSubMulDgt_BNU() -// -// cpMulAdc_BNU_school() -// cpSqrAdc_BNU_school() -// -// cpDiv_BNU() -// cpMod_BNU() -// cpGcd_BNU() -// cpModInv_BNU() -// -// -*/ - -#include "owncp.h" -#include "pcpbnuarith.h" -#include "pcpbnumisc.h" - - -/* Function cpAdd_BNU - addition of 2 BigNumbers */ -#if !((_IPP==_IPP_W7) || \ - (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || \ - (_IPP==_IPP_P8) || \ - (_IPP>=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8) || \ - (_IPPLRB>=_IPPLRB_B1)) -BNU_CHUNK_T cpAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns) -{ - BNU_CHUNK_T carry = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8) || \ - (_IPPLRB>=_IPPLRB_B1)) -BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns) -{ - BNU_CHUNK_T borrow = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val) -{ - cpSize i; - for(i=0; i=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val) -{ - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpAddAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pC, cpSize ns) -{ - BNU_CHUNK_T carry1 = 0; - BNU_CHUNK_T carry2 = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpAddSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pC, cpSize ns) -{ - BNU_CHUNK_T carry = 0; - BNU_CHUNK_T borrow = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val) -{ - BNU_CHUNK_T extension = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) -BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val) -{ - BNU_CHUNK_T extension = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8) || \ - (_IPPLRB >= _IPPLRB_B1)) -BNU_CHUNK_T cpSubMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val) -{ - BNU_CHUNK_T extension = 0; - cpSize i; - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8) ) -// || (_IPPLRB >= _IPPLRB_B1)) //dlaptev: is it renaming? -//BNU_CHUNK_T cpMul_BNU_school(BNU_CHUNK_T* pR, -// const BNU_CHUNK_T* pA, cpSize nsA, -// const BNU_CHUNK_T* pB, cpSize nsB) -BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB) -{ - const BNU_CHUNK_T* pa = (BNU_CHUNK_T*)pA; - const BNU_CHUNK_T* pb = (BNU_CHUNK_T*)pB; - BNU_CHUNK_T* pr = (BNU_CHUNK_T*)pR; - - BNU_CHUNK_T extension = 0; - cpSize i, j; - - ZEXPAND_BNU(pr, 0, nsA+nsB); - - for(i=0; i=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8) ) -//|| (_IPPLRB >= _IPPLRB_B1)) //dlaptev: is it renaming? -//BNU_CHUNK_T cpSqr_BNU_school(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA) -BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA) -{ - cpSize i; - - BNU_CHUNK_T extension; - BNU_CHUNK_T rH, rL; - - /* init result */ - pR[0] = 0; - for(i=1, extension=0; i b){ - gcd = a; - t = b; - } else { - t = a; - gcd = b; - } - - while (t != 0) { - r = gcd % t; - gcd = t; - t = r; - } - return gcd; -} - -/* -// cpMAC_BNU -// -// Multiply with ACcumulation -// Computes r <- r + a * b, returns real size of the r in the size_r variable -// Returns 0 if there are no enought buffer size to write to r[MAX(size_r + 1, size_a + size_b) - 1] -// Returns 1 if no error -// -// Note: -// DO NOT run in inplace mode -// The minimum buffer size for the r must be (size_a + size_b - 1) -// the maximum buffer size for the r is MAX(size_r + 1, size_a + size_b) -*/ -static int cpMac_BNU(BNU_CHUNK_T* pR, cpSize nsR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB) -{ - /* cleanup the rest of destination buffer */ - ZEXPAND_BNU(pR, nsR, nsA+nsB-1); - //nsR = IPP_MAX(nsR, nsA+nsB); - - { - BNU_CHUNK_T expansion = 0; - cpSize i; - for(i=0; i -static void Print_BNU(const char* note, const BNU_CHUNK_T* pData, int len) -{ - if(note) - printf("%s", note); - { - int n; - Ipp32u* pDataT = (Ipp32u*)pData; - len *= (sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); - for(n=len; n>0; n--) { - Ipp32u x = pDataT[n-1]; - printf("%08x ", x); - } - printf("\n"); - } -} -#endif - -int cpModInv_BNU(BNU_CHUNK_T* pInv, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pM, cpSize nsM, - BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM) -{ - FIX_BNU(pA, nsA); - FIX_BNU(pM, nsM); - - /* inv(1) = 1 */ - if(nsA==1 && pA[0]==1) { - pInv[0] = 1; - return 1; - } - - { - cpSize moduloSize = nsM; - - BNU_CHUNK_T* X1 = pInv; - BNU_CHUNK_T* X2 = bufM; - BNU_CHUNK_T* Q = bufInv; - cpSize nsX1 = 1; - cpSize nsX2 = 1; - cpSize nsQ; - - COPY_BNU(bufA, pA, nsA); - - ZEXPAND_BNU(X1, 0, moduloSize); - ZEXPAND_BNU(X2, 0, moduloSize); - X2[0] = 1; - - //printf("\n"); - for(;;) { - nsM = cpDiv_BNU(Q, &nsQ, (BNU_CHUNK_T*)pM, nsM, bufA, nsA); - //Print_BNU(" q: ", Q, nsQ); - //Print_BNU(" m: ", pM, nsM); - nsX1 = cpMac_BNU(X1,moduloSize, Q,nsQ, X2,nsX2); - //Print_BNU("X1: ", X1, nsX1); - - if (nsM==1 && pM[0]==1) { - ////ZEXPAND_BNU(X2, nsX2, moduloSize); - nsX2 = cpMac_BNU(X2,moduloSize, X1,nsX1, bufA, nsA); - COPY_BNU((BNU_CHUNK_T*)pM, X2, moduloSize); - cpSub_BNU(pInv, pM, X1, moduloSize); - FIX_BNU(pInv, moduloSize); - return moduloSize; - } - else if (nsM==1 && pM[0]==0) { - cpMul_BNU_school((BNU_CHUNK_T*)pM, X1,nsX1, bufA, nsA); - /* gcd = buf_a */ - return 0; - } - - nsA = cpDiv_BNU(Q, &nsQ, bufA, nsA, (BNU_CHUNK_T*)pM, nsM); - //Print_BNU(" q: ", Q, nsQ); - //Print_BNU(" a: ", bufA, nsA); - nsX2 = cpMac_BNU(X2,moduloSize, Q,nsQ, X1,nsX1); - //Print_BNU("X2: ", X2, nsX2); - - if(nsA==1 && bufA[0]==1) { - ////ZEXPAND_BNU(X1, nsX1, moduloSize); - nsX1 = cpMac_BNU(X1, moduloSize, X2, nsX2, pM, nsM); - COPY_BNU((BNU_CHUNK_T*)pM, X1, moduloSize); - COPY_BNU(pInv, X2, nsX2); - return nsX2; - } - else if (nsA==1 && bufA[0]==0) { - /* gcd = m */ - COPY_BNU(X1, pM, nsM); - cpMul_BNU_school((BNU_CHUNK_T*)pM, X2, nsX2, X1, nsM); - return 0; - } - } - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.h deleted file mode 100644 index 9481317d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnuarith.h +++ /dev/null @@ -1,169 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. -// Internal Unsigned internal arithmetic -// -// -*/ - -#if !defined(_CP_BNU_ARITH_H) -#define _CP_BNU_ARITH_H - -#include "pcpbnuimpl.h" -#include "pcpbnu32arith.h" -#include "pcpmulbnukara.h" - -BNU_CHUNK_T cpAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns); -BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns); -BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val); -BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val); - -#if defined(_USE_KARATSUBA_) -BNU_CHUNK_T cpAddAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pC, cpSize size); -BNU_CHUNK_T cpAddSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pC, cpSize size); -#endif - -BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val); -#if 0 -BNU_CHUNK_T cpMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val); -BNU_CHUNK_T cpSubMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val); -#endif - - -BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB); -BNU_CHUNK_T cpMulAdx_BNU_school(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB); - -__INLINE BNU_CHUNK_T cpMul_BNU_school(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB) -{ -#if(_ADCOX_NI_ENABLING_==_FEATURE_ON_) - return cpMulAdx_BNU_school(pR, pA,nsA, pB,nsB); -#elif(_ADCOX_NI_ENABLING_==_FEATURE_TICKTOCK_) - return IsFeatureEnabled(ADCOX_ENABLED)? cpMulAdx_BNU_school(pR, pA,nsA, pB,nsB) - : cpMulAdc_BNU_school(pR, pA,nsA, pB,nsB); -#else - return cpMulAdc_BNU_school(pR, pA,nsA, pB,nsB); -#endif -} - -BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA); -BNU_CHUNK_T cpSqrAdx_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA); - -__INLINE BNU_CHUNK_T cpSqr_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA) -{ -#if(_ADCOX_NI_ENABLING_==_FEATURE_ON_) - return cpSqrAdx_BNU_school(pR, pA,nsA); -#elif(_ADCOX_NI_ENABLING_==_FEATURE_TICKTOCK_) - return IsFeatureEnabled(ADCOX_ENABLED)? cpSqrAdx_BNU_school(pR, pA,nsA) - : cpSqrAdc_BNU_school(pR, pA,nsA); -#else - return cpSqrAdc_BNU_school(pR, pA,nsA); -#endif -} - -#if(_IPP_ARCH==_IPP_ARCH_EM64T) -BNU_CHUNK_T* gf256_add(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pModulus); -BNU_CHUNK_T* gf256_sub(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pModulus); -BNU_CHUNK_T* gf256_neg(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pModulus); -BNU_CHUNK_T* gf256_mulm(BNU_CHUNK_T* pR,const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, const BNU_CHUNK_T* pModulus, BNU_CHUNK_T m0); -BNU_CHUNK_T* gf256_sqrm(BNU_CHUNK_T* pR,const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pModulus, BNU_CHUNK_T m0); -BNU_CHUNK_T* gf256_div2(BNU_CHUNK_T* pR,const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pModulus); -#endif - -BNU_CHUNK_T cpGcd_BNU(BNU_CHUNK_T a, BNU_CHUNK_T b); - -int cpModInv_BNU(BNU_CHUNK_T* pInv, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pM, cpSize nsM, - BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM); - - -/* -// multiplication/squaring wrappers -*/ -__INLINE cpSize cpMul_BNU_BufferSize(cpSize opLen) -{ -#if !defined (_USE_KARATSUBA_) - UNREFERENCED_PARAMETER(opLen); - return 0; -#else - return cpKaratsubaBufferSize(opLen); -#endif -} -__INLINE BNU_CHUNK_T cpMul_BNU(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, cpSize nsA, - const BNU_CHUNK_T* pB, cpSize nsB, - BNU_CHUNK_T* pBuffer) -{ -#if !defined(_USE_KARATSUBA_) - UNREFERENCED_PARAMETER(pBuffer); - return cpMul_BNU_school(pR, pA,nsA, pB,nsB); -#else - if(nsA!=nsB || nsA> (BNU_CHUNK_BITS/2)) - -/* (carry,R) = A+B */ -#define ADD_AB(CARRY,R, A,B) \ -do { \ - BNU_CHUNK_T __s = (A) + (B); \ - (CARRY) = __s < (A); \ - (R) = __s; \ -} while(0) - -/* (carry,R) = A+B+C */ -#define ADD_ABC(CARRY,R, A,B,C) \ -do { \ - BNU_CHUNK_T __s = (A) + (B); \ - BNU_CHUNK_T __t1= __s < (A); \ - BNU_CHUNK_T __r = __s + (C); \ - BNU_CHUNK_T __t2 = __r < __s; \ - (CARRY) = __t1 + __t2; \ - (R) = __r; \ -} while(0) - -/* (borrow,R) = A-B */ -#define SUB_AB(BORROW,R, A,B) \ -do { \ - (BORROW) = (A)<(B); \ - (R) = (A)-(B); \ -} while(0) - -/* (borrow,R) = A-B-C */ -#define SUB_ABC(BORROW,R, A,B,C) \ -do { \ - BNU_CHUNK_T __s = (A) -( B); \ - BNU_CHUNK_T __t1= __s > (A); \ - BNU_CHUNK_T __r = __s - (C); \ - BNU_CHUNK_T __t2 = __r > __s; \ - (BORROW) = __t1 + __t2; \ - (R) = __r; \ -} while(0) - -/* (RH,RL) = A*B */ -#define MUL_AB(RH, RL, A, B) \ - do { \ - BNU_CHUNK_T __aL = LO_CHUNK((A)); \ - BNU_CHUNK_T __aH = HI_CHUNK((A)); \ - BNU_CHUNK_T __bL = LO_CHUNK((B)); \ - BNU_CHUNK_T __bH = HI_CHUNK((B)); \ - \ - BNU_CHUNK_T __x0 = (BNU_CHUNK_T) __aL * __bL; \ - BNU_CHUNK_T __x1 = (BNU_CHUNK_T) __aL * __bH; \ - BNU_CHUNK_T __x2 = (BNU_CHUNK_T) __aH * __bL; \ - BNU_CHUNK_T __x3 = (BNU_CHUNK_T) __aH * __bH; \ - \ - __x1 += HI_CHUNK(__x0); \ - __x1 += __x2; \ - if(__x1 < __x2) \ - __x3 += BNU_CHUNK_2H; \ - \ - (RH) = __x3 + HI_CHUNK(__x1); \ - (RL) = (__x1 << BNU_CHUNK_BITS/2) + LO_CHUNK(__x0); \ - } while (0) - -#endif /* _CP_BNU_IMPL_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.c deleted file mode 100644 index 47bfcffd..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.c +++ /dev/null @@ -1,294 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Internal Unsigned BNU misc functionality -// -// Contents: -// cpNLZ_BNU() -// cpNTZ_BNU() -// -// cpLSL_BNU() -// cpLSR_BNU() -// -// cpLSBit_BNU() -// cpMSBit_BNU() -// -// cpFromOctStr_BNU() -// cpToOctStrS_BNU() -// -// -*/ - -#include "owncp.h" -#include "pcpbnumisc.h" - - -/* -// number of leading zeros -*/ -cpSize cpNLZ_BNU(BNU_CHUNK_T x) -{ - cpSize nlz = BNU_CHUNK_BITS; - if(x) { - nlz = 0; - #if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT) - if( 0==(x & 0xFFFFFFFF00000000) ) { nlz +=32; x<<=32; } - if( 0==(x & 0xFFFF000000000000) ) { nlz +=16; x<<=16; } - if( 0==(x & 0xFF00000000000000) ) { nlz += 8; x<<= 8; } - if( 0==(x & 0xF000000000000000) ) { nlz += 4; x<<= 4; } - if( 0==(x & 0xC000000000000000) ) { nlz += 2; x<<= 2; } - if( 0==(x & 0x8000000000000000) ) { nlz++; } - #else - if( 0==(x & 0xFFFF0000) ) { nlz +=16; x<<=16; } - if( 0==(x & 0xFF000000) ) { nlz += 8; x<<= 8; } - if( 0==(x & 0xF0000000) ) { nlz += 4; x<<= 4; } - if( 0==(x & 0xC0000000) ) { nlz += 2; x<<= 2; } - if( 0==(x & 0x80000000) ) { nlz++; } - #endif - } - return nlz; -} - -/* -// number of trailing zeros -*/ -cpSize cpNTZ_BNU(BNU_CHUNK_T x) -{ - cpSize ntz = BNU_CHUNK_BITS; - if(x) { - ntz = 0; - #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) - if( 0==(x & 0x00000000FFFFFFFF) ) { ntz+=32; x>>=32; } - if( 0==(x & 0x000000000000FFFF) ) { ntz+=16; x>>=16; } - if( 0==(x & 0x00000000000000FF) ) { ntz+= 8; x>>= 8; } - if( 0==(x & 0x000000000000000F) ) { ntz+= 4; x>>= 4; } - if( 0==(x & 0x0000000000000003) ) { ntz+= 2; x>>= 2; } - if( 0==(x & 0x0000000000000001) ) { ntz++; } - #else - if( 0==(x & 0x0000FFFF) ) { ntz+=16; x>>=16; } - if( 0==(x & 0x000000FF) ) { ntz+= 8; x>>= 8; } - if( 0==(x & 0x0000000F) ) { ntz+= 4; x>>= 4; } - if( 0==(x & 0x00000003) ) { ntz+= 2; x>>= 2; } - if( 0==(x & 0x00000001) ) { ntz++; } - #endif - } - return ntz; -} - -/* -// Logical shift left (including inplace) -// -// Returns new length -// -*/ -#if 0 -cpSize cpLSL_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA, cpSize nBits) -{ - cpSize nlz = cpNLZ_BNU(pA[nsA-1]); - cpSize nw = nBits/BNU_CHUNK_BITS; - cpSize n; - - pR += nw; - - nBits %= BNU_CHUNK_BITS; - if(nBits) { - BNU_CHUNK_T hi,lo; - - if(nlz < nBits ) - hi = 0; - else - hi = pA[--nsA]; - - for(n=nsA; n>0; n--) { - lo = pA[n-1]; - pR[n] = (hi<>(BNU_CHUNK_BITS-nBits)); - hi = lo; - } - pR[0] = (hi<0; n--) - pR[n-1] = pA[n-1]; - } - - pR--; - for(n=0; n>nBits) | (hi<<(BNU_CHUNK_BITS-nBits)); - lo = hi; - } - pR[nsA-1] = (lo>>nBits); - } - else { - for(n=0; n=(int)sizeof(BNU_CHUNK_T); nsA++,strLen-=(int)(sizeof(BNU_CHUNK_T))) { - /* pack sizeof(BNU_CHUNK_T) bytes into single BNU_CHUNK_T value*/ - *pA++ = - #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) - +( (BNU_CHUNK_T)pStr[strLen-8]<<(8*7) ) - +( (BNU_CHUNK_T)pStr[strLen-7]<<(8*6) ) - +( (BNU_CHUNK_T)pStr[strLen-6]<<(8*5) ) - +( (BNU_CHUNK_T)pStr[strLen-5]<<(8*4) ) - #endif - +( (BNU_CHUNK_T)pStr[strLen-4]<<(8*3) ) - +( (BNU_CHUNK_T)pStr[strLen-3]<<(8*2) ) - +( (BNU_CHUNK_T)pStr[strLen-2]<<(8*1) ) - + (BNU_CHUNK_T)pStr[strLen-1]; - } - - /* convert the beginning of the string */ - if(strLen) { - BNU_CHUNK_T x = 0; - for(x=0; strLen>0; strLen--) { - BNU_CHUNK_T d = *pStr++; - x = (x<<8) + d; - } - *pA++ = x; - nsA++; - } - - return nsA; -} - -/* -// Convert BNU into HexString representation -// -// Returns length of the string or 0 if no success -*/ -cpSize cpToOctStr_BNU(Ipp8u* pStr, cpSize strLen, const BNU_CHUNK_T* pA, cpSize nsA) -{ - FIX_BNU(pA, nsA); - { - cpSize bnuBitSize = BITSIZE_BNU(pA, nsA); - if(bnuBitSize <= strLen*BYTESIZE) { - int cnvLen = 0; - BNU_CHUNK_T x = pA[nsA-1]; - - ZEXPAND_BNU(pStr, 0, strLen); - pStr += strLen - BITS2WORD8_SIZE(bnuBitSize); - - if(x) { - //int nb; - cpSize nb; - for(nb=cpNLZ_BNU(x)/BYTESIZE; nb<(cpSize)(sizeof(BNU_CHUNK_T)); cnvLen++, nb++) - *pStr++ = EBYTE(x, sizeof(BNU_CHUNK_T)-1-nb); - - for(--nsA; nsA>0; cnvLen+=sizeof(BNU_CHUNK_T), nsA--) { - x = pA[nsA-1]; - #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) - *pStr++ = EBYTE(x,7); - *pStr++ = EBYTE(x,6); - *pStr++ = EBYTE(x,5); - *pStr++ = EBYTE(x,4); - #endif - *pStr++ = EBYTE(x,3); - *pStr++ = EBYTE(x,2); - *pStr++ = EBYTE(x,1); - *pStr++ = EBYTE(x,0); - } - } - return strLen; - } - else - return 0; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.h deleted file mode 100644 index 30e5bb65..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnumisc.h +++ /dev/null @@ -1,160 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptography Primitives. -// Internal Miscellaneous BNU Definitions & Function Prototypes -// -// -*/ - -#if !defined(_PCP_BNUMISC_H) -#define _PCP_BNUMISC_H - -#include "pcpbnuimpl.h" - - -/* bit operations */ -#define BITSIZE_BNU(p,ns) ((ns)*BNU_CHUNK_BITS-cpNLZ_BNU((p)[(ns)-1])) -#define BIT_BNU(bnu, ns,nbit) ((((nbit)>>BNU_CHUNK_LOG2) < (ns))? ((((bnu))[(nbit)>>BNU_CHUNK_LOG2] >>((nbit)&(BNU_CHUNK_BITS))) &1) : 0) -#define TST_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) & ((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) -#define SET_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) |= ((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) -#define CLR_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) &=~((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) - -/* convert bitsize nbits into the number of BNU_CHUNK_T */ -#define BITS_BNU_CHUNK(nbits) (((nbits)+BNU_CHUNK_BITS-1)/BNU_CHUNK_BITS) - -/* mask for top BNU_CHUNK_T */ -#define MASK_BNU_CHUNK(nbits) ((BNU_CHUNK_T)(-1) >>((BNU_CHUNK_BITS- ((nbits)&(BNU_CHUNK_BITS-1))) &(BNU_CHUNK_BITS-1))) - -/* copy BNU content */ -#define COPY_BNU(dst, src, len) \ -{ \ - cpSize __idx; \ - for(__idx=0; __idx<(len); __idx++) (dst)[__idx] = (src)[__idx]; \ -} - -/* expand by zeros */ -#define ZEXPAND_BNU(srcdst,srcLen, dstLen) \ -{ \ - cpSize __idx; \ - for(__idx=(srcLen); __idx<(dstLen); __idx++) (srcdst)[__idx] = 0; \ -} - -/* copy and expand by zeros */ -#define ZEXPAND_COPY_BNU(dst,dstLen, src,srcLen) \ -{ \ - cpSize __idx; \ - for(__idx=0; __idx<(srcLen); __idx++) (dst)[__idx] = (src)[__idx]; \ - for(; __idx<(dstLen); __idx++) (dst)[__idx] = 0; \ -} - -/* compare */ -#if 0 -#define CMP_BNU(sign, pA, pB, len) \ -{ \ - for((sign)=(len); (sign)>0; (sign)--) { \ - if( (pA)[(sign)-1] != (pB)[(sign)-1] ) \ - break; \ - } \ - (sign) = (sign)? ((pA)[(sign)-1] > (pB)[(sign)-1])? 1:-1 : 0; \ -} -#endif - -/* fix actual length; {} is required to build with GCC6 */ -#define FIX_BNU(src,srcLen) \ - for(; ((srcLen)>1) && (0==(src)[(srcLen)-1]); (srcLen)--){} - - -/* copy and set */ -__INLINE void cpCpy_BNU(BNU_CHUNK_T* pDst, const BNU_CHUNK_T* pSrc, cpSize ns) -{ COPY_BNU(pDst, pSrc, ns); } - -__INLINE void cpSet_BNU(BNU_CHUNK_T* pDst, cpSize ns, BNU_CHUNK_T val) -{ - ZEXPAND_BNU(pDst, 0, ns); - pDst[0] = val; -} - -/* fix up */ -__INLINE int cpFix_BNU(const BNU_CHUNK_T* pA, int nsA) -{ - FIX_BNU(pA, nsA); - return nsA; -} - -/* comparison -// -// returns -// negative, if A < B -// 0, if A = B -// positive, if A > B -*/ -__INLINE int cpCmp_BNU(const BNU_CHUNK_T* pA, cpSize nsA, const BNU_CHUNK_T* pB, cpSize nsB) -{ - if(nsA!=nsB) - return nsA>nsB? 1 : -1; - else { - for(; nsA>0; nsA--) { - if(pA[nsA-1] > pB[nsA-1]) - return 1; - else if(pA[nsA-1] < pB[nsA-1]) - return -1; - } - return 0; - } -} -__INLINE int cpEqu_BNU_CHUNK(const BNU_CHUNK_T* pA, cpSize nsA, BNU_CHUNK_T b) -{ - return (pA[0]==b && 1==cpFix_BNU(pA, nsA)); -} - -/* -// test -// -// returns -// 0, if A = 0 -// >0, if A > 0 -// <0, looks like impossible (or error) case -*/ -__INLINE int cpTst_BNU(const BNU_CHUNK_T* pA, int nsA) -{ - for(; (nsA>0) && (0==pA[nsA-1]); nsA--) ; - return nsA; -} - -/* number of leading/trailing zeros */ -cpSize cpNLZ_BNU(BNU_CHUNK_T x); -cpSize cpNTZ_BNU(BNU_CHUNK_T x); - -/* logical shift left/right */ -int cpLSR_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA, cpSize nBits); -#if 0 -int cpLSL_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA, cpSize nBits); -#endif - -/* least and most significant BNU bit */ -#if 0 -int cpLSBit_BNU(const BNU_CHUNK_T* pA, cpSize nsA); -#endif -int cpMSBit_BNU(const BNU_CHUNK_T* pA, cpSize nsA); - -/* BNU <-> hex-string conversion */ -int cpToOctStr_BNU(Ipp8u* pStr, cpSize strLen, const BNU_CHUNK_T* pA, cpSize nsA); -int cpFromOctStr_BNU(BNU_CHUNK_T* pA, const Ipp8u* pStr, cpSize strLen); - -#endif /* _PCP_BNUMISC_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccp.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccp.h deleted file mode 100644 index ae7ac556..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccp.h +++ /dev/null @@ -1,260 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal ECC (prime) basic Definitions & Function Prototypes -// -// -*/ - -#if !defined(_PCP_ECCP_H) -#define _PCP_ECCP_H - -#include "pcpbnresource.h" -#include "pcppma.h" -#include "pcpeccppoint.h" -#include "pcpeccpsscm.h" - - -typedef struct eccp_method_st ECCP_METHOD; - -/* -// ECC over prime GF(p) Context -*/ -struct _cpECCP { - IppCtxId idCtx; /* prime EC identifier */ - - IppsBigNumState* pPrime; /* specify finite field GF(p) */ - IppsBigNumState* pA; /* scecify A & B of EC equation: */ - IppsBigNumState* pB; /* y^2 = x^3 + A*x + B (mod)p */ - - IppsBigNumState* pGX; /* Base Point (X coordinate) */ - IppsBigNumState* pGY; /* Base Point (Y coordinate) */ - IppsBigNumState* pR; /* order (r) of Base Point */ - /* fields above mainly for ippsECCPSet()/ippsECCPGet() */ - - Ipp32u eccStandard;/* generic/standard ecc */ - - ECCP_METHOD* pMethod; - - int gfeBitSize; /* size (bits) of field element */ - int ordBitSize; /* size (bits) of BP order */ - - int a_3; /* ==1 if A==-3 or A==P-3 */ - IppsBigNumState* pAenc; /* internal formatted pA value */ - IppsBigNumState* pBenc; /* internal formatted pB value */ - IppsMontState* pMontP; /* montromery engine (modulo p) */ - - IppsECCPPointState* pGenc; /* internal formatted Base Point */ - IppsBigNumState* pCofactor; /* cofactor = #E/base_point_order*/ - IppsMontState* pMontR; /* montromery engine (modulo r) */ - - IppsBigNumState* pPrivate; /* private key */ - IppsECCPPointState* pPublic; /* public key (affine) */ - IppsBigNumState* pPrivateE; /* ephemeral private key */ - IppsECCPPointState* pPublicE; /* ephemeral public key (affine) */ - - #if defined(_USE_NN_VERSION_) - Ipp32u randMask; /* mask of high bits random */ - IppsBigNumState* pRandCnt; /* random engine content */ - IppsPRNGState* pRandGen; /* random generator engine */ - #endif - - IppsPrimeState* pPrimary; /* prime engine */ - -#if defined (_USE_ECCP_SSCM_) - Ipp8u* pSscmBuffer;/* pointer to sscm buffer */ -#endif - - BigNumNode* pBnList; /* list of big numbers */ - /*BigNumNode* pBnListExt;*//* list of big numbers */ -}; - -/* some useful constants */ -#define BNLISTSIZE (32) /* list size (probably less) */ - -/* -// Contetx Access Macros -*/ -#define ECP_ID(ctx) ((ctx)->idCtx) - -#define ECP_PRIME(ctx) ((ctx)->pPrime) -#define ECP_A(ctx) ((ctx)->pA) -#define ECP_B(ctx) ((ctx)->pB) - -#define ECP_GX(ctx) ((ctx)->pGX) -#define ECP_GY(ctx) ((ctx)->pGY) -#define ECP_ORDER(ctx) ((ctx)->pR) - -#define ECP_TYPE(ctx) ((ctx)->eccStandard) - -#define ECP_METHOD(ctx) ((ctx)->pMethod) - -#define ECP_GFEBITS(ctx) ((ctx)->gfeBitSize) -#define ECP_ORDBITS(ctx) ((ctx)->ordBitSize) - -#define ECP_AMI3(ctx) ((ctx)->a_3) -#define ECP_AENC(ctx) ((ctx)->pAenc) -#define ECP_BENC(ctx) ((ctx)->pBenc) -#define ECP_PMONT(ctx) ((ctx)->pMontP) - -#define ECP_GENC(ctx) ((ctx)->pGenc) -#define ECP_COFACTOR(ctx) ((ctx)->pCofactor) -#define ECP_RMONT(ctx) ((ctx)->pMontR) - -#define ECP_PRIVATE(ctx) ((ctx)->pPrivate) -#define ECP_PUBLIC(ctx) ((ctx)->pPublic) -#define ECP_PRIVATE_E(ctx) ((ctx)->pPrivateE) -#define ECP_PUBLIC_E(ctx) ((ctx)->pPublicE) - -#if defined(_USE_NN_VERSION_) -#define ECP_RANDMASK(ctx) ((ctx)->randMask) -#define ECP_RANDCNT(ctx) ((ctx)->pRandCnt) -#define ECP_RAND(ctx) ((ctx)->pRandGen) -#endif - -#define ECP_PRIMARY(ctx) ((ctx)->pPrimary) -#if defined (_USE_ECCP_SSCM_) -# define ECP_SCCMBUFF(ctx) ((ctx)->pSscmBuffer) -#endif -#define ECP_BNCTX(ctx) ((ctx)->pBnList) - -#define ECP_VALID_ID(ctx) (ECP_ID((ctx))==idCtxECCP) - -/* -// Recommended (Standard) Domain Parameters -*/ -extern const Ipp32u secp112r1_p[]; // (2^128 -3)/76439 -extern const Ipp32u secp112r1_a[]; -extern const Ipp32u secp112r1_b[]; -extern const Ipp32u secp112r1_gx[]; -extern const Ipp32u secp112r1_gy[]; -extern const Ipp32u secp112r1_r[]; -extern Ipp32u secp112r1_h; - -extern const Ipp32u secp112r2_p[]; // (2^128 -3)/76439 -extern const Ipp32u secp112r2_a[]; -extern const Ipp32u secp112r2_b[]; -extern const Ipp32u secp112r2_gx[]; -extern const Ipp32u secp112r2_gy[]; -extern const Ipp32u secp112r2_r[]; -extern Ipp32u secp112r2_h; - -extern const Ipp32u secp128r1_p[]; // 2^128 -2^97 -1 -extern const Ipp32u secp128r1_a[]; -extern const Ipp32u secp128r1_b[]; -extern const Ipp32u secp128r1_gx[]; -extern const Ipp32u secp128r1_gy[]; -extern const Ipp32u secp128r1_r[]; -extern Ipp32u secp128r1_h; - -extern const Ipp32u* secp128_mx[]; - -extern const Ipp32u secp128r2_p[]; // 2^128 -2^97 -1 -extern const Ipp32u secp128r2_a[]; -extern const Ipp32u secp128r2_b[]; -extern const Ipp32u secp128r2_gx[]; -extern const Ipp32u secp128r2_gy[]; -extern const Ipp32u secp128r2_r[]; -extern Ipp32u secp128r2_h; - -extern const Ipp32u secp160r1_p[]; // 2^160 -2^31 -1 -extern const Ipp32u secp160r1_a[]; -extern const Ipp32u secp160r1_b[]; -extern const Ipp32u secp160r1_gx[]; -extern const Ipp32u secp160r1_gy[]; -extern const Ipp32u secp160r1_r[]; -extern Ipp32u secp160r1_h; - -extern const Ipp32u secp160r2_p[]; // 2^160 -2^32 -2^14 -2^12 -2^9 -2^8 -2^7 -2^2 -1 -extern const Ipp32u secp160r2_a[]; -extern const Ipp32u secp160r2_b[]; -extern const Ipp32u secp160r2_gx[]; -extern const Ipp32u secp160r2_gy[]; -extern const Ipp32u secp160r2_r[]; -extern Ipp32u secp160r2_h; - -extern const Ipp32u secp192r1_p[]; // 2^192 -2^64 -1 -extern const Ipp32u secp192r1_a[]; -extern const Ipp32u secp192r1_b[]; -extern const Ipp32u secp192r1_gx[]; -extern const Ipp32u secp192r1_gy[]; -extern const Ipp32u secp192r1_r[]; -extern Ipp32u secp192r1_h; - -extern const Ipp32u secp224r1_p[]; // 2^224 -2^96 +1 -extern const Ipp32u secp224r1_a[]; -extern const Ipp32u secp224r1_b[]; -extern const Ipp32u secp224r1_gx[]; -extern const Ipp32u secp224r1_gy[]; -extern const Ipp32u secp224r1_r[]; -extern Ipp32u secp224r1_h; - -extern const Ipp32u secp256r1_p[]; // 2^256 -2^224 +2^192 +2^96 -1 -extern const Ipp32u secp256r1_a[]; -extern const Ipp32u secp256r1_b[]; -extern const Ipp32u secp256r1_gx[]; -extern const Ipp32u secp256r1_gy[]; -extern const Ipp32u secp256r1_r[]; -extern Ipp32u secp256r1_h; - -extern const Ipp32u secp384r1_p[]; // 2^384 -2^128 -2^96 +2^32 -1 -extern const Ipp32u secp384r1_a[]; -extern const Ipp32u secp384r1_b[]; -extern const Ipp32u secp384r1_gx[]; -extern const Ipp32u secp384r1_gy[]; -extern const Ipp32u secp384r1_r[]; -extern Ipp32u secp384r1_h; - -extern const Ipp32u secp521r1_p[]; // 2^521 -1 -extern const Ipp32u secp521r1_a[]; -extern const Ipp32u secp521r1_b[]; -extern const Ipp32u secp521r1_gx[]; -extern const Ipp32u secp521r1_gy[]; -extern const Ipp32u secp521r1_r[]; -extern Ipp32u secp521r1_h; - -extern const Ipp32u tpmBN_p256p_p[]; // TPM BN_P256 -extern const Ipp32u tpmBN_p256p_a[]; -extern const Ipp32u tpmBN_p256p_b[]; -extern const Ipp32u tpmBN_p256p_gx[]; -extern const Ipp32u tpmBN_p256p_gy[]; -extern const Ipp32u tpmBN_p256p_r[]; -extern Ipp32u tpmBN_p256p_h; - -extern const Ipp32u tpmSM2_p256_p[]; // TPM SM2_P256 -extern const Ipp32u tpmSM2_p256_a[]; -extern const Ipp32u tpmSM2_p256_b[]; -extern const Ipp32u tpmSM2_p256_gx[]; -extern const Ipp32u tpmSM2_p256_gy[]; -extern const Ipp32u tpmSM2_p256_r[]; -extern Ipp32u tpmSM2_p256_h; - -extern const Ipp32u* tpmSM2_p256_p_mx[]; - -/* half of some std modulus */ -extern const Ipp32u h_secp128r1_p[]; -extern const Ipp32u h_secp192r1_p[]; -extern const Ipp32u h_secp224r1_p[]; -extern const Ipp32u h_secp256r1_p[]; -extern const Ipp32u h_secp384r1_p[]; -extern const Ipp32u h_secp521r1_p[]; -extern const Ipp32u h_tpmSM2_p256_p[]; - -#endif /* _PCP_ECCP_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpdpca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpdpca.c deleted file mode 100644 index b3e09a9b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpdpca.c +++ /dev/null @@ -1,801 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (setup/retrieve domain parameters) -// -// Contents: -// ippsECCPSet() -// ippsECCPSetStd() -// ippsECCPSetStd128r1() -// ippsECCPSetStd128r2() -// ippsECCPSetStd192r1() -// ippsECCPSetStd224r1() -// ippsECCPSetStd256r1() -// ippsECCPSetStd384r1() -// ippsECCPSetStd521r1() -// ippsECCPSetStdSM2() -// -// ippsECCPGet() -// ippsECCPGetBitSizeOrder() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccp.h" -#include "pcpeccppoint.h" -#include "pcpbnresource.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcppma.h" - -#if (_ECP_128_==_ECP_IMPL_SPECIFIC_) -# include "pcpeccpmethod128.h" -#endif -#if (_ECP_192_==_ECP_IMPL_SPECIFIC_) || (_ECP_192_==_ECP_IMPL_MFM_) -# include "pcpeccpmethod192.h" -#endif -#if (_ECP_224_==_ECP_IMPL_SPECIFIC_) || (_ECP_224_==_ECP_IMPL_MFM_) -# include "pcpeccpmethod224.h" -#endif -#if (_ECP_256_==_ECP_IMPL_SPECIFIC_) || (_ECP_256_==_ECP_IMPL_MFM_) -# include "pcpeccpmethod256.h" -#endif -#if (_ECP_384_==_ECP_IMPL_SPECIFIC_) || (_ECP_384_==_ECP_IMPL_MFM_) -# include "pcpeccpmethod384.h" -#endif -#if (_ECP_521_==_ECP_IMPL_SPECIFIC_) || (_ECP_521_==_ECP_IMPL_MFM_) -# include "pcpeccpmethod521.h" -#endif -#if (_ECP_SM2_==_ECP_IMPL_SPECIFIC_) || (_ECP_SM2_==_ECP_IMPL_MFM_) -# include "pcpeccpmethodsm2.h" -#endif - -/*F* -// Name: ippsECCPSet -// -// Purpose: Set EC Domain Parameters. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pPrime -// NULL == pA -// NULL == pB -// NULL == pGX -// NULL == pGY -// NULL == pOrder -// NULL == pECC -// -// ippStsContextMatchErr illegal pPrime->idCtx -// illegal pA->idCtx -// illegal pB->idCtx -// illegal pGX->idCtx -// illegal pGY->idCtx -// illegal pOrder->idCtx -// illegal pECC->idCtx -// -// ippStsRangeErr not enough room for: -// pPrime -// pA, pB, -// pGX,pGY -// pOrder -// -// ippStsRangeErr 0>= cofactor -// -// ippStsNoErr no errors -// -// Parameters: -// pPrime pointer to the prime (specify FG(p)) -// pA pointer to the A coefficient of EC equation -// pB pointer to the B coefficient of EC equation -// pGX,pGY pointer to the Base Point (x and y coordinates) of EC -// pOrder pointer to the Base Point order -// cofactor cofactor value -// pECC pointer to the ECC context -// -*F*/ -static -void ECCPSetDP(IppECCType flag, - int primeSize, const Ipp32u* pPrime, - int aSize, const Ipp32u* pA, - int bSize, const Ipp32u* pB, - int gxSize, const Ipp32u* pGx, - int gySize, const Ipp32u* pGy, - int orderSize, const Ipp32u* pOrder, - Ipp32u cofactor, - IppsECCPState* pECC) -{ - ECP_TYPE(pECC) = flag; - - /* reset size (bits) of field element */ - ECP_GFEBITS(pECC) = cpMSBit_BNU32(pPrime, primeSize) +1; - /* reset size (bits) of Base Point order */ - ECP_ORDBITS(pECC) = cpMSBit_BNU32(pOrder, orderSize) +1; - - /* set up prime */ - ippsSet_BN(ippBigNumPOS, primeSize, pPrime, ECP_PRIME(pECC)); - /* set up A */ - ippsSet_BN(ippBigNumPOS, aSize, pA, ECP_A(pECC)); - /* test A */ - BN_Word(ECP_B(pECC), 3); - PMA_add(ECP_B(pECC), ECP_A(pECC), ECP_B(pECC), ECP_PRIME(pECC)); - ECP_AMI3(pECC) = IsZero_BN(ECP_B(pECC)); - /* set up B */ - ippsSet_BN(ippBigNumPOS, bSize, pB, ECP_B(pECC)); - - /* set up affine coordinates of Base Point and order */ - ippsSet_BN(ippBigNumPOS, gxSize, pGx, ECP_GX(pECC)); - ippsSet_BN(ippBigNumPOS, gySize, pGy, ECP_GY(pECC)); - ippsSet_BN(ippBigNumPOS, orderSize, pOrder, ECP_ORDER(pECC)); - - /* set up cofactor */ - //ippsSet_BN(ippBigNumPOS, 1, &((Ipp32u)cofactor), ECP_COFACTOR(pECC)); - ippsSet_BN(ippBigNumPOS, 1, &cofactor, ECP_COFACTOR(pECC)); - - #if defined(_USE_NN_VERSION_) - /* set up randomizer */ - //gres 05/14/05: ECP_RANDMASK(pECC) = 0xFFFFFFFF >> ((32 -(ECP_ORDBITS(pECC)&0x1F)) &0x1F); - ECP_RANDMASK(pECC) = MAKEMASK32(ECP_ORDBITS(pECC)); - ECP_RANDMASK(pECC) &= ~pOrder[orderSize-1]; - /* reinit randomizer */ - ippsPRNGInit(ECP_ORDBITS(pECC), ECP_RAND(pECC)); - /* default randomizer settings */ - { - Ipp32u seed[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - ippsPRNGSetSeed(seed, ECP_RAND(pECC)); - ippsSet_BN(ippBigNumPOS, RAND_CONTENT_LEN, seed, ECP_RANDCNT(pECC)); - } - #endif - - /* montgomery engine (prime) */ - if( ippStsNoErr == ippsMontSet((Ipp32u*)BN_NUMBER(ECP_PRIME(pECC)), BN_SIZE32(ECP_PRIME(pECC)), ECP_PMONT(pECC)) ) { - /* modulo reduction and montgomery form of A and B */ - PMA_mod(ECP_AENC(pECC), ECP_A(pECC), ECP_PRIME(pECC)); - PMA_enc(ECP_AENC(pECC), ECP_AENC(pECC), ECP_PMONT(pECC)); - PMA_mod(ECP_BENC(pECC), ECP_B(pECC), ECP_PRIME(pECC)); - PMA_enc(ECP_BENC(pECC), ECP_BENC(pECC), ECP_PMONT(pECC)); - /* projective coordinates and montgomery form of of Base Point */ - if( ( IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity1(ECP_GX(pECC), ECP_GY(pECC))) || - (!IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity0(ECP_GX(pECC), ECP_GY(pECC))) ) - ECCP_SetPointToInfinity(ECP_GENC(pECC)); - else { - ECP_METHOD(pECC)->SetPointProjective(ECP_GX(pECC), ECP_GY(pECC), BN_ONE_REF(), ECP_GENC(pECC), pECC); - } - } - - /* montgomery engine (order) */ - if( ippStsNoErr == ippsMontSet((Ipp32u*)BN_NUMBER(ECP_ORDER(pECC)), BN_SIZE32(ECP_ORDER(pECC)), ECP_RMONT(pECC)) ) - PMA_enc(ECP_COFACTOR(pECC), ECP_COFACTOR(pECC), ECP_RMONT(pECC)); - - /* set zero private keys */ - BN_Word(ECP_PRIVATE(pECC), 0); - BN_Word(ECP_PRIVATE_E(pECC), 0); - - /* set infinity public keys */ - ECCP_SetPointToInfinity(ECP_PUBLIC(pECC)); - ECCP_SetPointToInfinity(ECP_PUBLIC_E(pECC)); -} - - -IPPFUN(IppStatus, ippsECCPSet, (const IppsBigNumState* pPrime, - const IppsBigNumState* pA, const IppsBigNumState* pB, - const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, - int cofactor, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test pPrime */ - IPP_BAD_PTR1_RET(pPrime); - pPrime = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrime, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrime), ippStsContextMatchErr); - IPP_BADARG_RET((cpBN_bitsize(pPrime)>ECP_GFEBITS(pECC)), ippStsRangeErr); - - /* test pA and pB */ - IPP_BAD_PTR2_RET(pA,pB); - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, ALIGN_VAL) ); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - IPP_BADARG_RET((cpBN_bitsize(pA)>ECP_GFEBITS(pECC)), ippStsRangeErr); - IPP_BADARG_RET((cpBN_bitsize(pB)>ECP_GFEBITS(pECC)), ippStsRangeErr); - - /* test pG and pGorder pointers */ - IPP_BAD_PTR3_RET(pGX,pGY, pOrder); - pGX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pGX, ALIGN_VAL) ); - pGY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pGY, ALIGN_VAL) ); - pOrder = (IppsBigNumState*)( IPP_ALIGNED_PTR(pOrder, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pGX), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pGY), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pOrder), ippStsContextMatchErr); - IPP_BADARG_RET((cpBN_bitsize(pGX)>ECP_GFEBITS(pECC)), ippStsRangeErr); - IPP_BADARG_RET((cpBN_bitsize(pGY)>ECP_GFEBITS(pECC)), ippStsRangeErr); - IPP_BADARG_RET((cpBN_bitsize(pOrder)>ECP_ORDBITS(pECC)), ippStsRangeErr); - - /* test cofactor */ - IPP_BADARG_RET(!(0idCtx -// -// ippStsECCInvalidFlagErr invalid flag -// -// ippStsNoErr no errors -// -// Parameters: -// flag specify standard ECC parameter(s) to be setup -// pECC pointer to the ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPSetStd, (IppECCType flag, IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods());//ECCPcom; - - switch(flag) { - case IppECCPStd112r1: - ECCPSetDP(IppECCPStd112r1, - BITS2WORD32_SIZE(112), secp112r1_p, - BITS2WORD32_SIZE(112), secp112r1_a, - BITS2WORD32_SIZE(112), secp112r1_b, - BITS2WORD32_SIZE(112), secp112r1_gx, - BITS2WORD32_SIZE(112), secp112r1_gy, - BITS2WORD32_SIZE(112), secp112r1_r, - secp112r1_h, pECC); - break; - case IppECCPStd112r2: - ECCPSetDP(IppECCPStd112r2, - BITS2WORD32_SIZE(112), secp112r2_p, - BITS2WORD32_SIZE(112), secp112r2_a, - BITS2WORD32_SIZE(112), secp112r2_b, - BITS2WORD32_SIZE(112), secp112r2_gx, - BITS2WORD32_SIZE(112), secp112r2_gy, - BITS2WORD32_SIZE(112), secp112r2_r, - secp112r2_h, pECC); - break; - case IppECCPStd128r1: - #if (_ECP_128_==_ECP_IMPL_SPECIFIC_) - *(ECP_METHOD(pECC)) = *(ECCP128_Methods());//ECCP128; - #endif - ECCPSetDP(IppECCPStd128r1, - BITS2WORD32_SIZE(128), secp128r1_p, - BITS2WORD32_SIZE(128), secp128r1_a, - BITS2WORD32_SIZE(128), secp128r1_b, - BITS2WORD32_SIZE(128), secp128r1_gx, - BITS2WORD32_SIZE(128), secp128r1_gy, - BITS2WORD32_SIZE(128), secp128r1_r, - secp128r1_h, pECC); - break; - case IppECCPStd128r2: - #if (_ECP_128_==_ECP_IMPL_SPECIFIC_) - *(ECP_METHOD(pECC)) = *(ECCP128_Methods());//ECCP128; - #endif - ECCPSetDP(IppECCPStd128r2, - BITS2WORD32_SIZE(128), secp128r2_p, - BITS2WORD32_SIZE(128), secp128r2_a, - BITS2WORD32_SIZE(128), secp128r2_b, - BITS2WORD32_SIZE(128), secp128r2_gx, - BITS2WORD32_SIZE(128), secp128r2_gy, - BITS2WORD32_SIZE(128), secp128r2_r, - secp128r2_h, pECC); - break; - case IppECCPStd160r1: - ECCPSetDP(IppECCPStd160r1, - BITS2WORD32_SIZE(160), secp160r1_p, - BITS2WORD32_SIZE(160), secp160r1_a, - BITS2WORD32_SIZE(160), secp160r1_b, - BITS2WORD32_SIZE(160), secp160r1_gx, - BITS2WORD32_SIZE(160), secp160r1_gy, - BITS2WORD32_SIZE(161), secp160r1_r, - secp160r1_h, pECC); - break; - case IppECCPStd160r2: - ECCPSetDP(IppECCPStd160r2, - BITS2WORD32_SIZE(160), secp160r2_p, - BITS2WORD32_SIZE(160), secp160r2_a, - BITS2WORD32_SIZE(160), secp160r2_b, - BITS2WORD32_SIZE(160), secp160r2_gx, - BITS2WORD32_SIZE(160), secp160r2_gy, - BITS2WORD32_SIZE(161), secp160r2_r, - secp160r2_h, pECC); - break; - case IppECCPStd192r1: - #if (_ECP_192_==_ECP_IMPL_SPECIFIC_) || (_ECP_192_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP192_Methods());//ECCP192; - #endif - ECCPSetDP(IppECCPStd192r1, - BITS2WORD32_SIZE(192), secp192r1_p, - BITS2WORD32_SIZE(192), secp192r1_a, - BITS2WORD32_SIZE(192), secp192r1_b, - BITS2WORD32_SIZE(192), secp192r1_gx, - BITS2WORD32_SIZE(192), secp192r1_gy, - BITS2WORD32_SIZE(192), secp192r1_r, - secp192r1_h, pECC); - break; - case IppECCPStd224r1: - #if (_ECP_224_==_ECP_IMPL_SPECIFIC_) || (_ECP_224_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP224_Methods());//ECCP224; - #endif - ECCPSetDP(IppECCPStd224r1, - BITS2WORD32_SIZE(224), secp224r1_p, - BITS2WORD32_SIZE(224), secp224r1_a, - BITS2WORD32_SIZE(224), secp224r1_b, - BITS2WORD32_SIZE(224), secp224r1_gx, - BITS2WORD32_SIZE(224), secp224r1_gy, - BITS2WORD32_SIZE(224), secp224r1_r, - secp224r1_h, pECC); - break; - case IppECCPStd256r1: - #if (_ECP_256_==_ECP_IMPL_SPECIFIC_) || (_ECP_256_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP256_Methods());//ECCP256; - #endif - ECCPSetDP(IppECCPStd256r1, - BITS2WORD32_SIZE(256), secp256r1_p, - BITS2WORD32_SIZE(256), secp256r1_a, - BITS2WORD32_SIZE(256), secp256r1_b, - BITS2WORD32_SIZE(256), secp256r1_gx, - BITS2WORD32_SIZE(256), secp256r1_gy, - BITS2WORD32_SIZE(256), secp256r1_r, - secp256r1_h, pECC); - break; - case IppECCPStd384r1: - #if (_ECP_384_==_ECP_IMPL_SPECIFIC_) || (_ECP_384_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP384_Methods());//ECCP384; - #endif - ECCPSetDP(IppECCPStd384r1, - BITS2WORD32_SIZE(384), secp384r1_p, - BITS2WORD32_SIZE(384), secp384r1_a, - BITS2WORD32_SIZE(384), secp384r1_b, - BITS2WORD32_SIZE(384), secp384r1_gx, - BITS2WORD32_SIZE(384), secp384r1_gy, - BITS2WORD32_SIZE(384), secp384r1_r, - secp384r1_h, pECC); - break; - case IppECCPStd521r1: - #if (_ECP_521_==_ECP_IMPL_SPECIFIC_) || (_ECP_521_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP521_Methods());//ECCP521; - #endif - ECCPSetDP(IppECCPStd521r1, - BITS2WORD32_SIZE(521), secp521r1_p, - BITS2WORD32_SIZE(521), secp521r1_a, - BITS2WORD32_SIZE(521), secp521r1_b, - BITS2WORD32_SIZE(521), secp521r1_gx, - BITS2WORD32_SIZE(521), secp521r1_gy, - BITS2WORD32_SIZE(521), secp521r1_r, - secp521r1_h, pECC); - break; - case ippEC_TPM_BN_P256: - ECCPSetDP(ippEC_TPM_BN_P256, - BITS2WORD32_SIZE(256), tpmBN_p256p_p, - BITS2WORD32_SIZE(32), tpmBN_p256p_a, - BITS2WORD32_SIZE(32), tpmBN_p256p_b, - BITS2WORD32_SIZE(32), tpmBN_p256p_gx, - BITS2WORD32_SIZE(32), tpmBN_p256p_gy, - BITS2WORD32_SIZE(256), tpmBN_p256p_r, - tpmBN_p256p_h, pECC); - break; - case ippECPstdSM2: - #if (_ECP_SM2_==_ECP_IMPL_SPECIFIC_) || (_ECP_SM2_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP_SM2_Methods()); - #endif - ECCPSetDP(ippEC_TPM_SM2_P256, - BITS2WORD32_SIZE(256), tpmSM2_p256_p, - BITS2WORD32_SIZE(256), tpmSM2_p256_a, - BITS2WORD32_SIZE(256), tpmSM2_p256_b, - BITS2WORD32_SIZE(256), tpmSM2_p256_gx, - BITS2WORD32_SIZE(256), tpmSM2_p256_gy, - BITS2WORD32_SIZE(256), tpmSM2_p256_r, - tpmSM2_p256_h, pECC); - break; - default: - return ippStsECCInvalidFlagErr; - } - - return ippStsNoErr; -} - -/*F* -// Name: ippsECCPSetStd128r1 -// ippsECCPSetStd128r2 -// ippsECCPSetStd192r1 -// ippsECCPSetStd224r1 -// ippsECCPSetStd256r1 -// ippsECCPSetStd384r1 -// ippsECCPSetStd521r1 -// ippsECCPSetStdSM2 -*F*/ -IPPFUN(IppStatus, ippsECCPSetStd128r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_128_==_ECP_IMPL_SPECIFIC_) - *(ECP_METHOD(pECC)) = *(ECCP128_Methods()); // ECCP128; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd128r1, - BITS2WORD32_SIZE(128), secp128r1_p, - BITS2WORD32_SIZE(128), secp128r1_a, - BITS2WORD32_SIZE(128), secp128r1_b, - BITS2WORD32_SIZE(128), secp128r1_gx, - BITS2WORD32_SIZE(128), secp128r1_gy, - BITS2WORD32_SIZE(128), secp128r1_r, - secp128r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd128r2, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_128_==_ECP_IMPL_SPECIFIC_) - *(ECP_METHOD(pECC)) = *(ECCP128_Methods()); // ECCP128; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd128r2, - BITS2WORD32_SIZE(128), secp128r2_p, - BITS2WORD32_SIZE(128), secp128r2_a, - BITS2WORD32_SIZE(128), secp128r2_b, - BITS2WORD32_SIZE(128), secp128r2_gx, - BITS2WORD32_SIZE(128), secp128r2_gy, - BITS2WORD32_SIZE(128), secp128r2_r, - secp128r2_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd192r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_192_==_ECP_IMPL_SPECIFIC_) || (_ECP_192_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP192_Methods()); // ECCP192; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd192r1, - BITS2WORD32_SIZE(192), secp192r1_p, - BITS2WORD32_SIZE(192), secp192r1_a, - BITS2WORD32_SIZE(192), secp192r1_b, - BITS2WORD32_SIZE(192), secp192r1_gx, - BITS2WORD32_SIZE(192), secp192r1_gy, - BITS2WORD32_SIZE(192), secp192r1_r, - secp192r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd224r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_224_==_ECP_IMPL_SPECIFIC_) || (_ECP_224_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP224_Methods()); // ECCP224; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd224r1, - BITS2WORD32_SIZE(224), secp224r1_p, - BITS2WORD32_SIZE(224), secp224r1_a, - BITS2WORD32_SIZE(224), secp224r1_b, - BITS2WORD32_SIZE(224), secp224r1_gx, - BITS2WORD32_SIZE(224), secp224r1_gy, - BITS2WORD32_SIZE(224), secp224r1_r, - secp224r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd256r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_256_==_ECP_IMPL_SPECIFIC_) || (_ECP_256_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP256_Methods()); // ECCP256; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd256r1, - BITS2WORD32_SIZE(256), secp256r1_p, - BITS2WORD32_SIZE(256), secp256r1_a, - BITS2WORD32_SIZE(256), secp256r1_b, - BITS2WORD32_SIZE(256), secp256r1_gx, - BITS2WORD32_SIZE(256), secp256r1_gy, - BITS2WORD32_SIZE(256), secp256r1_r, - secp256r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd384r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_384_==_ECP_IMPL_SPECIFIC_) || (_ECP_384_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP384_Methods()); // ECCP384; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd384r1, - BITS2WORD32_SIZE(384), secp384r1_p, - BITS2WORD32_SIZE(384), secp384r1_a, - BITS2WORD32_SIZE(384), secp384r1_b, - BITS2WORD32_SIZE(384), secp384r1_gx, - BITS2WORD32_SIZE(384), secp384r1_gy, - BITS2WORD32_SIZE(384), secp384r1_r, - secp384r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStd521r1, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_521_==_ECP_IMPL_SPECIFIC_) || (_ECP_521_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP521_Methods()); // ECCP521; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(IppECCPStd521r1, - BITS2WORD32_SIZE(521), secp521r1_p, - BITS2WORD32_SIZE(521), secp521r1_a, - BITS2WORD32_SIZE(521), secp521r1_b, - BITS2WORD32_SIZE(521), secp521r1_gx, - BITS2WORD32_SIZE(521), secp521r1_gy, - BITS2WORD32_SIZE(521), secp521r1_r, - secp521r1_h, pECC); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsECCPSetStdSM2, (IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - #if (_ECP_SM2_==_ECP_IMPL_SPECIFIC_) || (_ECP_SM2_==_ECP_IMPL_MFM_) - *(ECP_METHOD(pECC)) = *(ECCP_SM2_Methods()); // ECCSM2; - #else - *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); // ECCPcom; - #endif - ECCPSetDP(ippEC_TPM_SM2_P256, - BITS2WORD32_SIZE(256), tpmSM2_p256_p, - BITS2WORD32_SIZE(256), tpmSM2_p256_a, - BITS2WORD32_SIZE(256), tpmSM2_p256_b, - BITS2WORD32_SIZE(256), tpmSM2_p256_gx, - BITS2WORD32_SIZE(256), tpmSM2_p256_gy, - BITS2WORD32_SIZE(256), tpmSM2_p256_r, - tpmSM2_p256_h, pECC); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPGet -// -// Purpose: Retrieve ECC Domain Parameter. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pPrime -// NULL == pA -// NULL == pB -// NULL == pGX -// NULL == pGY -// NULL == pOrder -// NULL == cofactor -// NULL == pECC -// -// ippStsContextMatchErr illegal pPrime->idCtx -// illegal pA->idCtx -// illegal pB->idCtx -// illegal pGX->idCtx -// illegal pGY->idCtx -// illegal pOrder->idCtx -// illegal pECC->idCtx -// -// ippStsRangeErr not enough room for: -// pPrime -// pA, pB, -// pGX,pGY -// pOrder -// -// ippStsNoErr no errors -// -// Parameters: -// pPrime pointer to the retrieval prime (specify FG(p)) -// pA pointer to the retrieval A coefficient of EC equation -// pB pointer to the retrieval B coefficient of EC equation -// pGX,pGY pointer to the retrieval Base Point (x and y coordinates) of EC -// pOrder pointer to the retrieval Base Point order -// cofactor pointer to the retrieval cofactor value -// pECC pointer to the ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPGet, (IppsBigNumState* pPrime, - IppsBigNumState* pA, IppsBigNumState* pB, - IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, - int* cofactor, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test pPrime */ - IPP_BAD_PTR1_RET(pPrime); - pPrime = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrime, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrime), ippStsContextMatchErr); - IPP_BADARG_RET((BN_ROOM(pPrime)*BITSIZE(BNU_CHUNK_T)idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pBitSize pointer to the size of base point order -// pECC pointer to the ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use 4-byte aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, 4) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test pBitSize*/ - IPP_BAD_PTR1_RET(pBitSize); - - *pBitSize = ECP_ORDBITS(pECC); - - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpgenkeyca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpgenkeyca.c deleted file mode 100644 index ec3d785d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpgenkeyca.c +++ /dev/null @@ -1,105 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (EC Key Generation) -// -// Contents: -// ippsECCPGenKeyPair() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" - - -/*F* -// Name: ippsECCPGenKeyPair -// -// Purpose: Generate (private,public) Key Pair -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPrivate -// NULL == pPublic -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pPrivate->idCtx -// illegal pPublic->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pPrivate pointer to the resultant private key -// pPublic pointer to the resultant public key -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPGenKeyPair, (IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, - IppsECCPState* pECC, - IppBitSupplier rndFunc, void* pRndParam)) -{ - IPP_BAD_PTR2_RET(pECC, rndFunc); - - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test private/public keys */ - IPP_BAD_PTR2_RET(pPrivate,pPublic); - pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); - pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); - IPP_BADARG_RET((BN_ROOM(pPrivate)*BITSIZE(BNU_CHUNK_T)MulPoint(ECP_GENC(pECC), pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); - ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); - - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpinitca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpinitca.c deleted file mode 100644 index bf164034..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpinitca.c +++ /dev/null @@ -1,454 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (initialization) -// -// Contents: -// ippsECCPGetSize() -// ippsECCPGetSizeStd128r1() -// ippsECCPGetSizeStd128r2() -// ippsECCPGetSizeStd192r1() -// ippsECCPGetSizeStd224r1() -// ippsECCPGetSizeStd256r1() -// ippsECCPGetSizeStd384r1() -// ippsECCPGetSizeStd521r1() -// ippsECCPGetSizeStdSM2() -// -// ippsECCPInit() -// ippsECCPInitStd128r1() -// ippsECCPInitStd128r2() -// ippsECCPInitStd192r1() -// ippsECCPInitStd224r1() -// ippsECCPInitStd256r1() -// ippsECCPInitStd384r1() -// ippsECCPInitStd521r1() -// ippsECCPInitStdSM2() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccp.h" -#include "pcpeccppoint.h" -#include "pcpbnresource.h" -#include "pcpeccpmethod.h" -#include "pcpeccpsscm.h" -#include "pcptool.h" - - -/*F* -// Name: ippsECCPGetSize -// -// Purpose: Returns size of ECC context (bytes). -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pSize -// -// ippStsSizeErr 2>feBitSize -// -// ippStsNoErr no errors -// -// Parameters: -// feBitSize size of field element (bits) -// pSize pointer to the size of internal ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPGetSize, (int feBitSize, int *pSize)) -{ - /* test size's pointer */ - IPP_BAD_PTR1_RET(pSize); - - /* test size of field element */ - IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); - - { - int bn1Size; - int bn2Size; - int pointSize; - int mont1Size; - int mont2Size; - #if defined(_USE_NN_VERSION_) - int randSize; - int randCntSize; - #endif - int primeSize; - int listSize; - - /* size of field element */ - int gfeSize = BITS2WORD32_SIZE(feBitSize); - /* size of order */ - int ordSize = BITS2WORD32_SIZE(feBitSize+1); - - #if defined (_USE_ECCP_SSCM_) - /* size of sscm buffer */ - int w = cpECCP_OptimalWinSize(feBitSize+1); - int nPrecomputed = 1<feBitSize -// -// ippStsNoErr no errors -// -// Parameters: -// feBitSize size of field element (bits) -// pECC pointer to the ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPInit, (int feBitSize, IppsECCPState* pECC)) -{ - /* test pECC pointer */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - - /* test size of field element */ - IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); - - /* clear context */ - PaddBlock(0, pECC, sizeof(IppsECCPState)); - - /* context ID */ - ECP_ID(pECC) = idCtxECCP; - - /* generic EC */ - ECP_TYPE(pECC) = IppECCArbitrary; - - /* size of field element & BP order */ - ECP_GFEBITS(pECC) = feBitSize; - ECP_ORDBITS(pECC) = feBitSize+1; - - /* - // init other context fields - */ - { - int bn1Size; - int bn2Size; - int pointSize; - int mont1Size; - int mont2Size; - #if defined(_USE_NN_VERSION_) - int randSize; - int randCntSize; - #endif - int primeSize; - //int listSize; - - /* size of field element */ - int gfeSize = BITS2WORD32_SIZE(feBitSize); - /* size of order */ - int ordSize = BITS2WORD32_SIZE(feBitSize+1); - - #if defined (_USE_ECCP_SSCM_) - /* size of sscm buffer */ - int w = cpECCP_OptimalWinSize(feBitSize+1); - int nPrecomputed = 1< pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP128_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA128_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA128_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA128_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA128_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA128_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA128_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA128_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA128_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP128_NegPoint -// -// Negative point -*/ -void ECCP128_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P128; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp128r1_p, pPy, LEN_P128); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP128_DblPoint -// -// Double point -*/ -void ECCP128_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA128_sqr(bnU, ECP_POINT_X(pP)); - PMA128_add(bnM, bnU, bnU); - PMA128_add(bnM, bnM, bnU); - PMA128_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA128_sqr(bnU, ECP_POINT_Z(pP)); - PMA128_add(bnS, ECP_POINT_X(pP), bnU); - PMA128_sub(bnT, ECP_POINT_X(pP), bnU); - PMA128_mul(bnM, bnS, bnT); - PMA128_add(bnU, bnM, bnM); - PMA128_add(bnM, bnU, bnM); - } - else { - PMA128_sqr(bnU, ECP_POINT_X(pP)); - PMA128_add(bnM, bnU, bnU); - PMA128_add(bnM, bnM, bnU); - PMA128_sqr(bnU, ECP_POINT_Z(pP)); - PMA128_sqr(bnU, bnU); - PMA128_mul(bnU, bnU, ECP_A(pECC)); - PMA128_add(bnM, bnM, bnU); - } - - PMA128_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA128_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA128_sqr(bnT, bnV); - PMA128_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA128_sqr(bnU, bnM); - PMA128_sub(bnU, bnU, bnS); - PMA128_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA128_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA128_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA128_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA128_mul(bnS, bnS, bnM); - PMA128_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP128_AddPoint -// -// Add points -*/ -void ECCP128_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP128_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA128_sqr(bnW, ECP_POINT_Z(pQ)); - PMA128_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA128_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA128_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA128_sqr(bnW, ECP_POINT_Z(pP)); - PMA128_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA128_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA128_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA128_sub(bnW, bnU0, bnU1); - PMA128_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P128, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P128, 0)) { - ECCP128_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA128_add(bnT, bnU0, bnU1); - PMA128_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA128_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA128_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA128_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA128_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA128_sqr(ECP_POINT_X(pR), bnR); - PMA128_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA128_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA128_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA128_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA128_mul(bnU1, bnU1, bnW); - PMA128_mul(bnU1, bnU1, bnM); - PMA128_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA128_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP128_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP128_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP128_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP128_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP128_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP128_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP128_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP128_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP128_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP128_MulPoint: SCCM version") - -void ECCP128_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP128_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP128_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP128_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP128_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP128_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP128_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP128_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP128_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP128_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP128_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP128_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP128_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP128_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP128_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP128_ProdPoint: SCCM version") - -void ECCP128_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP128_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP128_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP128_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_128_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192.h deleted file mode 100644 index 747173c3..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192.h +++ /dev/null @@ -1,117 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over GF(P192) -// -// -*/ - -#if !defined(_PCP_ECCPMETHOD192_H) -#define _PCP_ECCPMETHOD192_H - -#include "pcpeccp.h" - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP192_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP192_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP192_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP192_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP192_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP192_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP192_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP192_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP192_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP192_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP192_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP192_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP192_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHOD192_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192ca.c deleted file mode 100644 index 39b1b631..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod192ca.c +++ /dev/null @@ -1,880 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P192) -// -// Contents: -// ECCP192_SetPointProjective() -// ECCP192_SetPointAffine() -// ECCP192_GetPointAffine() -// -// ECCP192_IsPointOnCurve() -// -// ECCP192_ComparePoint() -// ECCP192_NegPoint() -// ECCP192_DblPoint() -// ECCP192_AddPoint() -// ECCP192_MulPoint() -// ECCP192_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_192_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethod192.h" -#include "pcppma192.h" - -/* - NOTE: - ECCP192 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP192 = { - ECCP192_SetPointProjective, - ECCP192_SetPointAffine, - ECCP192_GetPointAffine, - - ECCP192_IsPointOnCurve, - - ECCP192_ComparePoint, - ECCP192_NegPoint, - ECCP192_DblPoint, - ECCP192_AddPoint, - ECCP192_MulPoint, - ECCP192_MulBasePoint, - ECCP192_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP192_Methods(void) -{ - return &ECCP192; -} - -/* -// ECCP192_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP192_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP192_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP192_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP192_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP192_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP192_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP192_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP192_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMA192_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMA192_sqr(pT, pU); - - if(pX) { - PMA192_mul(pX,pT, ECP_POINT_X(pPoint)); - cpBN_fix(pX); - } - if(pY) { - /* U = 1/(Z^3) */ - PMA192_mul(pU, pU, pT); - PMA192_mul(pY,pU, ECP_POINT_Y(pPoint)); - cpBN_fix(pY); - } - } -} - -/* -// ECCP192_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP192_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMA192_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMA192_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA192_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMA192_sqr(pZ4, pT); // Z^4 - PMA192_mul(pZ6, pZ4, pT); // Z^6 - - PMA192_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA192_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMA192_add(pU, pU, pT); - PMA192_sub(pR, pR, pU); - } - else { - PMA192_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMA192_add(pR, pR, pT); - } - PMA192_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA192_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA192_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMA192_add(pT, pT, ECP_POINT_X(pPoint)); - PMA192_sub(pR, pR, pT); - } - else { - PMA192_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMA192_add(pR, pR, pT); - } - PMA192_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMA192_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP192_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP192_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA192_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA192_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA192_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA192_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA192_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA192_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA192_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA192_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP192_NegPoint -// -// Negative point -*/ -void ECCP192_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P192; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp192r1_p, pPy, LEN_P192); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP192_DblPoint -// -// Double point -*/ -void ECCP192_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA192_sqr(bnU, ECP_POINT_X(pP)); - PMA192_add(bnM, bnU, bnU); - PMA192_add(bnM, bnM, bnU); - PMA192_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA192_sqr(bnU, ECP_POINT_Z(pP)); - PMA192_add(bnS, ECP_POINT_X(pP), bnU); - PMA192_sub(bnT, ECP_POINT_X(pP), bnU); - PMA192_mul(bnM, bnS, bnT); - PMA192_add(bnU, bnM, bnM); - PMA192_add(bnM, bnU, bnM); - } - else { - PMA192_sqr(bnU, ECP_POINT_X(pP)); - PMA192_add(bnM, bnU, bnU); - PMA192_add(bnM, bnM, bnU); - PMA192_sqr(bnU, ECP_POINT_Z(pP)); - PMA192_sqr(bnU, bnU); - PMA192_mul(bnU, bnU, ECP_A(pECC)); - PMA192_add(bnM, bnM, bnU); - } - - PMA192_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA192_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA192_sqr(bnT, bnV); - PMA192_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA192_sqr(bnU, bnM); - PMA192_sub(bnU, bnU, bnS); - PMA192_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA192_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA192_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA192_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA192_mul(bnS, bnS, bnM); - PMA192_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP192_AddPoint -// -// Add points -*/ -void ECCP192_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP192_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA192_sqr(bnW, ECP_POINT_Z(pQ)); - PMA192_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA192_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA192_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA192_sqr(bnW, ECP_POINT_Z(pP)); - PMA192_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA192_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA192_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA192_sub(bnW, bnU0, bnU1); - PMA192_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P192, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P192, 0)) { - ECCP192_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA192_add(bnT, bnU0, bnU1); - PMA192_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA192_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA192_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA192_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA192_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA192_sqr(ECP_POINT_X(pR), bnR); - PMA192_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA192_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA192_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA192_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA192_mul(bnU1, bnU1, bnW); - PMA192_mul(bnU1, bnU1, bnM); - PMA192_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA192_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP192_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP192_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP192_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP192_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP192_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - //ECCP192_NegPoint(&T, &U, pECC); - ECCP_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP192_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP192_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP192_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP192_MulPoint: SCCM version") - -void ECCP192_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP192_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP192_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP192_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP192_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP192_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP192_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP192_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP192_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP192_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP192_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP192_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP192_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP192_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP192_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP192_ProdPoint: SCCM version") - -void ECCP192_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP192_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP192_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP192_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_192_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224.h deleted file mode 100644 index 97d910c2..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224.h +++ /dev/null @@ -1,118 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over GF(P224) -// -// -*/ - -#if !defined(_PCP_ECCPMETHOD224_H) -#define _PCP_ECCPMETHOD224_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP224_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP224_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP224_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP224_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP224_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP224_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP224_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP224_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP224_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP224_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP224_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP224_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP224_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHOD224_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224ca.c deleted file mode 100644 index dbd0462d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod224ca.c +++ /dev/null @@ -1,877 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P224) -// -// Contents: -// ECCP224_SetPointProjective() -// ECCP224_SetPointAffine() -// ECCP224_GetPointAffine() -// -// ECCP224_IsPointOnCurve() -// -// ECCP224_ComparePoint() -// ECCP224_NegPoint() -// ECCP224_DblPoint() -// ECCP224_AddPoint() -// ECCP224_MulPoint() -// ECCP224_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_224_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethod224.h" -#include "pcppma224.h" - -/* - NOTE: - ECCP224 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP224 = { - ECCP224_SetPointProjective, - ECCP224_SetPointAffine, - ECCP224_GetPointAffine, - - ECCP224_IsPointOnCurve, - - ECCP224_ComparePoint, - ECCP224_NegPoint, - ECCP224_DblPoint, - ECCP224_AddPoint, - ECCP224_MulPoint, - ECCP224_MulBasePoint, - ECCP224_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP224_Methods(void) -{ - return &ECCP224; -} - -/* -// ECCP224_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP224_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP224_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP224_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP224_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP224_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP224_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP224_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP224_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMA224_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMA224_sqr(pT, pU); - - if(pX) { - PMA224_mul(pX,pT, ECP_POINT_X(pPoint)); - } - if(pY) { - /* U = 1/(Z^3) */ - PMA224_mul(pU, pU, pT); - PMA224_mul(pY,pU, ECP_POINT_Y(pPoint)); - } - } -} - -/* -// ECCP224_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP224_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMA224_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMA224_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA224_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMA224_sqr(pZ4, pT); // Z^4 - PMA224_mul(pZ6, pZ4, pT); // Z^6 - - PMA224_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA224_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMA224_add(pU, pU, pT); - PMA224_sub(pR, pR, pU); - } - else { - PMA224_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMA224_add(pR, pR, pT); - } - PMA224_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA224_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA224_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMA224_add(pT, pT, ECP_POINT_X(pPoint)); - PMA224_sub(pR, pR, pT); - } - else { - PMA224_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMA224_add(pR, pR, pT); - } - PMA224_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMA224_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP224_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP224_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA224_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA224_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA224_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA224_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA224_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA224_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA224_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA224_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP224_NegPoint -// -// Negative point -*/ -void ECCP224_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P224; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp224r1_p, pPy, LEN_P224); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP224_DblPoint -// -// Double point -*/ -void ECCP224_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA224_sqr(bnU, ECP_POINT_X(pP)); - PMA224_add(bnM, bnU, bnU); - PMA224_add(bnM, bnM, bnU); - PMA224_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA224_sqr(bnU, ECP_POINT_Z(pP)); - PMA224_add(bnS, ECP_POINT_X(pP), bnU); - PMA224_sub(bnT, ECP_POINT_X(pP), bnU); - PMA224_mul(bnM, bnS, bnT); - PMA224_add(bnU, bnM, bnM); - PMA224_add(bnM, bnU, bnM); - } - else { - PMA224_sqr(bnU, ECP_POINT_X(pP)); - PMA224_add(bnM, bnU, bnU); - PMA224_add(bnM, bnM, bnU); - PMA224_sqr(bnU, ECP_POINT_Z(pP)); - PMA224_sqr(bnU, bnU); - PMA224_mul(bnU, bnU, ECP_A(pECC)); - PMA224_add(bnM, bnM, bnU); - } - - PMA224_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA224_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA224_sqr(bnT, bnV); - PMA224_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA224_sqr(bnU, bnM); - PMA224_sub(bnU, bnU, bnS); - PMA224_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA224_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA224_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA224_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA224_mul(bnS, bnS, bnM); - PMA224_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP224_AddPoint -// -// Add points -*/ -void ECCP224_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP224_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA224_sqr(bnW, ECP_POINT_Z(pQ)); - PMA224_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA224_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA224_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA224_sqr(bnW, ECP_POINT_Z(pP)); - PMA224_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA224_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA224_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA224_sub(bnW, bnU0, bnU1); - PMA224_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P224, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P224, 0)) { - ECCP224_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA224_add(bnT, bnU0, bnU1); - PMA224_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA224_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA224_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA224_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA224_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA224_sqr(ECP_POINT_X(pR), bnR); - PMA224_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA224_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA224_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA224_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA224_mul(bnU1, bnU1, bnW); - PMA224_mul(bnU1, bnU1, bnM); - PMA224_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA224_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP224_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP224_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP224_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP224_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP224_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP224_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP224_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP224_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP224_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP224_MulPoint: SCCM version") - -void ECCP224_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP224_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP224_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP224_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP224_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP224_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP224_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP224_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP224_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP224_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP224_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP224_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP224_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP224_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP224_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP224_ProdPoint: SCCM version") - -void ECCP224_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP224_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP224_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP224_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_224_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256.h deleted file mode 100644 index 3d85a85d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256.h +++ /dev/null @@ -1,118 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over GF(P256) -// -// -*/ - -#if !defined(_PCP_ECCPMETHOD256_H) -#define _PCP_ECCPMETHOD256_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP256_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP256_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP256_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP256_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP256_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP256_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP256_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP256_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP256_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP256_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP256_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP256_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP256_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHOD256_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256ca.c deleted file mode 100644 index b1bb0d4b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod256ca.c +++ /dev/null @@ -1,879 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P256) -// -// Contents: -// ECCP256_SetPointProjective() -// ECCP256_SetPointAffine() -// ECCP256_GetPointAffine() -// -// ECCP256_IsPointOnCurve() -// -// ECCP256_ComparePoint() -// ECCP256_NegPoint() -// ECCP256_DblPoint() -// ECCP256_AddPoint() -// ECCP256_MulPoint() -// ECCP256_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_256_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethod256.h" -#include "pcppma256.h" - -/* - NOTE: - ECCP256 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP256 = { - ECCP256_SetPointProjective, - ECCP256_SetPointAffine, - ECCP256_GetPointAffine, - - ECCP256_IsPointOnCurve, - - ECCP256_ComparePoint, - ECCP256_NegPoint, - ECCP256_DblPoint, - ECCP256_AddPoint, - ECCP256_MulPoint, - ECCP256_MulBasePoint, - ECCP256_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP256_Methods(void) -{ - return &ECCP256; -} - -/* -// ECCP256_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP256_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP256_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP256_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP256_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP256_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP256_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP256_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP256_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMA256_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMA256_sqr(pT, pU); - - if(pX) { - PMA256_mul(pX,pT, ECP_POINT_X(pPoint)); - cpBN_fix(pX); - } - if(pY) { - /* U = 1/(Z^3) */ - PMA256_mul(pU, pU, pT); - PMA256_mul(pY,pU, ECP_POINT_Y(pPoint)); - cpBN_fix(pY); - } - } -} - -/* -// ECCP256_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP256_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMA256_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMA256_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA256_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMA256_sqr(pZ4, pT); // Z^4 - PMA256_mul(pZ6, pZ4, pT); // Z^6 - - PMA256_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA256_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMA256_add(pU, pU, pT); - PMA256_sub(pR, pR, pU); - } - else { - PMA256_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMA256_add(pR, pR, pT); - } - PMA256_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA256_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA256_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMA256_add(pT, pT, ECP_POINT_X(pPoint)); - PMA256_sub(pR, pR, pT); - } - else { - PMA256_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMA256_add(pR, pR, pT); - } - PMA256_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMA256_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP256_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP256_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA256_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA256_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA256_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA256_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA256_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA256_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA256_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA256_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP256_NegPoint -// -// Negative point -*/ -void ECCP256_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P256; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp256r1_p, pPy, LEN_P256); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP256_DblPoint -// -// Double point -*/ -void ECCP256_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA256_sqr(bnU, ECP_POINT_X(pP)); - PMA256_add(bnM, bnU, bnU); - PMA256_add(bnM, bnM, bnU); - PMA256_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA256_sqr(bnU, ECP_POINT_Z(pP)); - PMA256_add(bnS, ECP_POINT_X(pP), bnU); - PMA256_sub(bnT, ECP_POINT_X(pP), bnU); - PMA256_mul(bnM, bnS, bnT); - PMA256_add(bnU, bnM, bnM); - PMA256_add(bnM, bnU, bnM); - } - else { - PMA256_sqr(bnU, ECP_POINT_X(pP)); - PMA256_add(bnM, bnU, bnU); - PMA256_add(bnM, bnM, bnU); - PMA256_sqr(bnU, ECP_POINT_Z(pP)); - PMA256_sqr(bnU, bnU); - PMA256_mul(bnU, bnU, ECP_A(pECC)); - PMA256_add(bnM, bnM, bnU); - } - - PMA256_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA256_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA256_sqr(bnT, bnV); - PMA256_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA256_sqr(bnU, bnM); - PMA256_sub(bnU, bnU, bnS); - PMA256_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA256_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA256_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA256_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA256_mul(bnS, bnS, bnM); - PMA256_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP256_AddPoint -// -// Add points -*/ -void ECCP256_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP256_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA256_sqr(bnW, ECP_POINT_Z(pQ)); - PMA256_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA256_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA256_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA256_sqr(bnW, ECP_POINT_Z(pP)); - PMA256_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA256_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA256_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA256_sub(bnW, bnU0, bnU1); - PMA256_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P256, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P256, 0)) { - ECCP256_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA256_add(bnT, bnU0, bnU1); - PMA256_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA256_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA256_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA256_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA256_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA256_sqr(ECP_POINT_X(pR), bnR); - PMA256_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA256_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA256_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA256_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA256_mul(bnU1, bnU1, bnW); - PMA256_mul(bnU1, bnU1, bnM); - PMA256_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA256_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP256_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP256_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP256_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP256_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP256_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP256_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP256_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP256_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP256_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP256_MulPoint: SCCM version") - -void ECCP256_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP256_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP256_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP256_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP256_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP256_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP256_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP256_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP256_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP256_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP256_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP256_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP256_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP256_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP256_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP256_ProdPoint: SCCM version") - -void ECCP256_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP256_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP256_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP256_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_256_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384.h deleted file mode 100644 index 6fab8945..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384.h +++ /dev/null @@ -1,118 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over GF(P384) -// -// -*/ - -#if !defined(_PCP_ECCPMETHOD384_H) -#define _PCP_ECCPMETHOD384_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP384_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP384_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP384_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP384_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP384_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP384_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP384_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP384_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP384_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP384_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP384_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP384_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP384_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHOD384_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384ca.c deleted file mode 100644 index 72252e8b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod384ca.c +++ /dev/null @@ -1,879 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P384) -// -// Contents: -// ECCP384_SetPointProjective() -// ECCP384_SetPointAffine() -// ECCP384_GetPointAffine() -// -// ECCP384_IsPointOnCurve() -// -// ECCP384_ComparePoint() -// ECCP384_NegPoint() -// ECCP384_DblPoint() -// ECCP384_AddPoint() -// ECCP384_MulPoint() -// ECCP384_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_384_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethod384.h" -#include "pcppma384.h" - -/* - NOTE: - ECCP384 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP384 = { - ECCP384_SetPointProjective, - ECCP384_SetPointAffine, - ECCP384_GetPointAffine, - - ECCP384_IsPointOnCurve, - - ECCP384_ComparePoint, - ECCP384_NegPoint, - ECCP384_DblPoint, - ECCP384_AddPoint, - ECCP384_MulPoint, - ECCP384_MulBasePoint, - ECCP384_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP384_Methods(void) -{ - return &ECCP384; -} - -/* -// ECCP384_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP384_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP384_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP384_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP384_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP384_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP384_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP384_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP384_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMA384_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMA384_sqr(pT, pU); - - if(pX) { - PMA384_mul(pX,pT, ECP_POINT_X(pPoint)); - cpBN_fix(pX); - } - if(pY) { - /* U = 1/(Z^3) */ - PMA384_mul(pU, pU, pT); - PMA384_mul(pY,pU, ECP_POINT_Y(pPoint)); - cpBN_fix(pY); - } - } -} - -/* -// ECCP384_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP384_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMA384_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMA384_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA384_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMA384_sqr(pZ4, pT); // Z^4 - PMA384_mul(pZ6, pZ4, pT); // Z^6 - - PMA384_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA384_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMA384_add(pU, pU, pT); - PMA384_sub(pR, pR, pU); - } - else { - PMA384_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMA384_add(pR, pR, pT); - } - PMA384_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA384_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA384_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMA384_add(pT, pT, ECP_POINT_X(pPoint)); - PMA384_sub(pR, pR, pT); - } - else { - PMA384_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMA384_add(pR, pR, pT); - } - PMA384_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMA384_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP384_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP384_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA384_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA384_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA384_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA384_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA384_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA384_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA384_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA384_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP384_NegPoint -// -// Negative point -*/ -void ECCP384_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P384; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp384r1_p, pPy, LEN_P384); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP384_DblPoint -// -// Double point -*/ -void ECCP384_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA384_sqr(bnU, ECP_POINT_X(pP)); - PMA384_add(bnM, bnU, bnU); - PMA384_add(bnM, bnM, bnU); - PMA384_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA384_sqr(bnU, ECP_POINT_Z(pP)); - PMA384_add(bnS, ECP_POINT_X(pP), bnU); - PMA384_sub(bnT, ECP_POINT_X(pP), bnU); - PMA384_mul(bnM, bnS, bnT); - PMA384_add(bnU, bnM, bnM); - PMA384_add(bnM, bnU, bnM); - } - else { - PMA384_sqr(bnU, ECP_POINT_X(pP)); - PMA384_add(bnM, bnU, bnU); - PMA384_add(bnM, bnM, bnU); - PMA384_sqr(bnU, ECP_POINT_Z(pP)); - PMA384_sqr(bnU, bnU); - PMA384_mul(bnU, bnU, ECP_A(pECC)); - PMA384_add(bnM, bnM, bnU); - } - - PMA384_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA384_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA384_sqr(bnT, bnV); - PMA384_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA384_sqr(bnU, bnM); - PMA384_sub(bnU, bnU, bnS); - PMA384_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA384_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA384_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA384_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA384_mul(bnS, bnS, bnM); - PMA384_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP384_AddPoint -// -// Add points -*/ -void ECCP384_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP384_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA384_sqr(bnW, ECP_POINT_Z(pQ)); - PMA384_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA384_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA384_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA384_sqr(bnW, ECP_POINT_Z(pP)); - PMA384_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA384_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA384_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA384_sub(bnW, bnU0, bnU1); - PMA384_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P384, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P384, 0)) { - ECCP384_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA384_add(bnT, bnU0, bnU1); - PMA384_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA384_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA384_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA384_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA384_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA384_sqr(ECP_POINT_X(pR), bnR); - PMA384_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA384_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA384_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA384_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA384_mul(bnU1, bnU1, bnW); - PMA384_mul(bnU1, bnU1, bnM); - PMA384_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA384_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP384_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP384_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP384_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP384_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP384_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP384_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP384_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP384_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP384_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP384_MulPoint: SCCM version") - -void ECCP384_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP384_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP384_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP384_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP384_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP384_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP384_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP384_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP384_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP384_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP384_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP384_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP384_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP384_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP384_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP384_ProdPoint: SCCM version") - -void ECCP384_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP384_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP384_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP384_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_384_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521.h deleted file mode 100644 index d931bc6d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521.h +++ /dev/null @@ -1,118 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over GF(P521) -// -// -*/ - -#if !defined(_PCP_ECCPMETHOD521_H) -#define _PCP_ECCPMETHOD521_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP521_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP521_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP521_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP521_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP521_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP521_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP521_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP521_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP521_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP521_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP521_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP521_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP521_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHOD521_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521ca.c deleted file mode 100644 index 0bc7c59c..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethod521ca.c +++ /dev/null @@ -1,879 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P521) -// -// Contents: -// ECCP521_SetPointProjective() -// ECCP521_SetPointAffine() -// ECCP521_GetPointAffine() -// -// ECCP521_IsPointOnCurve() -// -// ECCP521_ComparePoint() -// ECCP521_NegPoint() -// ECCP521_DblPoint() -// ECCP521_AddPoint() -// ECCP521_MulPoint() -// ECCP521_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_521_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethod521.h" -#include "pcppma521.h" - -/* - NOTE: - ECCP521 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP521 = { - ECCP521_SetPointProjective, - ECCP521_SetPointAffine, - ECCP521_GetPointAffine, - - ECCP521_IsPointOnCurve, - - ECCP521_ComparePoint, - ECCP521_NegPoint, - ECCP521_DblPoint, - ECCP521_AddPoint, - ECCP521_MulPoint, - ECCP521_MulBasePoint, - ECCP521_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP521_Methods(void) -{ - return &ECCP521; -} - -/* -// ECCP521_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP521_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP521_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP521_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP521_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP521_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP521_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP521_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP521_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMA521_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMA521_sqr(pT, pU); - - if(pX) { - PMA521_mul(pX,pT, ECP_POINT_X(pPoint)); - cpBN_fix(pX); - } - if(pY) { - /* U = 1/(Z^3) */ - PMA521_mul(pU, pU, pT); - PMA521_mul(pY,pU, ECP_POINT_Y(pPoint)); - cpBN_fix(pY); - } - } -} - -/* -// ECCP521_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP521_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMA521_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMA521_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA521_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMA521_sqr(pZ4, pT); // Z^4 - PMA521_mul(pZ6, pZ4, pT); // Z^6 - - PMA521_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA521_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMA521_add(pU, pU, pT); - PMA521_sub(pR, pR, pU); - } - else { - PMA521_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMA521_add(pR, pR, pT); - } - PMA521_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA521_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA521_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMA521_add(pT, pT, ECP_POINT_X(pPoint)); - PMA521_sub(pR, pR, pT); - } - else { - PMA521_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMA521_add(pR, pR, pT); - } - PMA521_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMA521_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP521_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP521_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA521_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMA521_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA521_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMA521_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA521_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMA521_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA521_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMA521_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP521_NegPoint -// -// Negative point -*/ -void ECCP521_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P521; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)secp521r1_p, pPy, LEN_P521); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP521_DblPoint -// -// Double point -*/ -void ECCP521_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA521_sqr(bnU, ECP_POINT_X(pP)); - PMA521_add(bnM, bnU, bnU); - PMA521_add(bnM, bnM, bnU); - PMA521_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMA521_sqr(bnU, ECP_POINT_Z(pP)); - PMA521_add(bnS, ECP_POINT_X(pP), bnU); - PMA521_sub(bnT, ECP_POINT_X(pP), bnU); - PMA521_mul(bnM, bnS, bnT); - PMA521_add(bnU, bnM, bnM); - PMA521_add(bnM, bnU, bnM); - } - else { - PMA521_sqr(bnU, ECP_POINT_X(pP)); - PMA521_add(bnM, bnU, bnU); - PMA521_add(bnM, bnM, bnU); - PMA521_sqr(bnU, ECP_POINT_Z(pP)); - PMA521_sqr(bnU, bnU); - PMA521_mul(bnU, bnU, ECP_A(pECC)); - PMA521_add(bnM, bnM, bnU); - } - - PMA521_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA521_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMA521_sqr(bnT, bnV); - PMA521_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMA521_sqr(bnU, bnM); - PMA521_sub(bnU, bnU, bnS); - PMA521_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMA521_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMA521_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMA521_sub(bnS, bnS, ECP_POINT_X(pR)); - PMA521_mul(bnS, bnS, bnM); - PMA521_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP521_AddPoint -// -// Add points -*/ -void ECCP521_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP521_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA521_sqr(bnW, ECP_POINT_Z(pQ)); - PMA521_mul(bnU0,ECP_POINT_X(pP), bnW); - PMA521_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMA521_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA521_sqr(bnW, ECP_POINT_Z(pP)); - PMA521_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMA521_mul(bnW, ECP_POINT_Z(pP), bnW); - PMA521_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA521_sub(bnW, bnU0, bnU1); - PMA521_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P521, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P521, 0)) { - ECCP521_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA521_add(bnT, bnU0, bnU1); - PMA521_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA521_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMA521_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMA521_sqr(bnU1, bnW); /* U1 = W^2 */ - PMA521_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA521_sqr(ECP_POINT_X(pR), bnR); - PMA521_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA521_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMA521_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA521_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMA521_mul(bnU1, bnU1, bnW); - PMA521_mul(bnU1, bnU1, bnM); - PMA521_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMA521_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP521_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP521_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP521_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP521_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP521_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP521_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP521_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP521_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP521_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP521_MulPoint: SCCM version") - -void ECCP521_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP521_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP521_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP521_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP521_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP521_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP521_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP521_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP521_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP521_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP521_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP521_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP521_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP521_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP521_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP521_ProdPoint: SCCM version") - -void ECCP521_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP521_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP521_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP521_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_521_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcom.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcom.h deleted file mode 100644 index 57057f1b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcom.h +++ /dev/null @@ -1,133 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of EC methods over common GF(p) -// -// -*/ - -#if !defined(_PCP_ECCPMETHODCOM_H) -#define _PCP_ECCPMETHODCOM_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCPcom_Methods(void); - -/* -// Copy -*/ -void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst); - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Set To Infinity -*/ -void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint); -void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY); -void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY); - -/* -// Test Is At Infinity -// Test is On EC -*/ -int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint); -int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY); -int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY); -int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -#endif /* _PCP_ECCPMETHODCOM_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcomca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcomca.c deleted file mode 100644 index 396e01b7..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodcomca.c +++ /dev/null @@ -1,1025 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over common GF(p) -// -// Contents: -// ECCP_CopyPoint() -// ECCP_SetPointProjective() -// ECCP_SetPointAffine() -// -// ECCP_GetPointProjective() -// ECCP_GetPointAffine() -// -// ECCP_SetPointToInfinity() -// ECCP_SetPointToAffineInfinity0() -// ECCP_SetPointToAffineInfinity1() -// -// ECCP_IsPointAtInfinity() -// ECCP_IsPointAtAffineInfinity0() -// ECCP_IsPointAtAffineInfinity1() -// -// ECCP_IsPointOnCurve() -// -// ECCP_ComparePoint() -// ECCP_NegPoint() -// ECCP_DblPoint() -// ECCP_AddPoint() -// ECCP_MulPoint() -// ECCP_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcppma.h" -#include "pcpeccpsscm.h" - - -/* - NOTE: - ECCPcom methods are used representation of point coordinates - in Montgomery domain, because of Montgomery mul/sqr operations inside -*/ -static -ECCP_METHOD ECCPcom = { - ECCP_SetPointProjective, - ECCP_SetPointAffine, - ECCP_GetPointAffine, - - ECCP_IsPointOnCurve, - - ECCP_ComparePoint, - ECCP_NegPoint, - ECCP_DblPoint, - ECCP_AddPoint, - ECCP_MulPoint, - ECCP_MulBasePoint, - ECCP_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCPcom_Methods(void) -{ - return &ECCPcom; -} - - -/* -// Copy Point -*/ -void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst) -{ - cpBN_copy(ECP_POINT_X(pDst), ECP_POINT_X(pSrc)); - cpBN_copy(ECP_POINT_Y(pDst), ECP_POINT_Y(pSrc)); - cpBN_copy(ECP_POINT_Z(pDst), ECP_POINT_Z(pSrc)); - ECP_POINT_AFFINE(pDst) = ECP_POINT_AFFINE(pSrc); -} - -/* -// ECCP_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - IppsMontState* pMont = ECP_PMONT(pECC); - - PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont); - PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont); - PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)pZ, pMont); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - IppsMontState* pMont = ECP_PMONT(pECC); - PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont); - PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont); - PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)cpBN_OneRef(), pMont); - ECP_POINT_AFFINE(pPoint) = 1; -} - -/* -// ECCP_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - IppsMontState* pMont = ECP_PMONT(pECC); - - PMA_dec(pX, ECP_POINT_X(pPoint), pMont); - PMA_dec(pY, ECP_POINT_Y(pPoint), pMont); - PMA_dec(pZ, ECP_POINT_Z(pPoint), pMont); -} -#endif - -/* -// ECCP_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsMontState* pMont = ECP_PMONT(pECC); - - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - PMA_dec(pX, ECP_POINT_X(pPoint), pMont); - } - if(pY) { - PMA_dec(pY, ECP_POINT_Y(pPoint), pMont); - } - } - - /* case Z != 1 */ - else { - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - /* decode Z */ - PMA_dec(pU, ECP_POINT_Z(pPoint), pMont); - /* regular T = Z^-1 */ - PMA_inv(pT, pU, pModulo); - /* montgomery U = Z^-1 */ - PMA_enc(pU, pT, pMont); - /* regular T = Z^-2 */ - PMA_mule(pT, pU, pT, pMont); - - if(pX) { - PMA_mule(pX,pT, ECP_POINT_X(pPoint), pMont); - } - if(pY) { - /* regular U = Z^-3 */ - PMA_mule(pU, pU, pT, pMont); - PMA_mule(pY,pU, ECP_POINT_Y(pPoint), pMont); - } - } -} - -/* -// ECCP_SetPointToInfinity -// ECCP_SetPointToAffineInfinity0 -// ECCP_SetPointToAffineInfinity1 -// -// Set point to Infinity -*/ -void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint) -{ - cpBN_zero(ECP_POINT_X(pPoint)); - cpBN_zero(ECP_POINT_Y(pPoint)); - cpBN_zero(ECP_POINT_Z(pPoint)); - ECP_POINT_AFFINE(pPoint) = 0; -} - -void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY) -{ - if(pX) cpBN_zero(pX); - if(pY) cpBN_zero(pY); -} - -void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY) -{ - if(pX) cpBN_zero(pX); - if(pY) BN_Word(pY,1); -} - -/* -// ECCP_IsPointAtInfinity -// ECCP_IsPointAtAffineInfinity0 -// ECCP_IsPointAtAffineInfinity1 -// -// Test point is at Infinity -*/ -int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint) -{ - return IsZero_BN( ECP_POINT_Z(pPoint) ); -} - -int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY) -{ - return IsZero_BN(pX) && IsZero_BN(pY); -} - -int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY) -{ - return IsZero_BN(pX) && !IsZero_BN(pY); -} - -/* -// ECCP_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - PMA_sqre(pR, ECP_POINT_X(pPoint), pMont); // R = X^3 - PMA_mule(pR, pR, ECP_POINT_X(pPoint), pMont); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMA_sqre(pT, ECP_POINT_Z(pPoint), pMont); // Z^2 - PMA_sqre(pZ4, pT, pMont); // Z^4 - PMA_mule(pZ6, pZ4, pT, pMont); // Z^6 - - PMA_mule(pT, pZ4, ECP_POINT_X(pPoint), pMont); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMA_add(pU, pT, pT, pModulo); // R = X^3 +a*X*Z^4 - PMA_add(pU, pU, pT, pModulo); - PMA_sub(pR, pR, pU, pModulo); - } - else { - PMA_mule(pT, pT, ECP_AENC(pECC), pMont); // R = X^3 +a*X*Z^4 - PMA_add(pR, pR, pT, pModulo); - } - PMA_mule(pT, pZ6, ECP_BENC(pECC), pMont); // R = X^3 +a*X*Z^4 + b*Z^6 - PMA_add(pR, pR, pT, pModulo); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMA_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint), pModulo); // R = X^3 +a*X - PMA_add(pT, pT, ECP_POINT_X(pPoint), pModulo); - PMA_sub(pR, pR, pT, pModulo); - } - else { - PMA_mule(pT, ECP_POINT_X(pPoint), ECP_AENC(pECC), pMont); // R = X^3 +a*X - PMA_add(pR, pR, pT, pModulo); - } - PMA_add(pR, pR, ECP_BENC(pECC), pModulo); // R = X^3 +a*X + b - } - PMA_sqre(pT, ECP_POINT_Y(pPoint), pMont); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsMontState* pMont = ECP_PMONT(pECC); - - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA_sqre(pQZ, ECP_POINT_Z(pQ), pMont); /* Ptmp = P_X*Q_Z^2 */ - PMA_mule(pPtmp, ECP_POINT_X(pP), pQZ, pMont); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA_sqre(pPZ, ECP_POINT_Z(pP), pMont); /* Qtmp = Q_X*P_Z^2 */ - PMA_mule(pQtmp, ECP_POINT_X(pQ), pPZ, pMont); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMA_mule(pQZ, pQZ, ECP_POINT_Z(pQ), pMont); /* Ptmp = P_Y*Q_Z^3 */ - PMA_mule(pPtmp, ECP_POINT_Y(pP), pQZ, pMont); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMA_mule(pPZ, pPZ, ECP_POINT_Z(pP), pMont); /* Qtmp = Q_Y*P_Z^3 */ - PMA_mule(pQtmp, ECP_POINT_Y(pQ), pPZ, pMont); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP_NegPoint -// -// Negative point -*/ -void ECCP_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - } - PMA_sub(ECP_POINT_Y(pR), pModulo, ECP_POINT_Y(pP), pModulo); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } -} - -/* -// ECCP_DblPoint -// -// Double point -*/ -void ECCP_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsMontState* pMont = ECP_PMONT(pECC); - - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_sqre(bnU, ECP_POINT_X(pP), pMont); - PMA_add(bnM, bnU, bnU, pModulo); - PMA_add(bnM, bnM, bnU, pModulo); - PMA_add(bnM, bnM, ECP_AENC(pECC), pModulo); - } - else if( ECP_AMI3(pECC) ) { - PMA_sqre(bnU, ECP_POINT_Z(pP), pMont); - PMA_add(bnS, ECP_POINT_X(pP), bnU, pModulo); - PMA_sub(bnT, ECP_POINT_X(pP), bnU, pModulo); - PMA_mule(bnM, bnS, bnT, pMont); - PMA_add(bnU, bnM, bnM, pModulo); - PMA_add(bnM, bnU, bnM, pModulo); - } - else { - PMA_sqre(bnU, ECP_POINT_X(pP), pMont); - PMA_add(bnM, bnU, bnU, pModulo); - PMA_add(bnM, bnM, bnU, pModulo); - PMA_sqre(bnU, ECP_POINT_Z(pP), pMont); - PMA_sqre(bnU, bnU, pMont); - PMA_mule(bnU, bnU, ECP_AENC(pECC), pMont); - PMA_add(bnM, bnM, bnU, pModulo); - } - - PMA_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP), pModulo); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMA_mule(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP), pMont); - } - - /* S = 4*X*Y^2 */ - PMA_sqre(bnT, bnV, pMont); - PMA_mule(bnS, bnT, ECP_POINT_X(pP), pMont); - - /* R_X = M^2 - 2*S */ - PMA_sqre(bnU, bnM, pMont); - PMA_sub(bnU, bnU, bnS, pModulo); - PMA_sub(ECP_POINT_X(pR), bnU, bnS, pModulo); - - /* T = 8*Y^4 */ - PMA_mule(bnV, bnV, ECP_POINT_Y(pP), pMont); - PMA_mule(bnT, bnT, bnV, pMont); - - /* R_Y = M*(S - R_X) - T */ - PMA_sub(bnS, bnS, ECP_POINT_X(pR), pModulo); - PMA_mule(bnS, bnS, bnM, pMont); - PMA_sub(ECP_POINT_Y(pR), bnS, bnT, pModulo); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP_AddPoint -// -// Add points -*/ -void ECCP_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsMontState* pMont = ECP_PMONT(pECC); - - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMA_sqre(bnW, ECP_POINT_Z(pQ), pMont); - PMA_mule(bnU0,ECP_POINT_X(pP), bnW, pMont); - PMA_mule(bnW, ECP_POINT_Z(pQ), bnW, pMont); - PMA_mule(bnS0,ECP_POINT_Y(pP), bnW, pMont); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMA_sqre(bnW, ECP_POINT_Z(pP), pMont); - PMA_mule(bnU1,ECP_POINT_X(pQ), bnW, pMont); - PMA_mule(bnW, ECP_POINT_Z(pP), bnW, pMont); - PMA_mule(bnS1,ECP_POINT_Y(pQ), bnW, pMont); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMA_sub(bnW, bnU0, bnU1, pModulo); - PMA_sub(bnR, bnS0, bnS1, pModulo); - - if( IsZero_BN(bnW) ) { - if( IsZero_BN(bnR) ) { - ECCP_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMA_add(bnT, bnU0, bnU1, pModulo); - PMA_add(bnM, bnS0, bnS1, pModulo); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMA_mule(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ), pMont); - } - PMA_mule(ECP_POINT_Z(pR), bnU1, bnW, pMont); - } - - PMA_sqre(bnU1, bnW, pMont); /* U1 = W^2 */ - PMA_mule(bnS1, bnT, bnU1, pMont); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMA_sqre(ECP_POINT_X(pR), bnR, pMont); - PMA_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1, pModulo); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMA_sub(bnS1, bnS1, ECP_POINT_X(pR), pModulo); - PMA_sub(bnS1, bnS1, ECP_POINT_X(pR), pModulo); - - /* R_Y = (V * R - M * W^3) /2 */ - PMA_mule(ECP_POINT_Y(pR), bnS1, bnR, pMont); - PMA_mule(bnU1, bnU1, bnW, pMont); - PMA_mule(bnU1, bnU1, bnM, pMont); - PMA_sub(bnU1, ECP_POINT_Y(pR), bnU1, pModulo); - PMA_div2(ECP_POINT_Y(pR), bnU1, pModulo); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP_MulPoint: SCCM version") - -void ECCP_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -#if 0 -void ECCP_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - int n; - - IppsECCPPointState tmpPoint[15]; - IppsBigNumState* pX = cpBigNumListGet(&pList); - IppsBigNumState* pY = cpBigNumListGet(&pList); - - /* allocate temporary points */ - { - for(n=0; n<15; n++) { - ECP_POINT_X(&tmpPoint[n]) = cpBigNumListGet(&pList); - ECP_POINT_Y(&tmpPoint[n]) = cpBigNumListGet(&pList); - ECP_POINT_Z(&tmpPoint[n]) = cpBigNumListGet(&pList); - } - } - - /* precomputation */ - if( ippBigNumPOS == BN_SIGN(bnN) ) - ECCP_CopyPoint(pP, &tmpPoint[0]); - else - ECCP_NegPoint(pP, &tmpPoint[0], pECC); - - ECCP_GetPointAffine(pX, pY, &tmpPoint[0], pECC, pList); - ECCP_SetPointAffine(pX, pY, &tmpPoint[0], pECC); - - for(n=1; n<15; n+=2) { - ECCP_DblPoint(&tmpPoint[n/2], &tmpPoint[n], pECC, pList); - ECCP_GetPointAffine(pX, pY, &tmpPoint[n], pECC, pList); - ECCP_SetPointAffine(pX, pY, &tmpPoint[n], pECC); - - ECCP_AddPoint(&tmpPoint[n], &tmpPoint[0], &tmpPoint[n+1], pECC, pList); - ECCP_GetPointAffine(pX, pY, &tmpPoint[n+1], pECC, pList); - ECCP_SetPointAffine(pX, pY, &tmpPoint[n+1], pECC); - } - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=BN_SIZE(bnN); n>0; n--) { - Ipp32u scalar = BN_NUMBER(bnN)[n-1]; - - int shift; - for(shift=(32-4); shift>=0; shift-=4) { - int m; - int tblIdx = (scalar>>shift) & 0xF; - - if( !ECCP_IsPointAtInfinity(pR) ) { - for(m=0; m<4; m++) - ECCP_DblPoint(pR, pR, pECC, pList); - } - if( tblIdx ) - ECCP_AddPoint(pR, &tmpPoint[tblIdx-1], pR, pECC, pList); - } - } - } -} -#endif - -void ECCP_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} -#else -#pragma message ("ECCP_ProdPoint: SCCM version") -void ECCP_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP_AddPoint(&T, &U, pR, pECC, pList); -} -#endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2.h deleted file mode 100644 index 12b59bcc..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2.h +++ /dev/null @@ -1,120 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Definitions of methods over SM2 curve -// -// -*/ - -#if !defined(_PCP_ECCP_SM2_METHOD_H) -#define _PCP_ECCP_SM2_METHOD_H - -#include "pcpeccp.h" - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP_SM2_Methods(void); - - -/* -// Point Set. These operations implies -// transformation of regular coordinates into internal format -*/ -void ECCP_SM2_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -void ECCP_SM2_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC); - -/* -// Get Point. These operations implies -// transformation of internal format coordinates into regular -*/ -//void ECCP256_GetPointProjective(IppsBigNumState* pX, -// IppsBigNumState* pY, -// IppsBigNumState* pZ, -// const IppsECCPPointState* pPoint, -// const IppsECCPState* pECC); - -void ECCP_SM2_GetPointAffine(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Test is On EC -*/ -int ECCP_SM2_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList); - -/* -// Operations -*/ -int ECCP_SM2_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_SM2_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC); - -void ECCP_SM2_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_SM2_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_SM2_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_SM2_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - -void ECCP_SM2_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList); - - - -#endif /* _PCP_ECCP_SM2_METHOD_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2ca.c deleted file mode 100644 index 04d17a5b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpmethodsm2ca.c +++ /dev/null @@ -1,879 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC methods over GF(P256) SM2 -// -// Contents: -// ECCP_SM2_SetPointProjective() -// ECCP_SM2_SetPointAffine() -// ECCP_SM2_GetPointAffine() -// -// ECCP_SM2_IsPointOnCurve() -// -// ECCP_SM2_ComparePoint() -// ECCP_SM2_NegPoint() -// ECCP_SM2_DblPoint() -// ECCP_SM2_AddPoint() -// ECCP_SM2_MulPoint() -// ECCP_SM2_ProdPoint() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_SM2_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" -#include "pcpeccpmethodsm2.h" -#include "pcppmasm2.h" - -/* - NOTE: - ECCP256 methods are used representation of point coordinates - in regular (usual residue) domain, because of special modular reduction -*/ -static -ECCP_METHOD ECCP_SM2 = { - ECCP_SM2_SetPointProjective, - ECCP_SM2_SetPointAffine, - ECCP_SM2_GetPointAffine, - - ECCP_SM2_IsPointOnCurve, - - ECCP_SM2_ComparePoint, - ECCP_SM2_NegPoint, - ECCP_SM2_DblPoint, - ECCP_SM2_AddPoint, - ECCP_SM2_MulPoint, - ECCP_SM2_MulBasePoint, - ECCP_SM2_ProdPoint -}; - - -/* -// Returns reference -*/ -ECCP_METHOD* ECCP_SM2_Methods(void) -{ - return &ECCP_SM2; -} - -/* -// ECCP_SM2_PoinSettProjective -// Converts regular projective triplet (pX,pY,pZ) into pPoint -// (see note above) -*/ -void ECCP_SM2_SetPointProjective(const IppsBigNumState* pX, - const IppsBigNumState* pY, - const IppsBigNumState* pZ, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(ECP_POINT_X(pPoint), pX); - cpBN_copy(ECP_POINT_Y(pPoint), pY); - cpBN_copy(ECP_POINT_Z(pPoint), pZ); - ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0; -} - -/* -// ECCP_SM2_PointAffineSet -// Converts regular affine pair (pX,pY) into pPoint -*/ -void ECCP_SM2_SetPointAffine(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - ECCP_SM2_SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); -} - -/* -// ECCP_SM2_GetPointProjective -// Converts pPoint into regular projective triplet (pX,pY,pZ) -*/ -#if 0 -void ECCP_SM2_GetPointProjective(IppsBigNumState* pX, - IppsBigNumState* pY, - IppsBigNumState* pZ, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - cpBN_copy(pX, ECP_POINT_X(pPoint)); - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - cpBN_copy(pZ, ECP_POINT_Z(pPoint)); -} -#endif - -/* -// ECCP_SM2_GetPointAffine -// -// Converts pPoint into regular affine pair (pX,pY) -// -// Note: -// pPoint is not point at Infinity -// transform (X, Y, Z) into (x, y) = (X/Z^2, Y/Z^3) -*/ -void ECCP_SM2_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* case Z == 1 */ - if( ECP_POINT_AFFINE(pPoint) ) { - if(pX) { - cpBN_copy(pX, ECP_POINT_X(pPoint)); - } - if(pY) { - cpBN_copy(pY, ECP_POINT_Y(pPoint)); - } - } - - /* case Z != 1 */ - else { - //IppsMontState* pMont = ECP_PMONT(pECC); - IppsBigNumState* pModulo = ECP_PRIME(pECC); - - IppsBigNumState* pT = cpBigNumListGet(&pList); - IppsBigNumState* pU = cpBigNumListGet(&pList); - //IppsBigNumState* pModulo = cpBigNumListGet(&pList); - //BN_Set(MNT_MODULUS(pMont), MNT_SIZE(pMont), pModulo); - - /* U = 1/Z */ - PMAsm2_inv(pU, ECP_POINT_Z(pPoint), pModulo); - /* T = 1/(Z^2) */ - PMAsm2_sqr(pT, pU); - - if(pX) { - PMAsm2_mul(pX,pT, ECP_POINT_X(pPoint)); - cpBN_fix(pX); - } - if(pY) { - /* U = 1/(Z^3) */ - PMAsm2_mul(pU, pU, pT); - PMAsm2_mul(pY,pU, ECP_POINT_Y(pPoint)); - cpBN_fix(pY); - } - } -} - -/* -// ECCP_SM2_IsPointOnCurve -// -// Test point is lie on curve -// -// Note -// We deal with equation: y^2 = x^3 + A*x + B. -// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6. -// The point under test is given by projective triplet (X,Y,Z), -// which represents actually (x,y) = (X/Z^2,Y/Z^3). -*/ -int ECCP_SM2_IsPointOnCurve(const IppsECCPPointState* pPoint, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* let think Infinity point is on the curve */ - if( ECCP_IsPointAtInfinity(pPoint) ) - return 1; - - else { - IppsBigNumState* pR = cpBigNumListGet(&pList); - IppsBigNumState* pT = cpBigNumListGet(&pList); - - PMAsm2_sqr(pR, ECP_POINT_X(pPoint)); // R = X^3 - PMAsm2_mul(pR, pR, ECP_POINT_X(pPoint)); - - /* case Z != 1 */ - if( !ECP_POINT_AFFINE(pPoint) ) { - IppsBigNumState* pZ4 = cpBigNumListGet(&pList); - IppsBigNumState* pZ6 = cpBigNumListGet(&pList); - PMAsm2_sqr(pT, ECP_POINT_Z(pPoint)); // Z^2 - PMAsm2_sqr(pZ4, pT); // Z^4 - PMAsm2_mul(pZ6, pZ4, pT); // Z^6 - - PMAsm2_mul(pT, pZ4, ECP_POINT_X(pPoint)); // T = X*Z^4 - if( ECP_AMI3(pECC) ) { - IppsBigNumState* pU = cpBigNumListGet(&pList); - PMAsm2_add(pU, pT, pT); // R = X^3 +a*X*Z^4 - PMAsm2_add(pU, pU, pT); - PMAsm2_sub(pR, pR, pU); - } - else { - PMAsm2_mul(pT, pT, ECP_A(pECC)); // R = X^3 +a*X*Z^4 - PMAsm2_add(pR, pR, pT); - } - PMAsm2_mul(pT, pZ6, ECP_B(pECC)); // R = X^3 +a*X*Z^4 + b*Z^6 - PMAsm2_add(pR, pR, pT); - - } - /* case Z == 1 */ - else { - if( ECP_AMI3(pECC) ) { - PMAsm2_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint)); // R = X^3 +a*X - PMAsm2_add(pT, pT, ECP_POINT_X(pPoint)); - PMAsm2_sub(pR, pR, pT); - } - else { - PMAsm2_mul(pT, ECP_POINT_X(pPoint), ECP_A(pECC)); // R = X^3 +a*X - PMAsm2_add(pR, pR, pT); - } - PMAsm2_add(pR, pR, ECP_B(pECC)); // R = X^3 +a*X + b - } - PMAsm2_sqr(pT, ECP_POINT_Y(pPoint)); // T = Y^2 - return 0==cpBN_cmp(pR, pT); - } -} - -/* -// ECCP_SM2_ComparePoint -// -// Compare two points: -// returns 0 => pP==pQ (maybe both pP and pQ are at Infinity) -// returns 1 => pP!=pQ -// -// Note -// In general we check: -// P_X*Q_Z^2 ~ Q_X*P_Z^2 -// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 -*/ -int ECCP_SM2_ComparePoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - UNREFERENCED_PARAMETER(pECC); - - /* P or/and Q at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - return ECCP_IsPointAtInfinity(pQ)? 0:1; - if( ECCP_IsPointAtInfinity(pQ) ) - return ECCP_IsPointAtInfinity(pP)? 0:1; - - /* (P_Z==1) && (Q_Z==1) */ - if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) - return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; - - { - IppsBigNumState* pPtmp = cpBigNumListGet(&pList); - IppsBigNumState* pQtmp = cpBigNumListGet(&pList); - IppsBigNumState* pPZ = cpBigNumListGet(&pList); - IppsBigNumState* pQZ = cpBigNumListGet(&pList); - - /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMAsm2_sqr(pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_X*Q_Z^2 */ - PMAsm2_mul(pPtmp, ECP_POINT_X(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_X(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMAsm2_sqr(pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_X*P_Z^2 */ - PMAsm2_mul(pQtmp, ECP_POINT_X(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_X(pQ)); - } - if ( cpBN_cmp(pPtmp, pQtmp) ) - return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ - - /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ - if( !ECP_POINT_AFFINE(pQ) ) { - PMAsm2_mul(pQZ, pQZ, ECP_POINT_Z(pQ)); /* Ptmp = P_Y*Q_Z^3 */ - PMAsm2_mul(pPtmp, ECP_POINT_Y(pP), pQZ); - } - else { - PMA_set(pPtmp, ECP_POINT_Y(pP)); - } - if( !ECP_POINT_AFFINE(pP) ) { - PMAsm2_mul(pPZ, pPZ, ECP_POINT_Z(pP)); /* Qtmp = Q_Y*P_Z^3 */ - PMAsm2_mul(pQtmp, ECP_POINT_Y(pQ), pPZ); - } - else { - PMA_set(pQtmp, ECP_POINT_Y(pQ)); - } - return cpBN_cmp(pPtmp, pQtmp)? 1:0; - } -} - -/* -// ECCP_SM2_NegPoint -// -// Negative point -*/ -void ECCP_SM2_NegPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC) -{ - UNREFERENCED_PARAMETER(pECC); - - /* test point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - BNU_CHUNK_T* pRy = BN_NUMBER(ECP_POINT_Y(pR)); - BNU_CHUNK_T* pPy = BN_NUMBER(ECP_POINT_Y(pP)); - int size = LEN_P256; - - if( pP!=pR ) { - PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); - PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); - ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); - } - cpSub_BNU(pRy, (BNU_CHUNK_T*)tpmSM2_p256_p, pPy, LEN_P256); - FIX_BNU(pRy,size); - BN_SIZE(ECP_POINT_Y(pR)) = size; - BN_SIGN(ECP_POINT_Y(pR)) = ippBigNumPOS; - } -} - -/* -// ECCP_SM2_DblPoint -// -// Double point -*/ -void ECCP_SM2_DblPoint(const IppsECCPPointState* pP, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* P at infinity */ - if( ECCP_IsPointAtInfinity(pP) ) - ECCP_SetPointToInfinity(pR); - - else { - IppsBigNumState* bnV = cpBigNumListGet(&pList); - IppsBigNumState* bnU = cpBigNumListGet(&pList); - IppsBigNumState* bnM = cpBigNumListGet(&pList); - IppsBigNumState* bnS = cpBigNumListGet(&pList); - IppsBigNumState* bnT = cpBigNumListGet(&pList); - - /* M = 3*X^2 + A*Z^4 */ - if( ECP_POINT_AFFINE(pP) ) { - PMAsm2_sqr(bnU, ECP_POINT_X(pP)); - PMAsm2_add(bnM, bnU, bnU); - PMAsm2_add(bnM, bnM, bnU); - PMAsm2_add(bnM, bnM, ECP_A(pECC)); - } - else if( ECP_AMI3(pECC) ) { - PMAsm2_sqr(bnU, ECP_POINT_Z(pP)); - PMAsm2_add(bnS, ECP_POINT_X(pP), bnU); - PMAsm2_sub(bnT, ECP_POINT_X(pP), bnU); - PMAsm2_mul(bnM, bnS, bnT); - PMAsm2_add(bnU, bnM, bnM); - PMAsm2_add(bnM, bnU, bnM); - } - else { - PMAsm2_sqr(bnU, ECP_POINT_X(pP)); - PMAsm2_add(bnM, bnU, bnU); - PMAsm2_add(bnM, bnM, bnU); - PMAsm2_sqr(bnU, ECP_POINT_Z(pP)); - PMAsm2_sqr(bnU, bnU); - PMAsm2_mul(bnU, bnU, ECP_A(pECC)); - PMAsm2_add(bnM, bnM, bnU); - } - - PMAsm2_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP)); - - /* R_Z = 2*Y*Z */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnV); - } - else { - PMAsm2_mul(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP)); - } - - /* S = 4*X*Y^2 */ - PMAsm2_sqr(bnT, bnV); - PMAsm2_mul(bnS, bnT, ECP_POINT_X(pP)); - - /* R_X = M^2 - 2*S */ - PMAsm2_sqr(bnU, bnM); - PMAsm2_sub(bnU, bnU, bnS); - PMAsm2_sub(ECP_POINT_X(pR), bnU, bnS); - - /* T = 8*Y^4 */ - PMAsm2_mul(bnV, bnV, ECP_POINT_Y(pP)); - PMAsm2_mul(bnT, bnT, bnV); - - /* R_Y = M*(S - R_X) - T */ - PMAsm2_sub(bnS, bnS, ECP_POINT_X(pR)); - PMAsm2_mul(bnS, bnS, bnM); - PMAsm2_sub(ECP_POINT_Y(pR), bnS, bnT); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP_SM2_AddPoint -// -// Add points -*/ -void ECCP_SM2_AddPoint(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ -#if 0 - /* test stupid call */ - if( pP == pQ ) { - ECCP_SM2_DblPoint(pP, pR, pECC, pList); - return; - } -#endif - - /* prevent operation with point at Infinity */ - if( ECCP_IsPointAtInfinity(pP) ) { - ECCP_CopyPoint(pQ, pR); - return; - } - if( ECCP_IsPointAtInfinity(pQ) ) { - ECCP_CopyPoint(pP, pR); - return; - } - - /* - // addition - */ - { - IppsBigNumState* bnU0 = cpBigNumListGet(&pList); - IppsBigNumState* bnS0 = cpBigNumListGet(&pList); - IppsBigNumState* bnU1 = cpBigNumListGet(&pList); - IppsBigNumState* bnS1 = cpBigNumListGet(&pList); - IppsBigNumState* bnW = cpBigNumListGet(&pList); - IppsBigNumState* bnR = cpBigNumListGet(&pList); - IppsBigNumState *bnT = bnU0; - IppsBigNumState *bnM = bnS0; - - /* U0 = P_X * Q_Z^2 */ - /* S0 = P_Y * Q_Z^3 */ - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU0, ECP_POINT_X(pP)); - PMA_set(bnS0, ECP_POINT_Y(pP)); - } - else { - PMAsm2_sqr(bnW, ECP_POINT_Z(pQ)); - PMAsm2_mul(bnU0,ECP_POINT_X(pP), bnW); - PMAsm2_mul(bnW, ECP_POINT_Z(pQ), bnW); - PMAsm2_mul(bnS0,ECP_POINT_Y(pP), bnW); - } - - /* U1 = Q_X * P_Z^2 */ - /* S1 = Q_Y * P_Z^3 */ - if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_X(pQ)); - PMA_set(bnS1, ECP_POINT_Y(pQ)); - } - else { - PMAsm2_sqr(bnW, ECP_POINT_Z(pP)); - PMAsm2_mul(bnU1,ECP_POINT_X(pQ), bnW); - PMAsm2_mul(bnW, ECP_POINT_Z(pP), bnW); - PMAsm2_mul(bnS1,ECP_POINT_Y(pQ), bnW); - } - - /* W = U0-U1 */ - /* R = S0-S1 */ - PMAsm2_sub(bnW, bnU0, bnU1); - PMAsm2_sub(bnR, bnS0, bnS1); - - //if( IsZero_BN(bnW) ) { - //if( IsZero_BN(bnR) ) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnW), LEN_P256, 0)) { - if(cpEqu_BNU_CHUNK(BN_NUMBER(bnR), LEN_P256, 0)) { - ECCP_SM2_DblPoint(pP, pR, pECC, pList); - return; - } - else { - ECCP_SetPointToInfinity(pR); - return; - } - } - - /* T = U0+U1 */ - /* M = S0+S1 */ - PMAsm2_add(bnT, bnU0, bnU1); - PMAsm2_add(bnM, bnS0, bnS1); - - /* R_Z = P_Z * Q_Z * W */ - if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { - PMA_set(ECP_POINT_Z(pR), bnW); - } - else { - if( ECP_POINT_AFFINE(pQ) ) { - PMA_set(bnU1, ECP_POINT_Z(pP)); - } - else if( ECP_POINT_AFFINE(pP) ) { - PMA_set(bnU1, ECP_POINT_Z(pQ)); - } - else { - PMAsm2_mul(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ)); - } - PMAsm2_mul(ECP_POINT_Z(pR), bnU1, bnW); - } - - PMAsm2_sqr(bnU1, bnW); /* U1 = W^2 */ - PMAsm2_mul(bnS1, bnT, bnU1); /* S1 = T * W^2 */ - - /* R_X = R^2 - T * W^2 */ - PMAsm2_sqr(ECP_POINT_X(pR), bnR); - PMAsm2_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1); - - /* V = T * W^2 - 2 * R_X (S1) */ - PMAsm2_sub(bnS1, bnS1, ECP_POINT_X(pR)); - PMAsm2_sub(bnS1, bnS1, ECP_POINT_X(pR)); - - /* R_Y = (V * R - M * W^3) /2 */ - PMAsm2_mul(ECP_POINT_Y(pR), bnS1, bnR); - PMAsm2_mul(bnU1, bnU1, bnW); - PMAsm2_mul(bnU1, bnU1, bnM); - PMAsm2_sub(bnU1, ECP_POINT_Y(pR), bnU1); - PMAsm2_div2(ECP_POINT_Y(pR), bnU1); - - ECP_POINT_AFFINE(pR) = 0; - } -} - -/* -// ECCP_SM2_MulPoint -// -// Multiply point by scalar -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP_SM2_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - IppsECCPPointState T; - IppsECCPPointState U; - IppsBigNumState* bnKH = cpBigNumListGet(&pList); - Ipp32u* pK; - Ipp32u* pH; - Ipp32u carry; - int lenKH; - int bitH; - - /* init result */ - ECCP_CopyPoint(pP, pR); - - /* if scalar is negative */ - if( ippBigNumNEG == BN_SIGN(bnN) ) { - /* negative R */ - ECCP_SM2_NegPoint(pR, pR, pECC); - } - - /* copy K = N and compute H=3*K */ - lenKH = BN_SIZE(bnN)+1; - pK = BN_NUMBER(bnKH); - pH = BN_BUFFER(bnKH); - Cpy_BNU(BN_NUMBER(bnN), pK, BN_SIZE(bnN)); - pK[lenKH-1] = 0; - carry = cpAdd_BNU(pH, pK, pK, lenKH); - carry = cpAdd_BNU(pH, pK, pH, lenKH); - - /* init temporary T = (X/Z^2, Y/Z^3, 1) */ - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - ECCP_SM2_GetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), pR, pECC, pList); - ECCP_SM2_SetPointAffine(ECP_POINT_X(&T), ECP_POINT_Y(&T), &T, pECC); - - /* temporary point U =-T */ - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - ECCP_SM2_NegPoint(&T, &U, pECC); - - for(bitH=MSB_BNU(pH, lenKH)-1; bitH>0; bitH--) { - int hBit = TST_BIT(pH, bitH); - int kBit = TST_BIT(pK, bitH); - ECCP_SM2_DblPoint(pR, pR, pECC, pList); - if( hBit && !kBit ) - ECCP_SM2_AddPoint(pR, &T, pR, pECC, pList); - if(!hBit && kBit ) - ECCP_SM2_AddPoint(pR, &U, pR, pECC, pList); - } - } -} - -#else -#pragma message ("ECCP_SM2_MulPoint: SCCM version") - -void ECCP_SM2_MulPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnN, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalar or input point at Infinity */ - if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { - ECCP_SetPointToInfinity(pR); - return; - } - - /* - // scalar multiplication - */ - else { - Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); - - BNU_CHUNK_T* pN = BN_NUMBER(bnN); - cpSize nsN = BN_SIZE(bnN); - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int w = cpECCP_OptimalWinSize(scalarBitSize); - /* number of table entries */ - int nPrecomputed = 1<>shift) & dmask; - - /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ - cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); - ECP_POINT_AFFINE(pR) = 0; - - /* initialize temporary T (ECP_PROJECTIVE) */ - ECP_POINT_AFFINE(&T) = 0; - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - /* w times doubling */ - int k; - for(k=0; k>shift) & dmask; - - /* extract value from the pre-computed table */ - cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); - - /* and add it */ - ECCP_SM2_AddPoint(pR, &T, pR, pECC, pList); - } - } - } -} -#endif - -void ECCP_SM2_MulBasePoint(const IppsBigNumState* pK, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - ECCP_SM2_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); -} - -/* -// ECCP_SM2_ProdPoint -// -// Point product -*/ -#if !defined (_USE_ECCP_SSCM_) -void ECCP_SM2_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - /* test zero scalars */ - if( IsZero_BN(bnPscalar) ) { - ECCP_SM2_MulPoint(pQ, bnQscalar, pR, pECC, pList); - return; - } - if( IsZero_BN(bnQscalar) ) { - ECCP_SM2_MulPoint(pP, bnPscalar, pR, pECC, pList); - return; - } - - /* - // point product - */ - else { - int n; - Ipp32u* pbnPscalar = BN_NUMBER(bnPscalar); - int bnPscalarSize = BN_SIZE(bnPscalar); - Ipp32u* pbnQscalar = BN_NUMBER(bnQscalar); - int bnQscalarSize = BN_SIZE(bnQscalar); - - int size = bnPscalarSize>bnQscalarSize? bnPscalarSize : bnQscalarSize; - - IppsECCPPointState* pPointPQ[4] = {NULL, NULL, NULL, NULL}; - - /* allocate temporary PQ point */ - IppsECCPPointState PQ; - ECP_POINT_X(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Y(&PQ) = cpBigNumListGet(&pList); - ECP_POINT_Z(&PQ) = cpBigNumListGet(&pList); - - /* init temporary point array */ - if(ippBigNumPOS == BN_SIGN(bnPscalar)) - pPointPQ[1] = (IppsECCPPointState*)pP; - else { - IppsECCPPointState P; - ECP_POINT_X(&P) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P) = cpBigNumListGet(&pList); - ECCP_SM2_NegPoint(pP, &P, pECC); - pPointPQ[1] = &P; - } - if(ippBigNumPOS == BN_SIGN(bnQscalar)) - pPointPQ[2] = (IppsECCPPointState*)pQ; - else { - IppsECCPPointState Q; - ECP_POINT_X(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Y(&Q) = cpBigNumListGet(&pList); - ECP_POINT_Z(&Q) = cpBigNumListGet(&pList); - ECCP_SM2_NegPoint(pQ, &Q, pECC); - pPointPQ[2] = &Q; - } - - ECCP_SM2_AddPoint(pPointPQ[1], pPointPQ[2], &PQ, pECC, pList); - ECCP_SM2_GetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC, pList); - ECCP_SM2_SetPointAffine(ECP_POINT_X(pR), ECP_POINT_Y(pR), &PQ, pECC); - pPointPQ[3] = &PQ; - - /* pad scalars by zeros */ - ZEXPAND_BNU(pbnPscalar,bnPscalarSize, size); - ZEXPAND_BNU(pbnQscalar,bnQscalarSize, size); - - /* init result */ - ECCP_SetPointToInfinity(pR); - - for(n=size; n>0; n--) { - Ipp32u scalarPn = pbnPscalar[n-1]; - Ipp32u scalarQn = pbnQscalar[n-1]; - - int nBit; - for(nBit=31; nBit>=0; nBit--) { - int - PnQnBits = scalarPn&0x80000000? 1:0; - PnQnBits+= scalarQn&0x80000000? 2:0; - - if( !ECCP_IsPointAtInfinity(pR) ) - ECCP_SM2_DblPoint(pR, pR, pECC, pList); - if( PnQnBits ) - ECCP_SM2_AddPoint(pR, pPointPQ[PnQnBits], pR, pECC, pList); - - scalarPn <<= 1; - scalarQn <<= 1; - } - } - } -} - -#else -#pragma message ("ECCP_SM2_ProdPoint: SCCM version") - -void ECCP_SM2_ProdPoint(const IppsECCPPointState* pP, - const IppsBigNumState* bnPscalar, - const IppsECCPPointState* pQ, - const IppsBigNumState* bnQscalar, - IppsECCPPointState* pR, - const IppsECCPState* pECC, - BigNumNode* pList) -{ - IppsECCPPointState T; - IppsECCPPointState U; - - ECP_POINT_X(&T) = cpBigNumListGet(&pList); - ECP_POINT_Y(&T) = cpBigNumListGet(&pList); - ECP_POINT_Z(&T) = cpBigNumListGet(&pList); - - ECP_POINT_X(&U) = cpBigNumListGet(&pList); - ECP_POINT_Y(&U) = cpBigNumListGet(&pList); - ECP_POINT_Z(&U) = cpBigNumListGet(&pList); - - ECCP_SM2_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); - ECCP_SM2_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); - ECCP_SM2_AddPoint(&T, &U, pR, pECC, pList); -} -#endif - -#endif /* _ECP_SM2_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppoint.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppoint.h deleted file mode 100644 index bf13c8e0..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppoint.h +++ /dev/null @@ -1,54 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal EC Point Definitions & Function Prototypes -// -// -*/ - -#if !defined(_PCP_ECCPPOINT_H) -#define _PCP_ECCPPOINT_H - -#include "pcpeccp.h" - - -/* -// EC Point context -*/ -struct _cpECCPPoint { - IppCtxId idCtx; /* EC Point identifier */ - - IppsBigNumState* pX; /* projective X */ - IppsBigNumState* pY; /* Y */ - IppsBigNumState* pZ; /* Z coordinates */ - int affine; /* impotrant case Z=1 */ -}; - -/* -// Contetx Access Macros -*/ -#define ECP_POINT_ID(ctx) ((ctx)->idCtx) -#define ECP_POINT_X(ctx) ((ctx)->pX) -#define ECP_POINT_Y(ctx) ((ctx)->pY) -#define ECP_POINT_Z(ctx) ((ctx)->pZ) -#define ECP_POINT_AFFINE(ctx) ((ctx)->affine) -#define ECP_POINT_VALID_ID(ctx) (ECP_POINT_ID((ctx))==idCtxECCPPoint) - -#endif /* _PCP_ECCPPOINT_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointca.c deleted file mode 100644 index 4df8d1e8..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointca.c +++ /dev/null @@ -1,126 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC (prime) Point -// -// Contents: -// ippsECCPPointGetSize() -// ippsECCPPointInit() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccppoint.h" - - -/*F* -// Name: ippsECCPPointGetSize -// -// Purpose: Returns size of EC Point context (bytes). -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pSzie -// ippStsSizeErr 2>feBitSize -// ippStsNoErr no errors -// -// Parameters: -// feBitSize size of field element (bits) -// pSize pointer to the size of EC Point context -// -*F*/ -IPPFUN(IppStatus, ippsECCPPointGetSize, (int feBitSize, int* pSize)) -{ - /* test size's pointer */ - IPP_BAD_PTR1_RET(pSize); - - /* test size of field element */ - IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); - - { - int bnSize; - ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize); - *pSize = sizeof(IppsECCPPointState) - + bnSize /* X coodinate */ - + bnSize /* Y coodinate */ - + bnSize /* Z coodinate */ - +(ALIGN_VAL-1); - } - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPPointInit -// -// Purpose: Init EC Point context. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pPoint -// ippStsSizeErr 2>feBitSize -// ippStsNoErr no errors -// -// Parameters: -// feBitSize size of field element (bits) -// pECC pointer to ECC context -// -*F*/ -IPPFUN(IppStatus, ippsECCPPointInit, (int feBitSize, IppsECCPPointState* pPoint)) -{ - /* test pEC pointer */ - IPP_BAD_PTR1_RET(pPoint); - - /* use aligned context */ - pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); - - /* test size of field element */ - IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); - - /* context ID */ - ECP_POINT_ID(pPoint) = idCtxECCPPoint; - - /* meaning: point was not set */ - ECP_POINT_AFFINE(pPoint) =-1; - - /* - // init other context fields - */ - { - Ipp8u* ptr = (Ipp8u*)pPoint; - int bnLen = BITS2WORD32_SIZE(feBitSize); - int bnSize; - ippsBigNumGetSize(bnLen, &bnSize); - - /* allocate coordinate buffers */ - ptr += sizeof(IppsECCPPointState); - ECP_POINT_X(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); - ptr += bnSize; - ECP_POINT_Y(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); - ptr += bnSize; - ECP_POINT_Z(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); - - /* init coordinate buffers */ - ippsBigNumInit(bnLen, ECP_POINT_X(pPoint)); - ippsBigNumInit(bnLen, ECP_POINT_Y(pPoint)); - ippsBigNumInit(bnLen, ECP_POINT_Z(pPoint)); - } - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointopca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointopca.c deleted file mode 100644 index 02188f92..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppointopca.c +++ /dev/null @@ -1,482 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (EC Point operations) -// -// Contents: -// ippsECCPSetPoint() -// ippsECCPSetPointAtInfinity() -// ippsECCPGetPoint() -// -// ippsECCPCheckPoint() -// ippsECCPComparePoint() -// -// ippsECCPNegativePoint() -// ippsECCPAddPoint() -// ippsECCPMulPointScalar() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" - - -/*F* -// Name: ippsECCPSetPoint -// -// Purpose: Converts regular affine coordinates EC point (pX,pY) -// into internal presentation - montgomery projective. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPoint -// NULL == pX -// NULL == pY -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pX->idCtx -// illegal pY->idCtx -// illegal pPoint->idCtx -// -// ippStsOutOfECErr point out-of EC -// -// ippStsNoErr no errors -// -// Parameters: -// pX pointer to the regular affine coordinate X -// pY pointer to the regular affine coordinate Y -// pPoint pointer to the EC Point context -// pECC pointer to the ECCP context -// -// Note: -// if B==0 and (x,y)=(0,y) then point at Infinity will be set up -// if B!=0 and (x,y)=(0,0) then point at Infinity will be set up -// else point with requested coordinates (x,y) wil be set up -// There are no check validation inside! -// -*F*/ -IPPFUN(IppStatus, ippsECCPSetPoint,(const IppsBigNumState* pX, - const IppsBigNumState* pY, - IppsECCPPointState* pPoint, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test pX and pY */ - IPP_BAD_PTR2_RET(pX,pY); - pX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pX, ALIGN_VAL) ); - pY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pY, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pX), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pY), ippStsContextMatchErr); - - /* test pPoint */ - IPP_BAD_PTR1_RET(pPoint); - pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); - - /* set affine coordinates at Infinity */ - if( ( IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity1(pX,pY)) || - (!IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity0(pX,pY)) ) - ECCP_SetPointToInfinity(pPoint); - /* set point */ - else { - ECP_METHOD(pECC)->SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); - } - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPSetPointAtInfinity -// -// Purpose: Set point at Infinity -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPoint -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pPoint->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pPoint pointer to the EC Point context -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test pPoint */ - IPP_BAD_PTR1_RET(pPoint); - pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); - - ECCP_SetPointToInfinity(pPoint); - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPGetPoint -// -// Purpose: Converts internal presentation EC point - montgomery projective -// into regular affine coordinates EC point (pX,pY) -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPoint -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pPoint->idCtx -// NULL != pX, illegal pX->idCtx -// NULL != pY, illegal pY->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pX pointer to the regular affine coordinate X -// pY pointer to the regular affine coordinate Y -// pLength pointer to the length of coordinates -// pPoint pointer to the EC Point context -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPGetPoint,(IppsBigNumState* pX, - IppsBigNumState* pY, - const IppsECCPPointState* pPoint, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test source point */ - IPP_BAD_PTR1_RET(pPoint); - pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); - - /* test pX and pY */ - if(pX) { - pX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pX, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pX), ippStsContextMatchErr); - } - if(pY) { - pY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pY, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pY), ippStsContextMatchErr); - } - - if( ECCP_IsPointAtInfinity(pPoint) ) { - if( IsZero_BN(ECP_BENC(pECC)) ) - ECCP_SetPointToAffineInfinity1(pX, pY); - else - ECCP_SetPointToAffineInfinity0(pX, pY); - } - else - ECP_METHOD(pECC)->GetPointAffine(pX, pY, pPoint, pECC, ECP_BNCTX(pECC)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPCheckPoint -// -// Purpose: Check EC point: -// - is point lie on EC -// - is point at infinity -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pP -// NULL == pResult -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pP->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pPoint pointer to the EC Point context -// pECC pointer to the ECCP context -// pResult pointer to the result: -// ippECValid -// ippECPointIsNotValid -// ippECPointIsAtInfinite -// -*F*/ -IPPFUN(IppStatus, ippsECCPCheckPoint,(const IppsECCPPointState* pP, - IppECResult* pResult, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test point */ - IPP_BAD_PTR1_RET(pP); - pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); - - /* test pResult */ - IPP_BAD_PTR1_RET(pResult); - - if( ECCP_IsPointAtInfinity(pP) ) - *pResult = ippECPointIsAtInfinite; - else if( ECP_METHOD(pECC)->IsPointOnCurve(pP, pECC, ECP_BNCTX(pECC)) ) - *pResult = ippECValid; - else - *pResult = ippECPointIsNotValid; - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPComparePoint -// -// Purpose: Compare two EC points -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pP -// NULL == pQ -// NULL == pResult -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pP->idCtx -// illegal pQ->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pP pointer to the EC Point context -// pQ pointer to the EC Point context -// pECC pointer to the ECCP context -// pResult pointer to the result: -// ippECPointIsEqual -// ippECPointIsNotEqual -// -*F*/ -IPPFUN(IppStatus, ippsECCPComparePoint,(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppECResult* pResult, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test points */ - IPP_BAD_PTR2_RET(pP,pQ); - pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); - pQ = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pQ, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pQ), ippStsContextMatchErr); - - /* test pResult */ - IPP_BAD_PTR1_RET(pResult); - - *pResult = ECP_METHOD(pECC)->ComparePoint(pP, pQ, pECC, ECP_BNCTX(pECC))? ippECPointIsNotEqual : ippECPointIsEqual; - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPNegativePoint -// -// Purpose: Perforn EC point operation: R = -P -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pP -// NULL == pR -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pP->idCtx -// illegal pR->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pP pointer to the source EC Point context -// pR pointer to the resultant EC Point context -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPNegativePoint, (const IppsECCPPointState* pP, - IppsECCPPointState* pR, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test points */ - IPP_BAD_PTR2_RET(pP,pR); - pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); - pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); - - ECP_METHOD(pECC)->NegPoint(pP, pR, pECC); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPAddPoint -// -// Purpose: Perforn EC point operation: R = P+Q -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pP -// NULL == pQ -// NULL == pR -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pP->idCtx -// illegal pQ->idCtx -// illegal pR->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pP pointer to the source EC Point context -// pQ pointer to the source EC Point context -// pR pointer to the resultant EC Point context -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPAddPoint,(const IppsECCPPointState* pP, - const IppsECCPPointState* pQ, - IppsECCPPointState* pR, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test points */ - IPP_BAD_PTR3_RET(pP,pQ,pR); - pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); - pQ = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pQ, ALIGN_VAL) ); - pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pQ), ippStsContextMatchErr); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); - - if(pP==pQ) - ECP_METHOD(pECC)->DblPoint(pP, pR, pECC, ECP_BNCTX(pECC)); - else - ECP_METHOD(pECC)->AddPoint(pP, pQ, pR, pECC, ECP_BNCTX(pECC)); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsECCPMulPointScalar -// -// Purpose: Perforn EC point operation: R = k*P -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pP -// NULL == pK -// NULL == pR -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pP->idCtx -// illegal pK->idCtx -// illegal pR->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pP pointer to the source EC Point context -// pK pointer to the source BigNum multiplier context -// pR pointer to the resultant EC Point context -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPMulPointScalar,(const IppsECCPPointState* pP, - const IppsBigNumState* pK, - IppsECCPPointState* pR, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test points */ - IPP_BAD_PTR2_RET(pP,pR); - pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); - pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); - - /* test scalar */ - IPP_BAD_PTR1_RET(pK); - pK = (IppsBigNumState*)( IPP_ALIGNED_PTR(pK, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pK), ippStsContextMatchErr); - - ECP_METHOD(pECC)->MulPoint(pP, pK, pR, pECC, ECP_BNCTX(pECC)); - - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppublickeyca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppublickeyca.c deleted file mode 100644 index d2455d25..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccppublickeyca.c +++ /dev/null @@ -1,87 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (EC Key Generation) -// -// Contents: -// ippsECCPPublicKey() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" - - -/*F* -// Name: ippsECCPPublicKey -// -// Purpose: Calculate Public Key -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPrivate -// NULL == pPublic -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pPrivate->idCtx -// illegal pPublic->idCtx -// -// ippStsIvalidPrivateKey !(0 < pPrivate < order) -// -// ippStsNoErr no errors -// -// Parameters: -// pPrivate pointer to the private key -// pPublic pointer to the resultant public key -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPPublicKey, (const IppsBigNumState* pPrivate, - IppsECCPPointState* pPublic, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test public key */ - IPP_BAD_PTR1_RET(pPublic); - pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr); - - /* test private keys */ - IPP_BAD_PTR1_RET(pPrivate); - pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); - IPP_BADARG_RET(!((0cpBN_cmp(pPrivate, ECP_ORDER(pECC))) ), ippStsIvalidPrivateKey); - - /* calculates public key */ - //ECP_METHOD(pECC)->MulPoint(ECP_GENC(pECC), pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); - ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); - - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsetkeyca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsetkeyca.c deleted file mode 100644 index dabce4dd..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsetkeyca.c +++ /dev/null @@ -1,102 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (EC Key Generation) -// -// Contents: -// ippsECCPSetKeyPair() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" - - -/*F* -// Name: ippsECCPSetKeyPair -// -// Purpose: Generate (private,public) Key Pair -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pPrivate -// NULL == pPublic -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pPrivate->idCtx -// illegal pPublic->idCtx -// -// ippStsNoErr no errors -// -// Parameters: -// pPrivate pointer to the private key -// pPublic pointer to the public key -// regular flag regular/ephemeral keys -// pECC pointer to the ECCP context -// -*F*/ -IPPFUN(IppStatus, ippsECCPSetKeyPair, (const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, - IppBool regular, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - /* test ID */ - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - { - IppsBigNumState* targetPrivate; - IppsECCPPointState* targetPublic; - - if( regular ) { - targetPrivate = ECP_PRIVATE(pECC); - targetPublic = ECP_PUBLIC(pECC); - } - else { - targetPrivate = ECP_PRIVATE_E(pECC); - targetPublic = ECP_PUBLIC_E(pECC); - } - - /* set up private key request */ - if( pPrivate ) { - pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); - ippsSet_BN(ippBigNumPOS, BN_SIZE32(pPrivate), (Ipp32u*)BN_NUMBER(pPrivate), targetPrivate); - } - - /* set up public key request */ - if( pPublic ) { - pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr); - - ECP_METHOD(pECC)->GetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), pPublic, pECC, ECP_BNCTX(pECC)); - ECP_METHOD(pECC)->SetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), targetPublic, pECC); - } - - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsigndsaca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsigndsaca.c deleted file mode 100644 index 182d505b..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsigndsaca.c +++ /dev/null @@ -1,146 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// EC over Prime Finite Field (Sign, DSA version) -// -// Contents: -// ippsECCPSignDSA() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccp.h" -#include "pcpeccppoint.h" -#include "pcpeccpmethod.h" -#include "pcpeccpmethodcom.h" - - -/*F* -// Name: ippsECCPSignDSA -// -// Purpose: Signing of message representative. -// (DSA version). -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pECC -// NULL == pMsgDigest -// NULL == pPrivate -// NULL == pSignX -// NULL == pSignY -// -// ippStsContextMatchErr illegal pECC->idCtx -// illegal pMsgDigest->idCtx -// illegal pPrivate->idCtx -// illegal pSignX->idCtx -// illegal pSignY->idCtx -// -// ippStsMessageErr MsgDigest >= order -// -// ippStsRangeErr not enough room for: -// signX -// signY -// -// ippStsEphemeralKeyErr (0==signX) || (0==signY) -// -// ippStsNoErr no errors -// -// Parameters: -// pMsgDigest pointer to the message representative to be signed -// pPrivate pointer to the regular private key -// pSignX,pSignY pointer to the signature -// pECC pointer to the ECCP context -// -// Note: -// - ephemeral key pair extracted from pECC and -// must be generated and before ippsECCPDSASign() usage -// - ephemeral key pair destroy before exit -// -*F*/ -IPPFUN(IppStatus, ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, - const IppsBigNumState* pPrivate, - IppsBigNumState* pSignX, IppsBigNumState* pSignY, - IppsECCPState* pECC)) -{ - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test private key*/ - IPP_BAD_PTR1_RET(pPrivate); - pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); - - /* test message representative */ - IPP_BAD_PTR1_RET(pMsgDigest); - pMsgDigest = (IppsBigNumState*)( IPP_ALIGNED_PTR(pMsgDigest, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pMsgDigest), ippStsContextMatchErr); - IPP_BADARG_RET((0<=cpBN_cmp(pMsgDigest, ECP_ORDER(pECC))), ippStsMessageErr); - - /* test signature */ - IPP_BAD_PTR2_RET(pSignX,pSignY); - pSignX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignX, ALIGN_VAL) ); - pSignY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignY, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pSignX), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pSignY), ippStsContextMatchErr); - IPP_BADARG_RET((BN_ROOM(pSignX)*BITSIZE(BNU_CHUNK_T)GetPointAffine(pTmp, NULL, ECP_PUBLIC_E(pECC), pECC, pList); - - /* - // compute - // signX = eph_pub_x (mod order) - */ - PMA_mod(pSignX, pTmp, pOrder); - if( !IsZero_BN(pSignX) ) { - - IppsBigNumState* pEncMsg = cpBigNumListGet(&pList); - IppsBigNumState* pEncSignX = cpBigNumListGet(&pList); - PMA_enc(pEncMsg, (IppsBigNumState*)pMsgDigest, rMont); - PMA_enc(pEncSignX, pSignX, rMont); - - /* - // compute - // signY = (1/eph_private)*(pMsgDigest + private*signX) (mod order) - */ - PMA_inv(pSignY, ECP_PRIVATE_E(pECC), pOrder); - PMA_enc(ECP_PRIVATE_E(pECC), pPrivate, rMont); - PMA_mule(pTmp, ECP_PRIVATE_E(pECC), pEncSignX, rMont); - PMA_add(pTmp, pTmp, pEncMsg, pOrder); - PMA_mule(pSignY, pSignY, pTmp, rMont); - if( !IsZero_BN(pSignY) ) - return ippStsNoErr; - } - - return ippStsEphemeralKeyErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsscm.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsscm.c deleted file mode 100644 index 6978a0a8..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpeccpsscm.c +++ /dev/null @@ -1,160 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// ECCP SSCM stuff -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpbn.h" -#include "pcpeccppoint.h" - -#if defined (_USE_ECCP_SSCM_) -#pragma message ("ECCP SCCM version") - -//#define LOG2_CACHE_LINE_SIZE (6) /* LOG2(CACHE_LINE_SIZE) */ -#define LOG2_CACHE_LINE_SIZE (LOG_CACHE_LINE_SIZE) - -static int div_upper(int a, int d) -{ return (a+d-1)/d; } - -static int getNumOperations(int bitsize, int w) -{ - int n_overhead = (1<=n_opt) break; - w_opt = w_trial; - n_opt = n_trial; - } - return w_opt; -#undef LIMIT -} - -int cpECCP_ConvertRepresentation(BNU_CHUNK_T* pInput, int inpBits, int w) -{ - Ipp32u* pR = (Ipp32u*)pInput; - Ipp16u* pR16 = (Ipp16u*)pInput; - - int outBits = 0; - Ipp32u base = (BNU_CHUNK_T)1<>digitShift) &digitMask; - - Ipp32u delta = (base-digit) & ~digitMask; - delta <<= digitShift; - cpDec_BNU32((Ipp32u*)(pR16+chunkIdx), (Ipp32u*)(pR16+chunkIdx), (2*nsR-chunkIdx+1)/2, delta); - - inpBits = BITSIZE_BNU32(pR, nsR); - outBits += w; - } - - return outBits; -} - -/* -// cpsScramblePut/cpsScrambleGet -// stores to/retrieves from pScrambleEntry position -// pre-computed data if fixed window method is used -*/ -void cpECCP_ScramblePut(Ipp8u* pScrambleEntry, int proposity, - const IppsECCPPointState* pPoint, cpSize coordLen) -{ - int i; - Ipp8u* pCoord; - - BNU_CHUNK_T* pX = BN_NUMBER(ECP_POINT_X(pPoint)); - BNU_CHUNK_T* pY = BN_NUMBER(ECP_POINT_Y(pPoint)); - BNU_CHUNK_T* pZ = BN_NUMBER(ECP_POINT_Z(pPoint)); - int coordSize = coordLen*sizeof(BNU_CHUNK_T); - - ZEXPAND_BNU(pX, BN_SIZE(ECP_POINT_X(pPoint)), coordLen); - ZEXPAND_BNU(pY, BN_SIZE(ECP_POINT_Y(pPoint)), coordLen); - ZEXPAND_BNU(pZ, BN_SIZE(ECP_POINT_Z(pPoint)), coordLen); - - pCoord = (Ipp8u*)pX; - for(i=0; iidCtx -// illegal pMsgDigest->idCtx -// illegal pSignX->idCtx -// illegal pSignY->idCtx -// -// ippStsMessageErr MsgDigest >= order -// -// ippStsNoErr no errors -// -// Parameters: -// pMsgDigest pointer to the message representative to be signed -// pSignX,pSignY pointer to the signature -// pResult pointer to the result: ippECValid/ippECInvalidSignature -// pECC pointer to the ECCP context -// -// Note: -// - signer's key must be set up in ECCP context -// before ippsECCPVerifyDSA() usage -// -*F*/ -IPPFUN(IppStatus, ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, - const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, - IppECResult* pResult, - IppsECCPState* pECC)) -{ - IppsMontState* rMont; - - /* test pECC */ - IPP_BAD_PTR1_RET(pECC); - /* use aligned EC context */ - pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); - IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); - - /* test message representative */ - IPP_BAD_PTR1_RET(pMsgDigest); - pMsgDigest = (IppsBigNumState*)( IPP_ALIGNED_PTR(pMsgDigest, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pMsgDigest), ippStsContextMatchErr); - rMont = ECP_RMONT(pECC); - IPP_BADARG_RET((0<=cpBN_cmp(pMsgDigest, ECP_ORDER(pECC))), ippStsMessageErr); - - /* test result */ - IPP_BAD_PTR1_RET(pResult); - - /* test signature */ - IPP_BAD_PTR2_RET(pSignX,pSignY); - pSignX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignX, ALIGN_VAL) ); - pSignY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignY, ALIGN_VAL) ); - IPP_BADARG_RET(!BN_VALID_ID(pSignX), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pSignY), ippStsContextMatchErr); - - /* test signature value */ - if( (0>cpBN_tst(pSignX)) || (0>cpBN_tst(pSignY)) || - (0<=cpBN_cmp(pSignX, ECP_ORDER(pECC))) || - (0<=cpBN_cmp(pSignY, ECP_ORDER(pECC))) ) { - *pResult = ippECInvalidSignature; - return ippStsNoErr; - } - - /* validate signature */ - else { - IppsECCPPointState P1; - - BigNumNode* pList = ECP_BNCTX(pECC); - IppsBigNumState* pH1 = cpBigNumListGet(&pList); - IppsBigNumState* pH2 = cpBigNumListGet(&pList); - IppsBigNumState* pOrder = cpBigNumListGet(&pList); - BN_Set(MNT_MODULUS(rMont), MNT_SIZE(rMont), pOrder); - - ECP_POINT_X(&P1) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P1) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P1) = cpBigNumListGet(&pList); - - PMA_inv(pH1, (IppsBigNumState*)pSignY, pOrder);/* h = 1/signY (mod order) */ - PMA_enc(pH1, pH1, rMont); - PMA_mule(pH2, (IppsBigNumState*)pSignX, pH1, rMont); /* h2 = pSignX * h (mod order) */ - PMA_mule(pH1, (IppsBigNumState*)pMsgDigest, pH1, rMont); /* h1 = pMsgDigest * h (mod order) */ -#if 0 - /* compute h1*BasePoint + h2*publicKey */ - if(ippEC_TPM_SM2_P256 == ECP_TYPE(pECC)) { - IppsECCPPointState P0; - ECP_POINT_X(&P0) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P0) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P0) = cpBigNumListGet(&pList); - ECP_METHOD(pECC)->MulBasePoint(pH1, &P0, pECC, pList); - ECP_METHOD(pECC)->MulPoint(ECP_PUBLIC(pECC), pH2, &P1, pECC, pList); - ECP_METHOD(pECC)->AddPoint(&P1, &P0, &P1, pECC, pList); - } - else - ECP_METHOD(pECC)->ProdPoint(ECP_GENC(pECC), pH1, - ECP_PUBLIC(pECC), pH2, - &P1, pECC, pList); -#endif - /* compute h1*BasePoint + h2*publicKey */ - if((IppECCPStd128r1 == ECP_TYPE(pECC)) || (IppECCPStd128r2 == ECP_TYPE(pECC)) - ||(IppECCPStd192r1 == ECP_TYPE(pECC)) - ||(IppECCPStd224r1 == ECP_TYPE(pECC)) - ||(IppECCPStd256r1 == ECP_TYPE(pECC)) - ||(IppECCPStd384r1 == ECP_TYPE(pECC)) - ||(IppECCPStd521r1 == ECP_TYPE(pECC)) - ||(IppECCPStdSM2 == ECP_TYPE(pECC))) { - IppsECCPPointState P0; - ECP_POINT_X(&P0) = cpBigNumListGet(&pList); - ECP_POINT_Y(&P0) = cpBigNumListGet(&pList); - ECP_POINT_Z(&P0) = cpBigNumListGet(&pList); - ECP_METHOD(pECC)->MulBasePoint(pH1, &P0, pECC, pList); - ECP_METHOD(pECC)->MulPoint(ECP_PUBLIC(pECC), pH2, &P1, pECC, pList); - ECP_METHOD(pECC)->AddPoint(&P1, &P0, &P1, pECC, pList); - } - else - ECP_METHOD(pECC)->ProdPoint(ECP_GENC(pECC), pH1, - ECP_PUBLIC(pECC), pH2, - &P1, pECC, pList); - - if( ECCP_IsPointAtInfinity(&P1) ) { - *pResult = ippECInvalidSignature; - return ippStsNoErr; - } - /* extract X component */ - ECP_METHOD(pECC)->GetPointAffine(pH1, NULL, &P1, pECC, pList); - /* compare with signX */ - PMA_mod(pH1, pH1, pOrder); - *pResult = (0==cpBN_cmp(pH1, pSignX))? ippECValid : ippECInvalidSignature; - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphash.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphash.h deleted file mode 100644 index 6ffd67a3..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphash.h +++ /dev/null @@ -1,239 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Security Hash Standard -// Internal Definitions and Internal Functions Prototypes -// -// -*/ - -#if !defined(_PCP_HASH_H) -#define _PCP_HASH_H - - -/* messge block size */ -#define MBS_SHA1 (64) /* SHA1 message block size (bytes) */ -#define MBS_SHA256 (64) /* SHA256 and SHA224 */ -#define MBS_SHA224 (64) /* SHA224 */ -#define MBS_SHA512 (128) /* SHA512 and SHA384 */ -#define MBS_SHA384 (128) /* SHA384 */ -#define MBS_MD5 (64) /* MD5 */ -#define MBS_SM3 (64) /* SM3 */ -#define MBS_HASH_MAX (MBS_SHA512) /* max message block size (bytes) */ - -#define MAX_HASH_SIZE (IPP_SHA512_DIGEST_BITSIZE/8) /* hash of the max len (bytes) */ - -/* hold some old definition for a purpose */ -typedef Ipp32u DigestSHA1[5]; /* SHA1 digest */ -typedef Ipp32u DigestSHA224[7]; /* SHA224 digest */ -typedef Ipp32u DigestSHA256[8]; /* SHA256 digest */ -typedef Ipp64u DigestSHA384[6]; /* SHA384 digest */ -typedef Ipp64u DigestSHA512[8]; /* SHA512 digest */ -typedef Ipp32u DigestMD5[4]; /* MD5 digest */ -typedef Ipp32u DigestSM3[8]; /* SM3 digest */ - -#define SHA1_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define SHA224_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define SHA256_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define SHA384_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define SHA512_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define MD5_ALIGNMENT ((int)(sizeof(Ipp32u))) -#define SM3_ALIGNMENT ((int)(sizeof(Ipp32u))) - - -#if defined(_ENABLE_ALG_SHA1_) -struct _cpSHA1 { - IppCtxId idCtx; /* SHA1 identifier */ - int index; /* internal buffer entry (free) */ - Ipp64u msgLenLo; /* message length (bytes) */ - Ipp8u msgBuffer[MBS_SHA1]; /* buffer */ - DigestSHA1 msgHash; /* intermediate digest */ -}; -#endif - -#if defined(_ENABLE_ALG_SHA256_) || defined(_ENABLE_ALG_SHA224_) -struct _cpSHA256 { - IppCtxId idCtx; /* SHA224 identifier */ - int index; /* internal buffer entry (free) */ - Ipp64u msgLenLo; /* message length (bytes) */ - Ipp8u msgBuffer[MBS_SHA256]; /* buffer */ - DigestSHA256 msgHash; /* intermediate digest */ -}; -#endif - -#if defined(_ENABLE_ALG_SHA512_) || defined(_ENABLE_ALG_SHA384_) || defined(_ENABLE_ALG_SHA512_224_) || defined(_ENABLE_ALG_SHA512_256_) -struct _cpSHA512 { - IppCtxId idCtx; /* SHA384 identifier */ - int index; /* internal buffer entry (free) */ - Ipp64u msgLenLo; /* message length (bytes) */ - Ipp64u msgLenHi; /* message length (bytes) */ - Ipp8u msgBuffer[MBS_SHA512]; /* buffer */ - DigestSHA512 msgHash; /* intermediate digest */ -}; -#endif - -#if defined(_ENABLE_ALG_MD5_) -struct _cpMD5 { - IppCtxId idCtx; /* MD5 identifier */ - int index; /* internal buffer entry (free) */ - Ipp64u msgLenLo; /* message length (bytes) */ - Ipp8u msgBuffer[MBS_MD5]; /* buffer */ - DigestMD5 msgHash; /* intermediate digest */ -}; -#endif - -#if defined(_ENABLE_ALG_SM3_) -struct _cpSM3 { - IppCtxId idCtx; /* SM3 identifier */ - int index; /* internal buffer entry (free) */ - Ipp64u msgLenLo; /* message length (bits) */ - Ipp8u msgBuffer[MBS_SM3]; /* buffer */ - DigestSM3 msgHash; /* intermediate digest */ -}; -#endif - -/* -// Useful macros -*/ -#define SHS_ID(stt) ((stt)->idCtx) -#define SHS_INDX(stt) ((stt)->index) -#define SHS_LENL(stt) ((stt)->msgLenLo) -#define SHS_LENH(stt) ((stt)->msgLenHi) -#define SHS_BUFF(stt) ((stt)->msgBuffer) -#define SHS_HASH(stt) ((stt)->msgHash) - -/* initial hash values */ -extern const Ipp32u SHA1_IV[]; -extern const Ipp32u SHA256_IV[]; -extern const Ipp32u SHA224_IV[]; -extern const Ipp64u SHA512_IV[]; -extern const Ipp64u SHA384_IV[]; -extern const Ipp32u MD5_IV[]; -extern const Ipp32u SM3_IV[]; -extern const Ipp64u SHA512_224_IV[]; -extern const Ipp64u SHA512_256_IV[]; - -/* hash alg additive constants */ -extern __ALIGN16 const Ipp32u SHA1_cnt[]; -extern __ALIGN16 const Ipp32u SHA256_cnt[]; -extern __ALIGN16 const Ipp64u SHA512_cnt[]; -extern __ALIGN16 const Ipp32u MD5_cnt[]; -extern __ALIGN16 const Ipp32u SM3_cnt[]; - -/* */ - - -/* hash alg attributes */ -typedef struct _cpHashAttr { - int ivSize; /* attr: length (bytes) of initial value cpHashIV */ - int hashSize; /* attr: length (bytes) of hash */ - int msgBlkSize; /* attr: length (bytes) of message block */ - int msgLenRepSize; /* attr: length (bytes) in representation of processed message length */ - Ipp64u msgLenMax[2]; /* attr: max message length (bytes) (low high) */ -} cpHashAttr; - - -/* hash value */ -typedef Ipp64u cpHash[IPP_SHA512_DIGEST_BITSIZE/BITSIZE(Ipp64u)]; /* hash value */ - -/* hash update function */ -typedef void (*cpHashProc)(void* pHash, const Ipp8u* pMsg, int msgLen, const void* pParam); - - - -/* hash context */ -struct _cpHashCtx { - IppCtxId idCtx; /* hash identifier */ - IppHashAlgId algID; /* hash algorithm ID */ - Ipp64u msgLenLo; /* length (bytes) of processed message: */ - Ipp64u msgLenHi; /* low and high parts */ - cpHashProc hashProc; /* hash update function */ - const void* pParam; /* optional hashProc's parameter */ - cpHash hashVal; /* intermadiate has value */ - int buffOffset; /* current buffer position */ - Ipp8u msgBuffer[MBS_HASH_MAX]; /* buffer */ -}; - -/* accessors */ -#define HASH_CTX_ID(stt) ((stt)->idCtx) -#define HASH_ALG_ID(stt) ((stt)->algID) -#define HASH_LENLO(stt) ((stt)->msgLenLo) -#define HASH_LENHI(stt) ((stt)->msgLenHi) -#define HASH_FUNC(stt) ((stt)->hashProc) -#define HASH_FUNC_PAR(stt) ((stt)->pParam) -#define HASH_VALUE(stt) ((stt)->hashVal) -#define HAHS_BUFFIDX(stt) ((stt)->buffOffset) -#define HASH_BUFF(stt) ((stt)->msgBuffer) -#define HASH_VALID_ID(pCtx) (HASH_CTX_ID((pCtx))==idCtxHash) -/* old some old accessors */ -//#define SHS_DGST(stt) HASH_VALUE((stt)) -//#define SHS_BUFF(stt) HASH_BUFF((stt)) - - -/* hash alg opt argument */ -extern const void* cpHashProcFuncOpt[]; - -/* enabled hash alg */ -extern const IppHashAlgId cpEnabledHashAlgID[]; - -/* hash alg IV (init value) */ -extern const Ipp8u* cpHashIV[]; - -/* hash alg attribute DB */ -extern const cpHashAttr cpHashAlgAttr[]; - -/* IV size helper */ -__INLINE int cpHashIvSize(IppHashAlgId algID) -{ return cpHashAlgAttr[algID].ivSize; } - -/* hash size helper */ -__INLINE int cpHashSize(IppHashAlgId algID) -{ return cpHashAlgAttr[algID].hashSize; } - -/* message block size helper */ -__INLINE int cpHashMBS(IppHashAlgId algID) -{ return cpHashAlgAttr[algID].msgBlkSize; } - -/* maps algID into enabled IppHashAlgId value */ -__INLINE IppHashAlgId cpValidHashAlg(IppHashAlgId algID) -{ - /* maps algID into the valid range */ - algID = (((int)ippHashAlg_Unknown < (int)algID) && ((int)algID < (int)ippHashAlg_MaxNo))? algID : ippHashAlg_Unknown; - return cpEnabledHashAlgID[algID]; -} - - -/* processing functions */ -void UpdateSHA1 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -void UpdateSHA256(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -void UpdateSHA512(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -void UpdateMD5 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -void UpdateSM3 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); - -#if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) -void UpdateSHA1ni (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -void UpdateSHA256ni(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); -#endif - -/* general methods */ -//void cpHashUpdate(const Ipp8u* pSrc, int len, IppsHashState* pCtx, cpHashProc hashFunc, const void* pParam, int mbs); -int cpReInitHash(IppsHashState* pCtx, IppHashAlgId algID); - -#endif /* _PCP_HASH_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashcnt.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashcnt.c deleted file mode 100644 index 1202f371..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashcnt.c +++ /dev/null @@ -1,434 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Security Hash Standard -// Constants -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" - -#if defined( _IPP_DATA ) - -/* -// enabled hash alg IDs -*/ -const IppHashAlgId cpEnabledHashAlgID[] = { - IPP_ALG_HASH_UNKNOWN, - -#if defined(_ENABLE_ALG_SHA1_) - IPP_ALG_HASH_SHA1, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA256_) - IPP_ALG_HASH_SHA256, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA224_) - IPP_ALG_HASH_SHA224, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA512_) - IPP_ALG_HASH_SHA512, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA384_) - IPP_ALG_HASH_SHA384, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_MD5_) - IPP_ALG_HASH_MD5, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SM3_) - IPP_ALG_HASH_SM3, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA512_224_) - IPP_ALG_HASH_SHA512_224, -#else - IPP_ALG_HASH_UNKNOWN, -#endif - -#if defined(_ENABLE_ALG_SHA512_256_) - IPP_ALG_HASH_SHA512_256 -#else - IPP_ALG_HASH_UNKNOWN -#endif -}; -//////////////////////////////////////////////////////////// - -/* -// hash init values -*/ -const Ipp32u UnknownHash_IV[] = { - 0}; - -#if defined(_ENABLE_ALG_SHA1_) -const Ipp32u SHA1_IV[] = { - 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; -#endif - -#if defined(_ENABLE_ALG_SHA256_) -const Ipp32u SHA256_IV[] = { - 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, - 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19}; -#endif - -#if defined(_ENABLE_ALG_SHA224_) -const Ipp32u SHA224_IV[] = { - 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, - 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4}; -#endif - -#if defined(_ENABLE_ALG_SHA512_) -const Ipp64u SHA512_IV[] = { - CONST_64(0x6A09E667F3BCC908), CONST_64(0xBB67AE8584CAA73B), - CONST_64(0x3C6EF372FE94F82B), CONST_64(0xA54FF53A5F1D36F1), - CONST_64(0x510E527FADE682D1), CONST_64(0x9B05688C2B3E6C1F), - CONST_64(0x1F83D9ABFB41BD6B), CONST_64(0x5BE0CD19137E2179)}; -#endif - -#if defined(_ENABLE_ALG_SHA384_) -const Ipp64u SHA384_IV[] = { - CONST_64(0xCBBB9D5DC1059ED8), CONST_64(0x629A292A367CD507), - CONST_64(0x9159015A3070DD17), CONST_64(0x152FECD8F70E5939), - CONST_64(0x67332667FFC00B31), CONST_64(0x8EB44A8768581511), - CONST_64(0xDB0C2E0D64F98FA7), CONST_64(0x47B5481DBEFA4FA4)}; -#endif - -#if defined(_ENABLE_ALG_MD5_) -const Ipp32u MD5_IV[] = { - 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}; -#endif - -#if defined(_ENABLE_ALG_SM3_) -const Ipp32u SM3_IV[] = { - 0x7380166F, 0x4914B2B9, 0x172442D7, 0xDA8A0600, - 0xA96F30BC, 0x163138AA, 0xE38DEE4D, 0xB0FB0E4E}; -#endif - -#if defined(_ENABLE_ALG_SHA512_224_) -const Ipp64u SHA512_224_IV[] = { - CONST_64(0x8C3D37C819544DA2), CONST_64(0x73E1996689DCD4D6), - CONST_64(0x1DFAB7AE32FF9C82), CONST_64(0x679DD514582F9FCF), - CONST_64(0x0F6D2B697BD44DA8), CONST_64(0x77E36F7304C48942), - CONST_64(0x3F9D85A86A1D36C8), CONST_64(0x1112E6AD91D692A1)}; -#endif - -#if defined(_ENABLE_ALG_SHA512_256_) -const Ipp64u SHA512_256_IV[] = { - CONST_64(0x22312194FC2BF72C), CONST_64(0x9F555FA3C84C64C2), - CONST_64(0x2393B86B6F53B151), CONST_64(0x963877195940EABD), - CONST_64(0x96283EE2A88EFFE3), CONST_64(0xBE5E1E2553863992), - CONST_64(0x2B0199FC2C85B8AA), CONST_64(0x0EB72DDC81C52CA2)}; -#endif - -const Ipp8u* cpHashIV[] = { - (Ipp8u*)UnknownHash_IV, - - #if defined(_ENABLE_ALG_SHA1_) - (Ipp8u*)SHA1_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA256_) - (Ipp8u*)SHA256_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA224_) - (Ipp8u*)SHA224_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA512_) - (Ipp8u*)SHA512_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA384_) - (Ipp8u*)SHA384_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_MD5_) - (Ipp8u*)MD5_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SM3_) - (Ipp8u*)SM3_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA512_224_) - (Ipp8u*)SHA512_224_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif - - #if defined(_ENABLE_ALG_SHA512_256_) - (Ipp8u*)SHA512_256_IV, - #else - (Ipp8u*)UnknownHash_IV, - #endif -}; - -//////////////////////////////////////////////////////////// - -/* -// additive constatns -*/ -#if defined(_ENABLE_ALG_SHA1_) -__ALIGN16 const Ipp32u SHA1_cnt[] = { - 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 -}; -#endif - -#if defined(_ENABLE_ALG_SHA256_) || defined(_ENABLE_ALG_SHA224_) -__ALIGN16 const Ipp32u SHA256_cnt[] = { - 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, - 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, - 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, - 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, - 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, - 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, - 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, - 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, - 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, - 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, - 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, - 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, - 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, - 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, - 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, - 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 -}; -#endif - -#if defined(_ENABLE_ALG_SHA512_) || defined(_ENABLE_ALG_SHA384_) || defined(_ENABLE_ALG_SHA512_224_) || defined(_ENABLE_ALG_SHA512_256_) -__ALIGN16 const Ipp64u SHA512_cnt[] = { - CONST_64(0x428A2F98D728AE22), CONST_64(0x7137449123EF65CD), CONST_64(0xB5C0FBCFEC4D3B2F), CONST_64(0xE9B5DBA58189DBBC), - CONST_64(0x3956C25BF348B538), CONST_64(0x59F111F1B605D019), CONST_64(0x923F82A4AF194F9B), CONST_64(0xAB1C5ED5DA6D8118), - CONST_64(0xD807AA98A3030242), CONST_64(0x12835B0145706FBE), CONST_64(0x243185BE4EE4B28C), CONST_64(0x550C7DC3D5FFB4E2), - CONST_64(0x72BE5D74F27B896F), CONST_64(0x80DEB1FE3B1696B1), CONST_64(0x9BDC06A725C71235), CONST_64(0xC19BF174CF692694), - CONST_64(0xE49B69C19EF14AD2), CONST_64(0xEFBE4786384F25E3), CONST_64(0x0FC19DC68B8CD5B5), CONST_64(0x240CA1CC77AC9C65), - CONST_64(0x2DE92C6F592B0275), CONST_64(0x4A7484AA6EA6E483), CONST_64(0x5CB0A9DCBD41FBD4), CONST_64(0x76F988DA831153B5), - CONST_64(0x983E5152EE66DFAB), CONST_64(0xA831C66D2DB43210), CONST_64(0xB00327C898FB213F), CONST_64(0xBF597FC7BEEF0EE4), - CONST_64(0xC6E00BF33DA88FC2), CONST_64(0xD5A79147930AA725), CONST_64(0x06CA6351E003826F), CONST_64(0x142929670A0E6E70), - CONST_64(0x27B70A8546D22FFC), CONST_64(0x2E1B21385C26C926), CONST_64(0x4D2C6DFC5AC42AED), CONST_64(0x53380D139D95B3DF), - CONST_64(0x650A73548BAF63DE), CONST_64(0x766A0ABB3C77B2A8), CONST_64(0x81C2C92E47EDAEE6), CONST_64(0x92722C851482353B), - CONST_64(0xA2BFE8A14CF10364), CONST_64(0xA81A664BBC423001), CONST_64(0xC24B8B70D0F89791), CONST_64(0xC76C51A30654BE30), - CONST_64(0xD192E819D6EF5218), CONST_64(0xD69906245565A910), CONST_64(0xF40E35855771202A), CONST_64(0x106AA07032BBD1B8), - CONST_64(0x19A4C116B8D2D0C8), CONST_64(0x1E376C085141AB53), CONST_64(0x2748774CDF8EEB99), CONST_64(0x34B0BCB5E19B48A8), - CONST_64(0x391C0CB3C5C95A63), CONST_64(0x4ED8AA4AE3418ACB), CONST_64(0x5B9CCA4F7763E373), CONST_64(0x682E6FF3D6B2B8A3), - CONST_64(0x748F82EE5DEFB2FC), CONST_64(0x78A5636F43172F60), CONST_64(0x84C87814A1F0AB72), CONST_64(0x8CC702081A6439EC), - CONST_64(0x90BEFFFA23631E28), CONST_64(0xA4506CEBDE82BDE9), CONST_64(0xBEF9A3F7B2C67915), CONST_64(0xC67178F2E372532B), - CONST_64(0xCA273ECEEA26619C), CONST_64(0xD186B8C721C0C207), CONST_64(0xEADA7DD6CDE0EB1E), CONST_64(0xF57D4F7FEE6ED178), - CONST_64(0x06F067AA72176FBA), CONST_64(0x0A637DC5A2C898A6), CONST_64(0x113F9804BEF90DAE), CONST_64(0x1B710B35131C471B), - CONST_64(0x28DB77F523047D84), CONST_64(0x32CAAB7B40C72493), CONST_64(0x3C9EBE0A15C9BEBC), CONST_64(0x431D67C49C100D4C), - CONST_64(0x4CC5D4BECB3E42B6), CONST_64(0x597F299CFC657E2A), CONST_64(0x5FCB6FAB3AD6FAEC), CONST_64(0x6C44198C4A475817) -}; -#endif - -#if defined(_ENABLE_ALG_MD5_) -__ALIGN16 const Ipp32u MD5_cnt[] = { - 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, - 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, - 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, - 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, - - 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, - 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, - 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, - 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, - - 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, - 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, - 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, - 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, - - 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, - 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, - 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, - 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 -}; -#endif - -#if defined(_ENABLE_ALG_SM3_) -__ALIGN16 const Ipp32u SM3_cnt[] = { - 0x79CC4519,0xF3988A32,0xE7311465,0xCE6228CB,0x9CC45197,0x3988A32F,0x7311465E,0xE6228CBC, - 0xCC451979,0x988A32F3,0x311465E7,0x6228CBCE,0xC451979C,0x88A32F39,0x11465E73,0x228CBCE6, - 0x9D8A7A87,0x3B14F50F,0x7629EA1E,0xEC53D43C,0xD8A7A879,0xB14F50F3,0x629EA1E7,0xC53D43CE, - 0x8A7A879D,0x14F50F3B,0x29EA1E76,0x53D43CEC,0xA7A879D8,0x4F50F3B1,0x9EA1E762,0x3D43CEC5, - 0x7A879D8A,0xF50F3B14,0xEA1E7629,0xD43CEC53,0xA879D8A7,0x50F3B14F,0xA1E7629E,0x43CEC53D, - 0x879D8A7A,0x0F3B14F5,0x1E7629EA,0x3CEC53D4,0x79D8A7A8,0xF3B14F50,0xE7629EA1,0xCEC53D43, - 0x9D8A7A87,0x3B14F50F,0x7629EA1E,0xEC53D43C,0xD8A7A879,0xB14F50F3,0x629EA1E7,0xC53D43CE, - 0x8A7A879D,0x14F50F3B,0x29EA1E76,0x53D43CEC,0xA7A879D8,0x4F50F3B1,0x9EA1E762,0x3D43CEC5 -}; -#endif - -/* -// hash alg default processing opt argument -*/ -const void* cpHashProcFuncOpt[] = { - NULL, - - #if defined(_ENABLE_ALG_SHA1_) - SHA1_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA256_) - SHA256_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA224_) - SHA256_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA512_) - SHA512_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA384_) - SHA512_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_MD5_) - MD5_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SM3_) - SM3_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA512_224_) - SHA512_cnt, - #else - NULL, - #endif - - #if defined(_ENABLE_ALG_SHA512_256_) - SHA512_cnt, - #else - NULL, - #endif -}; -//////////////////////////////////////////////////////////// - -/* hash alg attributes */ -const cpHashAttr cpHashAlgAttr[] = { - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, /* unknown */ - -#if defined(_ENABLE_ALG_SHA1_) /* sha1 / unknown */ - {IPP_SHA1_DIGEST_BITSIZE/8, IPP_SHA1_DIGEST_BITSIZE/8, MBS_SHA1, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA256_) /* sha256 / unknown */ - {IPP_SHA256_DIGEST_BITSIZE/8,IPP_SHA256_DIGEST_BITSIZE/8, MBS_SHA256, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA224_) /* sha224 / unknown */ - {IPP_SHA256_DIGEST_BITSIZE/8,IPP_SHA224_DIGEST_BITSIZE/8, MBS_SHA224, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA512_) /* sha512 / unknown */ - {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA384_) /* sha384 / unknown */ - {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA384_DIGEST_BITSIZE/8, MBS_SHA384, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_MD5_) /* md5 / unknown */ - {IPP_MD5_DIGEST_BITSIZE/8,IPP_MD5_DIGEST_BITSIZE/8, MBS_MD5, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SM3_) /* sm3 / unknown */ - {IPP_SM3_DIGEST_BITSIZE/8,IPP_SM3_DIGEST_BITSIZE/8, MBS_SM3, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA512_224_) /* sha512/224 / unknown */ - {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_224_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, -#endif - -#if defined(_ENABLE_ALG_SHA512_256_) /* sha512/256 / unknown */ - {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_256_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}} -#else - {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}} -#endif -}; - -#endif /* _IPP_DATA */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashmd5px.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashmd5px.c deleted file mode 100644 index 6eea7950..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashmd5px.c +++ /dev/null @@ -1,211 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Message block processing according to MD5 -// -// Contents: -// UpdateMD5() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - -#if !defined(_ENABLE_ALG_MD5_) -#pragma message("IPP_ALG_HASH_MD5 disabled") - -#else -#pragma message("IPP_ALG_HASH_MD5 enabled") - -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_M5) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) - - -/* -// Magic functions defined in RFC 1321 -// -*/ -#define F(X,Y,Z) ((Z) ^ ((X) & ((Y) ^ (Z)))) /* sightly optimized form of (((X) & (Y)) | ((~(X) & (Z)))*/ -#define G(X,Y,Z) F((Z),(X),(Y)) /* replace the original (((X) & (Z)) | ((Y) & ~(Z))) */ -#define H(X,Y,Z) ((X) ^ (Y) ^ (Z)) -#define I(X,Y,Z) ((Y) ^ ((X) | ~(Z))) - -/* -// MD5 step -*/ -#define MD5_STEP(MAGIC, A,B,C,D, data, constant, nrot) \ - (A = B +ROL32((A +MAGIC(B,C,D) +data +constant), nrot)) - -/* -// MD5 left rotations (number of bits) -// depends on round type -*/ -#define F1 7 -#define F2 12 -#define F3 17 -#define F4 22 - -#define G1 5 -#define G2 9 -#define G3 14 -#define G4 20 - -#define H1 4 -#define H2 11 -#define H3 16 -#define H4 23 - -#define I1 6 -#define I2 10 -#define I3 15 -#define I4 21 - -/*F* -// Name: UpdateMD5 -// -// Purpose: Update internal hash according to input message stream. -// -// Parameters: -// uniHash pointer to in/out hash -// mblk pointer to message stream -// mlen message stream length (multiple by message block size) -// uniParam pointer to the optional parameter -// -*F*/ -void UpdateMD5(void* uinHash, const Ipp8u* mblk, int mlen, const void* uniParam) -{ - Ipp32u* digest = (Ipp32u*)uinHash; - Ipp32u* MD5_cnt_loc = (Ipp32u*)uniParam; - - for(; mlen>=MBS_MD5; mblk += MBS_MD5, mlen -= MBS_MD5) { - - /* allocate data */ - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - Ipp32u data[MBS_MD5/sizeof(Ipp32u)]; - #else - /* or just word alias */ - Ipp32u* data = (Ipp32u*)mblk; - #endif - - /* init variables */ - Ipp32u a = digest[0]; - Ipp32u b = digest[1]; - Ipp32u c = digest[2]; - Ipp32u d = digest[3]; - - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - int t; - for(t=0; t<16; t++) { - data[t] = ENDIANNESS(((Ipp32u*)mblk)[t]); - } - #endif - - /* rounds type F */ - MD5_STEP(F, a,b,c,d, data[ 0], MD5_cnt_loc[ 0], F1); - MD5_STEP(F, d,a,b,c, data[ 1], MD5_cnt_loc[ 1], F2); - MD5_STEP(F, c,d,a,b, data[ 2], MD5_cnt_loc[ 2], F3); - MD5_STEP(F, b,c,d,a, data[ 3], MD5_cnt_loc[ 3], F4); - MD5_STEP(F, a,b,c,d, data[ 4], MD5_cnt_loc[ 4], F1); - MD5_STEP(F, d,a,b,c, data[ 5], MD5_cnt_loc[ 5], F2); - MD5_STEP(F, c,d,a,b, data[ 6], MD5_cnt_loc[ 6], F3); - MD5_STEP(F, b,c,d,a, data[ 7], MD5_cnt_loc[ 7], F4); - MD5_STEP(F, a,b,c,d, data[ 8], MD5_cnt_loc[ 8], F1); - MD5_STEP(F, d,a,b,c, data[ 9], MD5_cnt_loc[ 9], F2); - MD5_STEP(F, c,d,a,b, data[10], MD5_cnt_loc[10], F3); - MD5_STEP(F, b,c,d,a, data[11], MD5_cnt_loc[11], F4); - MD5_STEP(F, a,b,c,d, data[12], MD5_cnt_loc[12], F1); - MD5_STEP(F, d,a,b,c, data[13], MD5_cnt_loc[13], F2); - MD5_STEP(F, c,d,a,b, data[14], MD5_cnt_loc[14], F3); - MD5_STEP(F, b,c,d,a, data[15], MD5_cnt_loc[15], F4); - - /* rounds type G */ - MD5_STEP(G, a,b,c,d, data[ 1], MD5_cnt_loc[16], G1); - MD5_STEP(G, d,a,b,c, data[ 6], MD5_cnt_loc[17], G2); - MD5_STEP(G, c,d,a,b, data[11], MD5_cnt_loc[18], G3); - MD5_STEP(G, b,c,d,a, data[ 0], MD5_cnt_loc[19], G4); - MD5_STEP(G, a,b,c,d, data[ 5], MD5_cnt_loc[20], G1); - MD5_STEP(G, d,a,b,c, data[10], MD5_cnt_loc[21], G2); - MD5_STEP(G, c,d,a,b, data[15], MD5_cnt_loc[22], G3); - MD5_STEP(G, b,c,d,a, data[ 4], MD5_cnt_loc[23], G4); - MD5_STEP(G, a,b,c,d, data[ 9], MD5_cnt_loc[24], G1); - MD5_STEP(G, d,a,b,c, data[14], MD5_cnt_loc[25], G2); - MD5_STEP(G, c,d,a,b, data[ 3], MD5_cnt_loc[26], G3); - MD5_STEP(G, b,c,d,a, data[ 8], MD5_cnt_loc[27], G4); - MD5_STEP(G, a,b,c,d, data[13], MD5_cnt_loc[28], G1); - MD5_STEP(G, d,a,b,c, data[ 2], MD5_cnt_loc[29], G2); - MD5_STEP(G, c,d,a,b, data[ 7], MD5_cnt_loc[30], G3); - MD5_STEP(G, b,c,d,a, data[12], MD5_cnt_loc[31], G4); - - /* rounds type H */ - MD5_STEP(H, a,b,c,d, data[ 5], MD5_cnt_loc[32], H1); - MD5_STEP(H, d,a,b,c, data[ 8], MD5_cnt_loc[33], H2); - MD5_STEP(H, c,d,a,b, data[11], MD5_cnt_loc[34], H3); - MD5_STEP(H, b,c,d,a, data[14], MD5_cnt_loc[35], H4); - MD5_STEP(H, a,b,c,d, data[ 1], MD5_cnt_loc[36], H1); - MD5_STEP(H, d,a,b,c, data[ 4], MD5_cnt_loc[37], H2); - MD5_STEP(H, c,d,a,b, data[ 7], MD5_cnt_loc[38], H3); - MD5_STEP(H, b,c,d,a, data[10], MD5_cnt_loc[39], H4); - MD5_STEP(H, a,b,c,d, data[13], MD5_cnt_loc[40], H1); - MD5_STEP(H, d,a,b,c, data[ 0], MD5_cnt_loc[41], H2); - MD5_STEP(H, c,d,a,b, data[ 3], MD5_cnt_loc[42], H3); - MD5_STEP(H, b,c,d,a, data[ 6], MD5_cnt_loc[43], H4); - MD5_STEP(H, a,b,c,d, data[ 9], MD5_cnt_loc[44], H1); - MD5_STEP(H, d,a,b,c, data[12], MD5_cnt_loc[45], H2); - MD5_STEP(H, c,d,a,b, data[15], MD5_cnt_loc[46], H3); - MD5_STEP(H, b,c,d,a, data[ 2], MD5_cnt_loc[47], H4); - - /* rounds type I */ - MD5_STEP(I, a,b,c,d, data[ 0], MD5_cnt_loc[48], I1); - MD5_STEP(I, d,a,b,c, data[ 7], MD5_cnt_loc[49], I2); - MD5_STEP(I, c,d,a,b, data[14], MD5_cnt_loc[50], I3); - MD5_STEP(I, b,c,d,a, data[ 5], MD5_cnt_loc[51], I4); - MD5_STEP(I, a,b,c,d, data[12], MD5_cnt_loc[52], I1); - MD5_STEP(I, d,a,b,c, data[ 3], MD5_cnt_loc[53], I2); - MD5_STEP(I, c,d,a,b, data[10], MD5_cnt_loc[54], I3); - MD5_STEP(I, b,c,d,a, data[ 1], MD5_cnt_loc[55], I4); - MD5_STEP(I, a,b,c,d, data[ 8], MD5_cnt_loc[56], I1); - MD5_STEP(I, d,a,b,c, data[15], MD5_cnt_loc[57], I2); - MD5_STEP(I, c,d,a,b, data[ 6], MD5_cnt_loc[58], I3); - MD5_STEP(I, b,c,d,a, data[13], MD5_cnt_loc[59], I4); - MD5_STEP(I, a,b,c,d, data[ 4], MD5_cnt_loc[60], I1); - MD5_STEP(I, d,a,b,c, data[11], MD5_cnt_loc[61], I2); - MD5_STEP(I, c,d,a,b, data[ 2], MD5_cnt_loc[62], I3); - MD5_STEP(I, b,c,d,a, data[ 9], MD5_cnt_loc[63], I4); - - /* update digest */ - digest[0] += a; - digest[1] += b; - digest[2] += c; - digest[3] += d; - } -} - -#endif -#endif /* IPP_ALG_HASH_MD5 */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha1px.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha1px.c deleted file mode 100644 index ab0d68f3..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha1px.c +++ /dev/null @@ -1,189 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Message block processing according to SHA1 -// -// Contents: -// UpdateSHA1() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - -//#if !defined(_ENABLE_ALG_SHA1_) -//#pragma message("IPP_ALG_HASH_SHA1 disabled") - -//#else -//#pragma message("IPP_ALG_HASH_SHA1 enabled") - -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_M5) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) - -/* -// Magic functions defined in FIPS 180-1 -// -*/ -#define MAGIC_F0(B,C,D) (((B) & (C)) | ((~(B)) & (D))) -#define MAGIC_F1(B,C,D) ((B) ^ (C) ^ (D)) -#define MAGIC_F2(B,C,D) (((B) & (C)) | ((B) & (D)) | ((C) & (D))) -#define MAGIC_F3(B,C,D) ((B) ^ (C) ^ (D)) - -#define SHA1_STEP(A,B,C,D,E, MAGIC_FUN, W,K) \ - (E)+= ROL32((A),5) + MAGIC_FUN((B),(C),(D)) + (W) + (K); \ - (B) = ROL32((B),30) - -#define COMPACT_SHA1_STEP(A,B,C,D,E, MAGIC_FUN, W,K, t) { \ - Ipp32u _T = ROL32((A),5) + MAGIC_FUN((t)/20, (B),(C),(D)) + (E) + (W)[(t)] + (K)[(t)/20]; \ - (E) = (D); \ - (D) = (C); \ - (C) = ROL32((B),30); \ - (B) = (A); \ - (A) = _T; \ -} - -#if defined(_ALG_SHA1_COMPACT_) -__INLINE Ipp32u MagicFun(int s, Ipp32u b, Ipp32u c, Ipp32u d) -{ - switch(s) { - case 0: return MAGIC_F0(b,c,d); - case 2: return MAGIC_F2(b,c,d); - default:return MAGIC_F1(b,c,d); - } -} -#endif - - -/*F* -// Name: UpdateSHA1 -// -// Purpose: Update internal hash according to input message stream. -// -// Parameters: -// uniHash pointer to in/out hash -// mblk pointer to message stream -// mlen message stream length (multiple by message block size) -// uniParam pointer to the optional parameter -// -*F*/ -#if defined(_ALG_SHA1_COMPACT_) -#pragma message("SHA1 compact") -#endif - -void UpdateSHA1(void* uinHash, const Ipp8u* mblk, int mlen, const void *uniParam) -{ - Ipp32u* data = (Ipp32u*)mblk; - - Ipp32u* digest = (Ipp32u*)uinHash; - Ipp32u* SHA1_cnt_loc = (Ipp32u*)uniParam; - - for(; mlen>=MBS_SHA1; data += MBS_SHA1/sizeof(Ipp32u), mlen -= MBS_SHA1) { - int t; - - /* - // expand message block - */ - Ipp32u W[80]; - /* initialize the first 16 words in the array W (remember about endian) */ - for(t=0; t<16; t++) { - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - W[t] = data[t]; - #else - W[t] = ENDIANNESS(data[t]); - #endif - } - /* schedule another 80-16 words in the array W */ - for(; t<80; t++) { - W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1); - } - - /* - // update hash - */ - { - /* init A, B, C, D, E by the the input hash */ - Ipp32u A = digest[0]; - Ipp32u B = digest[1]; - Ipp32u C = digest[2]; - Ipp32u D = digest[3]; - Ipp32u E = digest[4]; - - #if defined(_ALG_SHA1_COMPACT_) - /* steps 0-79 */ - for(t=0; t<80; t++) - COMPACT_SHA1_STEP(A,B,C,D,E, MagicFun, W, SHA1_cnt_loc, t); - - #else - /* perform 0-19 steps */ - for(t=0; t<20; t+=5) { - SHA1_STEP(A,B,C,D,E, MAGIC_F0, W[t ],SHA1_cnt_loc[0]); - SHA1_STEP(E,A,B,C,D, MAGIC_F0, W[t+1],SHA1_cnt_loc[0]); - SHA1_STEP(D,E,A,B,C, MAGIC_F0, W[t+2],SHA1_cnt_loc[0]); - SHA1_STEP(C,D,E,A,B, MAGIC_F0, W[t+3],SHA1_cnt_loc[0]); - SHA1_STEP(B,C,D,E,A, MAGIC_F0, W[t+4],SHA1_cnt_loc[0]); - } - /* perform 20-39 steps */ - for(; t<40; t+=5) { - SHA1_STEP(A,B,C,D,E, MAGIC_F1, W[t ],SHA1_cnt_loc[1]); - SHA1_STEP(E,A,B,C,D, MAGIC_F1, W[t+1],SHA1_cnt_loc[1]); - SHA1_STEP(D,E,A,B,C, MAGIC_F1, W[t+2],SHA1_cnt_loc[1]); - SHA1_STEP(C,D,E,A,B, MAGIC_F1, W[t+3],SHA1_cnt_loc[1]); - SHA1_STEP(B,C,D,E,A, MAGIC_F1, W[t+4],SHA1_cnt_loc[1]); - } - /* perform 40-59 steps */ - for(; t<60; t+=5) { - SHA1_STEP(A,B,C,D,E, MAGIC_F2, W[t ],SHA1_cnt_loc[2]); - SHA1_STEP(E,A,B,C,D, MAGIC_F2, W[t+1],SHA1_cnt_loc[2]); - SHA1_STEP(D,E,A,B,C, MAGIC_F2, W[t+2],SHA1_cnt_loc[2]); - SHA1_STEP(C,D,E,A,B, MAGIC_F2, W[t+3],SHA1_cnt_loc[2]); - SHA1_STEP(B,C,D,E,A, MAGIC_F2, W[t+4],SHA1_cnt_loc[2]); - } - /* perform 60-79 steps */ - for(; t<80; t+=5) { - SHA1_STEP(A,B,C,D,E, MAGIC_F3, W[t ],SHA1_cnt_loc[3]); - SHA1_STEP(E,A,B,C,D, MAGIC_F3, W[t+1],SHA1_cnt_loc[3]); - SHA1_STEP(D,E,A,B,C, MAGIC_F3, W[t+2],SHA1_cnt_loc[3]); - SHA1_STEP(C,D,E,A,B, MAGIC_F3, W[t+3],SHA1_cnt_loc[3]); - SHA1_STEP(B,C,D,E,A, MAGIC_F3, W[t+4],SHA1_cnt_loc[3]); - } - #endif - - /* update digest */ - digest[0] += A; - digest[1] += B; - digest[2] += C; - digest[3] += D; - digest[4] += E; - } - } -} - -#endif -//#endif /* IPP_ALG_HASH_SHA1 */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha256px.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha256px.c deleted file mode 100644 index e355de3c..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha256px.c +++ /dev/null @@ -1,214 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Message block processing according to SHA256 -// -// Contents: -// UpdateSHA256() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - -#if !defined(_ENABLE_ALG_SHA256_) && !defined(_ENABLE_ALG_SHA224_) -#pragma message("IPP_ALG_HASH_SHA256 disabled") - -#else -#pragma message("IPP_ALG_HASH_SHA256 enabled") - -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_M5) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) - -/* -// SHA256 Specific Macros (reference proposal 256-384-512) -*/ -#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z))) -#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) - -#define SUM0(x) (ROR32((x), 2) ^ ROR32((x),13) ^ ROR32((x),22)) -#define SUM1(x) (ROR32((x), 6) ^ ROR32((x),11) ^ ROR32((x),25)) - -#define SIG0(x) (ROR32((x), 7) ^ ROR32((x),18) ^ LSR32((x), 3)) -#define SIG1(x) (ROR32((x),17) ^ ROR32((x),19) ^ LSR32((x),10)) - -#define SHA256_UPDATE(i) \ - wdat[i & 15] += SIG1(wdat[(i+14)&15]) + wdat[(i+9)&15] + SIG0(wdat[(i+1)&15]) - -#define SHA256_STEP(i,j) \ - v[(7 - i) & 7] += (j ? SHA256_UPDATE(i) : wdat[i&15]) \ - + SHA256_cnt_loc[i + j] \ - + SUM1(v[(4-i)&7]) \ - + CH(v[(4-i)&7], v[(5-i)&7], v[(6-i)&7]); \ - v[(3-i)&7] += v[(7-i)&7]; \ - v[(7-i)&7] += SUM0(v[(0-i)&7]) + MAJ(v[(0-i)&7], v[(1-i)&7], v[(2-i)&7]) - -#define COMPACT_SHA256_STEP(A,B,C,D,E,F,G,H, W,K, r) { \ - Ipp32u _T1 = (H) + SUM1((E)) + CH((E),(F),(G)) + (W)[(r)] + (K)[(r)]; \ - Ipp32u _T2 = SUM0((A)) + MAJ((A),(B),(C)); \ - (H) = (G); \ - (G) = (F); \ - (F) = (E); \ - (E) = (D)+_T1; \ - (D) = (C); \ - (C) = (B); \ - (B) = (A); \ - (A) = _T1+_T2; \ -} - -/*F* -// Name: UpdateSHA256 -// -// Purpose: Update internal hash according to input message stream. -// -// Parameters: -// uniHash pointer to in/out hash -// mblk pointer to message stream -// mlen message stream length (multiple by message block size) -// uniParam pointer to the optional parameter -// -*F*/ -#if defined(_ALG_SHA256_COMPACT_) -#pragma message("SHA256 compact") - -void UpdateSHA256(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniParam) -{ - Ipp32u* data = (Ipp32u*)mblk; - - Ipp32u* digest = (Ipp32u*)uniHash; - Ipp32u* SHA256_cnt_loc = (Ipp32u*)uniParam; - - for(; mlen>=MBS_SHA256; data += MBS_SHA256/sizeof(Ipp32u), mlen -= MBS_SHA256) { - int t; - - /* - // expand message block - */ - Ipp32u W[64]; - /* initialize the first 16 words in the array W (remember about endian) */ - for(t=0; t<16; t++) { - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - W[t] = data[t]; - #else - W[t] = ENDIANNESS( data[t] ); - #endif - } - for(; t<64; t++) - W[t] = SIG1(W[t-2]) + W[t-7] + SIG0(W[t-15]) + W[t-16]; - - /* - // update hash - */ - { - /* init A, B, C, D, E, F, G, H by the input hash */ - Ipp32u A = digest[0]; - Ipp32u B = digest[1]; - Ipp32u C = digest[2]; - Ipp32u D = digest[3]; - Ipp32u E = digest[4]; - Ipp32u F = digest[5]; - Ipp32u G = digest[6]; - Ipp32u H = digest[7]; - - for(t=0; t<64; t++) - COMPACT_SHA256_STEP(A,B,C,D,E,F,G,H, W,SHA256_cnt_loc, t); - - /* update hash*/ - digest[0] += A; - digest[1] += B; - digest[2] += C; - digest[3] += D; - digest[4] += E; - digest[5] += F; - digest[6] += G; - digest[7] += H; - } - } -} - -#else -void UpdateSHA256(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniParam) -{ - Ipp32u* data = (Ipp32u*)mblk; - - Ipp32u* digest = (Ipp32u*)uniHash; - Ipp32u* SHA256_cnt_loc = (Ipp32u*)uniParam; - - for(; mlen>=MBS_SHA256; data += MBS_SHA256/sizeof(Ipp32u), mlen -= MBS_SHA256) { - Ipp32u wdat[16]; - int j; - - /* copy digest */ - Ipp32u v[8]; - CopyBlock(digest, v, IPP_SHA256_DIGEST_BITSIZE/BYTESIZE); - - /* initialize the first 16 words in the array W (remember about endian) */ - for(j=0; j<16; j++) { - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - wdat[j] = data[j]; - #else - wdat[j] = ENDIANNESS( data[j] ); - #endif - } - - for(j=0; j<64; j+=16) { - SHA256_STEP( 0, j); - SHA256_STEP( 1, j); - SHA256_STEP( 2, j); - SHA256_STEP( 3, j); - SHA256_STEP( 4, j); - SHA256_STEP( 5, j); - SHA256_STEP( 6, j); - SHA256_STEP( 7, j); - SHA256_STEP( 8, j); - SHA256_STEP( 9, j); - SHA256_STEP(10, j); - SHA256_STEP(11, j); - SHA256_STEP(12, j); - SHA256_STEP(13, j); - SHA256_STEP(14, j); - SHA256_STEP(15, j); - } - - /* update digest */ - digest[0] += v[0]; - digest[1] += v[1]; - digest[2] += v[2]; - digest[3] += v[3]; - digest[4] += v[4]; - digest[5] += v[5]; - digest[6] += v[6]; - digest[7] += v[7]; - } -} -#endif - -#endif -#endif /* IPP_ALG_HASH_SHA256 */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha512px.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha512px.c deleted file mode 100644 index 9e6d5fcb..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcphashsha512px.c +++ /dev/null @@ -1,221 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Message block processing according to SHA512 -// -// Contents: -// UpdateSHA512() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - -#if !defined(_ENABLE_ALG_SHA512_) && !defined(_ENABLE_ALG_SHA_SHA384_) && !defined(_ENABLE_ALG_SHA512_224_) && !defined(_ENABLE_ALG_SHA512_256_) -#pragma message("IPP_ALG_HASH_SHA512 disabled") - -#else -#pragma message("IPP_ALG_HASH_SHA512 enabled") - -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) - -/* -// SHA512 Specific Macros (reference proposal 256-384-512) -// -// Note: All operations act on DWORDs (64-bits) -*/ -#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z))) -#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) - -#define SUM0(x) (ROR64((x),28) ^ ROR64((x),34) ^ ROR64((x),39)) -#define SUM1(x) (ROR64((x),14) ^ ROR64((x),18) ^ ROR64((x),41)) - -#define SIG0(x) (ROR64((x), 1) ^ ROR64((x), 8) ^ LSR64((x), 7)) -#define SIG1(x) (ROR64((x),19) ^ ROR64((x),61) ^ LSR64((x), 6)) - -#define SHA512_UPDATE(i) \ - wdat[i&15] += SIG1(wdat[(i+14)&15]) + wdat[(i+9)&15] + SIG0(wdat[(i+1)&15]) - -#define SHA512_STEP(i,j) \ - v[(7-i)&7] += (j ? SHA512_UPDATE(i) : wdat[i&15]) \ - + SHA512_cnt_loc[i+j] \ - + SUM1(v[(4-i)&7]) \ - + CH(v[(4-i)&7], v[(5-i)&7], v[(6-i)&7]); \ - v[(3-i)&7] += v[(7-i)&7]; \ - v[(7-i)&7] += SUM0(v[(0-i)&7]) + MAJ(v[(0-i)&7], v[(1-i)&7], v[(2-i)&7]) - -#define COMPACT_SHA512_STEP(A,B,C,D,E,F,G,H, W,K, r) { \ - Ipp64u _T1 = (H) + SUM1((E)) + CH((E),(F),(G)) + (W)[(r)] + (K)[(r)]; \ - Ipp64u _T2 = SUM0((A)) + MAJ((A),(B),(C)); \ - (H) = (G); \ - (G) = (F); \ - (F) = (E); \ - (E) = (D)+_T1; \ - (D) = (C); \ - (C) = (B); \ - (B) = (A); \ - (A) = _T1+_T2; \ -} - -/*F* -// Name: UpdateSHA512 -// -// Purpose: Update internal hash according to input message stream. -// -// Parameters: -// uniHash pointer to in/out hash -// mblk pointer to message stream -// mlen message stream length (multiple by message block size) -// uniParam pointer to the optional parameter -// -*F*/ -#if defined(_ALG_SHA512_COMPACT_) -#pragma message("SHA512 compact") - -void UpdateSHA512(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram) -{ - Ipp32u* data = (Ipp32u*)mblk; - - Ipp64u* digest = (Ipp64u*)uniHash; - Ipp64u* SHA512_cnt_loc = (Ipp64u*)uniPraram; - - - for(; mlen>=MBS_SHA512; data += MBS_SHA512/sizeof(Ipp32u), mlen -= MBS_SHA512) { - int t; - Ipp64u W[80]; - - /* - // expand message block - */ - /* initialize the first 16 words in the array W (remember about endian) */ - for(t=0; t<16; t++) { - Ipp32u hiX = data[2*t]; - Ipp32u loX = data[2*t+1]; - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - W[t] = MAKEDWORD(loX, hiX); - #else - W[t] = MAKEDWORD( ENDIANNESS(loX), ENDIANNESS(hiX) ); - #endif - } - for(; t<80; t++) - W[t] = SIG1(W[t-2]) + W[t-7] + SIG0(W[t-15]) + W[t-16]; - - /* - // update hash - */ - { - /* init A, B, C, D, E, F, G, H by the input hash */ - Ipp64u A = digest[0]; - Ipp64u B = digest[1]; - Ipp64u C = digest[2]; - Ipp64u D = digest[3]; - Ipp64u E = digest[4]; - Ipp64u F = digest[5]; - Ipp64u G = digest[6]; - Ipp64u H = digest[7]; - - for(t=0; t<80; t++) - COMPACT_SHA512_STEP(A,B,C,D,E,F,G,H, W,SHA512_cnt_loc, t); - - /* update hash*/ - digest[0] += A; - digest[1] += B; - digest[2] += C; - digest[3] += D; - digest[4] += E; - digest[5] += F; - digest[6] += G; - digest[7] += H; - } - } -} - -#else -void UpdateSHA512(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram) -{ - Ipp32u* data = (Ipp32u*)mblk; - - Ipp64u* digest = (Ipp64u*)uniHash; - Ipp64u* SHA512_cnt_loc = (Ipp64u*)uniPraram; - - for(; mlen>=MBS_SHA512; data += MBS_SHA512/sizeof(Ipp32u), mlen -= MBS_SHA512) { - Ipp64u wdat[16]; - int j; - - Ipp64u v[8]; - - /* initialize the first 16 words in the array W (remember about endian) */ - for(j=0; j<16; j++) { - Ipp32u hiX = data[2*j]; - Ipp32u loX = data[2*j+1]; - #if (IPP_ENDIAN == IPP_BIG_ENDIAN) - wdat[j] = MAKEDWORD(loX, hiX); - #else - wdat[j] = MAKEDWORD( ENDIANNESS(loX), ENDIANNESS(hiX) ); - #endif - } - - /* copy digest */ - CopyBlock(digest, v, IPP_SHA512_DIGEST_BITSIZE/BYTESIZE); - - for(j=0; j<80; j+=16) { - SHA512_STEP( 0, j); - SHA512_STEP( 1, j); - SHA512_STEP( 2, j); - SHA512_STEP( 3, j); - SHA512_STEP( 4, j); - SHA512_STEP( 5, j); - SHA512_STEP( 6, j); - SHA512_STEP( 7, j); - SHA512_STEP( 8, j); - SHA512_STEP( 9, j); - SHA512_STEP(10, j); - SHA512_STEP(11, j); - SHA512_STEP(12, j); - SHA512_STEP(13, j); - SHA512_STEP(14, j); - SHA512_STEP(15, j); - } - - /* update digest */ - digest[0] += v[0]; - digest[1] += v[1]; - digest[2] += v[2]; - digest[3] += v[3]; - digest[4] += v[4]; - digest[5] += v[5]; - digest[6] += v[6]; - digest[7] += v[7]; - } -} -#endif - -#endif -#endif /* IPP_ALG_HASH_SHA512 */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmd5ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmd5ca.c deleted file mode 100644 index 91c44e88..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmd5ca.c +++ /dev/null @@ -1,485 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Digesting message according to MD5 -// (derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm) -// -// Equivalent code is available from RFC 1321. -// -// Contents: -// ippsMD5GetSize() -// ippsMD5Init() -// ippsMD5Pack() -// ippsMD5Unpack() -// ippsMD5Duplicate() -// ippsMD5Update() -// ippsMD5GetTag() -// ippsMD5Final() -// ippsMD5MessageDigest() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - - -#if !defined (_ENABLE_ALG_MD5_) -#pragma message("IPP_ALG_HASH_MD5 disabled") -#else -#pragma message("IPP_ALG_HASH_MD5 enabled") - -/* -// Init MD5 digest -*/ -IppStatus InitMD5(IppsMD5State* pState) -{ - /* test state pointer */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsMD5State*)( IPP_ALIGNED_PTR(pState, MD5_ALIGNMENT) ); - - /* set state ID */ - SHS_ID(pState) = idCtxMD5; - - /* zeros message length */ - SHS_LENL(pState) = 0; - - /* message buffer is free */ - SHS_INDX(pState) = 0; - - /* setup initial digest */ - SHS_HASH(pState)[0] = MD5_IV[0]; - SHS_HASH(pState)[1] = MD5_IV[1]; - SHS_HASH(pState)[2] = MD5_IV[2]; - SHS_HASH(pState)[3] = MD5_IV[3]; - - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5GetSize -// -// Purpose: Returns size (bytes) of IppsMD5State state. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// ippStsNoErr no errors -// -// Parameters: -// pSize pointer to size -// -*F*/ -IPPFUN(IppStatus, ippsMD5GetSize,(int* pSize)) -{ - /* test pointer */ - IPP_BAD_PTR1_RET(pSize); - - *pSize = sizeof(IppsMD5State) +(MD5_ALIGNMENT-1); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5Init -// -// Purpose: Init MD5 state. -// -// Returns: Reason: -// ippStsNullPtrErr pState == NULL -// ippStsNoErr no errors -// -// Parameters: -// pState pointer to the MD5 state -// -*F*/ -IPPFUN(IppStatus, ippsMD5Init,(IppsMD5State* pState)) -{ - return InitMD5(pState); -} - - -/*F* -// Name: ippsMD5Pack -// -// Purpose: Copy initialized context to the buffer. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -IPPFUN(IppStatus, ippsMD5Pack,(const IppsMD5State* pCtx, Ipp8u* pBuffer)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsMD5State*)( IPP_ALIGNED_PTR(pCtx, MD5_ALIGNMENT) ); - /* test the context */ - IPP_BADARG_RET(idCtxMD5 !=SHS_ID(pCtx), ippStsContextMatchErr); - - CopyBlock(pCtx, pBuffer, sizeof(IppsMD5State)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5Unpack -// -// Purpose: Unpack buffer content into the initialized context. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -IPPFUN(IppStatus, ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pCtx)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsMD5State*)( IPP_ALIGNED_PTR(pCtx, MD5_ALIGNMENT) ); - - CopyBlock(pBuffer, pCtx, sizeof(IppsMD5State)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5Duplicate -// -// Purpose: Clone MD5 state. -// -// Returns: Reason: -// ippStsNullPtrErr pSrcState == NULL -// pDstState == NULL -// ippStsContextMatchErr pSrcState->idCtx != idCtxMD5 -// pDstState->idCtx != idCtxMD5 -// ippStsNoErr no errors -// -// Parameters: -// pSrcState pointer to the source MD5 state -// pDstState pointer to the target MD5 state -// -// Note: -// pDstState may to be uninitialized by ippsMD5Init() -// -*F*/ -IPPFUN(IppStatus, ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) -{ - /* test state pointers */ - IPP_BAD_PTR2_RET(pSrcState, pDstState); - /* use aligned context */ - pSrcState = (IppsMD5State*)( IPP_ALIGNED_PTR(pSrcState, MD5_ALIGNMENT) ); - pDstState = (IppsMD5State*)( IPP_ALIGNED_PTR(pDstState, MD5_ALIGNMENT) ); - /* test states ID */ - IPP_BADARG_RET(idCtxMD5 !=SHS_ID(pSrcState), ippStsContextMatchErr); - - /* copy state */ - CopyBlock(pSrcState, pDstState, sizeof(IppsMD5State)); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5Update -// -// Purpose: Updates intermadiate digest based on input stream. -// -// Returns: Reason: -// ippStsNullPtrErr pSrc == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxMD5 -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pSrc pointer to the input stream -// len input stream length -// pState pointer to the MD5 state -// -*F*/ -IPPFUN(IppStatus, ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsMD5State*)( IPP_ALIGNED_PTR(pState, MD5_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxMD5 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test input length */ - IPP_BADARG_RET((len<0), ippStsLengthErr); - /* test source pointer */ - IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); - - /* - // handle non empty message - */ - if(len) { - int processingLen; - - int n = SHS_INDX(pState); - Ipp8u* pBuffer = SHS_BUFF(pState); - Ipp8u* pHash = (Ipp8u*)SHS_HASH(pState); - - Ipp64u lenLo = SHS_LENL(pState); - lenLo += len; - - /* if non empty internal buffer filling */ - if(n) { - /* copy from input stream to the internal buffer as match as possible */ - processingLen = IPP_MIN(len, (MBS_MD5 - SHS_INDX(pState))); - CopyBlock(pSrc, pBuffer+n, processingLen); - - pSrc += processingLen; - len -= processingLen; - SHS_INDX(pState) = n += processingLen; - - /* update digest if buffer full */ - if( MBS_MD5 == n) { - UpdateMD5(pHash, pBuffer, MBS_MD5, MD5_cnt); - SHS_INDX(pState) = 0; - } - } - - /* main message part processing */ - processingLen = len & ~(MBS_MD5-1); - if(processingLen) { - UpdateMD5(pHash, pSrc, processingLen, MD5_cnt); - pSrc += processingLen; - len -= processingLen; - } - - /* store rest of message into the internal buffer */ - if(len) { - CopyBlock(pSrc, pBuffer, len); - SHS_INDX(pState) += len; - } - - SHS_LENL(pState) = lenLo; - } - - return ippStsNoErr; -} - - -/* -// Compute digest -*/ -void ComputeDigestMD5(Ipp32u* pHash, const IppsMD5State* pState) -{ - const Ipp8u* stateBuff = SHS_BUFF(pState); - int stateBuffLen = SHS_INDX(pState); - - /* local buffer and it length */ - Ipp8u buffer[MBS_MD5*2]; - int bufferLen = stateBuffLen < (MBS_MD5-(int)sizeof(Ipp64u))? MBS_MD5 : MBS_MD5*2; - - /* copy rest of message into internal buffer */ - CopyBlock(stateBuff, buffer, stateBuffLen); - - /* padd message */ - buffer[stateBuffLen++] = 0x80; - PaddBlock(0, buffer+stateBuffLen, bufferLen-stateBuffLen-sizeof(Ipp64u)); - - /* message length representation */ - { - Ipp64u lo = SHS_LENL(pState); /* message length in bytes */ - lo = LSL64(lo,3); /* message length in bits */ - ((Ipp64u*)(buffer+bufferLen))[-1] = lo; - } - - /* copmplete hash computation */ - UpdateMD5(pHash, buffer, bufferLen, MD5_cnt); - - /* convert hash into big endian */ - /* is not necessary if little endian */ -} - - -/*F* -// Name: ippsMD5GetTag -// -// Purpose: Compute digest based on current state. -// Note, that futher digest update is possible -// -// Returns: Reason: -// ippStsNullPtrErr pTag == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxMD5 -// ippStsLengthErr max_MD5_digestLen < tagLen <1 -// ippStsNoErr no errors -// -// Parameters: -// pTag address of the output digest -// tagLen length of digest -// pState pointer to the MD5 state -// -*F*/ -IPPFUN(IppStatus, ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsMD5State*)( IPP_ALIGNED_PTR(pState, MD5_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxMD5 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pTag); - IPP_BADARG_RET((tagLen<1)||(sizeof(DigestMD5)idCtx != idCtxMD5 -// ippStsNoErr no errors -// -// Parameters: -// pMD address of the output digest -// pState pointer to the MD5 state -// -*F*/ -IPPFUN(IppStatus, ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsMD5State*)( IPP_ALIGNED_PTR(pState, MD5_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxMD5 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestMD5(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestMD5)); - InitMD5(pState); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsMD5MessageDigest -// -// Purpose: Ddigest of the whole message. -// -// Returns: Reason: -// ippStsNullPtrErr pMsg == NULL -// pDigest == NULL -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pMsg pointer to the input message -// len input message length -// pMD address of the output digest -// -*F*/ -IPPFUN(IppStatus, ippsMD5MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - /* test message length */ - IPP_BADARG_RET((msgLen<0), ippStsLengthErr); - /* test message pointer */ - IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); - - { - /* message length in the multiple MBS and the rest */ - int msgLenBlks = msgLen & (-MBS_MD5); - int msgLenRest = msgLen - msgLenBlks; - - /* init hash value */ - DigestMD5 hash = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}; - - /* process main part of the message */ - if(msgLenBlks) - UpdateMD5(hash, pMsg, msgLenBlks, MD5_cnt); - - /* process message padding */ - { - #define MREP_SIZE_MD5 (sizeof(Ipp64u)) - Ipp8u buffer[MBS_MD5*2]; - int bufferLen = msgLenRest < (int)(MBS_MD5-MREP_SIZE_MD5)? (int)MBS_MD5 : (int)(MBS_MD5*2); - - /* message bitlength representation */ - Ipp64u msgLenBits = (Ipp64u)msgLen*8; - - /* copy end of message */ - CopyBlock(pMsg+msgLen-msgLenRest, buffer, msgLenRest); - - /* end of message bit */ - buffer[msgLenRest++] = 0x80; - - /* padd buffer */ - PaddBlock(0, buffer+msgLenRest, bufferLen-msgLenRest-MREP_SIZE_MD5); - /* copy message bitlength representation */ - ((Ipp64u*)(buffer+bufferLen))[-1] = msgLenBits; - - UpdateMD5(hash, buffer, bufferLen, MD5_cnt); - #undef MREP_SIZE_MD5 - } - - /* copy hash bytes */ - ((Ipp32u*)pMD)[0] = hash[0]; - ((Ipp32u*)pMD)[1] = hash[1]; - ((Ipp32u*)pMD)[2] = hash[2]; - ((Ipp32u*)pMD)[3] = hash[3]; - - return ippStsNoErr; - } -} - -#endif /* _ENABLE_ALG_MD5_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontexpbinca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontexpbinca.c deleted file mode 100644 index 37a7352c..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontexpbinca.c +++ /dev/null @@ -1,562 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Modular Exponentiation (binary version) -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpbn.h" -#include "pcpmontgomery.h" - - -#if 0 -/* -// Exponentiation -// Y = X^e -// X and Y belongs Montgomery Domain -*/ -void cpMontExp_32u(IppsBigNumState* pY, - const IppsBigNumState* pX, Ipp32u e, - IppsMontState* pMont) -{ - if(pY!=pX) /* copy base */ - BN_copy(pX, pY); - - { - int j, back_step; - - /* Montgomery engine data */ - Ipp32u* pModulus = BN_NUMBER(MNT_MODULO(pMont)); - int mSize = BN_SIZE(MNT_MODULO(pMont)); - Ipp32u* pHelper = MNT_HELPER(pMont); - - /* result and base of exponent */ - Ipp32u* dataY = BN_NUMBER(pY); - Ipp32u* dataX = BN_BUFFER(pY); - int ySize = BN_SIZE(pY); - - /* temporary buffers */ - Ipp32u* dataT = BN_NUMBER(MNT_PRODUCT(pMont)); - Ipp32u* pBuffer = BN_BUFFER(MNT_PRODUCT(pMont)); - - /* expand result */ - ZEXPAND_BNU(dataY,ySize, mSize); - /* copy base */ - COPY_BNU(dataY,dataX, mSize); - - j = 32-NLZ32u(e)-1; - - back_step = 0; - for(j-=1; j>=0; j--) { - int i; - Ipp32u mask_pattern = (Ipp32u)(back_step-1); - - /* T = (Y[] and mask_pattern) or (X[] and ~mask_pattern) */ - for(i=0; i>j) & 0x01) & (back_step^1); - j += back_step; - } - - BN_SIZE(pY) = ySize; - } -} -#endif - -/* -// Binary method of Exponentiation -*/ -#if !defined(_USE_ERNIE_CBA_MITIGATION_) && !defined(_USE_GRES_CBA_MITIGATION_) // unsafe version -void cpSafeMontExp_Binary(IppsBigNumState* pY, - const IppsBigNumState* pX, const IppsBigNumState* pE, - IppsMontState* pMont) -{ - int k; - - /* if E==0 then Y=R mod m */ - if (pE->size == 1 && pE->number[0] == 0) { - int len = IPP_MULTIPLE_OF(pMont->n->size, BNUBASE_TYPE_SIZE); - cpMemset32u(pMont->wb->number, 0, len); - pMont->wb->number[len] = 1; - - cpMod_BNU(pMont->wb->number, len + 1, pMont->n->number, pMont->n->size, &pY->size); - - cpMemcpy32u(pY->number, pMont->wb->number, pY->size); - pY->sgn = ippBigNumPOS; - return; - } - - else { - Ipp32u* r_number = pY->workBuffer; - int r_size = pY->size; - - int flag=1; - Ipp32u power = pE->number[pE->size-1]; - - for( k = 31; k >= 0; k-- ) { - Ipp32u powd = power & 0x80000000;/* from top to bottom*/ - power <<= 1; - - if((flag == 1) && (powd == 0)) - continue; - - else if (flag == 0) { - #if defined(_USE_NN_MONTMUL_) - cpMontMul(r_number, r_size, r_number,r_size, - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number); - #else - cpMontMul(r_number, r_size, r_number,r_size, - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number, pMont->pBuffer); - #endif - if (powd) - #if defined(_USE_NN_MONTMUL_) - cpMontMul(r_number, r_size, pX->number,pX->size, - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number); - #else - cpMontMul(r_number, r_size, pX->number,pX->size, - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number, pMont->pBuffer); - #endif - } - - else { - int i; - flag = 0; - r_size = pMont->n->size; - if( pX->size < pMont->n->size ) - for(i = r_size - 1; i >= pX->size; i-- ) - r_number[i] = 0; - - for( i = pX->size - 1; i >= 0; i-- ) - r_number[i] = pX->number[i]; - } - } - - if (pE->size > 1) { - struct BNU { - Ipp32u *number; - int *size; - } BNUs[2]; - BNUs[0].number = r_number; - BNUs[0].size = &r_size; - BNUs[1].number = pX->number; - BNUs[1].size = &(((IppsBigNumState*)pX)->size); - - for( k = pE->size - 2; k >= 0; k-- ) { - int j; - Ipp32u powd = 0; - power = pE->number[k]; - - for( j = 31; j >= 0; j-- ) { - #if defined(_USE_NN_MONTMUL_) - cpMontMul(r_number, r_size, BNUs[powd].number, *(BNUs[powd].size), - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number); - #else - cpMontMul(r_number, r_size, BNUs[powd].number, *(BNUs[powd].size), - pMont->n->number, pMont->n->size, - r_number,&r_size, pMont->n0, pMont->wb->number, pMont->pBuffer); - #endif - //gres: powd = ((power >> j) & 0x1) * (powd ^ 1); - powd = ((power >> j) & 0x1) & (powd ^ 1); - j += powd; - } - } - } - - for(k=r_size-1; k>= 0; k--) - pY->number[k] = r_number[k]; - - pY->sgn = ippBigNumPOS; - pY->size = r_size; - - while((pY->size > 1) && (pY->number[pY->size-1] == 0)) - pY->size--; - - return; - } -} -#endif /* _xUSE_ERNIE_CBA_MITIGATION_, _xUSE_GRES_CBA_MITIGATION_ */ - - -#if defined(_USE_ERNIE_CBA_MITIGATION_) -/* -// The version below was designed according to recommendation -// from Ernie Brickell and Mattew Wood. -// The reason was to mitigate "cache monitoring" attack on RSA -// Note: this version slower than pre-mitigated version ~ 30-40% -*/ -#define SET_BNU(dst,val,len) \ -{ \ - int n; \ - for(n=0; n<(len); n++) (dst)[n] = (val); \ -} - -#define AND_BNU(dst,src1,src2,len) \ -{ \ - int n; \ - for(n=0; n<(len); n++) (dst)[n] = (src1)[n] & (src2)[n]; \ -} - -void cpSafeMontExp_Binary(IppsBigNumState* pY, - const IppsBigNumState* pX, const IppsBigNumState* pE, - IppsMontState* pMont) -{ - Ipp32u* eData = BN_NUMBER(pE); - int eSize = BN_SIZE(pE); - - /* - // if e==0 then r=R mod m (i.e MontEnc(1)) - */ - if (eSize == 1 && eData[0] == 0) { - cpBN_copy(MNT_1(pMont), pY); - return; - } - - /* - // modulo exponentiation - */ - if(pY!=pX) /* init result */ - cpBN_copy(pX, pY); - - { - Ipp32u eValue; - int nBits; - - Ipp32u* pModulus = BN_NUMBER(MNT_MODULO(pMont)); - int mSize = BN_SIZE(MNT_MODULO(pMont)); - Ipp32u* pHelper = MNT_HELPER(pMont); - - Ipp32u* yData = BN_NUMBER(pY); - Ipp32u* xData = BN_BUFFER(pY); - int ySize = BN_SIZE(pY); - - Ipp32u* tData = BN_NUMBER(MNT_PRODUCT(pMont)); - Ipp32u* pBuffer = BN_BUFFER(MNT_PRODUCT(pMont)); - Ipp32u* pMontOne= BN_NUMBER(MNT_1(pMont)); - - /* expand Mont(1) */ - ZEXPAND_BNU(pMontOne, BN_SIZE(MNT_1(pMont)), mSize); - - /* copy base */ - ZEXPAND_COPY_BNU(yData,ySize, xData,mSize); - - - /* execute most significant part pE */ - eValue = eData[eSize-1]; - nBits = 32-NLZ32u(eValue); - eValue <<= (32-nBits); - - nBits--; - eValue <<=1; - for(; nBits>0; nBits--, eValue<<=1) { - Ipp32u carry; - - /* squaring: R^2 mod Modulus */ - #if defined(_USE_NN_MONTMUL_) - cpMontMul(yData, ySize, - yData, ySize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer); - #else - cpMontMul(yData, ySize, - yData, ySize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer, MNT_BUFFER(pMont)); - #endif - - /* T = (X-1)*bitof(E,j) + 1 */ - SET_BNU(pBuffer, ((Ipp32s)eValue)>>31, mSize); - carry = cpSub_BNU(tData, xData, pMontOne, mSize); - AND_BNU(tData, tData, pBuffer, mSize); - carry = cpAdd_BNU(tData, tData, pMontOne, mSize); - - /* multiply: Y*T mod Modulus */ - #if defined(_USE_NN_MONTMUL_) - cpMontMul(yData, ySize, - tData, mSize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer); - #else - cpMontMul(yData, ySize, - tData, mSize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer, MNT_BUFFER(pMont)); - #endif - } - - /* execute rest bits of E */ - eSize--; - for(; eSize>0; eSize--) { - eValue = eData[eSize-1]; - - for(nBits=32; nBits>0; nBits--, eValue<<=1) { - Ipp32u carry; - - /* squaring: R^2 mod Modulus */ - #if defined(_USE_NN_MONTMUL_) - cpMontMul(yData, ySize, - yData, ySize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer); - #else - cpMontMul(yData, ySize, - yData, ySize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer, MNT_BUFFER(pMont)); - #endif - - /* T = (X-1)*bitof(E,j) + 1 */ - SET_BNU(pBuffer, ((Ipp32s)eValue)>>31, mSize); - carry = cpSub_BNU(tData, xData, pMontOne, mSize); - AND_BNU(tData, tData, pBuffer, mSize); - carry = cpAdd_BNU(tData, tData, pMontOne, mSize); - - /* multiply: R*T mod Modulus */ - #if defined(_USE_NN_MONTMUL_) - cpMontMul(yData, ySize, - tData, mSize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer); - #else - cpMontMul(yData, ySize, - tData, mSize, - pModulus, mSize, - yData, &ySize, - pHelper, pBuffer, MNT_BUFFER(pMont)); - #endif - } - } - - BN_SIZE(pY) = ySize; - } -} -#endif /* _USE_ERNIE_CBA_MITIGATION_ */ - - -#if defined(_USE_GRES_CBA_MITIGATION_) -/* -// The reason was to mitigate "cache monitoring" attack on RSA -// -// This is improved version of modular exponentiation. -// Current version provide both either mitigation and perrformance. -// This version in comparison with previous (IPP 4.1.3) one ~30-40% faster, -// i.e the the performance stayed as was for pre-mitigated version -// -*/ -cpSize cpMontExpBin_BNU_sscm(BNU_CHUNK_T* dataY, - const BNU_CHUNK_T* dataX, cpSize nsX, - const BNU_CHUNK_T* dataE, cpSize nsE, - IppsMontState* pMont) -{ - cpSize nsM = MNT_SIZE(pMont); - - /* - // test for special cases: - // x^0 = 1 - // 0^e = 0 - */ - if( cpEqu_BNU_CHUNK(dataE, nsE, 0) ) { - COPY_BNU(dataY, MNT_1(pMont), nsM); - } - else if( cpEqu_BNU_CHUNK(dataX, nsX, 0) ) { - ZEXPAND_BNU(dataY, 0, nsM); - } - - /* general case */ - else { - BNU_CHUNK_T* dataM = MNT_MODULUS(pMont); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - - /* Montgomery engine buffers */ - BNU_CHUNK_T* pKBuffer = MNT_KBUFFER(pMont); - BNU_CHUNK_T* pProduct = MNT_PRODUCT(pMont); - - BNU_CHUNK_T* dataT = MNT_TBUFFER(pMont); - BNU_CHUNK_T* sscmBuffer = MNT_SBUFFER(pMont); - - cpSize i; - BNU_CHUNK_T mask_pattern; - - /* execute most significant part pE */ - BNU_CHUNK_T eValue = dataE[nsE-1]; - int j = BNU_CHUNK_BITS - cpNLZ_BNU(eValue)-1; - - int back_step = 0; - - /* expand base and init result */ - ZEXPAND_COPY_BNU(dataT, nsM, dataX, nsX); - COPY_BNU(dataY, dataT, nsM); - - for(j-=1; j>=0; j--) { - mask_pattern = (BNU_CHUNK_T)(back_step-1); - - /* safeBuffer = (Y[] and mask_pattern) or (X[] and ~mask_pattern) */ - for(i=0; i>j) & 0x1) & (back_step^1); - j += back_step; - } - - /* execute rest bits of E */ - for(--nsE; nsE>0; nsE--) { - eValue = dataE[nsE-1]; - - for(j=BNU_CHUNK_BITS-1; j>=0; j--) { - mask_pattern = (BNU_CHUNK_T)(back_step-1); - - /* safeBuffer = (Y[] and mask_pattern) or (X[] and ~mask_pattern) */ - for(i=0; i>j) & 0x1) & (back_step^1); - j += back_step; - } - } - } - - return nsM; -} -#endif /* _USE_GRES_CBA_MITIGATION_ */ - - -cpSize cpMontExpBin_BNU(BNU_CHUNK_T* dataY, - const BNU_CHUNK_T* dataX, cpSize nsX, - const BNU_CHUNK_T* dataE, cpSize nsE, - IppsMontState* pMont) -{ - cpSize nsM = MNT_SIZE(pMont); - - /* - // test for special cases: - // x^0 = 1 - // 0^e = 0 - */ - if( cpEqu_BNU_CHUNK(dataE, nsE, 0) ) { - COPY_BNU(dataY, MNT_1(pMont), nsM); - } - else if( cpEqu_BNU_CHUNK(dataX, nsX, 0) ) { - ZEXPAND_BNU(dataY, 0, nsM); - } - - /* general case */ - else { - BNU_CHUNK_T* dataM = MNT_MODULUS(pMont); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - - /* Montgomery engine buffers */ - BNU_CHUNK_T* pKBuffer = MNT_KBUFFER(pMont); - BNU_CHUNK_T* pProduct = MNT_PRODUCT(pMont); - - BNU_CHUNK_T* dataT = MNT_TBUFFER(pMont); - - /* execute most significant part pE */ - BNU_CHUNK_T eValue = dataE[nsE-1]; - int n = cpNLZ_BNU(eValue)+1; - - /* expand base and init result */ - ZEXPAND_COPY_BNU(dataT, nsM, dataX, nsX); - COPY_BNU(dataY, dataT, nsM); - - eValue <<= n; - for(; n0; nsE--) { - eValue = dataE[nsE-1]; - - for(n=0; nidCtx) -#define MNT_ROOM(eng) ((eng)->maxLen) -#define MNT_SIZE(eng) ((eng)->modLen) -#define MNT_HELPER(eng) ((eng)->m0) -#define MNT_MODULUS(eng) ((eng)->pModulus) -#define MNT_1(eng) ((eng)->pIdentity) -#define MNT_IDENT_R(eng) (MNT_1((eng))) -#define MNT_SQUARE_R(eng) ((eng)->pSquare) -#define MNT_CUBE_R(eng) ((eng)->pCube) -#define MNT_TBUFFER(eng) ((eng)->pTBuffer) -#define MNT_SBUFFER(eng) ((eng)->pSBuffer) -#define MNT_PRODUCT(eng) ((eng)->pProduct) -#define MNT_KBUFFER(eng) ((eng)->pKBuffer) - -#define MNT_VALID_ID(eng) (MNT_ID((eng))==idCtxMontgomery) - -/* default methos */ -#define EXPONENT_METHOD (ippBinaryMethod) - -/* alignment */ -#define MONT_ALIGNMENT ((int)(sizeof(void*))) - - -/* -// Pacp/unpack Montgomery context -*/ -void cpPackMontCtx(const IppsMontState* pCtx, Ipp8u* pBuffer); -void cpUnpackMontCtx(const Ipp8u* pBuffer, IppsMontState* pCtx); - - -/* -// Montgomery reduction, multiplication and squaring -*/ -//void cpMontRed_BNU(BNU_CHUNK_T* pR, -// BNU_CHUNK_T* pProduct, -// const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0); -void cpMontRedAdc_BNU(BNU_CHUNK_T* pR, - BNU_CHUNK_T* pProduct, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0); -void cpMontRedAdx_BNU(BNU_CHUNK_T* pR, - BNU_CHUNK_T* pProduct, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0); - -__INLINE void cpMontRed_BNU(BNU_CHUNK_T* pR, - BNU_CHUNK_T* pProduct, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0) -{ -#if 0 -#if(_IPP32E < _IPP32E_L9) - cpMontRedAdc_BNU(pR, pProduct, pModulus, nsM, m0); -#else - IsFeatureEnabled(ADCOX_ENABLED)? cpMontRedAdx_BNU(pR, pProduct, pModulus, nsM, m0) - : cpMontRedAdc_BNU(pR, pProduct, pModulus, nsM, m0); -#endif -#endif - -#if(_ADCOX_NI_ENABLING_==_FEATURE_ON_) - cpMontRedAdx_BNU(pR, pProduct, pModulus, nsM, m0); -#elif(_ADCOX_NI_ENABLING_==_FEATURE_TICKTOCK_) - IsFeatureEnabled(ADCOX_ENABLED)? cpMontRedAdx_BNU(pR, pProduct, pModulus, nsM, m0) - : cpMontRedAdc_BNU(pR, pProduct, pModulus, nsM, m0); -#else - cpMontRedAdc_BNU(pR, pProduct, pModulus, nsM, m0); -#endif -} - -__INLINE void cpMontMul_BNU(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pX, cpSize nsX, - const BNU_CHUNK_T* pY, cpSize nsY, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0, - BNU_CHUNK_T* pProduct, BNU_CHUNK_T* pKBuffer) -{ - cpMul_BNU(pProduct, pX,nsX, pY,nsY, pKBuffer); - ZEXPAND_BNU(pProduct,nsX+nsY, 2*nsM); - cpMontRed_BNU(pR, pProduct, pModulus, nsM, m0); -} - -__INLINE void cpMontSqr_BNU(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pX, cpSize nsX, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0, - BNU_CHUNK_T* pProduct, BNU_CHUNK_T* pKBuffer) -{ - cpSqr_BNU(pProduct, pX,nsX, pKBuffer); - ZEXPAND_BNU(pProduct, 2*nsX, 2*nsM); - cpMontRed_BNU(pR, pProduct, pModulus, nsM, m0); -} - -/* -// Montgomery encoding/decoding -*/ -__INLINE cpSize cpMontEnc_BNU(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pXreg, cpSize nsX, - IppsMontState* pMont) -{ - cpSize nsM = MNT_SIZE(pMont); - cpMontMul_BNU(pR, - pXreg, nsX, MNT_SQUARE_R(pMont), nsM, - MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont), - MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); - - FIX_BNU(pR, nsM); - return nsM; -} - -__INLINE cpSize cpMontDec_BNU(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pXmont, cpSize nsX, - IppsMontState* pMont) -{ - cpSize nsM = MNT_SIZE(pMont); - ZEXPAND_COPY_BNU(MNT_PRODUCT(pMont), 2*nsM, pXmont, nsX); - - cpMontRed_BNU(pR, MNT_PRODUCT(pMont), MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont)); - - FIX_BNU(pR, nsM); - return nsM; -} - -__INLINE void cpMontEnc_BN(IppsBigNumState* pRbn, - const IppsBigNumState* pXbn, - IppsMontState* pMont) -{ - BNU_CHUNK_T* pR = BN_NUMBER(pRbn); - cpSize nsM = MNT_SIZE(pMont); - cpMontMul_BNU(pR, - BN_NUMBER(pXbn), BN_SIZE(pXbn), - MNT_SQUARE_R(pMont), nsM, - MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont), - MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); - - FIX_BNU(pR, nsM); - BN_SIZE(pRbn) = nsM; - BN_SIGN(pRbn) = ippBigNumPOS; -} - -__INLINE void cpMontDec_BN(IppsBigNumState* pRbn, - const IppsBigNumState* pXbn, - IppsMontState* pMont) -{ - BNU_CHUNK_T* pR = BN_NUMBER(pRbn); - cpSize nsM = MNT_SIZE(pMont); - ZEXPAND_COPY_BNU(MNT_PRODUCT(pMont), 2*nsM, BN_NUMBER(pXbn), BN_SIZE(pXbn)); - - cpMontRed_BNU(pR, MNT_PRODUCT(pMont), MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont)); - - FIX_BNU(pR, nsM); - BN_SIZE(pRbn) = nsM; - BN_SIGN(pRbn) = ippBigNumPOS; -} - -#if 0 -/* -// Size of scratch buffer, involved in MontExp operation -*/ -cpSize cpMontExpScratchBufferSize(cpSize modulusBitSize, - cpSize expBitSize, - cpSize nExponents); -#endif - -/* -// Montgomery exponentiation (binary) "fast" and "safe" versions -*/ -cpSize cpMontExpBin_BNU_sscm(BNU_CHUNK_T* pY, - const BNU_CHUNK_T* pX, cpSize nsX, - const BNU_CHUNK_T* pE, cpSize nsE, - IppsMontState* pMont); - -cpSize cpMontExpBin_BNU(BNU_CHUNK_T* pY, - const BNU_CHUNK_T* pX, cpSize nsX, - const BNU_CHUNK_T* pE, cpSize nsE, - IppsMontState* pMont); - -__INLINE void cpMontExpBin_BN_sscm(IppsBigNumState* pYbn, - const IppsBigNumState* pXbn, - const IppsBigNumState* pEbn, - IppsMontState* pMont) -{ - BNU_CHUNK_T* pX = BN_NUMBER(pXbn); - cpSize nsX = BN_SIZE(pXbn); - BNU_CHUNK_T* pE = BN_NUMBER(pEbn); - cpSize nsE = BN_SIZE(pEbn); - BNU_CHUNK_T* pY = BN_NUMBER(pYbn); - cpSize nsY = cpMontExpBin_BNU_sscm(pY, pX,nsX, pE,nsE, pMont); - FIX_BNU(pY, nsY); - BN_SIZE(pYbn) = nsY; - BN_SIGN(pYbn) = ippBigNumPOS; -} - -__INLINE void cpMontExpBin_BN(IppsBigNumState* pYbn, - const IppsBigNumState* pXbn, - const IppsBigNumState* pEbn, - IppsMontState* pMont) -{ - BNU_CHUNK_T* pX = BN_NUMBER(pXbn); - cpSize nsX = BN_SIZE(pXbn); - BNU_CHUNK_T* pE = BN_NUMBER(pEbn); - cpSize nsE = BN_SIZE(pEbn); - BNU_CHUNK_T* pY = BN_NUMBER(pYbn); - cpSize nsY = cpMontExpBin_BNU(pY, pX,nsX, pE,nsE, pMont); - FIX_BNU(pY, nsY); - BN_SIZE(pYbn) = nsY; - BN_SIGN(pYbn) = ippBigNumPOS; -} - - -/* -// Montgomery exponentiation (fixed window) -*/ -cpSize cpMontExp_WinSize(int bitsize); - -#if defined(_USE_WINDOW_EXP_) -void cpMontExpWin_BN_sscm(IppsBigNumState* pY, - const IppsBigNumState* pX, const IppsBigNumState* pE, - IppsMontState* pMont, - BNU_CHUNK_T* pPrecompResource); - -void cpMontExpWin_BN(IppsBigNumState* pY, - const IppsBigNumState* pX, const IppsBigNumState* pE, - IppsMontState* pMont, - BNU_CHUNK_T* pPrecompResource); -#endif - -/* -// Montgomery multi-exponentiation -*/ -/* precompute table for multi-exponentiation */ -void cpMontMultiExpInitArray(BNU_CHUNK_T* pPrecomTbl, - const BNU_CHUNK_T** ppX, cpSize xItemBitSize, cpSize numItems, - IppsMontState* pMont); - -/* multi-exponentiation */ -void cpFastMontMultiExp(BNU_CHUNK_T* pY, - const BNU_CHUNK_T* pPrecomTbl, - const Ipp8u** ppE, cpSize eItemBitSize, cpSize numItems, - IppsMontState* pMont); - -#endif /* _CP_MONTGOMETRY_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontgomeryca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontgomeryca.c deleted file mode 100644 index afa5e978..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontgomeryca.c +++ /dev/null @@ -1,479 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -// Contents: -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpbn.h" -#include "pcpmontgomery.h" -#include "pcpmulbnukara.h" -#include "pcptool.h" - -/*F* -// Name: ippsMontGetSize -// -// Purpose: Specifies size of buffer in bytes. -// -// Returns: Reason: -// ippStsNullPtrErr pCtxSize==NULL -// ippStsLengthErr maxLen32 < 1 -// ippStsNoErr no errors -// -// Parameters: -// method selected exponential method (unused parameter) -// maxLen32 max modulus length (in Ipp32u chunks) -// pCtxSize size of context -// -// Notes: Function always use method=ippBinaryMethod, -// so this parameter is ignored -*F*/ -IPPFUN(IppStatus, ippsMontGetSize, (IppsExpMethod method, cpSize maxLen32, cpSize* pCtxSize)) -{ - IPP_BAD_PTR1_RET(pCtxSize); - IPP_BADARG_RET(maxLen32< 1, ippStsLengthErr); - - UNREFERENCED_PARAMETER(method); - - { - /* convert modulus length to the number of BNU_CHUNK_T */ - cpSize modSize = INTERNAL_BNU_LENGTH(maxLen32); - - /* size of Karatsuba buffer */ - cpSize buffSize = 0; - #if defined(_USE_KARATSUBA_) - buffSize = cpKaratsubaBufferSize(modSize); - #if defined( _OPENMP ) - buffSize <<=1; /* double buffer size if OpenMP used */ - #endif - #else - buffSize = 0; - #endif - - *pCtxSize= sizeof(IppsMontState) - + modSize*sizeof(BNU_CHUNK_T) /* modulus */ - + modSize*sizeof(BNU_CHUNK_T) /* identity */ - + modSize*sizeof(BNU_CHUNK_T) /* square R */ - + modSize*sizeof(BNU_CHUNK_T) /* cube R */ - + modSize*sizeof(BNU_CHUNK_T) /* internal buffer */ - + modSize*sizeof(BNU_CHUNK_T) /* internal sscm buffer */ - + modSize*sizeof(BNU_CHUNK_T)*2 /* internal product */ - + buffSize /* K-mul buffer */ - + MONT_ALIGNMENT-1; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsMontInit -// -// Purpose: Initializes the symbolic data structure and partitions the -// specified buffer space. -// -// Returns: Reason: -// ippStsNullPtrErr pMont==NULL -// ippStsLengthErr maxLen32 < 1 -// ippStsNoErr no errors -// -// Parameters: -// method selected exponential method (unused parameter) -// maxLen32 max modulus length (in Ipp32u chunks) -// pMont pointer to Montgomery context -*F*/ -IPPFUN(IppStatus, ippsMontInit,(IppsExpMethod method, int maxLen32, IppsMontState* pMont)) -{ - IPP_BADARG_RET(maxLen32<1, ippStsLengthErr); - - IPP_BAD_PTR1_RET(pMont); - pMont = (IppsMontState*)( IPP_ALIGNED_PTR(pMont, MONT_ALIGNMENT) ); - - UNREFERENCED_PARAMETER(method); - - MNT_ID(pMont) = idCtxMontgomery; - MNT_ROOM(pMont) = INTERNAL_BNU_LENGTH(maxLen32); - MNT_SIZE(pMont) = 0; - MNT_HELPER(pMont) = 0; - - { - Ipp8u* ptr = (Ipp8u*)pMont; - - /* convert modulus length to the number of BNU_CHUNK_T */ - cpSize modSize = MNT_ROOM(pMont); - - /* size of buffer */ - cpSize buffSize = 0; - #if defined(_USE_KARATSUBA_) - buffSize = cpKaratsubaBufferSize(modSize); - #if defined( _OPENMP ) - buffSize <<=1; /* double buffer size if OpenMP used */ - #endif - #else - buffSize = 0; - #endif - - /* assign internal buffers */ - MNT_MODULUS(pMont) = (BNU_CHUNK_T*)( ptr += sizeof(IppsMontState) ); - - MNT_1(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - MNT_SQUARE_R(pMont)= (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - MNT_CUBE_R(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - - MNT_TBUFFER(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - MNT_SBUFFER(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - MNT_PRODUCT(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); - MNT_KBUFFER(pMont) = (buffSize)? (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T)*2 ) : NULL; - - /* init internal buffers */ - ZEXPAND_BNU(MNT_MODULUS(pMont), 0, modSize); - ZEXPAND_BNU(MNT_1(pMont), 0, modSize); - ZEXPAND_BNU(MNT_SQUARE_R(pMont), 0, modSize); - ZEXPAND_BNU(MNT_CUBE_R(pMont), 0, modSize); - - return ippStsNoErr; - } -} - -void cpPackMontCtx(const IppsMontState* pCtx, Ipp8u* pBuffer) -{ - IppsMontState* pAlignedBuffer = (IppsMontState*)(IPP_ALIGNED_PTR((pBuffer), MONT_ALIGNMENT)); - - /* max modulus length */ - int modSize = MNT_ROOM(pCtx); - /* size of context (bytes) without product and Karatsuba buffers */ - int ctxSize = sizeof(IppsMontState) - +sizeof(BNU_CHUNK_T)*(modSize*4); - - CopyBlock(pCtx, pAlignedBuffer, ctxSize); - MNT_MODULUS(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_MODULUS(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_1(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_1(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_SQUARE_R(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_SQUARE_R(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_CUBE_R(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_CUBE_R(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_PRODUCT(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_PRODUCT(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_TBUFFER(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_TBUFFER(pCtx))-IPP_UINT_PTR(pCtx)); - MNT_KBUFFER(pAlignedBuffer) = MNT_KBUFFER(pCtx)? (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(MNT_KBUFFER(pCtx))-IPP_UINT_PTR(pCtx)) : NULL; -} - -void cpUnpackMontCtx(const Ipp8u* pBuffer, IppsMontState* pCtx) -{ - IppsMontState* pAlignedBuffer = (IppsMontState*)(IPP_ALIGNED_PTR((pBuffer), MONT_ALIGNMENT)); - - /* max modulus length */ - int modSize = MNT_ROOM(pAlignedBuffer); - /* size of context (bytes) without product and Karatsuba buffers */ - int ctxSize = sizeof(IppsMontState) - +sizeof(BNU_CHUNK_T)*(modSize*4); - - CopyBlock(pAlignedBuffer, pCtx, ctxSize); - MNT_MODULUS(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_MODULUS(pAlignedBuffer))); - MNT_1(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_1(pAlignedBuffer))); - MNT_SQUARE_R(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_SQUARE_R(pAlignedBuffer))); - MNT_CUBE_R(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_CUBE_R(pAlignedBuffer))); - MNT_PRODUCT(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_PRODUCT(pAlignedBuffer))); - MNT_TBUFFER(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(MNT_TBUFFER(pAlignedBuffer))); - MNT_KBUFFER(pCtx) = MNT_KBUFFER(pCtx)? (BNU_CHUNK_T*)((Ipp8u*)pCtx + IPP_UINT_PTR(MNT_KBUFFER(pAlignedBuffer))) : NULL; -} - -/*F* -// Name: ippsMontSet -// -// Purpose: Setup modulus value -// -// Returns: Reason: -// ippStsNullPtrErr pMont==NULL -// pModulus==NULL -// ippStsContextMatchErr !MNT_VALID_ID() -// ippStsLengthErr len32<1 -// ippStsNoErr no errors -// -// Parameters: -// pModulus pointer to the modulus buffer -// len32 length of the modulus (in Ipp32u chunks). -// pMont pointer to the context -*F*/ - -/* -// See Dusse & Kaliski "A cryptographic library for the Motorola DSP56000" -// Unfortunately there is a misprint in the paper above -*/ -static BNU_CHUNK_T cpMontHelper(BNU_CHUNK_T m0) -{ - BNU_CHUNK_T y = 1; - BNU_CHUNK_T x = 2; - BNU_CHUNK_T mask = 2*x-1; - - int i; - for(i=2; i<=BNU_CHUNK_BITS; i++, x<<=1) { - BNU_CHUNK_T rH, rL; - MUL_AB(rH, rL, m0, y); - if( x < (rL & mask) ) /* x < ((m0*y) mod (2*x)) */ - y+=x; - mask += mask + 1; - } - return 0-y; -} - -IPPFUN(IppStatus, ippsMontSet,(const Ipp32u* pModulus, cpSize len32, IppsMontState* pMont)) -{ - IPP_BAD_PTR2_RET(pModulus, pMont); - pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); - IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); - - IPP_BADARG_RET(len32<1, ippStsLengthErr); - - /* modulus is not an odd number */ - IPP_BADARG_RET((pModulus[0] & 1) == 0, ippStsBadModulusErr); - IPP_BADARG_RET(MNT_ROOM(pMont)<(int)(INTERNAL_BNU_LENGTH(len32)), ippStsOutOfRangeErr); - - { - BNU_CHUNK_T m0; - cpSize len; - - /* fix input modulus */ - FIX_BNU(pModulus, len32); - - /* store modulus */ - ZEXPAND_BNU(MNT_MODULUS(pMont), 0, MNT_ROOM(pMont)); - COPY_BNU((Ipp32u*)(MNT_MODULUS(pMont)), pModulus, len32); - /* store modulus length */ - len = INTERNAL_BNU_LENGTH(len32); - MNT_SIZE(pMont) = len; - - /* pre-compute helper m0, m0*m = -1 mod R */ - m0 = cpMontHelper(MNT_MODULUS(pMont)[0]); - MNT_HELPER(pMont) = m0; - - /* setup identity */ - ZEXPAND_BNU(MNT_1(pMont), 0, len); - MNT_1(pMont)[len] = 1; - cpMod_BNU(MNT_1(pMont), len+1, MNT_MODULUS(pMont), len); - - /* setup square */ - ZEXPAND_BNU(MNT_SQUARE_R(pMont), 0, len); - COPY_BNU(MNT_SQUARE_R(pMont)+len, MNT_1(pMont), len); - cpMod_BNU(MNT_SQUARE_R(pMont), 2*len, MNT_MODULUS(pMont), len); - - /* setup cube */ - ZEXPAND_BNU(MNT_CUBE_R(pMont), 0, len); - COPY_BNU(MNT_CUBE_R(pMont)+len, MNT_SQUARE_R(pMont), len); - cpMod_BNU(MNT_CUBE_R(pMont), 2*len, MNT_MODULUS(pMont), len); - - /* clear buffers */ - ZEXPAND_BNU(MNT_TBUFFER(pMont), 0, len); - ZEXPAND_BNU(MNT_SBUFFER(pMont), 0, len); - ZEXPAND_BNU(MNT_PRODUCT(pMont), 0, 2*len); - - return ippStsNoErr; - } -} - -/*F* -// Name: ippsMontGet -// -// Purpose: Extracts modulus. -// -// Returns: Reason: -// ippStsNullPtrErr pMont==NULL -// pModulus==NULL -// pLen32==NULL -// ippStsContextMatchErr !MNT_VALID_ID() -// ippStsNoErr no errors -// -// Parameters: -// pModulus pointer to the modulus buffer -// pLen32 pointer to the modulus length (in Ipp32u chunks). -// pMont pointer to the context -*F*/ -IPPFUN(IppStatus, ippsMontGet,(Ipp32u* pModulus, cpSize* pLen32, const IppsMontState* pMont)) -{ - IPP_BAD_PTR3_RET(pMont, pModulus, pLen32); - - pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); - IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); - - { - cpSize len32 = MNT_SIZE(pMont)*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u); - Ipp32u* bnData = (Ipp32u*)MNT_MODULUS(pMont); - - FIX_BNU(bnData, len32); - COPY_BNU(pModulus, bnData, len32); - *pLen32 = len32; - - return ippStsNoErr; - } -} - -/*F* -// Name: ippsMontForm -// -// Purpose: Converts input into Montgomery domain. -// -// Returns: Reason: -// ippStsNullPtrErr pMont==NULL -// pA==NULL -// pR==NULL -// ippStsContextMatchErr !MNT_VALID_ID() -// !BN_VALID_ID(pA) -// !BN_VALID_ID(pR) -// ippStsBadArgErr A < 0. -// ippStsScaleRangeErr A >= Modulus. -// ippStsOutOfRangeErr R can't hold result -// ippStsNoErr no errors -// -// Parameters: -// pA pointer to the input [0, modulus-1] -// pMont Montgomery context -// pR pointer to the output (A*R mod modulus) -*F*/ -IPPFUN(IppStatus, ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pMont, IppsBigNumState* pR)) -{ - IPP_BAD_PTR3_RET(pMont, pA, pR); - - pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - - IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - IPP_BADARG_RET(BN_SIGN(pA) != ippBigNumPOS, ippStsBadArgErr); - IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); - IPP_BADARG_RET(BN_ROOM(pR) < MNT_SIZE(pMont), ippStsOutOfRangeErr); - - cpMontEnc_BN(pR, pA, pMont); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsMontMul -// -// Purpose: Computes Montgomery modular multiplication for positive big -// number integers of Montgomery form. The following pseudocode -// represents this function: -// r <- ( a * b * R^(-1) ) mod m -// -// Returns: Reason: -// ippStsNoErr Returns no error. -// ippStsNullPtrErr Returns an error when pointers are null. -// ippStsBadArgErr Returns an error when a or b is a negative integer. -// ippStsScaleRangeErr Returns an error when a or b is more than m. -// ippStsOutOfRangeErr Returns an error when IppsBigNumState *r is larger than -// IppsMontState *m. -// ippStsContextMatchErr Returns an error when the context parameter does -// not match the operation. -// -// Parameters: -// a Multiplicand within the range [0, m - 1]. -// b Multiplier within the range [0, m - 1]. -// m Modulus. -// r Montgomery multiplication result. -// -// Notes: The size of IppsBigNumState *r should not be less than the data -// length of the modulus m. -*F*/ -IPPFUN(IppStatus, ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* pMont, IppsBigNumState* pR)) -{ - IPP_BAD_PTR4_RET(pA, pB, pMont, pR); - - pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - - IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - IPP_BADARG_RET(BN_NEGATIVE(pA) || BN_NEGATIVE(pB), ippStsBadArgErr); - IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); - IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pB), BN_SIZE(pB), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); - IPP_BADARG_RET(BN_ROOM(pR) < MNT_SIZE(pMont), ippStsOutOfRangeErr); - - { - BNU_CHUNK_T* pDataR = BN_NUMBER(pR); - cpSize nsM = MNT_SIZE(pMont); - - cpMontMul_BNU(pDataR, - BN_NUMBER(pA), BN_SIZE(pA), - BN_NUMBER(pB), BN_SIZE(pB), - MNT_MODULUS(pMont), nsM, - MNT_HELPER(pMont), - MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); - - FIX_BNU(pDataR, nsM); - BN_SIZE(pR) = nsM; - BN_SIGN(pR) = ippBigNumPOS; - - return ippStsNoErr; - } -} - - -/******************************************************************************* -// Name: ippsMontExp -// Description: ippsMontExp() computes the Montgomery exponentiation with exponent -// IppsBigNumState *e to the given big number integer of Montgomery form -// IppsBigNumState *a with respect to the modulus IppsMontState *m. -// Input Arguments: a - big number integer of Montgomery form within the -// range [0,m-1] -// e - big number exponent -// m - Montgomery modulus of IppsMontState. -// Output Arguments: r - the Montgomery exponentiation result. -// Returns: IPPC_STATUS_OK - No Error -// IPPC_STATUS_MONT_BAD_MODULUS - If a>m or b>m or m>R or P_MONT *m has -// not been initialized by the primitive -// function ippsMontInit( ). -// IPPC_STATUS_BAD_ARG - Bad Arguments -// Notes: IppsBigNumState *r should possess enough memory space as to hold the result -// of the operation. i.e. both pointers r->d and r->buffer should possess -// no less than (m->n->length) number of 32-bit words. -*******************************************************************************/ -IPPFUN(IppStatus, ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* pMont, IppsBigNumState* pR)) -{ - IPP_BAD_PTR4_RET(pA, pE, pMont, pR); - - pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); - pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); - pE = (IppsBigNumState*)( IPP_ALIGNED_PTR(pE, BN_ALIGNMENT) ); - pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); - - IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pE), ippStsContextMatchErr); - IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); - - IPP_BADARG_RET(BN_ROOM(pR) < MNT_SIZE(pMont), ippStsOutOfRangeErr); - /* check a */ - IPP_BADARG_RET(BN_NEGATIVE(pA), ippStsBadArgErr); - IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); - /* check e */ - IPP_BADARG_RET(BN_NEGATIVE(pE), ippStsBadArgErr); - - cpMontExpBin_BN(pR, pA, pE, pMont); - - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontred.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontred.c deleted file mode 100644 index cd5fca48..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpmontred.c +++ /dev/null @@ -1,75 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -*/ - -#include "owncp.h" -#include "pcpbnuarith.h" - - -#if !((_IPP==_IPP_W7) || \ - (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || \ - (_IPP==_IPP_P8) || \ - (_IPP>=_IPP_G9) || \ - (_IPPLP32==_IPPLP32_S8) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E>=_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) - -#if 0 -#define MASKED_COPY_BNU(dst, mask, src1, src2, len) { \ - cpSize i; \ - for(i=0; i<(len); i++) (dst)[i] = ((mask) & (src1)[i]) | (~(mask) & (src2)[i]); \ -} -#endif - -void cpMontRedAdc_BNU(BNU_CHUNK_T* pR, - BNU_CHUNK_T* pProduct, - const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0) -{ - BNU_CHUNK_T carry; - BNU_CHUNK_T extension; - - cpSize n; - for(n=0, carry = 0; n<(nsM-1); n++) { - BNU_CHUNK_T u = pProduct[n]*m0; - BNU_CHUNK_T t = pProduct[nsM +n +1] + carry; - - extension = cpAddMulDgt_BNU(pProduct+n, pModulus, nsM, u); - ADD_AB(carry, pProduct[nsM+n], pProduct[nsM+n], extension); - t += carry; - - carry = t=_IPP_H9)) - #define CP_KARATSUBA_MUL_THRESHOLD 32 - #define CP_KARATSUBA_SQR_THRESHOLD 32 - -#elif ((_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || \ - (_IPP32E==_IPP32E_Y8) || \ - (_IPP32E==_IPP32E_E9) || \ - (_IPPLP64==_IPPLP64_N8)) - #define CP_KARATSUBA_MUL_THRESHOLD 16 - #define CP_KARATSUBA_SQR_THRESHOLD 40 -#elif ((_IPP32E>=_IPP32E_L9)) - #define CP_KARATSUBA_MUL_THRESHOLD 20 - #define CP_KARATSUBA_SQR_THRESHOLD 48 - -#else - #define CP_KARATSUBA_MUL_THRESHOLD 12 - #define CP_KARATSUBA_SQR_THRESHOLD 16 -#endif - - -cpSize cpKaratsubaBufferSize(cpSize len); - -BNU_CHUNK_T cpMul_BNU_karatsuba(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pX, const BNU_CHUNK_T* pY, cpSize ns, - BNU_CHUNK_T* pBuffer); -BNU_CHUNK_T cpSqr_BNU_karatsuba(BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pX, cpSize ns, - BNU_CHUNK_T* pBuffer); - - -#else - #define CP_KARATSUBA_MUL_THRESHOLD 0 - #define CP_KARATSUBA_SQR_THRESHOLD 0 -#endif /* _USE_KARATSUBA_ */ - -#endif /* _KARATSUBA_MUL_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma.h deleted file mode 100644 index 2a0c65f6..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma.h +++ /dev/null @@ -1,106 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA_H) -#define _PCP_PMA_H - - -#include "pcpbn.h" -#include "pcpmontgomery.h" - - -/* -// unsigned BN set/get -*/ -#define SET_BN(pBN,bnu,len) \ - BN_SIGN((pBN)) = ippBigNumPOS; \ - BN_SIZE((pBN)) = ((len)); \ - Cpy_BNU((bnu), BN_NUMBER((pBN)), (len)) - -#define GET_BN(pBN,bnu,len) \ - Set_BNU(0, (bnu), (len)); \ - Cpy_BNU(BN_NUMBER((pBN)), (bnu), BN_SIZE((pBN))) - - -/* -// Prime Modulo Arithmetic -*/ -#define PMA_set(r,a) \ - BN_SIGN((r)) = BN_SIGN((a)); \ - BN_SIZE((r)) = BN_SIZE((a)); \ - ZEXPAND_COPY_BNU(BN_NUMBER((r)),BN_ROOM((r)), BN_NUMBER((a)),BN_SIZE((a))) \ - -#define PMA_mod(r,a,modulo) \ - ippsMod_BN((a),(modulo),(r)) - -#define PMA_inv(r,a,modulo) \ - ippsModInv_BN((a),(modulo),(r)) - -#define PMA_neg(r,a,modulo) \ - ippsSub_BN((modulo),(a),(r)) - -#define PMA_lsr(r,a,modulo) \ - BN_SIZE((r)) = cpLSR_BNU(BN_NUMBER((a)), BN_NUMBER((r)), (int)BN_SIZE((a)), 1) - -#define PMA_div2(r,a,modulo) { \ - if( IsOdd_BN((a)) ) { \ - ippsAdd_BN((a), (modulo), (a)); \ - } \ - BN_SIZE((r)) = cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), (int)BN_SIZE((a)), 1); \ - cpBN_fix((r)); \ -} - -#define PMA_sqr(r,a,modulo) \ - PMA_mul(r,a,a,modulo) - -#define PMA_add(r,a,b,modulo) \ - ippsAdd_BN((a),(b),(r)); \ - if( cpCmp_BNU(BN_NUMBER((r)),BN_SIZE((r)),BN_NUMBER((modulo)),BN_SIZE(modulo)) >= 0 ) \ - ippsSub_BN((r),(modulo),(r)) - -#define PMA_sub(r,a,b,modulo) \ - ippsSub_BN((a),(b),(r)); \ - if( BN_NEGATIVE((r)) ) \ - ippsAdd_BN((r),(modulo),(r)) - -#define PMA_mul(r,a,b,modulo) \ - ippsMul_BN((a),(b),(r)); \ - if( cpCmp_BNU(BN_NUMBER((r)),BN_SIZE((r)),BN_NUMBER((modulo)),BN_SIZE(modulo)) >= 0 ) \ - ippsMod_BN((r),(modulo),(r)) - -#define PMA_enc(r,a,mont) \ - cpMontEnc_BN((r), (a), (mont)) - -#define PMA_dec(r,a,mont) \ - cpMontDec_BN((r), (a), (mont)) - -#define PMA_sqre(r,a,mont) \ - ippsMontMul((a),(a), (mont),(r)) - -#define PMA_mule(r,a,b,mont) \ - ippsMontMul((a),(b), (mont),(r)) - -#endif /* _PCP_PMA_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.c deleted file mode 100644 index 80061d59..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.c +++ /dev/null @@ -1,169 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// Contents: -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_128_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccp.h" -#include "pcppma128.h" - - -/* -// Specific Modulo Arithmetic -// P128 = 2^128 -2^97 -1 -// (reference secp128r1_p) -*/ - -/* -// Reduce modulo: -// -// x = c7|c6|c5|c4|c3|c2|c1|c0 -// -// s1 = c3| c2| c1| c0 -// s2 = 2c4| 00| 00| c4 -// s3 = 4c5| 00| c5|2c5 -// s4 = 8c6| c6|2c6|4c6 -// s5 =17c7|2c7|4c7|8c7 -// -// r = (s1+s2+s3+s4+s5) (mod P) -*/ -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) -void Reduce_P128r1(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u c7x2 = (Ipp64u)pR[7] + (Ipp64u)pR[7]; - Ipp64u c7x4 = c7x2 + c7x2; - Ipp64u c7x8 = c7x4 + c7x4; - - Ipp64u c6x2 = (Ipp64u)pR[6] + (Ipp64u)pR[6]; - Ipp64u c6x4 = c6x2 + c6x2; - Ipp64u c6x8 = c6x4 + c6x4; - - Ipp64u c5x2 = (Ipp64u)pR[5] + (Ipp64u)pR[5]; - Ipp64u c5x4 = c5x2 + c5x2; - - Ipp64u c4x2 = (Ipp64u)pR[4] + (Ipp64u)pR[4]; - - Ipp64u - sum = (Ipp64u)pR[0] + (Ipp64u)pR[4] + c5x2 + c6x4 + c7x8; - pR[0] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[1] + (Ipp64u)pR[5] + c6x2 + c7x4; - pR[1] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[2] + (Ipp64u)pR[6] + c7x2; - pR[2] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[3] + c4x2 + c5x4 + c6x8 + c7x8+c7x8+(Ipp64u)pR[7]; - pR[3] = LODWORD(sum); - pProduct[LEN_P128] = (BNU_CHUNK_T)(HIDWORD(sum)); - - if(pProduct[LEN_P128]) - cpSub_BNU(pProduct, pProduct, ((BNU_CHUNK_T**)secp128_mx)[pProduct[LEN_P128]], LEN_P128+1); - - while((BNS_CHUNK_T)pProduct[LEN_P128] <0) - cpAdd_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp128r1_p, LEN_P128+1); - - while(0 <= cpCmp_BNU(pProduct, LEN_P128+1, (BNU_CHUNK_T*)secp128r1_p, LEN_P128+1)) - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp128r1_p, LEN_P128+1); -} -#endif - -void cpAdde_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P128); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P128, (BNU_CHUNK_T*)secp128r1_p, LEN_P128))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp128r1_p, LEN_P128); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P128; -} - -void cpSube_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P128); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp128r1_p, LEN_P128); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P128; -} - -void cpSqre_128r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P128]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P128); - - Reduce_P128r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P128); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P128; -} - -void cpMule_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P128]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P128, bPtr, LEN_P128); - - Reduce_P128r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P128); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P128; -} - -#endif /* _ECP_128_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.h deleted file mode 100644 index 54b71f42..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma128.h +++ /dev/null @@ -1,79 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA128_H) -#define _PCP_PMA128_H - -#include "pcpbn.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (128) -#define LEN_P128 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - -/* -// Modular Arithmetic for secp128r1 ECC -*/ -void Reduce_P128r1(BNU_CHUNK_T* pR); -void cpAdde_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_128r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_128r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA128_add(r,a,b) \ - cpAdde_128r1((a),(b), (r)) - -#define PMA128_sub(r,a,b) \ - cpSube_128r1((a),(b), (r)) - -#define PMA128_sqr(r,a) \ - cpSqre_128r1((a),(r)) - -#define PMA128_mul(r,a,b) \ - cpMule_128r1((a),(b), (r)) - -#define PMA128_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P128, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P128, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp128r1_p, LEN_P128); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P128, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P128; \ -} - -#define PMA128_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P128); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P128; \ -} - -#endif /* _PCP_PMA128_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.c deleted file mode 100644 index 4cc1a69a..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.c +++ /dev/null @@ -1,153 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_192_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccp.h" -#include "pcppma192.h" - -/* -// Specific Modulo Arithmetic -// P192 = 2^192 -2^64 -1 -// (reference secp192r1_p) -*/ - -/* -// Reduce modulo: -// -// x = c11|c10|c9|c8|c7|c6|c5|c4|c3|c2|c1|c0 -// -// s1 = c05|c04|c03|c02|c01|c00 -// s2 = 000|000|c07|c06|c07|c06 -// s3 = c09|c08|c09|c08|000|000 -// -// r = (s1+s2+s3+s4) (mod P) -*/ -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) -void Reduce_P192r1(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u - sum = (Ipp64u)pR[0*2+0]+(Ipp64u)pR[3*2+0]+(Ipp64u)pR[5*2+0]; - pR[0] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[0*2+1]+(Ipp64u)pR[3*2+1]+(Ipp64u)pR[5*2+1]; - pR[1] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[1*2+0]+(Ipp64u)pR[3*2+0]+(Ipp64u)pR[4*2+0]+(Ipp64u)pR[5*2+0]; - pR[2] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[1*2+1]+(Ipp64u)pR[3*2+1]+(Ipp64u)pR[4*2+1]+(Ipp64u)pR[5*2+1]; - pR[3] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[2*2+0]+(Ipp64u)pR[4*2+0]+(Ipp64u)pR[5*2+0]; - pR[4] = LODWORD(sum); - sum = HIDWORD(sum); - - sum += (Ipp64u)pR[2*2+1]+(Ipp64u)pR[4*2+1]+(Ipp64u)pR[5*2+1]; - pR[5] = LODWORD(sum); - pProduct[LEN_P192] = (BNU_CHUNK_T)(HIDWORD(sum)); - - while(0<=cpCmp_BNU(pProduct, LEN_P192+1, (BNU_CHUNK_T*)secp192r1_p, LEN_P192+1)) - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp192r1_p, LEN_P192+1); -} -#endif - -void cpAdde_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P192); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P192, (BNU_CHUNK_T*)secp192r1_p, LEN_P192))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp192r1_p, LEN_P192); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P192; -} - -void cpSube_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P192); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp192r1_p, LEN_P192); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P192; -} - -void cpSqre_192r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P192]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P192); - - Reduce_P192r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P192); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P192; -} - -void cpMule_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P192]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P192, bPtr, LEN_P192); - - Reduce_P192r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P192); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P192; -} - -#endif /* _ECP_192_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.h deleted file mode 100644 index c2da25a5..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma192.h +++ /dev/null @@ -1,84 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if (_ECP_192_==_ECP_IMPL_SPECIFIC_) - -#if !defined(_PCP_PMA192_H) -#define _PCP_PMA192_H - - -#include "pcpbn.h" -//#include "pcppmafix.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (192) -#define LEN_P192 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - -/* -// Modular Arithmetic for secp192r1 ECC -*/ -void Reduce_P192r1(BNU_CHUNK_T* pR); -void cpAdde_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_192r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_192r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA192_add(r,a,b) \ - cpAdde_192r1((a),(b), (r)) - -#define PMA192_sub(r,a,b) \ - cpSube_192r1((a),(b), (r)) - -#define PMA192_sqr(r,a) \ - cpSqre_192r1((a),(r)) - -#define PMA192_mul(r,a,b) \ - cpMule_192r1((a),(b), (r)) - -#define PMA192_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P192, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P192, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp192r1_p, LEN_P192); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P192, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P192; \ -} - -#define PMA192_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P192); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P192; \ -} - -#endif /* _PCP_PMA192_H */ -#endif /* _ECP_192_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.c deleted file mode 100644 index 404a9d75..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.c +++ /dev/null @@ -1,169 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_224_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccp.h" -#include "pcppma224.h" - - -/* -// Specific Modulo Arithmetic -// P224 = 2^224 -2^96 +1 -// (reference secp224r1_p) -*/ - -/* -// Reduce modulo: -// -// x = c13|c12|c11|c10|c09|c08|c07|c06|c05|c04|c03|c02|c01|c00 - 32-bits values -// -// s1 = c06|c05|c04|c03|c02|c01|c00 -// s2 = c10|c09|c08|c07|000|000|000 -// s3 = 000|c13|c12|c11|000|000|000 -// -// s4 = c13|c12|c11|c10|c09|c08|c07 -// s5 = 000|000|000|000|c13|c12|c11 -// -// r = (s1+s2+s3-s4-s5) (mod P) -*/ -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) -void Reduce_P224r1(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u c7c11 = (Ipp64u)pR[ 7] + (Ipp64u)pR[11]; - Ipp64u c8c12 = (Ipp64u)pR[ 8] + (Ipp64u)pR[12]; - Ipp64u c9c13 = (Ipp64u)pR[ 9] + (Ipp64u)pR[13]; - - Ipp64s - sum = (Ipp64u)pR[ 0] - c7c11; - pR[0] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 1] - c8c12; - pR[1] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 2] - c9c13; - pR[2] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 3] + c7c11 - (Ipp64u)pR[10]; - pR[3] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 4] + c8c12 - (Ipp64u)pR[11]; - pR[4] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 5] + c9c13 - (Ipp64u)pR[12]; - pR[5] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 6] + (Ipp64u)pR[10] - (Ipp64u)pR[13]; - pR[6] = LODWORD(sum); - pR[7] = (Ipp32u)(sum>>32); - - while(((BNS_CHUNK_T)pProduct[BITS_BNU_CHUNK(OPERAND_BITSIZE+1)-1]) <0) { - cpAdd_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp224r1_p, BITS_BNU_CHUNK(OPERAND_BITSIZE+1)); - } - while(0 <= cpCmp_BNU(pProduct, BITS_BNU_CHUNK(OPERAND_BITSIZE+1), (BNU_CHUNK_T*)secp224r1_p, BITS_BNU_CHUNK(OPERAND_BITSIZE+1))) { - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp224r1_p, BITS_BNU_CHUNK(OPERAND_BITSIZE+1)); - } -} -#endif - -void cpAdde_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P224); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P224, (BNU_CHUNK_T*)secp224r1_p, LEN_P224))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp224r1_p, LEN_P224); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P224; -} - -void cpSube_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P224); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp224r1_p, LEN_P224); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P224; -} - -void cpSqre_224r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P224]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P224); - - Reduce_P224r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P224); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P224; -} - -void cpMule_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P224]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P224, bPtr, LEN_P224); - - Reduce_P224r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P224); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P224; -} - -#endif /* _ECP_224_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.h deleted file mode 100644 index 3ddab561..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma224.h +++ /dev/null @@ -1,81 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA224_H) -#define _PCP_PMA224_H - - -#include "pcpbn.h" -//#include "pcppmafix.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (224) -#define LEN_P224 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - -/* -// Modular Arithmetic for secp224r1 ECC -*/ -void Reduce_P224r1(BNU_CHUNK_T* pR); -void cpAdde_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_224r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_224r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA224_add(r,a,b) \ - cpAdde_224r1((a),(b), (r)) - -#define PMA224_sub(r,a,b) \ - cpSube_224r1((a),(b), (r)) - -#define PMA224_sqr(r,a) \ - cpSqre_224r1((a),(r)) - -#define PMA224_mul(r,a,b) \ - cpMule_224r1((a),(b), (r)) - -#define PMA224_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P224, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P224, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp224r1_p, LEN_P224); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P224, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P224; \ -} - -#define PMA224_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P224); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P224; \ -} - -#endif /* _PCP_PMA224_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.c deleted file mode 100644 index cc6a515d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.c +++ /dev/null @@ -1,181 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_256_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccp.h" -#include "pcppma256.h" - - -/* -// Specific Modulo Arithmetic -// P256 = 2^256 -2^224 +2^192 +2^96 -1 -// (reference secp256r1_p) -*/ - -/* -// Reduce modulo: -// -// x = c15|c14|c13|c12|c11|c10|c09|c08|c07|c06|c05|c04|c03|c02|c01|c00 - 32-bits values -// -// s1 = c07|c06|c05|c04|c03|c02|c01|c00 -// s2 = c15|c14|c13|c12|c11|000|000|000 -// s3 = 000|c15|c14|c13|c12|000|000|000 -// s4 = c15|c14|000|000|000|c10|c09|c08 -// s5 = c08|c13|c15|c14|c13|c11|c10|c09 -// -// s6 = c10|c08|000|000|000|c13|c12|c11 -// s7 = c11|c09|000|000|c15|c14|c13|c12 -// s8 = c12|000|c10|c09|c08|c15|c14|c13 -// s9 = c13|000|c11|c10|c09|000|c15|c14 -// -// r = (s1+2*s2+2*s3+s4+s5-s6-s7-s8-s9) (mod P) -*/ -#if !((_IPPXSC==_IPPXSC_S1) || (_IPPXSC==_IPPXSC_S2) || (_IPPXSC==_IPPXSC_C2) || \ - (_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ - (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ - (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) || \ - (_IPP32E==_IPP32E_M7) || \ - (_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \ - (_IPPLP64==_IPPLP64_N8) || (_IPP32E>=_IPP32E_E9) || \ - (_IPP64==_IPP64_I7) ) -void Reduce_P256r1(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u c8c9 = (Ipp64u)pR[ 8] + (Ipp64u)pR[ 9]; - Ipp64u c9c10= (Ipp64u)pR[ 9] + (Ipp64u)pR[10]; - Ipp64u c10c11= (Ipp64u)pR[10] + (Ipp64u)pR[11]; - Ipp64u c11c12= (Ipp64u)pR[11] + (Ipp64u)pR[12]; - Ipp64u c12c13= (Ipp64u)pR[12] + (Ipp64u)pR[13]; - Ipp64u c13c14= (Ipp64u)pR[13] + (Ipp64u)pR[14]; - Ipp64u c14c15= (Ipp64u)pR[14] + (Ipp64u)pR[15]; - - Ipp64s - sum = (Ipp64u)pR[ 0] + c8c9 - c11c12 - c13c14; - pR[0] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 1] + c9c10 - c12c13 - c14c15; - pR[1] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 2] + c10c11- c13c14 - (Ipp64u)pR[15]; - pR[2] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 3] + c11c12 + c11c12 + c13c14 - c14c15 - c8c9; - pR[3] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 4] + c12c13 + c12c13 + (Ipp64u)pR[14] - c9c10; - pR[4] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 5] + c13c14 + c13c14 + (Ipp64u)pR[15] - c10c11; - pR[5] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 6] + c14c15 +c14c15 +c13c14 - c8c9; - pR[6] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 7] + (Ipp64u)pR[ 8] + (Ipp64u)pR[15] + (Ipp64u)pR[15] + (Ipp64u)pR[15] - c10c11 -c12c13; - pR[7] = LODWORD(sum); - sum >>= 32; - pProduct[LEN_P256] = (BNU_CHUNK_T)(sum); - - while(((BNS_CHUNK_T)pProduct[LEN_P256]) <0) - cpAdd_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp256r1_p, LEN_P256+1); - - while(0 <= cpCmp_BNU(pProduct, LEN_P256+1, (BNU_CHUNK_T*)secp256r1_p, LEN_P256+1)) - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp256r1_p, LEN_P256+1); -} -#endif - -void cpAdde_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P256); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P256, (BNU_CHUNK_T*)secp256r1_p, LEN_P256))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp256r1_p, LEN_P256); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P256; -} - -void cpSube_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P256); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp256r1_p, LEN_P256); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P256; -} - -void cpSqre_256r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P256]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P256); - - Reduce_P256r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P256); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P256; -} - -void cpMule_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P256]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P256, bPtr, LEN_P256); - - Reduce_P256r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P256); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P256; -} - -#endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.h deleted file mode 100644 index 5137c049..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma256.h +++ /dev/null @@ -1,82 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA256_H) -#define _PCP_PMA256_H - - -#include "pcpbn.h" -//#include "pcppmafix.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (256) -#define LEN_P256 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - - -/* -// Modular Arithmetic for secp256r1 ECC -*/ -void Reduce_P256r1(BNU_CHUNK_T* pR); -void cpAdde_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_256r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_256r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA256_add(r,a,b) \ - cpAdde_256r1((a),(b), (r)) - -#define PMA256_sub(r,a,b) \ - cpSube_256r1((a),(b), (r)) - -#define PMA256_sqr(r,a) \ - cpSqre_256r1((a),(r)) - -#define PMA256_mul(r,a,b) \ - cpMule_256r1((a),(b), (r)) - -#define PMA256_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P256, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P256, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp256r1_p, LEN_P256); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P256, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P256; \ -} - -#define PMA256_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P256); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P256; \ -} - -#endif /* _PCP_PMA256_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.c deleted file mode 100644 index f2042f69..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.c +++ /dev/null @@ -1,191 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_384_==_ECP_IMPL_SPECIFIC_) || (_ECP_384_==_ECP_IMPL_MFM_) -#include "pcpeccp.h" -#include "pcppma384.h" - - -/* -// Specific Modulo Arithmetic -// P384 = 2^384 -2^128 -2^96 +2^32 -1 -// (reference secp384r1_p) -*/ - -/* -// Reduce modulo: -// -// x = c23|c22|c21|c20|c19|c18|c17|c16|c15|c14|c13|c12|c11|c10|c09|c08|c07|c06|c05|c04|c03|c02|c01|c00 - 32-bits values -// -// s1 = c11|c10|c09|c08|c07|c06|c05|c04|c03|c02|c01|c00 -// s2 = 000|000|000|000|000|c23|c22|c21|000|000|000|000 -// s3 = c23|c22|c21|c20|c19|c18|c17|c16|c15|c14|c13|c12 -// s4 = c20|c19|c18|c17|c16|c15|c14|c13|c12|c23|c22|c21 -// s5 = c19|c18|c17|c16|c15|c14|c13|c12|c20|000|c23|000 -// s6 = 000|000|000|000|c23|c22|c21|c20|000|000|000|000 -// s7 = 000|000|000|000|000|000|c23|c22|c21|000|000|c20 -// -// s8 = c22|c21|c20|c19|c18|c17|c16|c15|c14|c13|c12|c23 -// s9 = 000|000|000|000|000|000|000|c23|c22|c21|c20|000 -// s10= 000|000|000|000|000|000|000|c23|c23|000|000|000 -// -// r = (s1+2*s2+s3+s4+s5+s6+s7-s8-s9-10) (mod P) -*/ - -//static -void Reduce_P384r1(BNU_CHUNK_T* pProduct) -{ - #define CHUNK_LEN_P384 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u c12c21 = (Ipp64u)pR[12] + (Ipp64u)pR[21]; - Ipp64u c13c22 = (Ipp64u)pR[13] + (Ipp64u)pR[22]; - Ipp64u c14c23 = (Ipp64u)pR[14] + (Ipp64u)pR[23]; - - Ipp64s - sum = (Ipp64u)pR[ 0] + c12c21 + (Ipp64u)pR[20] - (Ipp64u)pR[23]; - pR[ 0]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 1] + c13c22 + (Ipp64u)pR[23] - (Ipp64u)pR[12] - (Ipp64u)pR[20]; - pR[ 1]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 2] + c14c23 - (Ipp64u)pR[13] - (Ipp64u)pR[21]; - pR[ 2]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 3] + c12c21 + (Ipp64u)pR[15] + (Ipp64u)pR[20] - c14c23 - (Ipp64u)pR[22]; - pR[ 3]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 4] + (Ipp64u)pR[21] + c12c21 + c13c22 + (Ipp64u)pR[16] + (Ipp64u)pR[20] - (Ipp64u)pR[15] - (Ipp64u)pR[23] - (Ipp64u)pR[23]; - pR[ 4]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 5] + (Ipp64u)pR[22] + c13c22 + c14c23 + (Ipp64u)pR[17] + (Ipp64u)pR[21] - (Ipp64u)pR[16]; - pR[ 5]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 6] + (Ipp64u)pR[23] + c14c23 + (Ipp64u)pR[15] + (Ipp64u)pR[18] + (Ipp64u)pR[22] - (Ipp64u)pR[17]; - pR[ 6]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 7] + (Ipp64u)pR[15] + (Ipp64u)pR[16] + (Ipp64u)pR[19] + (Ipp64u)pR[23] - (Ipp64u)pR[18]; - pR[ 7]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 8] + (Ipp64u)pR[16] + (Ipp64u)pR[17] + (Ipp64u)pR[20] - (Ipp64u)pR[19]; - pR[ 8]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 9] + (Ipp64u)pR[17] + (Ipp64u)pR[18] + (Ipp64u)pR[21] - (Ipp64u)pR[20]; - pR[ 9]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[10] + (Ipp64u)pR[18] + (Ipp64u)pR[19] + (Ipp64u)pR[22] - (Ipp64u)pR[21]; - pR[10]= LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[11] + (Ipp64u)pR[19] + (Ipp64u)pR[20] + (Ipp64u)pR[23] - (Ipp64u)pR[22]; - pR[11]= LODWORD(sum); - sum >>= 32; - pProduct[LEN_P384] = (BNU_CHUNK_T)sum; - - while(((BNS_CHUNK_T)pProduct[LEN_P384]) <0) - cpAdd_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp384r1_p, LEN_P384+1); - - while(0 <= cpCmp_BNU(pProduct, LEN_P384+1, (BNU_CHUNK_T*)secp384r1_p, LEN_P384+1)) - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)secp384r1_p, LEN_P384+1); -} - - -void cpSqre_384r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P384]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P384); - - Reduce_P384r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P384); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P384; -} - -void cpMule_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P384]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P384, bPtr, LEN_P384); - - Reduce_P384r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P384); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P384; -} -#endif /* (_ECP_384_==_ECP_IMPL_SPECIFIC_) || (_ECP_384_==_ECP_IMPL_MFM_) */ - -#if (_ECP_384_==_ECP_IMPL_SPECIFIC_) -void cpAdde_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P384); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P384, (BNU_CHUNK_T*)secp384r1_p, LEN_P384))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp384r1_p, LEN_P384); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P384; -} - -void cpSube_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P384); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp384r1_p, LEN_P384); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P384; -} -#endif /* _ECP_384_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.h deleted file mode 100644 index 688e49fa..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma384.h +++ /dev/null @@ -1,82 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA384_H) -#define _PCP_PMA384_H - - -#include "pcpbn.h" -//#include "pcppmafix.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (384) -#define LEN_P384 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - -/* -// Modular Arithmetic for secp384r1 ECC -*/ -void Reduce_P384r1(BNU_CHUNK_T* pProduct); - -void cpAdde_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_384r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_384r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA384_add(r,a,b) \ - cpAdde_384r1((a),(b), (r)) - -#define PMA384_sub(r,a,b) \ - cpSube_384r1((a),(b), (r)) - -#define PMA384_sqr(r,a) \ - cpSqre_384r1((a),(r)) - -#define PMA384_mul(r,a,b) \ - cpMule_384r1((a),(b), (r)) - -#define PMA384_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P384, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P384, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp384r1_p, LEN_P384); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P384, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P384; \ -} - -#define PMA384_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P384); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P384; \ -} - -#endif /* _PCP_PMA384_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.c deleted file mode 100644 index 6366285c..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.c +++ /dev/null @@ -1,124 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcpeccp.h" -#include "pcppma521.h" - -#if (_ECP_521_==_ECP_IMPL_SPECIFIC_) || (_ECP_521_==_ECP_IMPL_MFM_) - - -/* -// Specific Modulo Arithmetic -// P521 = 2^521 -1 -// (reference secp521r1_p) -*/ - -/* -// Reduce modulo: -// -// x = a1*2^521 + a0 - 521-bits values -// -// r = (s1+a0) (mod P) -*/ -static -void Reduce_P521r1(BNU_CHUNK_T* pProduct) -{ - BNU_CHUNK_T TT[LEN_P521]; - BNU_CHUNK_T* pR = pProduct; - - cpLSR_BNU(TT, pR+LEN_P521-1, LEN_P521, OPERAND_BITSIZE%BITSIZE(BNU_CHUNK_T)); - pR[LEN_P521-1] &= MASK_BNU_CHUNK(OPERAND_BITSIZE % BITSIZE(BNU_CHUNK_T)); - TT[LEN_P521-1] &= MASK_BNU_CHUNK(OPERAND_BITSIZE % BITSIZE(BNU_CHUNK_T)); - cpAdd_BNU(pR, pR, TT, LEN_P521); - - while(0 <= cpCmp_BNU(pR, LEN_P521, (BNU_CHUNK_T*)secp521r1_p, LEN_P521)) - cpSub_BNU(pR, pR, (BNU_CHUNK_T*)secp521r1_p, LEN_P521); -} - -void cpSqre_521r1(IppsBigNumState* pA, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P521]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpSqr_BNU_school(tmpR, aPtr, LEN_P521); - - Reduce_P521r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P521); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P521; -} - -void cpMule_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T tmpR[2*LEN_P521]; - - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - cpMul_BNU_school(tmpR, aPtr, LEN_P521, bPtr, LEN_P521); - - Reduce_P521r1(tmpR); - COPY_BNU(rPtr, tmpR, LEN_P521); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P521; -} -#endif /* (_ECP_521_==_ECP_IMPL_SPECIFIC_) || (_ECP_521_==_ECP_IMPL_MFM_) */ - -#if (_ECP_521_==_ECP_IMPL_SPECIFIC_) -void cpAdde_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T carry = cpAdd_BNU(rPtr, aPtr, bPtr, LEN_P521); - if(carry || (0<=cpCmp_BNU(rPtr, LEN_P521, (BNU_CHUNK_T*)secp521r1_p, LEN_P521))) - cpSub_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp521r1_p, LEN_P521); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P521; -} - -void cpSube_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR) -{ - BNU_CHUNK_T* aPtr = BN_NUMBER(pA); - BNU_CHUNK_T* bPtr = BN_NUMBER(pB); - BNU_CHUNK_T* rPtr = BN_NUMBER(pR); - - BNU_CHUNK_T borrow = cpSub_BNU(rPtr, aPtr, bPtr, LEN_P521); - if(borrow) - cpAdd_BNU(rPtr, rPtr, (BNU_CHUNK_T*)secp521r1_p, LEN_P521); - - BN_SIGN(pR) = ippBigNumPOS; - BN_SIZE(pR) = LEN_P521; -} -#endif /* _ECP_521_==_ECP_IMPL_SPECIFIC_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.h deleted file mode 100644 index 8dacdcfe..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppma521.h +++ /dev/null @@ -1,80 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Prime Modulo Arithmetic Function Prototypes -// -// -*/ - -#if !defined(_PCP_PMA521_H) -#define _PCP_PMA521_H - - -#include "pcpbn.h" -//#include "pcppmafix.h" - - -/* length of operand in bits and BNU32_CHUNK_T */ -#define OPERAND_BITSIZE (521) -#define LEN_P521 (BITS_BNU_CHUNK(OPERAND_BITSIZE)) - -/* -// Modular Arithmetic for secp521r1 ECC -*/ -void cpAdde_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSube_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); -void cpSqre_521r1(IppsBigNumState* pA, IppsBigNumState* pR); -void cpMule_521r1(IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR); - -#define PMA521_add(r,a,b) \ - cpAdde_521r1((a),(b), (r)) - -#define PMA521_sub(r,a,b) \ - cpSube_521r1((a),(b), (r)) - -#define PMA521_sqr(r,a) \ - cpSqre_521r1((a),(r)) - -#define PMA521_mul(r,a,b) \ - cpMule_521r1((a),(b), (r)) - -#define PMA521_div2(r,a) \ -{ \ - if( IsOdd_BN((a)) ) { \ - cpInc_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P521, 1); \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((r)), LEN_P521, 1); \ - cpAdd_BNU(BN_NUMBER((r)), BN_NUMBER((r)), (BNU_CHUNK_T*)h_secp521r1_p, LEN_P521); \ - } \ - else \ - cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), LEN_P521, 1); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P521; \ -} - -#define PMA521_inv(r,a,modulo) \ -{ \ - ippsModInv_BN((a),(modulo),(r)); \ - ZEXPAND_BNU(BN_NUMBER((r)),BN_SIZE((r)), LEN_P521); \ - BN_SIGN((r)) = ippBigNumPOS; \ - BN_SIZE((r)) = LEN_P521; \ -} - -#endif /* _PCP_PMA521_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppmasm2.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppmasm2.c deleted file mode 100644 index 28ebf80f..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcppmasm2.c +++ /dev/null @@ -1,311 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Prime Modulo Arithmetic Function -// -// -*/ - -#include "precomp.h" -#include "owncp.h" - -#if (_ECP_SM2_==_ECP_IMPL_SPECIFIC_) -#include "pcpeccp.h" -#include "pcppmasm2.h" - - -/* -// Specific Modulo Arithmetic -// P256 = 2^256 -2^224 -2^96 +2^64 -1 -// (reference tpmSM2_p256_p) -*/ - -/* -// Reduce modulo: -// -// x = c15|c14|c13|c12|c11|c10|c09|c08|c07|c06|c05|c04|c03|c02|c01|c00 - 32-bits values -// -// r7 r6 r5 r4 r3 r2 r1 r0 -// c08 deposit: | c08 | 000 | 000 | 000 | c08 |-c08 | 000 | c08 | -// c09 deposit: | c09 | 000 | 000 | c09 | 000 |-c09 | c09 | c09 | -// c10 deposit: | c10 | 000 | c10 | 000 | 000 | 000 | c10 | c10 | -// c11 deposit: | c11 | c11 | 000 | 000 | c11 | 000 | c11 | c11 | -// c12 deposit: |2*c12| 000 | 000 | c12 | c12 | 000 | c12 | c12 | -// c13 deposit: |2*c13| 000 | c13 | c13 |2*c13|-c13 | c13 |2*c13| -// c14 deposit: |2*c14| c14 | c14 |2*c14| c14 |-c14 |2*c14|2*c14| -// c15 deposit: |3*c15| c15 |2*c15| c15 | c15 | 000 |2*c15|2*c15| -// -*/ -//#if !((_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \ -// (_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \ -// (_IPPLP32==_IPPLP32_S8) || (_IPP>=_IPP_G9) ) -#if (_IPP < _IPP_W7) -void Reduce_SM2(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - Ipp64u t0 = (Ipp64u)pR[ 8] + pR[ 9] + pR[10] + pR[11] + pR[12]; - Ipp64u w0 = (Ipp64u)pR[13] +pR[14] + pR[15]; - Ipp64u u0 = w0<<1; - - Ipp64s - sum = (Ipp64u)pR[ 0] +t0 + u0; - pR[0] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 1] +(t0-pR[8]) +(u0-pR[13]); - pR[1] = LODWORD(sum); - sum >>= 32; - - //sum += (Ipp64u)pR[ 2] - (pR[8]+pR[9]) - (w0-pR[15]); - sum += (Ipp64u)pR[ 2] - pR[8] -pR[9] - (w0-pR[15]); - pR[2] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 3] +pR[ 8] +pR[11] +pR[12] +(w0+pR[13]); - pR[3] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 4] +pR[ 9] + pR[12] + (w0+pR[14]); - pR[4] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 5] +pR[10] +(w0+pR[15]); - pR[5] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 6] +pR[11] + (w0-pR[13]); - pR[6] = LODWORD(sum); - sum >>= 32; - - sum += (Ipp64u)pR[ 7] + (t0+pR[12]) + (u0+pR[15]); - pR[7] = LODWORD(sum); - sum >>= 32; - pProduct[LEN_P256] = (BNU_CHUNK_T)(sum); - - while(((BNS_CHUNK_T)pProduct[LEN_P256]) <0) - cpAdd_BNU(pProduct, pProduct, (BNU_CHUNK_T*)tpmSM2_p256_p, LEN_P256+1); - - while(0 <= cpCmp_BNU(pProduct, LEN_P256+1, (BNU_CHUNK_T*)tpmSM2_p256_p, LEN_P256+1)) - cpSub_BNU(pProduct, pProduct, (BNU_CHUNK_T*)tpmSM2_p256_p, LEN_P256+1); -} - -#else -#if 0 -void Reduce_SM2(BNU_CHUNK_T* pProduct) -{ - Ipp32u* pR = (Ipp32u*)pProduct; - - __m64 s8 = _mm_cvtsi32_si64((Ipp32s)pR[8]); - __m64 s9 = _mm_cvtsi32_si64((Ipp32s)pR[9]); - __m64 s10 = _mm_cvtsi32_si64((Ipp32s)pR[10]); - __m64 s11 = _mm_cvtsi32_si64((Ipp32s)pR[11]); - __m64 s12 = _mm_cvtsi32_si64((Ipp32s)pR[12]); - __m64 s13 = _mm_cvtsi32_si64((Ipp32s)pR[13]); - __m64 s14 = _mm_cvtsi32_si64((Ipp32s)pR[14]); - __m64 s15 = _mm_cvtsi32_si64((Ipp32s)pR[15]); - - __m64 w0 = _mm_add_si64(s13, - _mm_add_si64(s14, s15)); - __m64 t0 = _mm_add_si64(s8, - _mm_add_si64(s9, - _mm_add_si64(s10, - _mm_add_si64(s11, - _mm_add_si64(s12, - _mm_add_si64(w0, w0)))))); - - __m64 - // sum = pR[ 0] +t0 + u0 - sum = _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[0]), t0); - pR[0] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 1] +(t0-pR[8]) +(u0-pR[13]) - sum = _mm_sub_si64( - _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[1]), - _mm_add_si64(sum, t0)), - _mm_add_si64(s8, s13)); - pR[1] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 2] - pR[8] -pR[9] - (w0-pR[15]) - sum = _mm_sub_si64( - _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[2]), - _mm_add_si64(sum, s15)), - _mm_add_si64(s8, - _mm_add_si64(s9, w0))); - pR[2] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 3] +pR[ 8] +pR[11] +pR[12] +(w0+pR[13]); - sum = _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[3]), - _mm_add_si64(sum, - _mm_add_si64(s8, - _mm_add_si64(s11, - _mm_add_si64(s12, - _mm_add_si64(w0, s13)))))); - pR[3] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 4] +pR[ 9] + pR[12] + (w0+pR[14]); - sum = _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[4]), - _mm_add_si64(sum, - _mm_add_si64(s9, - _mm_add_si64(s12, - _mm_add_si64(w0, s14))))); - pR[4] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 5] +pR[10] +(w0+pR[15]); - sum = _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[5]), - _mm_add_si64(sum, - _mm_add_si64(s10, - _mm_add_si64(w0, s15)))); - pR[5] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 6] +pR[11] + (w0-pR[13]); - sum = _mm_sub_si64( - _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[6]), - _mm_add_si64(sum, - _mm_add_si64(s11, w0))), - s13); - pR[6] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - - // sum += pR[ 7] + (t0+pR[12]) + (u0+pR[15]); - sum = _mm_add_si64(_mm_cvtsi32_si64((Ipp32s)pR[7]), - _mm_add_si64(sum, - _mm_add_si64(t0, - _mm_add_si64(s12, s15)))); - pR[7] = (Ipp32u)( _mm_cvtsi64_si32(sum) ); - sum = _mm_shuffle_pi16(sum, 0xfe); - pProduct[LEN_P256] = (BNS_CHUNK_T)( _mm_cvtsi64_si32(sum) ); - - { - int n; - const Ipp32u* pMx; - - // reduce multiple modulus - if( pProduct[LEN_P256] ) { - pMx = tpmSM2_p256_p_mx[ pProduct[LEN_P256] ]; - sum = _mm_setzero_si64(); - for(n=0; nidCtx) -#define PRIME_MAXBITSIZE(ctx) ((ctx)->maxBitSize) -#define PRIME_NUMBER(ctx) ((ctx)->pPrime) -#define PRIME_TEMP1(ctx) ((ctx)->pT1) -#define PRIME_TEMP2(ctx) ((ctx)->pT2) -#define PRIME_TEMP3(ctx) ((ctx)->pT3) -#define PRIME_MONT(ctx) ((ctx)->pMont) - -#define PRIME_VALID_ID(ctx) (PRIME_ID((ctx))==idCtxPrimeNumber) - -/* easy prime test */ -int cpMimimalPrimeTest(const Ipp32u* pPrime, cpSize ns); - -/* prime test */ -int cpPrimeTest(const BNU_CHUNK_T* pPrime, cpSize primeLen, - cpSize nTrials, - IppsPrimeState* pCtx, - IppBitSupplier rndFunc, void* pRndParam); - -void cpPackPrimeCtx(const IppsPrimeState* pCtx, Ipp8u* pBuffer); -void cpUnpackPrimeCtx(const Ipp8u* pBuffer, IppsPrimeState* pCtx); - -#endif /* _CP_PRIME_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprimeginitca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprimeginitca.c deleted file mode 100644 index 9689d834..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprimeginitca.c +++ /dev/null @@ -1,158 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives. Cryptographic Primitives (ippcp) -// Prime Number Primitives. -// -// Contents: -// ippsPrimeGetSize() -// ippsPrimeInit() -// -// -*/ - -#include "owncp.h" -#include "pcpprimeg.h" -#include "pcptool.h" - - -/*F* -// Name: ippsPrimeGetSize -// -// Purpose: Returns size of Prime Number Generator context (bytes). -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pSize -// ippStsLengthErr 1 > maxBits -// ippStsNoErr no error -// -// Parameters: -// maxBits max length of a prime number -// pSize pointer to the size of internal context -*F*/ -IPPFUN(IppStatus, ippsPrimeGetSize, (cpSize maxBits, cpSize* pSize)) -{ - IPP_BAD_PTR1_RET(pSize); - IPP_BADARG_RET(maxBits<1, ippStsLengthErr); - - { - cpSize len = BITS_BNU_CHUNK(maxBits); - cpSize len32 = BITS2WORD32_SIZE(maxBits); - cpSize montSize; - ippsMontGetSize(ippBinaryMethod, len32, &montSize); - - *pSize = sizeof(IppsPrimeState) - +len*sizeof(BNU_CHUNK_T) - +len*sizeof(BNU_CHUNK_T) - +len*sizeof(BNU_CHUNK_T) - +len*sizeof(BNU_CHUNK_T) - +montSize - +PRIME_ALIGNMENT-1; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsPrimeInit -// -// Purpose: Initializes Prime Number Generator context -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pCtx -// ippStsLengthErr 1 > maxBits -// ippStsNoErr no error -// -// Parameters: -// maxBits max length of a prime number -// pCtx pointer to the context to be initialized -*F*/ -IPPFUN(IppStatus, ippsPrimeInit, (cpSize maxBits, IppsPrimeState* pCtx)) -{ - IPP_BAD_PTR1_RET(pCtx); - IPP_BADARG_RET(maxBits<1, ippStsLengthErr); - - /* use aligned PRNG context */ - pCtx = (IppsPrimeState*)( IPP_ALIGNED_PTR(pCtx, PRIME_ALIGNMENT) ); - - { - Ipp8u* ptr = (Ipp8u*)pCtx; - - cpSize len = BITS_BNU_CHUNK(maxBits); - cpSize len32 = BITS2WORD32_SIZE(maxBits); - - PRIME_ID(pCtx) = idCtxPrimeNumber; - PRIME_MAXBITSIZE(pCtx) = maxBits; - - ptr += sizeof(IppsPrimeState); - PRIME_NUMBER(pCtx) = (BNU_CHUNK_T*)ptr; - - ptr += len*sizeof(BNU_CHUNK_T); - PRIME_TEMP1(pCtx) = (BNU_CHUNK_T*)ptr; - - ptr += len*sizeof(BNU_CHUNK_T); - PRIME_TEMP2(pCtx) = (BNU_CHUNK_T*)ptr; - - ptr += len*sizeof(BNU_CHUNK_T); - PRIME_TEMP3(pCtx) = (BNU_CHUNK_T*)ptr; - - ptr += len*sizeof(BNU_CHUNK_T); - PRIME_MONT(pCtx) = (IppsMontState*)( IPP_ALIGNED_PTR((ptr), MONT_ALIGNMENT) ); - ippsMontInit(ippBinaryMethod, len32, PRIME_MONT(pCtx)); - - return ippStsNoErr; - } -} - - -void cpPackPrimeCtx(const IppsPrimeState* pCtx, Ipp8u* pBuffer) -{ - IppsPrimeState* pAlignedBuffer = (IppsPrimeState*)( IPP_ALIGNED_PTR(pBuffer, PRIME_ALIGNMENT) ); - - /* max length of prime */ - cpSize nsPrime = BITS_BNU_CHUNK(PRIME_MAXBITSIZE(pCtx)); - - CopyBlock(pCtx, pAlignedBuffer, sizeof(IppsPrimeState)); - PRIME_NUMBER(pAlignedBuffer)= (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(PRIME_NUMBER(pCtx))-IPP_UINT_PTR(pCtx)); - PRIME_TEMP1(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(PRIME_TEMP1(pCtx))-IPP_UINT_PTR(pCtx)); - PRIME_TEMP2(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(PRIME_TEMP2(pCtx))-IPP_UINT_PTR(pCtx)); - PRIME_TEMP3(pAlignedBuffer) = (BNU_CHUNK_T*)((Ipp8u*)NULL + IPP_UINT_PTR(PRIME_TEMP3(pCtx))-IPP_UINT_PTR(pCtx)); - PRIME_MONT(pAlignedBuffer) =(IppsMontState*)((Ipp8u*)NULL + IPP_UINT_PTR(PRIME_MONT(pCtx))-IPP_UINT_PTR(pCtx)); - - CopyBlock(PRIME_NUMBER(pCtx), (Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(PRIME_NUMBER(pAlignedBuffer)), nsPrime*sizeof(BNU_CHUNK_T)); - cpPackMontCtx(PRIME_MONT(pCtx), (Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(PRIME_MONT(pAlignedBuffer))); -} - -void cpUnpackPrimeCtx(const Ipp8u* pBuffer, IppsPrimeState* pCtx) -{ - IppsPrimeState* pAlignedBuffer = (IppsPrimeState*)( IPP_ALIGNED_PTR(pBuffer, PRIME_ALIGNMENT) ); - - /* max length of prime */ - cpSize nsPrime = BITS_BNU_CHUNK(PRIME_MAXBITSIZE(pAlignedBuffer)); - - CopyBlock(pAlignedBuffer, pCtx, sizeof(IppsPrimeState)); - PRIME_NUMBER(pCtx)= (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(PRIME_NUMBER(pAlignedBuffer))); - PRIME_TEMP1(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(PRIME_TEMP1(pAlignedBuffer))); - PRIME_TEMP2(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(PRIME_TEMP2(pAlignedBuffer))); - PRIME_TEMP3(pCtx) = (BNU_CHUNK_T*)((Ipp8u*)pCtx+ IPP_UINT_PTR(PRIME_TEMP3(pAlignedBuffer))); - PRIME_MONT(pCtx) = (IppsMontState*)((Ipp8u*)pCtx+ IPP_UINT_PTR(PRIME_MONT(pAlignedBuffer))); - - CopyBlock((Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(PRIME_NUMBER(pAlignedBuffer)), PRIME_NUMBER(pCtx), nsPrime*sizeof(BNU_CHUNK_T)); - cpUnpackMontCtx((Ipp8u*)pAlignedBuffer+IPP_UINT_PTR(PRIME_MONT(pAlignedBuffer)), PRIME_MONT(pCtx)); -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprng.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprng.h deleted file mode 100644 index 4d236ae3..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprng.h +++ /dev/null @@ -1,59 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions and -// Internal Pseudo Random Generator Function Prototypes -// -*/ - -#if !defined(_CP_PRNG_H) -#define _CP_PRNG_H - -/* -// Pseudo-random generation context -*/ - -#define MAX_XKEY_SIZE 512 -#define DEFAULT_XKEY_SIZE 512 /* must be >=160 || <=512 */ - -struct _cpPRNG { - IppCtxId idCtx; /* PRNG identifier */ - cpSize seedBits; /* secret seed-key bitsize */ - BNU_CHUNK_T Q[BITS_BNU_CHUNK(160)]; /* modulus */ - BNU_CHUNK_T T[BITS_BNU_CHUNK(160)]; /* parameter of SHA_G() funct */ - BNU_CHUNK_T xAug[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; /* optional entropy augment */ - BNU_CHUNK_T xKey[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; /* secret seed-key */ -}; - -/* alignment */ -#define PRNG_ALIGNMENT ((int)(sizeof(void*))) - -#define RAND_ID(ctx) ((ctx)->idCtx) -#define RAND_SEEDBITS(ctx) ((ctx)->seedBits) -#define RAND_Q(ctx) ((ctx)->Q) -#define RAND_T(ctx) ((ctx)->T) -#define RAND_XAUGMENT(ctx) ((ctx)->xAug) -#define RAND_XKEY(ctx) ((ctx)->xKey) - -#define RAND_VALID_ID(ctx) (RAND_ID((ctx))==idCtxPRNG) - -int cpPRNGen(Ipp32u* pBuffer, cpSize bitLen, IppsPRNGState* pCtx); - -#endif /* _CP_PRNG_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngenca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngenca.c deleted file mode 100644 index e3204f72..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngenca.c +++ /dev/null @@ -1,251 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// PRNG Functions -// -// Contents: -// ippsPRNGen() -// ippsPRNGen_BN() -// -// -*/ - -#include "precomp.h" - -#include "owncp.h" -#include "pcpbn.h" -#include "pcphash.h" -#include "pcpprng.h" -#include "pcptool.h" - -/* -// G() function based on SHA1 -// -// Parameters: -// T 160 bit parameter -// pHexStr input hex string -// hexStrLen size of hex string (Ipp8u segnments) -// xBNU 160 bit BNU result -// -// Note 1: -// must to be hexStrLen <= 64 (512 bits) -*/ -static -void SHA1_G(Ipp32u* xBNU, const Ipp32u* T, Ipp8u* pHexStr, int hexStrLen) -{ - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA1; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA1ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - else - #endif - updateFunc = UpdateSHA1; - #endif - - /* pad HexString zeros */ - PaddBlock(0, pHexStr+hexStrLen, BITS2WORD8_SIZE(MAX_XKEY_SIZE)-hexStrLen); - - /* reset initial HASH value */ - xBNU[0] = T[0]; - xBNU[1] = T[1]; - xBNU[2] = T[2]; - xBNU[3] = T[3]; - xBNU[4] = T[4]; - - /* SHA1 */ - //UpdateSHA1(xBNU, pHexStr, BITS2WORD8_SIZE(MAX_XKEY_SIZE), SHA1_cnt); - updateFunc(xBNU, pHexStr, BITS2WORD8_SIZE(MAX_XKEY_SIZE), SHA1_cnt); - - /* swap back */ - SWAP(xBNU[0],xBNU[4]); - SWAP(xBNU[1],xBNU[3]); -} - -/* -// Returns bitsize of the bitstring has beed added -*/ -int cpPRNGen(Ipp32u* pRand, cpSize nBits, IppsPRNGState* pRnd) -{ - BNU_CHUNK_T Xj [BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; - BNU_CHUNK_T XVAL[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; - - Ipp8u TXVAL[BITS2WORD8_SIZE(MAX_XKEY_SIZE)]; - - /* XKEY length in BNU_CHUNK_T */ - cpSize xKeyLen = BITS_BNU_CHUNK(RAND_SEEDBITS(pRnd)); - /* XKEY length in bytes */ - cpSize xKeySize= BITS2WORD8_SIZE(RAND_SEEDBITS(pRnd)); - /* XKEY word's mask */ - BNU_CHUNK_T xKeyMsk = MASK_BNU_CHUNK(RAND_SEEDBITS(pRnd)); - - /* number of Ipp32u chunks to be generated */ - cpSize genlen = BITS2WORD32_SIZE(nBits); - - ZEXPAND_BNU(Xj, 0, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); - ZEXPAND_BNU(XVAL, 0, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); - - while(genlen) { - cpSize len; - - /* Step 1: XVAL=(Xkey+Xseed) mod 2^b */ - BNU_CHUNK_T carry = cpAdd_BNU(XVAL, RAND_XKEY(pRnd), RAND_XAUGMENT(pRnd), xKeyLen); - XVAL[xKeyLen-1] &= xKeyMsk; - - /* Step 2: xj=G(t, XVAL) mod Q */ - cpToOctStr_BNU(TXVAL, xKeySize, XVAL, xKeyLen); - SHA1_G((Ipp32u*)Xj, (Ipp32u*)RAND_T(pRnd), TXVAL, xKeySize); - - { - cpSize sizeXj = BITS_BNU_CHUNK(160); - if(0 <= cpCmp_BNU(Xj, BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE), RAND_Q(pRnd),BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE)) ) - sizeXj = cpMod_BNU(Xj, BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE), RAND_Q(pRnd), BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE)); - FIX_BNU(Xj, sizeXj); - ZEXPAND_BNU(Xj, sizeXj, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); - } - - /* Step 3: Xkey=(1+Xkey+Xj) mod 2^b */ - cpInc_BNU(RAND_XKEY(pRnd), RAND_XKEY(pRnd), xKeyLen, 1); - carry = cpAdd_BNU(RAND_XKEY(pRnd), RAND_XKEY(pRnd), Xj, xKeyLen); - RAND_XKEY(pRnd)[xKeyLen-1] &= xKeyMsk; - - /* fill out result */ - len = genlenidCtx -// -// ippStsLengthErr 1 > nBits -// -// ippStsNoErr no error -// -// Parameters: -// pBuffer pointer to the buffer -// nBits number of bits be requested -// pRndCtx pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGen,(Ipp32u* pBuffer, cpSize nBits, void* pRnd)) -{ - IppsPRNGState* pRndCtx = (IppsPRNGState*)pRnd; - - /* test PRNG context */ - IPP_BAD_PTR2_RET(pBuffer, pRnd); - - pRndCtx = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRndCtx, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRndCtx), ippStsContextMatchErr); - - /* test sizes */ - IPP_BADARG_RET(nBits< 1, ippStsLengthErr); - - { - cpSize rndSize = BITS2WORD32_SIZE(nBits); - Ipp32u rndMask = MAKEMASK32(nBits); - - cpPRNGen(pBuffer, nBits, pRndCtx); - pBuffer[rndSize-1] &= rndMask; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsPRNGen_BN -// -// Purpose: Generates a pseudorandom big number of the specified nBits length. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pRandBN -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pRandBN->idCtx -// -// ippStsLengthErr 1 > nBits -// nBits > BN_ROOM(pRandBN) -// -// ippStsNoErr no error -// -// Parameters: -// pRandBN pointer to the BN random -// nBits number of bits be requested -// pRndCtx pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGen_BN,(IppsBigNumState* pRandBN, int nBits, void* pRnd)) -{ - IppsPRNGState* pRndCtx; - - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRndCtx = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRndCtx), ippStsContextMatchErr); - - /* test random BN */ - IPP_BAD_PTR1_RET(pRandBN); - pRandBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pRandBN, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pRandBN), ippStsContextMatchErr); - - /* test sizes */ - IPP_BADARG_RET(nBits< 1, ippStsLengthErr); - IPP_BADARG_RET(nBits> BN_ROOM(pRandBN)*BNU_CHUNK_BITS, ippStsLengthErr); - - - { - BNU_CHUNK_T* pRand = BN_NUMBER(pRandBN); - cpSize rndSize = BITS_BNU_CHUNK(nBits); - BNU_CHUNK_T rndMask = MASK_BNU_CHUNK(nBits); - - cpPRNGen((Ipp32u*)pRand, nBits, pRndCtx); - pRand[rndSize-1] &= rndMask; - - FIX_BNU(pRand, rndSize); - BN_SIZE(pRandBN) = rndSize; - BN_SIGN(pRandBN) = ippBigNumPOS; - - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprnginitca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprnginitca.c deleted file mode 100644 index cf52eb0d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprnginitca.c +++ /dev/null @@ -1,111 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// PRNG Functions -// -// Contents: -// ippsPRNGGetSize() -// ippsPRNGInit() -// -// -*/ - -#include "precomp.h" - -#include "owncp.h" -#include "pcpbn.h" -#include "pcpprng.h" -#include "pcphash.h" -#include "pcptool.h" - - -/*F* -// Name: ippsPRNGGetSize -// -// Purpose: Returns size of PRNG context (bytes). -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pSize -// -// ippStsNoErr no error -// -// Parameters: -// pSize pointer to the size of internal context -*F*/ -IPPFUN(IppStatus, ippsPRNGGetSize, (int* pSize)) -{ - IPP_BAD_PTR1_RET(pSize); - - *pSize = sizeof(IppsPRNGState) - +PRNG_ALIGNMENT-1; - return ippStsNoErr; -} - - -/*F* -// Name: ippsPRNGInit -// -// Purpose: Initializes PRNG context -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// -// ippStsLengthErr seedBits < 1 -// seedBits < MAX_XKEY_SIZE -// seedBits%8 !=0 -// -// ippStsNoErr no error -// -// Parameters: -// seedBits seed bitsize -// pRnd pointer to the context to be initialized -*F*/ -IPPFUN(IppStatus, ippsPRNGInit, (int seedBits, IppsPRNGState* pRnd)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - - /* test sizes */ - IPP_BADARG_RET((1>seedBits) || (seedBits>MAX_XKEY_SIZE) ||(seedBits&7), ippStsLengthErr); - - { - int hashIvSize = cpHashIvSize(ippHashAlg_SHA1); - const Ipp8u* iv = cpHashIV[ippHashAlg_SHA1]; - - /* cleanup context */ - ZEXPAND_BNU((Ipp8u*)pRnd, 0, (cpSize)(sizeof(IppsPRNGState))); - - RAND_ID(pRnd) = idCtxPRNG; - RAND_SEEDBITS(pRnd) = seedBits; - - /* default Q parameter */ - ((Ipp32u*)RAND_Q(pRnd))[0] = 0xFFFFFFFF; - ((Ipp32u*)RAND_Q(pRnd))[1] = 0xFFFFFFFF; - ((Ipp32u*)RAND_Q(pRnd))[2] = 0xFFFFFFFF; - ((Ipp32u*)RAND_Q(pRnd))[3] = 0xFFFFFFFF; - ((Ipp32u*)RAND_Q(pRnd))[4] = 0xFFFFFFFF; - - /* default T parameter */ - CopyBlock(iv, RAND_T(pRnd), hashIvSize); - - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngsetca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngsetca.c deleted file mode 100644 index f57c2e20..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpprngsetca.c +++ /dev/null @@ -1,239 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// PRNG Functions -// -// Contents: -// ippsPRNGSetModulus() -// ippsPRNGSetSeed() -// ippsPRNGSetAugment() -// ippsPRNGSetH0() -// -// -*/ - -#include "precomp.h" - -#include "owncp.h" -#include "pcpbn.h" -#include "pcpprng.h" - - -/*F* -// Name: ippsPRNGSetModulus -// -// Purpose: Sets 160-bit modulus Q. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pMod -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pMod->idCtx -// -// ippStsBadArgErr 160 != bitsize(pMOd) -// -// ippStsNoErr no error -// -// Parameters: -// pMod pointer to the 160-bit modulus -// pRnd pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGSetModulus, (const IppsBigNumState* pMod, IppsPRNGState* pRnd)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRnd), ippStsContextMatchErr); - - /* test modulus */ - IPP_BAD_PTR1_RET(pMod); - pMod = (IppsBigNumState*)( IPP_ALIGNED_PTR(pMod, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pMod), ippStsContextMatchErr); - IPP_BADARG_RET(160 != BITSIZE_BNU(BN_NUMBER(pMod),BN_SIZE(pMod)), ippStsBadArgErr); - - ZEXPAND_COPY_BNU(RAND_Q(pRnd), (int)(sizeof(RAND_Q(pRnd))/sizeof(BNU_CHUNK_T)), BN_NUMBER(pMod), BN_SIZE(pMod)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsPRNGSetH0 -// -// Purpose: Sets 160-bit parameter of G() function. -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pH0 -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pH0->idCtx -// -// ippStsNoErr no error -// -// Parameters: -// pH0 pointer to the parameter used into G() function -// pRnd pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGSetH0,(const IppsBigNumState* pH0, IppsPRNGState* pRnd)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRnd), ippStsContextMatchErr); - - /* test H0 */ - IPP_BAD_PTR1_RET(pH0); - pH0 = (IppsBigNumState*)( IPP_ALIGNED_PTR(pH0, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pH0), ippStsContextMatchErr); - - { - cpSize len = IPP_MIN(5, BN_SIZE(pH0)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u))); - ZEXPAND_BNU(RAND_T(pRnd), 0, (int)(sizeof(RAND_T(pRnd))/sizeof(BNU_CHUNK_T))); - ZEXPAND_COPY_BNU((Ipp32u*)RAND_T(pRnd), (int)(sizeof(RAND_T(pRnd))/sizeof(Ipp32u)), - (Ipp32u*)BN_NUMBER(pH0), len); - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsPRNGSetSeed -// -// Purpose: Sets the initial state with the SEED value -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pSeed -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pSeed->idCtx -// -// ippStsNoErr no error -// -// Parameters: -// pSeed pointer to the SEED -// pRnd pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGSetSeed, (const IppsBigNumState* pSeed, IppsPRNGState* pRnd)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRnd), ippStsContextMatchErr); - - /* test seed */ - IPP_BAD_PTR1_RET(pSeed); - pSeed = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSeed, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pSeed), ippStsContextMatchErr); - - { - cpSize argSize = BITS_BNU_CHUNK( RAND_SEEDBITS(pRnd) ); - BNU_CHUNK_T mask = MASK_BNU_CHUNK(RAND_SEEDBITS(pRnd)); - cpSize size = IPP_MIN(BN_SIZE(pSeed), argSize); - - ZEXPAND_COPY_BNU(RAND_XKEY(pRnd), (cpSize)(sizeof(RAND_XKEY(pRnd))/sizeof(BNU_CHUNK_T)), BN_NUMBER(pSeed), size); - RAND_XKEY(pRnd)[argSize-1] &= mask; - - return ippStsNoErr; - } -} - - -/*F* -// Name: ippsPRNGSetAugment -// -// Purpose: Sets the Entropy Augmentation -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pAug -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pAug->idCtx -// -// ippStsLengthErr nBits < 1 -// nBits > MAX_XKEY_SIZE -// ippStsNoErr no error -// -// Parameters: -// pAug pointer to the entropy eugmentation -// pRnd pointer to the context -*F*/ -IPPFUN(IppStatus, ippsPRNGSetAugment, (const IppsBigNumState* pAug, IppsPRNGState* pRnd)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRnd), ippStsContextMatchErr); - - /* test augmentation */ - IPP_BAD_PTR1_RET(pAug); - pAug = (IppsBigNumState*)( IPP_ALIGNED_PTR(pAug, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pAug), ippStsContextMatchErr); - - { - cpSize argSize = BITS_BNU_CHUNK( RAND_SEEDBITS(pRnd) ); - BNU_CHUNK_T mask = MASK_BNU_CHUNK(RAND_SEEDBITS(pRnd)); - cpSize size = IPP_MIN(BN_SIZE(pAug), argSize); - - ZEXPAND_COPY_BNU(RAND_XAUGMENT(pRnd), (cpSize)(sizeof(RAND_XAUGMENT(pRnd))/sizeof(BNU_CHUNK_T)), BN_NUMBER(pAug), size); - RAND_XAUGMENT(pRnd)[argSize-1] &= mask; - - return ippStsNoErr; - } -} - -/*F* -// Name: ippsPRNGGetSeed -// -// Purpose: Get current SEED value from the state -// -// Returns: Reason: -// ippStsNullPtrErr NULL == pRnd -// NULL == pSeed -// -// ippStsContextMatchErr illegal pRnd->idCtx -// illegal pSeed->idCtx -// ippStsOutOfRangeErr lengtrh of the actual SEED > length SEED destination -// -// ippStsNoErr no error -// -// Parameters: -// pRnd pointer to the context -// pSeed pointer to the SEED -*F*/ -IPPFUN(IppStatus, ippsPRNGGetSeed, (const IppsPRNGState* pRnd, IppsBigNumState* pSeed)) -{ - /* test PRNG context */ - IPP_BAD_PTR1_RET(pRnd); - pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); - IPP_BADARG_RET(!RAND_VALID_ID(pRnd), ippStsContextMatchErr); - - /* test seed */ - IPP_BAD_PTR1_RET(pSeed); - pSeed = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSeed, BN_ALIGNMENT) ); - IPP_BADARG_RET(!BN_VALID_ID(pSeed), ippStsContextMatchErr); - - return ippsSet_BN(ippBigNumPOS, - BITS2WORD32_SIZE(RAND_SEEDBITS(pRnd)), - (Ipp32u*)RAND_XKEY(pRnd), - pSeed); -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha1ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha1ca.c deleted file mode 100644 index 81d28a1f..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha1ca.c +++ /dev/null @@ -1,551 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Digesting message according to SHA1 -// -// Contents: -// - ippsSHA1GetSize() -// - ippsSHA1Init() -// - ippsSHA1Pack() -// - ippsSHA1Unpack() -// - ippsSHA1Duplicate() -// - ippsSHA1Update() -// - ippsSHA1GetTag() -// - ippsSHA1Final() -// ippsSHA1MessageDigest() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - - -#if !defined (_ENABLE_ALG_SHA1_) -#pragma message("IPP_ALG_HASH_SHA1 disabled") -#else -#pragma message("IPP_ALG_HASH_SHA1 enabled") - -/* -// Init SHA1 digest -*/ -IppStatus InitSHA1(IppsSHA1State* pState) -{ - /* test state pointer */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pState, SHA1_ALIGNMENT) ); - - /* set state ID */ - SHS_ID(pState) = idCtxSHA1; - - /* zeros message length */ - SHS_LENL(pState) = 0; - - /* message buffer is free */ - SHS_INDX(pState) = 0; - - /* setup initial digest */ - SHS_HASH(pState)[0] = SHA1_IV[0]; - SHS_HASH(pState)[1] = SHA1_IV[1]; - SHS_HASH(pState)[2] = SHA1_IV[2]; - SHS_HASH(pState)[3] = SHA1_IV[3]; - SHS_HASH(pState)[4] = SHA1_IV[4]; - - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1GetSize -// -// Purpose: Returns size (bytes) of IppsSHA1State state. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// ippStsNoErr no errors -// -// Parameters: -// pSize pointer to state size -// -*F*/ -IPPFUN(IppStatus, ippsSHA1GetSize,(int* pSize)) -{ - /* test pointer */ - IPP_BAD_PTR1_RET(pSize); - - *pSize = sizeof(IppsSHA1State) +(SHA1_ALIGNMENT-1); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1Init -// -// Purpose: Init SHA1 state. -// -// Returns: Reason: -// ippStsNullPtrErr pState == NULL -// ippStsNoErr no errors -// -// Parameters: -// pState pointer to the SHA1 state -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Init,(IppsSHA1State* pState)) -{ - return InitSHA1(pState); -} - - -/*F* -// Name: ippsSHA1Pack -// -// Purpose: Copy initialized context to the buffer. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hach state -// pSize pointer to the packed spec size -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Pack,(const IppsSHA1State* pCtx, Ipp8u* pBuffer)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA1State*)( IPP_ALIGNED_PTR(pCtx, SHA1_ALIGNMENT) ); - /* test the context */ - IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pCtx), ippStsContextMatchErr); - - CopyBlock(pCtx, pBuffer, sizeof(IppsSHA1State)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1Unpack -// -// Purpose: Unpack buffer content into the initialized context. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pCtx)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA1State*)( IPP_ALIGNED_PTR(pCtx, SHA1_ALIGNMENT) ); - - CopyBlock(pBuffer, pCtx, sizeof(IppsSHA1State)); - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1Duplicate -// -// Purpose: Clone SHA1 state. -// -// Returns: Reason: -// ippStsNullPtrErr pSrcState == NULL -// pDstState == NULL -// ippStsContextMatchErr pSrcState->idCtx != idCtxSHA1 -// pDstState->idCtx != idCtxSHA1 -// ippStsNoErr no errors -// -// Parameters: -// pSrcState pointer to the source SHA1 state -// pDstState pointer to the target SHA1 state -// -// Note: -// pDstState may to be uninitialized by ippsSHA1Init() -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) -{ - /* test state pointers */ - IPP_BAD_PTR2_RET(pSrcState, pDstState); - /* use aligned context */ - pSrcState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pSrcState, SHA1_ALIGNMENT) ); - pDstState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pDstState, SHA1_ALIGNMENT) ); - /* test states ID */ - IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pSrcState), ippStsContextMatchErr); - //IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pDstState), ippStsContextMatchErr); - - /* copy state */ - CopyBlock(pSrcState, pDstState, sizeof(IppsSHA1State)); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1Update -// -// Purpose: Updates intermadiate digest based on input stream. -// -// Returns: Reason: -// ippStsNullPtrErr pSrc == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA1 -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pSrc pointer to the input stream -// len input stream length -// pState pointer to the SHA1 state -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pState, SHA1_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test input length */ - IPP_BADARG_RET((len<0), ippStsLengthErr); - /* test source pointer */ - IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); - - /* - // handle non empty message - */ - if(len) { - int processingLen; - - int n = SHS_INDX(pState); - Ipp8u* pBuffer = SHS_BUFF(pState); - Ipp8u* pHash = (Ipp8u*)SHS_HASH(pState); - - Ipp64u lenLo = SHS_LENL(pState); - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA1; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA1ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - else - #endif - updateFunc = UpdateSHA1; - #endif - - lenLo += len; - - /* if non empty internal buffer filling */ - if(n) { - /* copy from input stream to the internal buffer as match as possible */ - processingLen = IPP_MIN(len, (MBS_SHA1-n)); - CopyBlock(pSrc, pBuffer+n, processingLen); - - pSrc += processingLen; - len -= processingLen; - SHS_INDX(pState) = n += processingLen; - - /* update digest if buffer full */ - if( MBS_SHA1 == n) { - updateFunc(pHash, pBuffer, MBS_SHA1, SHA1_cnt); - SHS_INDX(pState) = 0; - } - } - - /* main message part processing */ - processingLen = len & ~(MBS_SHA1-1); - if(processingLen) { - updateFunc(pHash, pSrc, processingLen, SHA1_cnt); - pSrc += processingLen; - len -= processingLen; - } - - /* store rest of message into the internal buffer */ - if(len) { - CopyBlock(pSrc, pBuffer, len); - SHS_INDX(pState) += len; - } - - SHS_LENL(pState) = lenLo; - } - - return ippStsNoErr; -} - - -/* -// Compute digest -*/ -void ComputeDigestSHA1(Ipp32u* pHash, const IppsSHA1State* pState) -{ - const Ipp8u* stateBuff = SHS_BUFF(pState); - int stateBuffLen = SHS_INDX(pState); - - /* local buffer and it length */ - Ipp8u buffer[MBS_SHA1*2]; - int bufferLen = stateBuffLen < (MBS_SHA1-(int)sizeof(Ipp64u))? MBS_SHA1 : MBS_SHA1*2; - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA1; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA1ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - else - #endif - updateFunc = UpdateSHA1; - #endif - - /* copy rest of message into internal buffer */ - CopyBlock(stateBuff, buffer, stateBuffLen); - - /* padd message */ - buffer[stateBuffLen++] = 0x80; - PaddBlock(0, buffer+stateBuffLen, bufferLen-stateBuffLen-sizeof(Ipp64u)); - - /* message length representation */ - { - Ipp64u lo = SHS_LENL(pState); /* message length in bytes */ - lo = LSL64(lo,3); /* message length in bits */ - ((Ipp64u*)(buffer+bufferLen))[-1] = ENDIANNESS64(lo); - } - - /* copmplete hash computation */ - updateFunc(pHash, buffer, bufferLen, SHA1_cnt); - - /* convert hash into big endian */ - pHash[0] = ENDIANNESS32(pHash[0]); - pHash[1] = ENDIANNESS32(pHash[1]); - pHash[2] = ENDIANNESS32(pHash[2]); - pHash[3] = ENDIANNESS32(pHash[3]); - pHash[4] = ENDIANNESS32(pHash[4]); -} - - -/*F* -// Name: ippsSHA1GetTag -// -// Purpose: Compute digest based on current state. -// Note, that futher digest update is possible -// -// Returns: Reason: -// ippStsNullPtrErr pTag == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA1 -// ippStsLengthErr max_SHA_digestLen < tagLen <1 -// ippStsNoErr no errors -// -// Parameters: -// pTag address of the output digest -// tagLen length of digest -// pState pointer to the SHS state -// -*F*/ -IPPFUN(IppStatus, ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pState, SHA1_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pTag); - IPP_BADARG_RET((tagLen<1)||(sizeof(DigestSHA1)idCtx != idCtxSHA1 -// ippStsNoErr no errors -// -// Parameters: -// pMD address of the output digest -// pState pointer to the SHS state -// -*F*/ -IPPFUN(IppStatus, ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA1State*)( IPP_ALIGNED_PTR(pState, SHA1_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA1 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestSHA1(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestSHA1)); - InitSHA1(pState); - - return ippStsNoErr; -} - - -/*F* -// Name: ippsSHA1MessageDigest -// -// Purpose: Digest of the whole message. -// -// Returns: Reason: -// ippStsNullPtrErr pMsg == NULL -// pMD == NULL -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pMsg pointer to the input message -// len input message length -// pMD address of the output digest -// -*F*/ -IPPFUN(IppStatus, ippsSHA1MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - /* test message length */ - IPP_BADARG_RET((msgLen<0), ippStsLengthErr); - /* test message pointer */ - IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); - - { - /* message length in the multiple MBS and the rest */ - int msgLenBlks = msgLen & (-MBS_SHA1); - int msgLenRest = msgLen - msgLenBlks; - - /* init hash value */ - DigestSHA1 hash = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA1; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA1ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA1ni; - else - #endif - updateFunc = UpdateSHA1; - #endif - - /* process main part of the message */ - if(msgLenBlks) - updateFunc(hash, pMsg, msgLenBlks, SHA1_cnt); - - /* process message padding */ - { - #define MREP_SIZE_SHA1 (sizeof(Ipp64u)) - Ipp8u buffer[MBS_SHA1*2]; - int bufferLen = msgLenRest < (int)(MBS_SHA1-MREP_SIZE_SHA1)? MBS_SHA1 : MBS_SHA1*2; - - /* message bitlength representation */ - Ipp64u msgLenBits = (Ipp64u)msgLen*8; - msgLenBits = ENDIANNESS64(msgLenBits); - - /* copy end of message */ - CopyBlock(pMsg+msgLen-msgLenRest, buffer, msgLenRest); - - /* end of message bit */ - buffer[msgLenRest++] = 0x80; - - /* padd buffer */ - PaddBlock(0, buffer+msgLenRest, bufferLen-msgLenRest-MREP_SIZE_SHA1); - /* copy message bitlength representation */ - ((Ipp64u*)(buffer+bufferLen))[-1] = msgLenBits; - - updateFunc(hash, buffer, bufferLen, SHA1_cnt); - #undef MREP_SIZE_SHA1 - } - - /* swap hash bytes */ - ((Ipp32u*)pMD)[0] = ENDIANNESS32(hash[0]); - ((Ipp32u*)pMD)[1] = ENDIANNESS32(hash[1]); - ((Ipp32u*)pMD)[2] = ENDIANNESS32(hash[2]); - ((Ipp32u*)pMD)[3] = ENDIANNESS32(hash[3]); - ((Ipp32u*)pMD)[4] = ENDIANNESS32(hash[4]); - - return ippStsNoErr; - } -} - -#endif /* _ENABLE_ALG_SHA1_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha256ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha256ca.c deleted file mode 100644 index ae20f91d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha256ca.c +++ /dev/null @@ -1,728 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Digesting message according to SHA256 -// -// Contents: -// ippsSHA256GetSize() -// ippsSHA256Init() -// ippsSHA256Pack() -// ippsSHA256Unpack() -// ippsSHA256Duplicate() -// ippsSHA256Update() -// ippsSHA256GetTag() -// ippsSHA256Final() -// ippsSHA256MessageDigest() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - - -#if !defined(_ENABLE_ALG_SHA256_) -#pragma message("IPP_ALG_HASH_SHA256 disabled") -#else -#pragma message("IPP_ALG_HASH_SHA256 enabled") -#endif - -#if !defined(_ENABLE_ALG_SHA224_) -#pragma message("IPP_ALG_HASH_SHA224 disabled") -#else -#pragma message("IPP_ALG_HASH_SHA224 enabled") -#endif - - -/* -// SHA256 init context -*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IppStatus GetSizeSHA256(int* pSize) -{ - /* test pointer */ - IPP_BAD_PTR1_RET(pSize); - - *pSize = sizeof(IppsSHA256State) +(SHA256_ALIGNMENT-1); - - return ippStsNoErr; -} - -IppStatus InitSHA256(const DigestSHA256 IV, IppsSHA256State* pState) -{ - /* test state pointer */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pState, SHA256_ALIGNMENT) ); - - /* set state ID */ - SHS_ID(pState) = idCtxSHA256; - - /* zeros message length */ - SHS_LENL(pState) = 0; - - /* message buffer is free */ - SHS_INDX(pState) = 0; - - /* setup initial digest */ - SHS_HASH(pState)[0] = IV[0]; - SHS_HASH(pState)[1] = IV[1]; - SHS_HASH(pState)[2] = IV[2]; - SHS_HASH(pState)[3] = IV[3]; - SHS_HASH(pState)[4] = IV[4]; - SHS_HASH(pState)[5] = IV[5]; - SHS_HASH(pState)[6] = IV[6]; - SHS_HASH(pState)[7] = IV[7]; - - return ippStsNoErr; -} -#endif - -/*F* -// Name: ippsSHA256GetSize -// ippsSHA224GetSize -// -// Purpose: Returns size (bytes) of IppsSHA256State state. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// ippStsNoErr no errors -// -// Parameters: -// pSize pointer to state size -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) -IPPFUN(IppStatus, ippsSHA256GetSize,(int* pSize)) -{ - return GetSizeSHA256(pSize); -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224GetSize,(int* pSize)) -{ - return GetSizeSHA256(pSize); -} -#endif - - -/*F* -// Name: ippsSHA256Init -// ippsSHA224Init -// -// Purpose: Init SHA256 -// -// Returns: Reason: -// ippStsNullPtrErr pState == NULL -// ippStsNoErr no errors -// -// Parameters: -// pState pointer to the SHA512 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) -IPPFUN(IppStatus, ippsSHA256Init,(IppsSHA256State* pState)) -{ - return InitSHA256(SHA256_IV, pState); -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Init,(IppsSHA224State* pState)) -{ - return InitSHA256(SHA224_IV, pState); -} -#endif - - -/*F* -// Name: ippsSHA256Pack -// ippsSHA224Pack -// -// Purpose: Copy initialized context to the buffer. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA256Pack,(const IppsSHA256State* pCtx, Ipp8u* pBuffer)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA256State*)( IPP_ALIGNED_PTR(pCtx, SHA256_ALIGNMENT) ); - /* test the context */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pCtx), ippStsContextMatchErr); - - CopyBlock(pCtx, pBuffer, sizeof(IppsSHA256State)); - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Pack,(const IppsSHA224State* pCtx, Ipp8u* pBuffer)) -{ - return ippsSHA256Pack(pCtx, pBuffer); -} -#endif - -/*F* -// Name: ippsSHA256Unpack -// ippsSHA224Unpack -// -// Purpose: Unpack buffer content into the initialized context. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pCtx)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA256State*)( IPP_ALIGNED_PTR(pCtx, SHA256_ALIGNMENT) ); - - CopyBlock(pBuffer, pCtx, sizeof(IppsSHA256State)); - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pCtx)) -{ - return ippsSHA256Unpack(pBuffer, pCtx); -} -#endif - - -/*F* -// Name: ippsSHA256Duplicate -// ippsSHA224Duplicate -// -// Purpose: Clone SHA256 state. -// -// Returns: Reason: -// ippStsNullPtrErr pSrcState == NULL -// pDstState == NULL -// ippStsContextMatchErr pSrcState->idCtx != idCtxSHA256 -// pDstState->idCtx != idCtxSHA256 -// ippStsNoErr no errors -// -// Parameters: -// pSrcState pointer to the source SHA256 state -// pDstState pointer to the target SHA256 state -// -// Note: -// pDstState may to be uninitialized by ippsSHA256Init() -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) -{ - /* test state pointers */ - IPP_BAD_PTR2_RET(pSrcState, pDstState); - /* use aligned context */ - pSrcState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pSrcState, SHA256_ALIGNMENT) ); - pDstState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pDstState, SHA256_ALIGNMENT) ); - /* test states ID */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pSrcState), ippStsContextMatchErr); - //IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pDstState), ippStsContextMatchErr); - - /* copy state */ - CopyBlock(pSrcState, pDstState, sizeof(IppsSHA256State)); - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) -{ - return ippsSHA256Duplicate(pSrcState, pDstState); -} -#endif - - -/*F* -// Name: ippsSHA256Update -// ippsSHA224Update -// -// Purpose: Updates intermadiate digest based on input stream. -// -// Returns: Reason: -// ippStsNullPtrErr pSrc == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA256 -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pSrc pointer to the input stream -// len input stream length -// pState pointer to the SHA256 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pState, SHA256_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test input length */ - IPP_BADARG_RET((len<0), ippStsLengthErr); - /* test source pointer */ - IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); - - /* - // handle non empty message - */ - if(len) { - int processingLen; - - int n = SHS_INDX(pState); - Ipp8u* pBuffer = SHS_BUFF(pState); - Ipp8u* pHash = (Ipp8u*)SHS_HASH(pState); - - Ipp64u lenLo = SHS_LENL(pState); - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA256; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA256ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - else - #endif - updateFunc = UpdateSHA256; - #endif - - lenLo += len; - - /* if non empty internal buffer filling */ - if(n) { - /* copy from input stream to the internal buffer as match as possible */ - processingLen = IPP_MIN(len, (MBS_SHA256 - SHS_INDX(pState))); - CopyBlock(pSrc, pBuffer+n, processingLen); - - pSrc += processingLen; - len -= processingLen; - SHS_INDX(pState) = n += processingLen; - - /* update digest if buffer full */ - if( MBS_SHA256 == n) { - updateFunc(pHash, pBuffer, MBS_SHA256, SHA256_cnt); - SHS_INDX(pState) = 0; - } - } - - /* main message part processing */ - processingLen = len & ~(MBS_SHA256-1); - if(processingLen) { - updateFunc(pHash, pSrc, processingLen, SHA256_cnt); - pSrc += processingLen; - len -= processingLen; - } - - /* store rest of message into the internal buffer */ - if(len) { - CopyBlock(pSrc, pBuffer, len); - SHS_INDX(pState) += len; - } - - SHS_LENL(pState) = lenLo; - } - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) -{ - return ippsSHA256Update(pSrc, len, pState); -} -#endif - - -/* -// Compute digest -*/ -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -void ComputeDigestSHA256(Ipp32u* pHash, const IppsSHA256State* pState) -{ - const Ipp8u* stateBuff = SHS_BUFF(pState); - int stateBuffLen = SHS_INDX(pState); - - /* local buffer and it length */ - Ipp8u buffer[MBS_SHA256*2]; - int bufferLen = stateBuffLen < (MBS_SHA1-(int)sizeof(Ipp64u))? MBS_SHA256 : MBS_SHA256*2; - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA256; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA256ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - else - #endif - updateFunc = UpdateSHA256; - #endif - - /* copy rest of message into internal buffer */ - CopyBlock(stateBuff, buffer, stateBuffLen); - - /* padd message */ - buffer[stateBuffLen++] = 0x80; - PaddBlock(0, buffer+stateBuffLen, bufferLen-stateBuffLen-sizeof(Ipp64u)); - - /* message length representation */ - { - Ipp64u lo = SHS_LENL(pState); /* message length in bytes */ - lo = LSL64(lo,3); /* message length in bits */ - ((Ipp64u*)(buffer+bufferLen))[-1] = ENDIANNESS64(lo); - } - - /* copmplete hash computation */ - updateFunc(pHash, buffer, bufferLen, SHA256_cnt); - - /* convert hash into big endian */ - pHash[0] = ENDIANNESS32(pHash[0]); - pHash[1] = ENDIANNESS32(pHash[1]); - pHash[2] = ENDIANNESS32(pHash[2]); - pHash[3] = ENDIANNESS32(pHash[3]); - pHash[4] = ENDIANNESS32(pHash[4]); - pHash[5] = ENDIANNESS32(pHash[5]); - pHash[6] = ENDIANNESS32(pHash[6]); - pHash[7] = ENDIANNESS32(pHash[7]); -} -#endif - - -/*F* -// Name: ippsSHA256GetTag -// ippsSHA224GetTag -// -// Purpose: Compute digest based on current state. -// Note, that futher digest update is possible -// -// Returns: Reason: -// ippStsNullPtrErr pTag == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA256 -// ippStsLengthErr max_SHA_digestLen < tagLen <1 -// ippStsNoErr no errors -// -// Parameters: -// pTag address of the output digest -// tagLen length of digest -// pState pointer to the SHS state -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) -IPPFUN(IppStatus, ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pState, SHA256_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pTag); - IPP_BADARG_RET((tagLen<1)||(sizeof(DigestSHA256)idCtx != idCtxSHA256 -// ippStsNoErr no errors -// -// Parameters: -// pMD address of the output digest -// pState pointer to the SHA256 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) -IPPFUN(IppStatus, ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA256State*)( IPP_ALIGNED_PTR(pState, SHA256_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestSHA256(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestSHA256)); - InitSHA256(SHA256_IV, pState); - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA224State*)( IPP_ALIGNED_PTR(pState, SHA256_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA256 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestSHA256(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestSHA224)); - InitSHA256(SHA224_IV, pState); - - return ippStsNoErr; -} -#endif - - -#if defined (_ENABLE_ALG_SHA256_) || defined (_ENABLE_ALG_SHA224_) -IppStatus cpSHA256MessageDigest(DigestSHA256 hash, const Ipp8u* pMsg, int msgLen, const DigestSHA256 IV) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(hash); - /* test message length */ - IPP_BADARG_RET((msgLen<0), ippStsLengthErr); - /* test message pointer */ - IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); - - { - /* message length in the multiple MBS and the rest */ - int msgLenBlks = msgLen & (-MBS_SHA256); - int msgLenRest = msgLen - msgLenBlks; - - /* select processing function */ -#if 0 - cpHashProc updateFunc = UpdateSHA256; - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - #endif -#endif - cpHashProc updateFunc; - #if (_SHA_NI_ENABLING_==_FEATURE_ON_) - updateFunc = UpdateSHA256ni; - #else - #if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_) - if( IsFeatureEnabled(SHA_NI_ENABLED) ) - updateFunc = UpdateSHA256ni; - else - #endif - updateFunc = UpdateSHA256; - #endif - - /* setup initial digest */ - hash[0] = IV[0]; - hash[1] = IV[1]; - hash[2] = IV[2]; - hash[3] = IV[3]; - hash[4] = IV[4]; - hash[5] = IV[5]; - hash[6] = IV[6]; - hash[7] = IV[7]; - - /* process main part of the message */ - if(msgLenBlks) - updateFunc(hash, pMsg, msgLenBlks, SHA256_cnt); - - /* process message padding */ - { - #define MREP_SIZE_SHA256 (sizeof(Ipp64u)) - Ipp8u buffer[MBS_SHA256*2]; - int bufferLen = msgLenRest < (int)(MBS_SHA256-MREP_SIZE_SHA256)? MBS_SHA256 : MBS_SHA256*2; - - /* message bitlength representation */ - Ipp64u msgLenBits = (Ipp64u)msgLen*8; - msgLenBits = ENDIANNESS64(msgLenBits); - - /* copy end of message */ - CopyBlock(pMsg+msgLen-msgLenRest, buffer, msgLenRest); - - /* end of message bit */ - buffer[msgLenRest++] = 0x80; - - /* padd buffer */ - PaddBlock(0, buffer+msgLenRest, bufferLen-msgLenRest-MREP_SIZE_SHA256); - /* copy message bitlength representation */ - ((Ipp64u*)(buffer+bufferLen))[-1] = msgLenBits; - - updateFunc(hash, buffer, bufferLen, SHA256_cnt); - #undef MREP_SIZE_SHA256 - } - - /* swap hash bytes */ - hash[0] = ENDIANNESS32(hash[0]); - hash[1] = ENDIANNESS32(hash[1]); - hash[2] = ENDIANNESS32(hash[2]); - hash[3] = ENDIANNESS32(hash[3]); - hash[4] = ENDIANNESS32(hash[4]); - hash[5] = ENDIANNESS32(hash[5]); - hash[6] = ENDIANNESS32(hash[6]); - hash[7] = ENDIANNESS32(hash[7]); - - return ippStsNoErr; - } -} -#endif - -/*F* -// Name: ippsSHA256MessageDigest, -// ippsSHA224MessageDigest -// -// Purpose: Digest of the whole message. -// -// Returns: Reason: -// ippStsNullPtrErr pMsg == NULL -// pDigest == NULL -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pMsg pointer to the input message -// len input message length -// pMD address of the output digest -// -*F*/ -#if defined (_ENABLE_ALG_SHA256_) -IPPFUN(IppStatus, ippsSHA256MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - { - DigestSHA256 hash; - IppStatus sts = cpSHA256MessageDigest(hash, pMsg, msgLen, SHA256_IV); - if(ippStsNoErr==sts) - CopyBlock(hash, pMD, IPP_SHA256_DIGEST_BITSIZE/BYTESIZE); - return sts; - } -} -#endif - -#if defined (_ENABLE_ALG_SHA224_) -IPPFUN(IppStatus, ippsSHA224MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - { - DigestSHA256 hash; - IppStatus sts = cpSHA256MessageDigest(hash, pMsg, msgLen, SHA224_IV); - if(ippStsNoErr==sts) - CopyBlock(hash, pMD, IPP_SHA224_DIGEST_BITSIZE/BYTESIZE); - return sts; - } -} -#endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha512ca.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha512ca.c deleted file mode 100644 index 8dcaab97..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpsha512ca.c +++ /dev/null @@ -1,674 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// SHA512 message digest -// -// Contents: -// ippsSHA512GetSize() -// ippsSHA512Init() -// ippsSHA512Pack() -// ippsSHA512Unpack() -// ippsSHA512Duplicate() -// ippsSHA512Update() -// ippsSHA512GetTag() -// ippsSHA512Final() -// ippsSHA512MessageDigest() -// -// -*/ - -#include "precomp.h" -#include "owncp.h" -#include "pcphash.h" -#include "pcptool.h" - - -#if !defined(_ENABLE_ALG_SHA512_) -#pragma message("IPP_ALG_HASH_SHA512 disabled") -#else -#pragma message("IPP_ALG_HASH_SHA512 enabled") -#endif - -#if !defined(_ENABLE_ALG_SHA384_) -#pragma message("IPP_ALG_HASH_SHA384 disabled") -#else -#pragma message("IPP_ALG_HASH_SHA384 enabled") -#endif - - -/* -// SHA512 init context -*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IppStatus GetSizeSHA512(int* pSize) -{ - /* test pointer */ - IPP_BAD_PTR1_RET(pSize); - - *pSize = sizeof(IppsSHA512State) +(SHA512_ALIGNMENT-1); - - return ippStsNoErr; -} - -IppStatus InitSHA512(const DigestSHA512 IV, IppsSHA512State* pState) -{ - /* test state pointer */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pState, SHA512_ALIGNMENT) ); - - /* set state ID */ - SHS_ID(pState) = idCtxSHA512; - - /* zeros message length */ - SHS_LENL(pState) = 0; - SHS_LENH(pState) = 0; - - /* message buffer is free */ - SHS_INDX(pState) = 0; - - /* setup initial digest */ - SHS_HASH(pState)[0] = IV[0]; - SHS_HASH(pState)[1] = IV[1]; - SHS_HASH(pState)[2] = IV[2]; - SHS_HASH(pState)[3] = IV[3]; - SHS_HASH(pState)[4] = IV[4]; - SHS_HASH(pState)[5] = IV[5]; - SHS_HASH(pState)[6] = IV[6]; - SHS_HASH(pState)[7] = IV[7]; - - return ippStsNoErr; -} -#endif - -/*F* -// Name: ippsSHA512GetSize -// ippsSHA384GetSize -// -// Purpose: Returns size (bytes) of IppsSHA512State state. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// ippStsNoErr no errors -// -// Parameters: -// pSize pointer to state size -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) -IPPFUN(IppStatus, ippsSHA512GetSize,(int* pSize)) -{ - return GetSizeSHA512(pSize); -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384GetSize,(int* pSize)) -{ - return GetSizeSHA512(pSize); -} -#endif - - -/*F* -// Name: ippsSHA512Init -// ippsSHA384Init -// -// Purpose: Init SHA512 -// -// Returns: Reason: -// ippStsNullPtrErr pState == NULL -// ippStsNoErr no errors -// -// Parameters: -// pState pointer to the SHA512 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) -IPPFUN(IppStatus, ippsSHA512Init,(IppsSHA512State* pState)) -{ - return InitSHA512(SHA512_IV, pState); -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Init,(IppsSHA384State* pState)) -{ - return InitSHA512(SHA384_IV, pState); -} -#endif - - -/*F* -// Name: ippsSHA512Pack -// ippsSHA384Pack -// -// Purpose: Copy initialized context to the buffer. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA512Pack,(const IppsSHA512State* pCtx, Ipp8u* pBuffer)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA512State*)( IPP_ALIGNED_PTR(pCtx, SHA512_ALIGNMENT) ); - /* test the context */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pCtx), ippStsContextMatchErr); - - CopyBlock(pCtx, pBuffer, sizeof(IppsSHA512State)); - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Pack,(const IppsSHA384State* pCtx, Ipp8u* pBuffer)) -{ - return ippsSHA512Pack(pCtx, pBuffer); -} -#endif - - -/*F* -// Name: ippsSHA512Unpack -// ippsSHA384Unpack -// -// Purpose: Unpack buffer content into the initialized context. -// -// Returns: Reason: -// ippStsNullPtrErr pSize == NULL -// pCtx == NULL -// ippStsNoErr no errors -// -// Parameters: -// pCtx pointer hash state -// pSize pointer to the packed spec size -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pCtx)) -{ - /* test pointers */ - IPP_BAD_PTR2_RET(pCtx, pBuffer); - /* use aligned context */ - pCtx = (IppsSHA512State*)( IPP_ALIGNED_PTR(pCtx, SHA512_ALIGNMENT) ); - - CopyBlock(pBuffer, pCtx, sizeof(IppsSHA512State)); - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pCtx)) -{ - return ippsSHA512Unpack(pBuffer, pCtx); -} -#endif - - -/*F* -// Name: ippsSHA512Duplicate -// ippsSHA384Duplicate -// -// Purpose: Clone SHA512 state. -// -// Returns: Reason: -// ippStsNullPtrErr pSrcState == NULL -// pDstState == NULL -// ippStsContextMatchErr pSrcState->idCtx != idCtxSHA512 -// pDstState->idCtx != idCtxSHA512 -// ippStsNoErr no errors -// -// Parameters: -// pSrcState pointer to the source SHA512 state -// pDstState pointer to the target SHA512 state -// Note: -// pDstState may to be uninitialized by ippsSHA512Init() -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) -{ - /* test state pointers */ - IPP_BAD_PTR2_RET(pSrcState, pDstState); - /* use aligned context */ - pSrcState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pSrcState, SHA512_ALIGNMENT) ); - pDstState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pDstState, SHA512_ALIGNMENT) ); - /* test states ID */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pSrcState), ippStsContextMatchErr); - //IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pDstState), ippStsContextMatchErr); - - /* copy state */ - CopyBlock(pSrcState, pDstState, sizeof(IppsSHA512State)); - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) -{ - return ippsSHA512Duplicate(pSrcState, pDstState); -} -#endif - - -/*F* -// Name: ippsSHA512Update -// ippsSHA384Update -// -// Purpose: Updates intermadiate digest based on input stream. -// -// Returns: Reason: -// ippStsNullPtrErr pSrc == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA512 -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pSrc pointer to the input stream -// len input stream length -// pState pointer to the SHA512 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pState, SHA512_ALIGNMENT) ); - - /* test state ID */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pState), ippStsContextMatchErr); - /* test input length */ - IPP_BADARG_RET((len<0), ippStsLengthErr); - /* test source pointer */ - IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); - - /* - // handle non empty message - */ - if(len) { - int processingLen; - - int n = SHS_INDX(pState); - Ipp8u* pBuffer = SHS_BUFF(pState); - Ipp8u* pHash = (Ipp8u*)SHS_HASH(pState); - - Ipp64u lenLo = SHS_LENL(pState); - Ipp64u lenHi = SHS_LENH(pState); - lenLo += len; - if(lenLo < SHS_LENL(pState)) lenHi++; - - /* if non empty internal buffer filling */ - if(n) { - /* copy from input stream to the internal buffer as match as possible */ - processingLen = IPP_MIN(len, (MBS_SHA512-n)); - CopyBlock(pSrc, pBuffer+n, processingLen); - - pSrc += processingLen; - len -= processingLen; - SHS_INDX(pState) = n += processingLen; - - /* update digest if buffer full */ - if(MBS_SHA512 == n) { - UpdateSHA512(pHash, pBuffer, MBS_SHA512, SHA512_cnt); - SHS_INDX(pState) = 0; - } - } - - /* main message part processing */ - processingLen = len & ~(MBS_SHA512-1); - if(processingLen) { - UpdateSHA512(pHash, pSrc, processingLen, SHA512_cnt); - pSrc += processingLen; - len -= processingLen; - } - - /* store rest of message into the internal buffer */ - if(len) { - CopyBlock(pSrc, pBuffer, len); - SHS_INDX(pState) += len; - } - - SHS_LENL(pState) = lenLo; - SHS_LENH(pState) = lenHi; - } - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) -{ - return ippsSHA512Update(pSrc, len, pState); -} -#endif - - -/* -// Compute digest -*/ -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -void ComputeDigestSHA512(Ipp64u* pHash, const IppsSHA512State* pState) -{ - const Ipp8u* stateBuff = SHS_BUFF(pState); - int stateBuffLen = SHS_INDX(pState); - - /* local buffer and it length */ - Ipp8u buffer[MBS_SHA512*2]; - int bufferLen = stateBuffLen < (MBS_SHA512-(int)sizeof(Ipp64u)*2)? MBS_SHA512 : MBS_SHA512*2; - - /* copy rest of message into internal buffer */ - CopyBlock(stateBuff, buffer, stateBuffLen); - - /* padd message */ - buffer[stateBuffLen++] = 0x80; - PaddBlock(0, buffer+stateBuffLen, bufferLen-stateBuffLen-sizeof(Ipp64u)*2); - - /* message length representation */ - { - Ipp64u lo = SHS_LENL(pState); /* message length in bytes */ - Ipp64u hi = SHS_LENH(pState); - hi = LSL64(hi,3) | LSR64(lo,63-3); /* message length in bits */ - lo = LSL64(lo,3); - ((Ipp64u*)(buffer+bufferLen))[-2] = ENDIANNESS64(hi); - ((Ipp64u*)(buffer+bufferLen))[-1] = ENDIANNESS64(lo); - } - - /* copmplete hash computation */ - UpdateSHA512(pHash, buffer, bufferLen, SHA512_cnt); - - /* convert hash into big endian */ - pHash[0] = ENDIANNESS64(pHash[0]); - pHash[1] = ENDIANNESS64(pHash[1]); - pHash[2] = ENDIANNESS64(pHash[2]); - pHash[3] = ENDIANNESS64(pHash[3]); - pHash[4] = ENDIANNESS64(pHash[4]); - pHash[5] = ENDIANNESS64(pHash[5]); - pHash[6] = ENDIANNESS64(pHash[6]); - pHash[7] = ENDIANNESS64(pHash[7]); -} -#endif - - -/*F* -// Name: ippsSHA512GetTag -// ippsSHA384GetTag -// -// Purpose: Compute digest based on current state. -// Note, that futher digest update is possible -// -// Returns: Reason: -// ippStsNullPtrErr pTag == NULL -// pState == NULL -// ippStsContextMatchErr pState->idCtx != idCtxSHA512 -// ippStsLengthErr max_SHA_digestLen < tagLen <1 -// ippStsNoErr no errors -// -// Parameters: -// pTag address of the output digest -// tagLen length of digest -// pState pointer to the SHS state -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) -IPPFUN(IppStatus, ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pState, SHA512_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pTag); - IPP_BADARG_RET((tagLen<1)||(sizeof(DigestSHA512)idCtx != idCtxSHA512 -// ippStsNoErr no errors -// -// Parameters: -// pMD address of the output digest -// pState pointer to the SHA512 state -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) -IPPFUN(IppStatus, ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA512State*)( IPP_ALIGNED_PTR(pState, SHA512_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestSHA512(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestSHA512)); - InitSHA512(SHA512_IV, pState); - - return ippStsNoErr; -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) -{ - /* test state pointer and ID */ - IPP_BAD_PTR1_RET(pState); - /* use aligned context */ - pState = (IppsSHA384State*)( IPP_ALIGNED_PTR(pState, SHA512_ALIGNMENT) ); - /* test state ID */ - IPP_BADARG_RET(idCtxSHA512 !=SHS_ID(pState), ippStsContextMatchErr); - - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - ComputeDigestSHA512(SHS_HASH(pState), pState); - CopyBlock(SHS_HASH(pState), pMD, sizeof(DigestSHA384)); - InitSHA512(SHA384_IV, pState); - - return ippStsNoErr; -} -#endif - - -#if defined (_ENABLE_ALG_SHA512_) || defined (_ENABLE_ALG_SHA384_) -IppStatus cpSHA512MessageDigest(DigestSHA512 hash, const Ipp8u* pMsg, int msgLen, const DigestSHA512 IV) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(hash); - /* test message length */ - IPP_BADARG_RET((msgLen<0), ippStsLengthErr); - /* test message pointer */ - IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); - - { - /* message length in the multiple MBS and the rest */ - int msgLenBlks = msgLen & (-MBS_SHA512); - int msgLenRest = msgLen - msgLenBlks; - - /* setup initial digest */ - hash[0] = IV[0]; - hash[1] = IV[1]; - hash[2] = IV[2]; - hash[3] = IV[3]; - hash[4] = IV[4]; - hash[5] = IV[5]; - hash[6] = IV[6]; - hash[7] = IV[7]; - - /* process main part of the message */ - if(msgLenBlks) - UpdateSHA512(hash, pMsg, msgLenBlks, SHA512_cnt); - - /* process message padding */ - { - #define MREP_SIZE_SHA512 (2*sizeof(Ipp64u)) - Ipp8u buffer[MBS_SHA512*2]; - int bufferLen = msgLenRest < (int)(MBS_SHA512-MREP_SIZE_SHA512)? MBS_SHA512 : MBS_SHA512*2; - - /* message bitlength representation */ - Ipp64u msgLenBits = (Ipp64u)msgLen*8; - msgLenBits = ENDIANNESS64(msgLenBits); - - /* copy end of message */ - CopyBlock(pMsg+msgLen-msgLenRest, buffer, msgLenRest); - - /* end of message bit */ - buffer[msgLenRest++] = 0x80; - - /* padd buffer */ - PaddBlock(0, buffer+msgLenRest, bufferLen-msgLenRest-MREP_SIZE_SHA512+sizeof(Ipp64u)); - /* copy message bitlength representation */ - ((Ipp64u*)(buffer+bufferLen))[-1] = msgLenBits; - - UpdateSHA512(hash, buffer, bufferLen, SHA512_cnt); - #undef MREP_SIZE_SHA512 - } - - /* swap hash bytes */ - hash[0] = ENDIANNESS64(hash[0]); - hash[1] = ENDIANNESS64(hash[1]); - hash[2] = ENDIANNESS64(hash[2]); - hash[3] = ENDIANNESS64(hash[3]); - hash[4] = ENDIANNESS64(hash[4]); - hash[5] = ENDIANNESS64(hash[5]); - hash[6] = ENDIANNESS64(hash[6]); - hash[7] = ENDIANNESS64(hash[7]); - - return ippStsNoErr; - } -} -#endif - -/*F* -// Name: ippsSHA512MessageDigest -// ippsSHA384MessageDigest -// -// Purpose: Digest of the whole message. -// -// Returns: Reason: -// ippStsNullPtrErr pMsg == NULL -// pDigest == NULL -// ippStsLengthErr len <0 -// ippStsNoErr no errors -// -// Parameters: -// pMsg pointer to the input message -// len input message length -// pMD address of the output digest -// -*F*/ -#if defined (_ENABLE_ALG_SHA512_) -IPPFUN(IppStatus, ippsSHA512MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - { - DigestSHA512 hash; - IppStatus sts = cpSHA512MessageDigest(hash, pMsg, msgLen, SHA512_IV); - if(ippStsNoErr==sts) - CopyBlock(hash, pMD, IPP_SHA512_DIGEST_BITSIZE/BYTESIZE); - return sts; - } -} -#endif - -#if defined (_ENABLE_ALG_SHA384_) -IPPFUN(IppStatus, ippsSHA384MessageDigest,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD)) -{ - /* test digest pointer */ - IPP_BAD_PTR1_RET(pMD); - - { - DigestSHA512 hash; - IppStatus sts = cpSHA512MessageDigest(hash, pMsg, msgLen, SHA384_IV); - if(ippStsNoErr==sts) - CopyBlock(hash, pMD, IPP_SHA384_DIGEST_BITSIZE/BYTESIZE); - return sts; - } -} -#endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcptool.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcptool.h deleted file mode 100644 index df8c798d..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcptool.h +++ /dev/null @@ -1,631 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Cryptography Primitive. -// Internal Definitions of Block Cipher Tools -// -// -*/ - -#if !defined(_PC_TOOL_H) -#define _CP_TOOL_H - -/* copy data block */ -__INLINE void CopyBlock(const void* pSrc, void* pDst, cpSize numBytes) -{ - const Ipp8u* s = (Ipp8u*)pSrc; - Ipp8u* d = (Ipp8u*)pDst; - cpSize k; - for(k=0; k=_IPP_W7) || (_IPP32E>=_IPP32E_M7)) -__INLINE void PurgeBlock(void* pDst, int len) -{ - int n; - for(n=0; n> (blkSize-numSize)%8 ); - - /* save crytical byte */ - Ipp8u save = (Ipp8u)( pCounter[maskPosition] & ~mask ); - - int len = BITS2WORD8_SIZE(blkSize); - Ipp32u carry = 1; - for(; (len>maskPosition) && carry; len--) { - Ipp32u x = pCounter[len-1] + carry; - pCounter[len-1] = (Ipp8u)x; - carry = (x>>8) & 0xFF; - } - - /* update crytical byte */ - pCounter[maskPosition] &= mask; - pCounter[maskPosition] |= save; -} - -/* vb */ -__INLINE void ompStdIncrement64( void* pInitCtrVal, void* pCurrCtrVal, - int ctrNumBitSize, int n ) -{ - int k; - Ipp64u cntr; - Ipp64u temp; - Ipp64s item; - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - ( ( Ipp8u* )&cntr )[k] = ( ( Ipp8u* )pInitCtrVal )[7 - k]; - #else - for( k = 0; k < 8; k++ ) - ( ( Ipp8u* )&cntr )[k] = ( ( Ipp8u* )pInitCtrVal )[k]; - #endif - - if( ctrNumBitSize == 64 ) - { - cntr += ( Ipp64u )n; - } - else - { - /* gres: Ipp64u mask = ( Ipp64u )0xFFFFFFFFFFFFFFFF >> ( 64 - ctrNumBitSize ); */ - Ipp64u mask = CONST_64(0xFFFFFFFFFFFFFFFF) >> ( 64 - ctrNumBitSize ); - Ipp64u save = cntr & ( ~mask ); - Ipp64u bndr = ( Ipp64u )1 << ctrNumBitSize; - - temp = cntr & mask; - cntr = temp + ( Ipp64u )n; - - if( cntr > bndr ) - { - item = ( Ipp64s )n - ( Ipp64s )( bndr - temp ); - - while( item > 0 ) - { - cntr = ( Ipp64u )item; - item -= ( Ipp64s )bndr; - } - } - - cntr = save | ( cntr & mask ); - } - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - ( ( Ipp8u* )pCurrCtrVal )[7 - k] = ( ( Ipp8u* )&cntr )[k]; - #else - for( k = 0; k < 8; k++ ) - ( ( Ipp8u* )pCurrCtrVal )[k] = ( ( Ipp8u* )&cntr )[k]; - #endif -} - - -/* vb */ -__INLINE void ompStdIncrement128( void* pInitCtrVal, void* pCurrCtrVal, - int ctrNumBitSize, int n ) -{ - int k; - Ipp64u low; - Ipp64u hgh; - Ipp64u flag; - Ipp64u mask = CONST_64(0xFFFFFFFFFFFFFFFF); - Ipp64u save; - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[15 - k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[7 - k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[8 + k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[k]; - } - #endif - - if( ctrNumBitSize == 64 ) - { - low += ( Ipp64u )n; - } - else if( ctrNumBitSize < 64 ) - { - Ipp64u bndr; - Ipp64u cntr; - Ipp64s item; - - mask >>= ( 64 - ctrNumBitSize ); - save = low & ( ~mask ); - cntr = ( low & mask ) + ( Ipp64u )n; - - if( ctrNumBitSize < 31 ) - { - bndr = ( Ipp64u )1 << ctrNumBitSize; - - if( cntr > bndr ) - { - item = ( Ipp64s )( ( Ipp64s )n - ( ( Ipp64s )bndr - - ( Ipp64s )( low & mask ) ) ); - - while( item > 0 ) - { - cntr = ( Ipp64u )item; - item -= ( Ipp64s )bndr; - } - } - } - - low = save | ( cntr & mask ); - } - else - { - flag = ( low >> 63 ); - - if( ctrNumBitSize != 128 ) - { - mask >>= ( 128 - ctrNumBitSize ); - save = hgh & ( ~mask ); - hgh &= mask; - } - - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) hgh++; - - if( ctrNumBitSize != 128 ) - { - hgh = save | ( hgh & mask ); - } - } - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[15 - k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[7 - k] = ( ( Ipp8u* )&hgh )[k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[8 + k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[k] = ( ( Ipp8u* )&hgh )[k]; - } - #endif -} - - -/* vb */ -__INLINE void ompStdIncrement192( void* pInitCtrVal, void* pCurrCtrVal, - int ctrNumBitSize, int n ) -{ - int k; - Ipp64u low; - Ipp64u mdl; - Ipp64u hgh; - Ipp64u flag; - Ipp64u mask = CONST_64(0xFFFFFFFFFFFFFFFF); - Ipp64u save; - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[23 - k]; - ( ( Ipp8u* )&mdl )[k] = ( ( Ipp8u* )pInitCtrVal )[15 - k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[7 - k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[16 + k]; - ( ( Ipp8u* )&mdl )[k] = ( ( Ipp8u* )pInitCtrVal )[8 + k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[k]; - } - #endif - - if( ctrNumBitSize == 64 ) - { - low += ( Ipp64u )n; - } - else if( ctrNumBitSize == 128 ) - { - flag = ( low >> 63 ); - low += ( Ipp64u )n; - if( flag != ( low >> 63 ) ) mdl++; - } - else if( ctrNumBitSize == 192 ) - { - flag = ( low >> 63 ); - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - if( flag != ( mdl >> 63 ) ) hgh++; - } - } - else if( ctrNumBitSize < 64 ) - { - Ipp64u bndr; - Ipp64u cntr; - Ipp64s item; - - mask >>= ( 64 - ctrNumBitSize ); - save = low & ( ~mask ); - cntr = ( low & mask ) + ( Ipp64u )n; - - if( ctrNumBitSize < 31 ) - { - bndr = ( Ipp64u )1 << ctrNumBitSize; - - if( cntr > bndr ) - { - item = ( Ipp64s )( ( Ipp64s )n - ( ( Ipp64s )bndr - - ( Ipp64s )( low & mask ) ) ); - - while( item > 0 ) - { - cntr = ( Ipp64u )item; - item -= ( Ipp64s )bndr; - } - } - } - - low = save | ( cntr & mask ); - } - else if( ctrNumBitSize < 128 ) - { - flag = ( low >> 63 ); - mask >>= ( 128 - ctrNumBitSize ); - save = mdl & ( ~mask ); - mdl &= mask; - low += ( Ipp64u )n; - if( flag != ( low >> 63 ) ) mdl++; - mdl = save | ( mdl & mask ); - } - else - { - flag = ( low >> 63 ); - mask >>= ( 192 - ctrNumBitSize ); - save = hgh & ( ~mask ); - hgh &= mask; - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - if( flag != ( mdl >> 63 ) ) hgh++; - } - - hgh = save | ( hgh & mask ); - } - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[23 - k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[15 - k] = ( ( Ipp8u* )&mdl )[k]; - ( ( Ipp8u* )pCurrCtrVal )[7 - k] = ( ( Ipp8u* )&hgh )[k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[16 + k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[8 + k] = ( ( Ipp8u* )&mdl )[k]; - ( ( Ipp8u* )pCurrCtrVal )[k] = ( ( Ipp8u* )&hgh )[k]; - } - #endif -} - - -/* vb */ -__INLINE void ompStdIncrement256( void* pInitCtrVal, void* pCurrCtrVal, - int ctrNumBitSize, int n ) -{ - int k; - Ipp64u low; - Ipp64u mdl; - Ipp64u mdm; - Ipp64u hgh; - Ipp64u flag; - Ipp64u mask = CONST_64(0xFFFFFFFFFFFFFFFF); - Ipp64u save; - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[31 - k]; - ( ( Ipp8u* )&mdl )[k] = ( ( Ipp8u* )pInitCtrVal )[23 - k]; - ( ( Ipp8u* )&mdm )[k] = ( ( Ipp8u* )pInitCtrVal )[15 - k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[7 - k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )&low )[k] = ( ( Ipp8u* )pInitCtrVal )[24 + k]; - ( ( Ipp8u* )&mdl )[k] = ( ( Ipp8u* )pInitCtrVal )[16 + k]; - ( ( Ipp8u* )&mdm )[k] = ( ( Ipp8u* )pInitCtrVal )[8 + k]; - ( ( Ipp8u* )&hgh )[k] = ( ( Ipp8u* )pInitCtrVal )[k]; - } - #endif - - if( ctrNumBitSize == 64 ) - { - low += ( Ipp64u )n; - } - else if( ctrNumBitSize == 128 ) - { - flag = ( low >> 63 ); - low += ( Ipp64u )n; - if( flag != ( low >> 63 ) ) mdl++; - } - else if( ctrNumBitSize == 192 ) - { - flag = ( low >> 63 ); - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - if( flag != ( mdl >> 63 ) ) hgh++; - } - } - else if( ctrNumBitSize == 256 ) - { - flag = ( low >> 63 ); - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - - if( flag != ( mdl >> 63 ) ) - { - flag = ( mdm >> 63 ); - mdm++; - if( flag != ( mdm >> 63 ) ) hgh++; - } - } - } - else if( ctrNumBitSize < 64 ) - { - Ipp64u bndr; - Ipp64u cntr; - Ipp64s item; - - mask >>= ( 64 - ctrNumBitSize ); - save = low & ( ~mask ); - cntr = ( low & mask ) + ( Ipp64u )n; - - if( ctrNumBitSize < 31 ) - { - bndr = ( Ipp64u )1 << ctrNumBitSize; - - if( cntr > bndr ) - { - item = ( Ipp64s )( ( Ipp64s )n - ( ( Ipp64s )bndr - - ( Ipp64s )( low & mask ) ) ); - - while( item > 0 ) - { - cntr = ( Ipp64u )item; - item -= ( Ipp64s )bndr; - } - } - } - - low = save | ( cntr & mask ); - } - else if( ctrNumBitSize < 128 ) - { - flag = ( low >> 63 ); - mask >>= ( 128 - ctrNumBitSize ); - save = mdl & ( ~mask ); - mdl &= mask; - low += ( Ipp64u )n; - if( flag != ( low >> 63 ) ) mdl++; - mdl = save | ( mdl & mask ); - } - else if( ctrNumBitSize < 192 ) - { - flag = ( low >> 63 ); - mask >>= ( 192 - ctrNumBitSize ); - save = mdm & ( ~mask ); - mdm &= mask; - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - if( flag != ( mdl >> 63 ) ) mdm++; - } - - mdm = save | ( mdm & mask ); - } - else - { - flag = ( low >> 63 ); - mask >>= ( 256 - ctrNumBitSize ); - save = hgh & ( ~mask ); - hgh &= mask; - low += ( Ipp64u )n; - - if( flag != ( low >> 63 ) ) - { - flag = ( mdl >> 63 ); - mdl++; - - if( flag != ( mdl >> 63 ) ) - { - flag = ( mdm >> 63 ); - mdm++; - if( flag != ( mdm >> 63 ) ) hgh++; - } - } - - hgh = save | ( hgh & mask ); - } - - #if( IPP_ENDIAN == IPP_LITTLE_ENDIAN ) - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[31 - k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[23 - k] = ( ( Ipp8u* )&mdl )[k]; - ( ( Ipp8u* )pCurrCtrVal )[15 - k] = ( ( Ipp8u* )&mdm )[k]; - ( ( Ipp8u* )pCurrCtrVal )[7 - k] = ( ( Ipp8u* )&hgh )[k]; - } - #else - for( k = 0; k < 8; k++ ) - { - ( ( Ipp8u* )pCurrCtrVal )[24 + k] = ( ( Ipp8u* )&low )[k]; - ( ( Ipp8u* )pCurrCtrVal )[16 + k] = ( ( Ipp8u* )&mdl )[k]; - ( ( Ipp8u* )pCurrCtrVal )[8 + k] = ( ( Ipp8u* )&mdm )[k]; - ( ( Ipp8u* )pCurrCtrVal )[k] = ( ( Ipp8u* )&hgh )[k]; - } - #endif -} - -#endif /* _CP_TOOL_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpvariant.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpvariant.h deleted file mode 100644 index aeda9c49..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpvariant.h +++ /dev/null @@ -1,326 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippcp) -// -// Purpose: -// Define ippCP variant -// -// -*/ - -#if !defined(_CP_VARIANT_H) -#define _CP_VARIANT_H - -/* -// modes of the CPU feature -*/ -#define _FEATURE_OFF_ (0) /* feature is OFF a priori */ -#define _FEATURE_ON_ (1) /* feature is ON a priori */ -#define _FEATURE_TICKTOCK_ (2) /* dectect is feature OFF/ON */ - -/* -// set _AES_NI_ENABLING_ -*/ -#if defined _IPP_AES_NI_ - #if (_IPP_AES_NI_ == 0) - #define _AES_NI_ENABLING_ _FEATURE_OFF_ - #elif (_IPP_AES_NI_ == 1) - #define _AES_NI_ENABLING_ _FEATURE_ON_ - #else - #error Define _IPP_AES_NI_=0 or 1 or omit _IPP_AES_NI_ at all - #endif -#else - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - #define _AES_NI_ENABLING_ _FEATURE_TICKTOCK_ - #else - #define _AES_NI_ENABLING_ _FEATURE_OFF_ - #endif -#endif - -/* -// select AES safe implementation -*/ -#define _ALG_AES_SAFE_COMPACT_SBOX_ (1) -#define _ALG_AES_SAFE_COMPOSITE_GF_ (2) - -#if (_AES_NI_ENABLING_==_FEATURE_ON_) - #define _ALG_AES_SAFE_ _FEATURE_OFF_ -#else - #if (_IPP>=_IPP_V8) || (_IPP32E>=_IPP32E_U8) - #define _ALG_AES_SAFE_ _ALG_AES_SAFE_COMPOSITE_GF_ - #else - #define _ALG_AES_SAFE_ _ALG_AES_SAFE_COMPACT_SBOX_ - #endif -#endif - - -/* -// set _SHA_NI_ENABLING_ -*/ -#if defined _IPP_SHA_NI_ - #if (_IPP_SHA_NI_ == 0) - #define _SHA_NI_ENABLING_ _FEATURE_OFF_ - #elif (_IPP_SHA_NI_ == 1) - #define _SHA_NI_ENABLING_ _FEATURE_ON_ - #else - #error Define _IPP_SHA_NI_=0 or 1 or omit _IPP_SHA_NI_ at all - #endif -#else - #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8) - #define _SHA_NI_ENABLING_ _FEATURE_TICKTOCK_ - #else - #define _SHA_NI_ENABLING_ _FEATURE_OFF_ - #endif -#endif - -/* -// set _ADCOX_NI_ENABLING_ -*/ -#if defined _IPP_ADCX_NI_ - #if (_IPP_ADCX_NI_ == 0) - #define _ADCOX_NI_ENABLING_ _FEATURE_OFF_ - #elif (_IPP_ADCX_NI_ == 1) - #define _ADCOX_NI_ENABLING_ _FEATURE_ON_ - #else - #error Define _IPP_ADCX_NI_=0 or 1 or omit _IPP_ADCX_NI_ at all - #endif -#else - #if (_IPP32E>=_IPP32E_L9) - #define _ADCOX_NI_ENABLING_ _FEATURE_TICKTOCK_ - #else - #define _ADCOX_NI_ENABLING_ _FEATURE_OFF_ - #endif -#endif - - -/* -// IPP supports several hash algorithms by default: -// SHA-1 -// SHA-256 -// SHA-224 (or SHA256/224 by the FIPS180-4 classification) -// SHA-512 -// SHA-384 (or SHA512/384 by the FIPS180-4 classification) -// MD5 -// SM3 -// -// By default all hash algorithms are included in IPP Crypto. -// -// If one need excludes code of particular hash, just define -// suitable _DISABLE_ALG_XXX, where XXX name of the hash algorithm -// -*/ -#if !defined(_DISABLE_ALG_SHA1_) -#define _ENABLE_ALG_SHA1_ /* SHA1 on */ -#else -# undef _ENABLE_ALG_SHA1_ /* SHA1 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA256_) -# define _ENABLE_ALG_SHA256_ /* SHA256 on */ -#else -# undef _ENABLE_ALG_SHA256_ /* SHA256 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA224_) -# define _ENABLE_ALG_SHA224_ /* SHA224 on */ -#else -# undef _ENABLE_ALG_SHA224_ /* SHA224 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA512_) -# define _ENABLE_ALG_SHA512_ /* SHA512 on */ -#else -# undef _ENABLE_ALG_SHA512_ /* SHA512 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA384_) -# define _ENABLE_ALG_SHA384_ /* SHA384 on */ -#else -# undef _ENABLE_ALG_SHA384_ /* SHA384 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA512_224_) -# define _ENABLE_ALG_SHA512_224_ /* SHA512/224 on */ -#else -# undef _ENABLE_ALG_SHA512_224_ /* SHA512/224 off */ -#endif - -#if !defined(_DISABLE_ALG_SHA512_256_) -# define _ENABLE_ALG_SHA512_256_ /* SHA512/256 on */ -#else -# undef _ENABLE_ALG_SHA512_256_ /* SHA512/256 off */ -#endif - -#if !defined(_DISABLE_ALG_MD5_) -# define _ENABLE_ALG_MD5_ /* MD5 on */ -#else -# undef _ENABLE_ALG_MD5_ /* MD5 off */ -#endif - -#if !defined(_DISABLE_ALG_SM3_) -# define _ENABLE_ALG_SM3_ /* SM3 on */ -#else -# undef _ENABLE_ALG_SM3_ /* SM3 off */ -#endif - -/* -// SHA1 plays especial role in IPP. Thus IPP random generator -// and therefore prime number generator are based on SHA1. -// So, do no exclude SHA1 from the active list of hash algorithms -*/ -//#if !defined(_ENABLE_ALG_SHA1_) -//#define _ENABLE_ALG_SHA1_ -//#endif - -/* -// Because of performane reason hash algorithms are implemented in form -// of unroller cycle and therefore these implementations are big enough. -// IPP supports "compact" implementation of some basic hash algorithms: -// SHA-1 -// SHA-256 -// SHA-512 -// SM3 -// -// Define any -// _ALG_SHA1_COMPACT_ -// _ALG_SHA256_COMPACT_ -// _ALG_SHA512_COMPACT_ -// _ALG_SM3_COMPACT_ -// -// to select "compact" implementation of particular hash algorithm. -// IPP does not define "compact" implementation by default. -// -// Don't know what performance degradation leads "compact" -// in comparison with default IPP implementation. -// -// Note: the definition like _ALG_XXX_COMPACT_ has effect -// if and only if IPP instance is _PX or _MX -*/ -//#define _ALG_SHA1_COMPACT_ -//#define _ALG_SHA256_COMPACT_ -//#define _ALG_SHA512_COMPACT_ -//#define _ALG_SM3_COMPACT_ -//#undef _ALG_SHA1_COMPACT_ -//#undef _ALG_SHA256_COMPACT_ -//#undef _ALG_SHA512_COMPACT_ -//#undef _ALG_SM3_COMPACT_ - - -/* -// BN arithmetic: -// - do/don't use special implementation of sqr instead of usual multication -// - do/don't use Karatsuba multiplication alg -*/ -#define _USE_SQR_ /* use implementaton of sqr */ -#define xUSE_KARATSUBA_ /* not use Karatsuba method for multiplication */ -#define _USE_WINDOW_EXP_ /* use fixed window exponentiation */ - -/* -// RSA: -// - do/don't use Ernie's style mitigation of CBA -// - do/don't use Gres's style mitigation of CBA -// - do/don't use Foldinf technique for RSA-1204 implementation -*/ -#define xUSE_ERNIE_CBA_MITIGATION_ /* not use (Ernie) mitigation of CBA */ -#define _USE_GRES_CBA_MITIGATION_ /* use (Gres) mitigation of CBA */ -#define xUSE_FOLD_MONT512_ /* use foding technique in RSA-1024 case */ - -/* -// IPP supports different implementation of NIST's (standard) EC over GF(0): -// P-128 (IppECCPStd128r1, IppECCPStd128r2) -// P-192 (IppECCPStd192r1) -// P-224 (IppECCPStd224r1) -// P-256 (IppECCPStd256r1) -// P-384 (IppECCPStd384r1) -// P-521 (IppECCPStd521r1) -// -// If one need replace the particular implementation by abritrary one -// assign _ECP_IMP_ARBIRTRARY_ to suitable symbol -// -// _ECP_IMPL_ARBIRTRARY_ means that implementtaion does not use any curve specific, -// provide the same (single) code for any type curve -// -// _ECP_IMPL_SPECIFIC_ means that implementation uses specific modular reduction -// based on prime structure; -// most of NIST's cures (p128, p192, p224, p256, p384, p521) are uses -// such kind of reduction procedure; -// in contrast with _ECP_IMPL_ARBIRTRARY_ and _ECP_IMPL_MFM_ -// this type of implementation uses point representation in REGULAR residual -// (not Montgometry!!) domain -// -// _ECP_IMPL_MFM_ means that implementation uses "Montgomary Friendly Modulus" (primes); -// p256 and sm2 are using such kind of optimization -*/ -#define _ECP_IMPL_ARBIRTRARY_ 0 -#define _ECP_IMPL_SPECIFIC_ 1 -#define _ECP_IMPL_MFM_ 2 - -#define _ECP_128_ _ECP_IMPL_SPECIFIC_ -#define _ECP_192_ _ECP_IMPL_SPECIFIC_ -#define _ECP_224_ _ECP_IMPL_SPECIFIC_ -#define _ECP_256_ _ECP_IMPL_SPECIFIC_ -#define _ECP_384_ _ECP_IMPL_SPECIFIC_ -#define _ECP_521_ _ECP_IMPL_SPECIFIC_ -#define _ECP_SM2_ _ECP_IMPL_SPECIFIC_ -//#define _ECP_SM2_ _ECP_IMPL_ARBIRTRARY_ - -#if (_IPP32E >= _IPP32E_M7) -#undef _ECP_192_ -#undef _ECP_224_ -#undef _ECP_256_ -#undef _ECP_384_ -#undef _ECP_521_ -#undef _ECP_SM2_ - -#define _ECP_192_ _ECP_IMPL_MFM_ -#define _ECP_224_ _ECP_IMPL_MFM_ -#define _ECP_256_ _ECP_IMPL_MFM_ -#define _ECP_384_ _ECP_IMPL_MFM_ -#define _ECP_521_ _ECP_IMPL_MFM_ -#define _ECP_SM2_ _ECP_IMPL_MFM_ -#endif - - -/* -// EC over GF(p): -// - do/don't use mitigation of CBA -*/ -#define _USE_ECCP_SSCM_ /* use SSCM ECCP */ - - -#if defined ( _OPENMP ) -#define DEFAULT_CPU_NUM (8) - -#define BF_MIN_BLK_PER_THREAD (32) -#define TF_MIN_BLK_PER_THREAD (16) - -#define DES_MIN_BLK_PER_THREAD (32) -#define TDES_MIN_BLK_PER_THREAD (16) - -#define RC5_64_MIN_BLK_PER_THREAD (16) -#define RC5_128_MIN_BLK_PER_THREAD (32) - -#define RIJ128_MIN_BLK_PER_THREAD (32) -#define RIJ192_MIN_BLK_PER_THREAD (16) -#define RIJ256_MIN_BLK_PER_THREAD (16) - -#define AESNI128_MIN_BLK_PER_THREAD (256) -#endif - -#endif /* _CP_VARIANT_H */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/Makefile b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/Makefile deleted file mode 100644 index 9ce46a53..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/make -f -API_INCLUDE_DIR = ../../include -SRC_INCLUDE_DIR = ../../sources/include -LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/ - -PCP_INCLUDE_DIR = ../ippcp/src -PCPEPID_INCLUDE_DIR = ./src -PCPEPID_SRC = $(wildcard ./src/*.c) -PCPEPID_OBJ = $(sort $(PCPEPID_SRC:.c=.o)) -PCPEPID_LIB = ./src/libippcpepid.a - - -ifeq ($(ARCH), x86_64) - CFLAGS += -DUSE_Y8_HEADER -else - CFLAGS += -DUSE_P8_HEADER -endif - -$(PCPEPID_OBJ): %.o: %.c - $(CC) $(CFLAGS) -I$(API_INCLUDE_DIR) -I$(SRC_INCLUDE_DIR) -I$(PCP_INCLUDE_DIR) -I$(PCPEPID_INCLUDE_DIR) -c -o $@ $< - -$(PCPEPID_LIB): $(PCPEPID_OBJ) - $(AR) rc $@ $^ - ranlib $@ - -build: all - -all: $(PCPEPID_LIB) - -install: - mkdir -p '$(LIB_INSTALL_DIR)' - cp $(PCPEPID_LIB) '$(LIB_INSTALL_DIR)' - -clean: - rm -f $(PCPEPID_OBJ) $(PCPEPID_LIB) - - diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/ippcpepid_y8.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/ippcpepid_y8.h deleted file mode 100644 index 8576622e..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/ippcpepid_y8.h +++ /dev/null @@ -1,44 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief This file does renames to allow using of the lib with - * commercial merged ippcp - */ - - -#ifndef IPPEPID_Y8_H_ -#define IPPEPID_Y8_H_ - -# define cpDiv_BNU32 y8_##cpDiv_BNU32 -# define cpLSR_BNU y8_##cpLSR_BNU -# define cpNLZ_BNU y8_##cpNLZ_BNU -# define cpNLZ_BNU32 y8_##cpNLZ_BNU32 -# define cpToOctStr_BNU y8_##cpToOctStr_BNU -# define cpFromOctStr_BNU y8_##cpFromOctStr_BNU -# define cpMulAdc_BNU_school y8_##cpMulAdc_BNU_school -# define cpMontRedAdc_BNU y8_##cpMontRedAdc_BNU -# define cpSqrAdc_BNU_school y8_##cpSqrAdc_BNU_school -# define cpModInv_BNU y8_##cpModInv_BNU -# define cpAdd_BNU y8_##cpAdd_BNU -# define cpSub_BNU y8_##cpSub_BNU -# define cpDec_BNU32 y8_##cpDec_BNU32 -# define cpNTZ_BNU y8_##cpNTZ_BNU -# define cpMontExpBin_BNU y8_##cpMontExpBin_BNU - -#endif // IPPEPID_Y8_H_ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/owncpepid.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/owncpepid.h deleted file mode 100644 index 6b0815da..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/owncpepid.h +++ /dev/null @@ -1,58 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Internal Cryptographic Primitives (Intel(R) EPID v2.0) -// -// -*/ - -#ifndef __OWNCP_EPID_H__ -#define __OWNCP_EPID_H__ - -#if defined (USE_P8_HEADER) - #include "ippcpepid_p8.h" -#elif defined (USE_Y8_HEADER) - #include "ippcpepid_y8.h" -#endif - -#ifndef __OWNDEFS_H__ - #include "owndefs.h" -#endif - -#ifndef __OWNCP_H__ - #include "owncp.h" -#endif - -#ifndef __IPPCP_EPID_H__ - #include "ippcpepid.h" -#endif - -#define LOG2_CACHE_LINE_SIZE (6) /* LOG2(CACHE_LINE_SIZE) */ - -/* convert bitsize nbits into the number of BNU_CHUNK_T */ -#define BITS_CHUNKSIZE(nbits) (((nbits)+BITSIZE(BNU_CHUNK_T)-1)/BITSIZE(BNU_CHUNK_T)) - -/* -// dst = (src1 & mask) | (src2 & ~mask) -*/ -#define MASKED_COPY(dst, mask, src1, src2, len) { \ - /*cpSize*/ int i; \ - for(i=0; i<(len); i++) (dst)[i] = ((mask) & (src1)[i]) | (~(mask) & (src2)[i]); \ -} - -#endif /* __OWNCP_EPID_H__ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfp.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfp.c deleted file mode 100644 index d764dae1..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfp.c +++ /dev/null @@ -1,846 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Performance Primitives. Cryptography Primitives. -// Operations over GF(p). -// -// Context: -// ippsGFpGetSize() -// ippsGFpInit() -// -// ippsGFpElementGetSize() -// ippsGFpElementInit() -// -// ippsGFpSetElement() -// ippsGFpSetElementOctString() -// ippsGFpSetElementRandom() -// ippsGFpSetElementHash() -// ippsGFpCpyElement() -// ippsGFpGetElement() -// ippsGFpGetElementOctString() -// -// ippsGFpCmpElement() -// ippsGFpIsZeroElement() -// ippsGFpIsUnityElement() -// -// ippsGFpSetPolyTerm() -// ippsGFpGetPolyTerm() -// -// ippsGFpConj() -// ippsGFpNeg() -// ippsGFpInv() -// ippsGFpSqrt() -// ippsGFpAdd() -// ippsGFpSub() -// ippsGFpMul() -// ippsGFpSqr() -// ippsGFpExp() -// ippsGFpMultiExp() -// -// ippsGFpAdd_GFpE() -// ippsGFpSub_GFpE() -// ippsGFpMul_GFpE() -// -// -*/ - -#include "owncpepid.h" - -#include "pcpgfpstuff.h" -#include "pcpgfpxstuff.h" -#include "pcpgfphashstuff.h" - - -IPPFUN(IppStatus, ippsGFpGetSize,(int bitSize, int* pSizeInBytes)) -{ - IPP_BAD_PTR1_RET(pSizeInBytes); - IPP_BADARG_RET((bitSize < 2) || (bitSize > GF_MAX_BITSIZE), ippStsSizeErr); - - { - int elemLen32 = BITS2WORD32_SIZE(bitSize); - int elemLen = BITS_BNU_CHUNK(bitSize); - int poolelemLen = elemLen + 1; - - int montgomeryCtxSize; - ippsMontGetSize(ippBinaryMethod, elemLen32, &montgomeryCtxSize); - - *pSizeInBytes = sizeof(IppsGFpState) /* sizeof(IppsGFPState)*/ - +elemLen*sizeof(BNU_CHUNK_T) /* modulus */ - +elemLen*sizeof(BNU_CHUNK_T) /* half of modulus */ - +elemLen*sizeof(BNU_CHUNK_T) /* quadratic non-residue */ - +montgomeryCtxSize /* montgomery engine */ - +poolelemLen*sizeof(BNU_CHUNK_T)*GF_POOL_SIZE /* pool */ - +CACHE_LINE_SIZE - +GFP_ALIGNMENT-1; - return ippStsNoErr; - } -} - - -static void gfpInitSqrt(IppsGFpState* pGF) -{ - int elemLen = GFP_FELEN(pGF); - BNU_CHUNK_T* e = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* t = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pMont1 = cpGFpGetPool(1, pGF); - - cpGFpElementCopyPadd(pMont1, elemLen, MNT_1(GFP_MONT(pGF)), elemLen); - - /* (modulus-1)/2 */ - cpLSR_BNU(e, GFP_MODULUS(pGF), elemLen, 1); - - /* find a non-square g, where g^{(modulus-1)/2} = -1 */ - cpGFpElementCopy(GFP_QNR(pGF), pMont1, elemLen); - do { - cpGFpAdd(GFP_QNR(pGF), pMont1, GFP_QNR(pGF), pGF); - cpGFpExp(t, GFP_QNR(pGF), e, elemLen, pGF); - cpGFpNeg(t, t, pGF); - } while( !GFP_EQ(pMont1, t, elemLen) ); - - cpGFpReleasePool(3, pGF); -} - -IPPFUN(IppStatus, ippsGFpInit,(const Ipp32u* pPrime, int primeBitSize, IppsGFpState* pGF)) -{ - IPP_BAD_PTR2_RET(pPrime, pGF); - IPP_BADARG_RET((primeBitSize< 2 ) || (primeBitSize> GF_MAX_BITSIZE), ippStsSizeErr); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - - { - Ipp8u* ptr = (Ipp8u*)pGF; - - int elemLen32 = BITS2WORD32_SIZE(primeBitSize); - int elemLen = BITS_BNU_CHUNK(primeBitSize); - int poolelemLen = elemLen + 1; - int montgomeryCtxSize; - ippsMontGetSize(ippBinaryMethod, elemLen32, &montgomeryCtxSize); - - GFP_ID(pGF) = idCtxGFP; - GFP_DEGREE(pGF) = 1; - GFP_FELEN(pGF) = elemLen; - GFP_FELEN32(pGF) = elemLen32; - GFP_PELEN(pGF) = poolelemLen; - FIELD_POLY_TYPE(pGF) = ARBITRARY; - - #if(_IPP_ARCH==_IPP_ARCH_EM64T) - /* 192 < primeBitSize <= 256 is considered as Intel(R) EPID param */ - EPID_PARAMS(pGF) = elemLen==4; - #else - EPID_PARAMS(pGF) = 0; - #endif - - GFP_GROUNDGF(pGF)= pGF; - - /* methods */ - pGF->add = cpGFpAdd; - pGF->sub = cpGFpSub; - pGF->neg = cpGFpNeg; - pGF->mul = cpGFpMul; - pGF->sqr = cpGFpSqr; - pGF->div2= cpGFpHalve; - - #if(_IPP32E >= _IPP32E_M7) - if(EPID_PARAMS(pGF)) { - pGF->add = cp256pAdd; - pGF->sub = cp256pSub; - pGF->neg = cp256pNeg; - pGF->mul = cp256pMul; - pGF->sqr = cp256pSqr; - pGF->div2= cp256pHalve; - } - #endif - - ptr += sizeof(IppsGFpState); - GFP_MODULUS(pGF) = (BNU_CHUNK_T*)(ptr); ptr += elemLen*sizeof(BNU_CHUNK_T); - GFP_HMODULUS(pGF) = (BNU_CHUNK_T*)(ptr); ptr += elemLen*sizeof(BNU_CHUNK_T); - GFP_QNR(pGF) = (BNU_CHUNK_T*)(ptr); ptr += elemLen*sizeof(BNU_CHUNK_T); - GFP_MONT(pGF) = (IppsMontState*)( IPP_ALIGNED_PTR((ptr), (MONT_ALIGNMENT)) ); ptr += montgomeryCtxSize; - GFP_POOL(pGF) = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(ptr, (int)sizeof(BNU_CHUNK_T))); - - ippsMontInit(ippBinaryMethod, elemLen32, GFP_MONT(pGF)); - ippsMontSet(pPrime, elemLen32, GFP_MONT(pGF)); - - /* modulus */ - cpGFpElementPadd(GFP_MODULUS(pGF), elemLen, 0); - COPY_BNU((Ipp32u*)GFP_MODULUS(pGF), pPrime, elemLen32); - /* half of modulus */ - cpGFpElementPadd(GFP_HMODULUS(pGF), elemLen, 0); - cpLSR_BNU(GFP_HMODULUS(pGF), GFP_MODULUS(pGF), elemLen, 1); - - /* do some additional initialization to make sqrt operation faster */ - cpGFpElementPadd(GFP_QNR(pGF), elemLen, 0); - gfpInitSqrt(pGF); - - return ippStsNoErr; - } -} - - -IPPFUN(IppStatus, ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) -{ - IPP_BAD_PTR2_RET(pGF, pBufferSize); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - - IPP_BADARG_RET( (0>=nExponents)||(nExponents>LOG2_CACHE_LINE_SIZE), ippStsBadArgErr); - - { - int elmDataSize = GFP_FELEN(pGF)*sizeof(BNU_CHUNK_T); - - /* get window_size */ - int w = (nExponents==1)? cpGFpGetOptimalWinSize(ExpBitSize) : /* use optimal window size, if single-scalar operation */ - nExponents; /* or pseudo-oprimal if multi-scalar operation */ - - /* number of table entries */ - int nPrecomputed = 1<nsA, ippStsSizeErr); - - { - int elemLen = GFP_FELEN(pGF); - - Ipp8u* ptr = (Ipp8u*)pR; - - GFPE_ID(pR) = idCtxGFPE; - GFPE_ROOM(pR) = elemLen; - ptr += sizeof(IppsGFpElement); - GFPE_DATA(pR) = (BNU_CHUNK_T*)ptr; - - return ippsGFpSetElement(pA, nsA, pR, pGF); - } -} - -IPPFUN(IppStatus, ippsGFpSetElement,(const Ipp32u* pDataA, int nsA, IppsGFpElement* pElm, IppsGFpState* pGF)) -{ - IPP_BAD_PTR2_RET(pElm, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - - IPP_BADARG_RET( (pDataA && (nsA<0)), ippStsSizeErr ); - - { - IppStatus sts = ippStsNoErr; - - int elemLen32 = GFP_FELEN32(pGF); - if(pDataA) FIX_BNU(pDataA, nsA); - if(pDataA && (nsA>elemLen32)) IPP_ERROR_RET(ippStsOutOfRangeErr); - - { - BNU_CHUNK_T* pTmp = cpGFpGetPool(1, pGF); - int elemLen = GFP_FELEN(pGF); - ZEXPAND_BNU(pTmp, 0, elemLen); - if(pDataA) - cpGFpxCopyToChunk(pTmp, pDataA, nsA, pGF); - - if(!cpGFpxSet(GFPE_DATA(pElm), pTmp, elemLen, pGF, USE_MONT_SPACE_REPRESENTATION)) - sts = ippStsOutOfRangeErr; - - cpGFpReleasePool(1, pGF); - } - - return sts; - } -} - -IPPFUN(IppStatus, ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pElm, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pStr, pElm, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - - { - IppsGFpState* pBasicGF = cpGFpBasic(pGF); - int basicDeg = cpGFpBasicDegreeExtension(pGF); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicSize = BITS2WORD8_SIZE(BITSIZE_BNU(GFP_MODULUS(pBasicGF),GFP_FELEN(pBasicGF))); - - BNU_CHUNK_T* pDataElm = GFPE_DATA(pElm); - - int deg, error; - /* set element to zero */ - cpGFpElementPadd(pDataElm, GFP_FELEN(pGF), 0); - - /* convert oct string to element (from low to high) */ - for(deg=0, error=0; deg GF_POOL_SIZE*GFP_PESIZE(pGFp)*BITSIZE(ipp32u), ippStsBadArgErr); - - { - Ipp32u moduloBitSize = GFP_FESIZE32(pGFp)*BITSIZE(ipp32u) - NLZ32u(GFP_MODULUS(pGFp)[GFP_FESIZE32(pGFp)-1]); - if(moduloBitSize>power) { - gfpFFelementPadd(0, GFPE_DATA(pR), GFP_FELEN(pGFp)); - SET_BIT(GFPE_DATA(pR), power); - } - else { - Ipp32u dataLen = BITS2WORD32_SIZE(power+1); - Ipp32u* pData = GFP_POOL(pGFp); - gfpFFelementPadd(0, pData, dataLen); - SET_BIT(pData, power); - gfpReduce(pData, dataLen, GFPE_DATA(pR), pGFp); - } - return ippStsNoErr; - } -} -#endif - - -IPPFUN(IppStatus, ippsGFpSetElementRandom,(IppBitSupplier rndFunc, void* pRndParam, - IppsGFpElement* pElm, IppsGFpState* pGF)) -{ - IPP_BAD_PTR2_RET(pElm, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - - cpGFpxRand(GFPE_DATA(pElm), pGF, rndFunc, pRndParam, USE_MONT_SPACE_REPRESENTATION); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpCpyElement, (const IppsGFpElement* pElmA, IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - cpGFpElementCopy(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFP_FELEN(pGF)); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpGetElement, (const IppsGFpElement* pElm, Ipp32u* pDataA, int nsA, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElm, pDataA, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - IPP_BADARG_RET( 0>nsA, ippStsSizeErr ); - - { - int elemLen = GFP_FELEN(pGF); - BNU_CHUNK_T* pTmp = cpGFpGetPool(1, pGF); - - cpGFpxGet(pTmp, elemLen, GFPE_DATA(pElm), pGF, USE_MONT_SPACE_REPRESENTATION); - cpGFpxCopyFromChunk(pDataA, pTmp, pGF); - - cpGFpReleasePool(1, pGF); - return ippStsNoErr; - } -} - -IPPFUN(IppStatus, ippsGFpGetElementOctString,(const IppsGFpElement* pElm, Ipp8u* pStr, int strSize, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pStr, pElm, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - - { - IppsGFpState* pBasicGF = cpGFpBasic(pGF); - int basicDeg = cpGFpBasicDegreeExtension(pGF); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicSize = BITS2WORD8_SIZE(BITSIZE_BNU(GFP_MODULUS(pBasicGF),GFP_FELEN(pBasicGF))); - - BNU_CHUNK_T* pDataElm = GFPE_DATA(pElm); - - int deg; - for(deg=0; degnsT, ippStsSizeErr ); - - if(termDegree>=0 && termDegree * GFP_FELEN(pGF) < GFPE_ROOM(pElm) ) - cpGFpxSetPolyTerm(GFPE_DATA(pElm), termDegree, pTerm, nsT, pGF, USE_MONT_SPACE_REPRESENTATION); - return ippStsNoErr; -} -#endif - -#if 0 -IPPFUN(IppStatus, ippsGFpGetPolyTerm, (const IppsGFpElement* pElm, int termDegree, Ipp32u* pTerm, int nsT, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElm, pTerm, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElm), ippStsContextMatchErr ); - IPP_BADARG_RET( 0>nsT, ippStsSizeErr ); - - cpGFpElementPadd(pTerm, nsT, 0); - if(termDegree>=0 && termDegree * GFP_FELEN(pGF) < GFPE_ROOM(pElm) ) - cpGFpxGetPolyTerm(pTerm, nsT, GFPE_DATA(pElm), termDegree, pGF, USE_MONT_SPACE_REPRESENTATION); - return ippStsNoErr; -} -#endif - -IPPFUN(IppStatus, ippsGFpConj,(const IppsGFpElement* pElmA, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( 2!=GFP_DEGREE(pGF), ippStsBadArgErr ) - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - cpGFpxConj(GFPE_DATA(pElmR), GFPE_DATA(pElmA), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpNeg,(const IppsGFpElement* pElmA, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - pGF->neg(GFPE_DATA(pElmR), GFPE_DATA(pElmA), pGF); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpInv,(const IppsGFpElement* pElmA, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - IPP_BADARG_RET( GFP_IS_ZERO(GFPE_DATA(pElmA),GFP_FELEN(pGF)), ippStsDivByZeroErr ); - - return NULL != cpGFpxInv(GFPE_DATA(pElmR), GFPE_DATA(pElmA), pGF)? ippStsNoErr : ippStsBadArgErr; -} - - -IPPFUN(IppStatus, ippsGFpSqrt,(const IppsGFpElement* pElmA, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFP_IS_BASIC(pGF), ippStsBadArgErr ) - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - return cpGFpSqrt(GFPE_DATA(pElmR), GFPE_DATA(pElmA), pGF)? ippStsNoErr : ippStsQuadraticNonResidueErr; -} - - -IPPFUN(IppStatus, ippsGFpAdd,(const IppsGFpElement* pElmA, const IppsGFpElement* pElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - pGF->add(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pElmB), pGF); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpSub,(const IppsGFpElement* pElmA, const IppsGFpElement* pElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - pGF->sub(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pElmB), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpMul,(const IppsGFpElement* pElmA, const IppsGFpElement* pElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - pGF->mul(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pElmB), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpSqr,(const IppsGFpElement* pElmA, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR3_RET(pElmA, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - pGF->sqr(GFPE_DATA(pElmR), GFPE_DATA(pElmA), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpAdd_GFpE,(const IppsGFpElement* pElmA, const IppsGFpElement* pGroundElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pGroundElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( GFP_IS_BASIC(pGF), ippStsBadArgErr ) - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pGroundElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - cpGFpxAdd_GFE(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pGroundElmB), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpSub_GFpE,(const IppsGFpElement* pElmA, const IppsGFpElement* pGroundElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pGroundElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( GFP_IS_BASIC(pGF), ippStsBadArgErr ) - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pGroundElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - cpGFpxSub_GFE(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pGroundElmB), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpMul_GFpE,(const IppsGFpElement* pElmA, const IppsGFpElement* pGroundElmB, - IppsGFpElement* pElmR, IppsGFpState* pGF)) -{ - IPP_BAD_PTR4_RET(pElmA, pGroundElmB, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( GFP_IS_BASIC(pGF), ippStsBadArgErr ) - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pGroundElmB), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - cpGFpxMul_GFE(GFPE_DATA(pElmR), GFPE_DATA(pElmA), GFPE_DATA(pGroundElmB), pGF); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpExp,(const IppsGFpElement* pElmA, const IppsBigNumState* pE, - IppsGFpElement* pElmR, IppsGFpState* pGF, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR4_RET(pElmA, pE, pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmA), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - IPP_BADARG_RET( !BN_VALID_ID(pE), ippStsContextMatchErr ); - IPP_BADARG_RET( BN_SIZE(pE) > GFP_FELEN(pGF), ippStsRangeErr ); - - cpGFpxExp(GFPE_DATA(pElmR), GFPE_DATA(pElmA), BN_NUMBER(pE), BN_SIZE(pE), pGF, pScratchBuffer); - - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, - IppsGFpElement* pElmR, IppsGFpState* pGF, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR2_RET(pElmR, pGF); - pGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGF), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pElmR), ippStsContextMatchErr ); - - IPP_BAD_PTR2_RET(ppElmA, ppE); - - if(nItems==1) - return ippsGFpExp(ppElmA[0], ppE[0], pElmR, pGF, pScratchBuffer); - - else { - int n; - for(n=0; n GFP_FELEN(pGF), ippStsRangeErr ); - } - - if(NULL==pScratchBuffer) { - BNU_CHUNK_T* pTmpR = cpGFpGetPool(1, pGF); - cpGFpxExp(GFPE_DATA(pElmR), GFPE_DATA(ppElmA[0]), BN_NUMBER(ppE[0]), BN_SIZE(ppE[0]), pGF, 0); - for(n=1; n=nScalars)||(nScalars>LOG2_CACHE_LINE_SIZE), ippStsBadArgErr); - - { - int pointDataSize = ECP_FELEN(pEC)*sizeof(BNU_CHUNK_T); - - /* get window_size */ - #if 0 - int w = (nScalars==1)? cpEcGFpGetOptimalWinSize(orderBitSize) : /* use optimal window size, if single-scalar operation */ - nScalars; /* or pseudo-oprimal if multi-scalar operation */ - #endif - int w = (nScalars==1)? 5 : nScalars; - - /* number of table entries */ - int nPrecomputed = 1<ECP_ORDBITSIZE(pEC), ippStsRangeErr) - - ECP_ORDBITSIZE(pEC) = inOrderBitSize; - ZEXPAND_COPY_BNU((Ipp32u*)ECP_R(pEC), BITS_BNU_CHUNK(inOrderBitSize)*(int)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)), pOrder,ordLen); - } - - if(pCofactor) { - int cofactorOrderBitSize; - FIX_BNU(pCofactor, cofactorLen); - cofactorOrderBitSize = BITSIZE_BNU32(pCofactor, cofactorLen); - IPP_BADARG_RET(cofactorOrderBitSize>elemLen*BITSIZE(BNU_CHUNK_T), ippStsRangeErr) - cofactorLen = BITS2WORD32_SIZE(cofactorOrderBitSize); - ZEXPAND_COPY_BNU((Ipp32u*)ECP_COFACTOR(pEC), BITS_BNU_CHUNK(cofactorOrderBitSize)*(int)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)), pCofactor,cofactorLen); - } - - return ippStsNoErr; - } -} - -IPPFUN(IppStatus, ippsGFpECGet,(const IppsGFpECState* pEC, - const IppsGFpState** ppGF, - IppsGFpElement* pA, IppsGFpElement* pB, - IppsGFpElement* pX, IppsGFpElement* pY, - const Ipp32u** ppOrder, int* pOrderLen, - const Ipp32u** ppCofactor, int* pCofactorLen)) -{ - IPP_BAD_PTR1_RET(pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - - { - const IppsGFpState* pGF = ECP_GFP(pEC); - Ipp32u elementSize = GFP_FELEN(pGF); - - if(ppGF) { - *ppGF = pGF; - } - - if(pA) { - IPP_BADARG_RET( !GFPE_TEST_ID(pA), ippStsContextMatchErr ); - cpGFpElementCopy(GFPE_DATA(pA), ECP_A(pEC), elementSize); - } - if(pB) { - IPP_BADARG_RET( !GFPE_TEST_ID(pB), ippStsContextMatchErr ); - cpGFpElementCopy(GFPE_DATA(pB), ECP_B(pEC), elementSize); - } - - if(pX) { - IPP_BADARG_RET( !GFPE_TEST_ID(pX), ippStsContextMatchErr ); - cpGFpElementCopy(GFPE_DATA(pX), ECP_G(pEC), elementSize); - } - if(pY) { - IPP_BADARG_RET( !GFPE_TEST_ID(pY), ippStsContextMatchErr ); - cpGFpElementCopy(GFPE_DATA(pY), ECP_G(pEC)+elementSize, elementSize); - } - - if(ppOrder) { - *ppOrder = (Ipp32u*)ECP_R(pEC); - } - if(pOrderLen) { - *pOrderLen = BITS2WORD32_SIZE(ECP_ORDBITSIZE(pEC)); - } - - if(ppCofactor) { - *ppCofactor = (Ipp32u*)ECP_COFACTOR(pEC); - } - if(pCofactorLen) { - int cofactorLen = GFP_FELEN32(pGF); - FIX_BNU((Ipp32u*)ECP_COFACTOR(pEC), cofactorLen); - *pCofactorLen = cofactorLen; - } - - return ippStsNoErr; - } -} - -IPPFUN(IppStatus, ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR2_RET(pEC, pResult); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - - *pResult = ippECValid; - - { - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* - // check discriminant ( 4*A^3 + 27*B^2 != 0 mod P) - */ - if(ippECValid == *pResult) { - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pU = cpGFpGetPool(1, pGF); - - if(EPID_PARAMS(pEC)) - cpGFpElementPadd(pT, elemLen, 0); /* T = 4*A^3 = 0 */ - else { - pGF->add(pT, ECP_A(pEC), ECP_A(pEC), pGF); /* T = 4*A^3 */ - pGF->sqr(pT, pT, pGF); - pGF->mul(pT, ECP_A(pEC), pT, pGF); - } - - pGF->add(pU, ECP_B(pEC), ECP_B(pEC), pGF); /* U = 9*B^2 */ - pGF->add(pU, pU, ECP_B(pEC), pGF); - pGF->sqr(pU, pU, pGF); - - pGF->add(pT, pU, pT, pGF); /* T += 3*U */ - pGF->add(pT, pU, pT, pGF); - pGF->add(pT, pU, pT, pGF); - - *pResult = GFP_IS_ZERO(pT, elemLen)? ippECIsZeroDiscriminant: ippECValid; - - cpGFpReleasePool(2, pGF); - } - - /* - // check base point and it order - */ - if(ippECValid == *pResult) { - IppsGFpECPoint G; - cpEcGFpInitPoint(&G, ECP_G(pEC), ECP_AFFINE_POINT|ECP_FINITE_POINT, pEC); - - /* check G != infinity */ - *pResult = cpEcGFpIsProjectivePointAtInfinity(&G, elemLen)? ippECPointIsAtInfinite : ippECValid; - - /* check G lies on EC */ - if(ippECValid == *pResult) - *pResult = cpEcGFpIsPointOnCurve(&G, pEC)? ippECValid : ippECPointIsNotValid; - - /* check Gorder*G = infinity */ - if(ippECValid == *pResult) { - IppsGFpECPoint T; - cpEcGFpInitPoint(&T, cpEcGFpGetPool(1, pEC),0, pEC); - - cpEcGFpMulPoint(&T, &G, ECP_R(pEC), BITS_BNU_CHUNK(ECP_ORDBITSIZE(pEC)), pEC, pScratchBuffer); - *pResult = cpEcGFpIsProjectivePointAtInfinity(&T, elemLen)? ippECValid : ippECInvalidOrder; - - cpEcGFpReleasePool(1, pEC); - } - } - - return ippStsNoErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpoint.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpoint.c deleted file mode 100644 index d1901b33..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpoint.c +++ /dev/null @@ -1,426 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Intel(R) Performance Primitives. Cryptography Primitives. -// EC over GF(p) Operations -// -// Context: -// ippsGFpECPointGetSize() -// ippsGFpECPointInit() -// -// ippsGFpECSetPointAtInfinity() -// ippsGFpECSetPoint() -// ippsGFpECMakePoint() -// ippsGFpECSetPointRandom() -// ippsGFpECSetPointHash() -// ippsGFpECGetPoint() -// ippsGFpECCpyPoint() -// -// ippsGFpECCmpPoint() -// ippsGFpECTstPoint() -// ippsGFpECNegPoint() -// ippsGFpECAddPoint() -// ippsGFpECMulPoint() -// -// -*/ - -#include "owncpepid.h" - -#include "pcpgfpecstuff.h" -#include "pcpgfphashstuff.h" - - -IPPFUN(IppStatus, ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) -{ - IPP_BAD_PTR2_RET(pEC, pSizeInBytes); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - - { - int elemLen = GFP_FELEN(ECP_GFP(pEC)); - *pSizeInBytes = sizeof(IppsGFpECPoint) - +elemLen*sizeof(BNU_CHUNK_T) /* X */ - +elemLen*sizeof(BNU_CHUNK_T) /* Y */ - +elemLen*sizeof(BNU_CHUNK_T);/* Z */ - return ippStsNoErr; - } -} - - -IPPFUN(IppStatus, ippsGFpECPointInit,(const IppsGFpElement* pX, const IppsGFpElement* pY, - IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - - { - Ipp8u* ptr = (Ipp8u*)pPoint; - int elemLen = GFP_FELEN(ECP_GFP(pEC)); - - ECP_POINT_ID(pPoint) = idCtxGFPPoint; - ECP_POINT_FLAGS(pPoint) = 0; - ECP_POINT_FELEN(pPoint) = elemLen; - ptr += sizeof(IppsGFpECPoint); - ECP_POINT_DATA(pPoint) = (BNU_CHUNK_T*)(ptr); - - if(pX && pY) - return ippsGFpECSetPoint(pX, pY, pPoint, pEC); - else { - cpEcGFpSetProjectivePointAtInfinity(pPoint, elemLen); - return ippStsNoErr; - } - } -} - - -IPPFUN(IppStatus, ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - - cpEcGFpSetProjectivePointAtInfinity(pPoint, GFP_FELEN(ECP_GFP(pEC))); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, - IppsGFpECPoint* pPoint, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - - IPP_BAD_PTR2_RET(pX, pY); - IPP_BADARG_RET( !GFPE_TEST_ID(pX), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pY), ippStsContextMatchErr ); - - cpEcGFpSetAffinePoint(pPoint, GFPE_DATA(pX), GFPE_DATA(pY), pEC); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -{ - IPP_BAD_PTR3_RET(pX, pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFP_IS_BASIC(ECP_GFP(pEC)), ippStsBadArgErr ); - IPP_BADARG_RET( !GFPE_TEST_ID(pX), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - - return cpEcGFpMakePoint(pPoint, GFPE_DATA(pX), pEC)? ippStsNoErr : ippStsQuadraticNonResidueErr; -} - - -IPPFUN(IppStatus, ippsGFpECSetPointRandom,(IppBitSupplier rndFunc, void* pRndParam, - IppsGFpECPoint* pPoint, IppsGFpECState* pEC, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - - IPP_BAD_PTR1_RET(rndFunc); - - { - IppsGFpState* pGF = ECP_GFP(pEC); - - if( GFP_IS_BASIC(pGF) ) { - BNU_CHUNK_T* pElm = cpGFpGetPool(1, pGF); - - do { - /* get random X */ - cpGFpRand(pElm, pGF, rndFunc, pRndParam, USE_MONT_SPACE_REPRESENTATION); - } while( !cpEcGFpMakePoint(pPoint, pElm, pEC) ); - - cpGFpReleasePool(1, pGF); - - /* R = cofactor*R */ - cpEcGFpMulPoint(pPoint, pPoint, ECP_COFACTOR(pEC), GFP_FELEN(pGF), pEC, pScratchBuffer); - - return ippStsNoErr; - } - - else { - /* number of bits and dwords being begerated */ - int generatedBits = ECP_ORDBITSIZE(pEC) + GF_RAND_ADD_BITS; - int generatedLen = BITS_BNU_CHUNK(generatedBits); - - /* allocate random exponent */ - int poolElements = (generatedLen + GFP_PELEN(pGF) -1) / GFP_PELEN(pGF); - BNU_CHUNK_T* pExp = cpGFpGetPool(poolElements, pGF); - - int nsE; - - /* setup copy of the base point */ - IppsGFpECPoint G; - cpEcGFpInitPoint(&G, ECP_G(pEC),ECP_AFFINE_POINT|ECP_FINITE_POINT, pEC); - - /* get random bits */ - rndFunc((Ipp32u*)pExp, generatedBits, pRndParam); - /* reduce with respect to order value */ - nsE = cpMod_BNU(pExp, generatedLen, ECP_R(pEC), BITS_BNU_CHUNK(ECP_ORDBITSIZE(pEC))); - - /* compute random point */ - cpEcGFpMulPoint(pPoint, &G, pExp, nsE, pEC, pScratchBuffer); - - cpGFpReleasePool(poolElements, pGF); - - return ippStsNoErr; - } - } -} - - -IPPFUN(IppStatus, ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, - IppsGFpElement* pX, IppsGFpElement* pY, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - - IPP_BADARG_RET( !IS_ECP_FINITE_POINT(pPoint), ippStsPointAtInfinity); - - IPP_BADARG_RET( pX && !GFPE_TEST_ID(pX), ippStsContextMatchErr ); - IPP_BADARG_RET( pY && !GFPE_TEST_ID(pY), ippStsContextMatchErr ); - - cpEcGFpGetAffinePoint((pX)? GFPE_DATA(pX):0, (pY)?GFPE_DATA(pY):0, pPoint, pEC); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, - IppsGFpECPoint* pR, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR3_RET(pA, pR, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pA), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pR), ippStsContextMatchErr ); - - cpEcGFpCopyPoint(pR, pA, GFP_FELEN(ECP_GFP(pEC))); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, - IppECResult* pResult, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR4_RET(pP, pQ, pResult, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pQ), ippStsContextMatchErr ); - - *pResult = cpEcGFpIsPointEquial(pP, pQ, pEC)? ippECPointIsEqual : ippECPointIsNotEqual; - return ippStsNoErr; -} - -#if 0 -IPPFUN(IppStatus, ippsGFpECTstPoint,(const IppsGFpECPoint* pP, - IppECResult* pResult, - IppsGFpECState* pEC, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR3_RET(pP, pResult, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - - { - Ipp32u elemLen = GFP_FELEN(ECP_GFP(pEC)); - - if( cpEcGFpIsProjectivePointAtInfinity(pP, elemLen) ) - *pResult = ippECPointIsAtInfinite; - else if( !cpEcGFpIsPointOnCurve(pP, pEC) ) - *pResult = ippECPointIsNotValid; - else { - IppsGFpECPoint T; - cpEcGFpInitPoint(&T, cpEcGFpGetPool(1, pEC),0, pEC); - cpEcGFpMulPoint(&T, pP, ECP_R(pEC), BITS_BNU_CHUNK(ECP_ORDBITSIZE(pEC)), pEC, pScratchBuffer); - *pResult = cpEcGFpIsProjectivePointAtInfinity(&T, elemLen)? ippECValid : ippECPointOutOfGroup; - cpEcGFpReleasePool(1, pEC); - } - - return ippStsNoErr; - } -} -#endif - -/* -// Version below is based on observation has been done by Zhao Hui Du. -// See "Opportunity to improve Intel(R) EPID 2.0 performance" Gentry Mark e-mail 1/23/20015. -// -// Shortly: In case of Intel(R) EPID 2.0 EC parameters all EC points belongs to G1. -*/ -IPPFUN(IppStatus, ippsGFpECTstPoint,(const IppsGFpECPoint* pP, - IppECResult* pResult, - IppsGFpECState* pEC, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR3_RET(pP, pResult, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - - { - Ipp32u elemLen = GFP_FELEN(ECP_GFP(pEC)); - - if( cpEcGFpIsProjectivePointAtInfinity(pP, elemLen) ) - *pResult = ippECPointIsAtInfinite; - else if( !cpEcGFpIsPointOnCurve(pP, pEC) ) - *pResult = ippECPointIsNotValid; - else { - if(EPID_PARAMS(pEC)&&GFP_IS_BASIC(ECP_GFP(pEC))) - *pResult = ippECValid; - else { - IppsGFpECPoint T; - cpEcGFpInitPoint(&T, cpEcGFpGetPool(1, pEC),0, pEC); - cpEcGFpMulPoint(&T, pP, ECP_R(pEC), BITS_BNU_CHUNK(ECP_ORDBITSIZE(pEC)), pEC, pScratchBuffer); - *pResult = cpEcGFpIsProjectivePointAtInfinity(&T, elemLen)? ippECValid : ippECPointOutOfGroup; - cpEcGFpReleasePool(1, pEC); - } - } - - return ippStsNoErr; - } -} - - -IPPFUN(IppStatus, ippsGFpECNegPoint,(const IppsGFpECPoint* pP, - IppsGFpECPoint* pR, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR3_RET(pP, pR, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pR), ippStsContextMatchErr ); - - cpEcGFpNegPoint(pR, pP, pEC); - return ippStsNoErr; -} - - -IPPFUN(IppStatus, ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, - IppsGFpECState* pEC)) -{ - IPP_BAD_PTR4_RET(pP, pQ, pR, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pQ), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pR), ippStsContextMatchErr ); - - cpEcGFpAddPoint(pR, pP, pQ, pEC); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpECMulPoint,(const IppsGFpECPoint* pP, - const IppsBigNumState* pN, - IppsGFpECPoint* pR, - IppsGFpECState* pEC, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR3_RET(pP, pR, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pP), ippStsContextMatchErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pR), ippStsContextMatchErr ); - - IPP_BAD_PTR1_RET(pN); - pN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pN, BN_ALIGNMENT) ); - /* test if N >= order */ - IPP_BADARG_RET(0<=cpCmp_BNU(BN_NUMBER(pN), BN_SIZE(pN), ECP_R(pEC), BITS_BNU_CHUNK(ECP_ORDBITSIZE(pEC))), ippStsOutOfRangeErr); - - cpEcGFpMulPoint(pR, pP, BN_NUMBER(pN), BN_SIZE(pN), pEC, pScratchBuffer); - return ippStsNoErr; -} - -IPPFUN(IppStatus, ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppHashID hashID, IppsGFpECPoint* pPoint, - IppsGFpECState* pEC, - Ipp8u* pScratchBuffer)) -{ - IPP_BAD_PTR2_RET(pPoint, pEC); - pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) ); - IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr ); - IPP_BADARG_RET( !GFP_IS_BASIC(ECP_GFP(pEC)), ippStsBadArgErr ); - IPP_BADARG_RET( !ECP_POINT_TEST_ID(pPoint), ippStsContextMatchErr ); - IPP_BADARG_RET( !cpTestHashID(hashID), ippStsBadArgErr); - - { - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - - Ipp8u md[IPP_SHA512_DIGEST_BITSIZE/BYTESIZE]; - int hashLen = cpHashLength(hashID); - BNU_CHUNK_T hashVal[BITS_BNU_CHUNK(IPP_SHA512_DIGEST_BITSIZE)+1]; - int hashValLen; - - Ipp8u hashCtx[sizeof(IppsSHA512State)+SHA512_ALIGNMENT-1]; - cpHashInit(hashCtx, hashID); - - { - BNU_CHUNK_T* pPoolElm = cpGFpGetPool(1, pGF); - - /* convert hdr => hdrStr */ - BNU_CHUNK_T locHdr = (BNU_CHUNK_T)hdr; - Ipp8u hdrOctStr[sizeof(hdr/*locHdr*/)]; - cpToOctStr_BNU(hdrOctStr, sizeof(hdrOctStr), &locHdr, 1); - - /* compute md = hash(hrd||msg) */ - cpHashUpdate(hdrOctStr, sizeof(hdrOctStr), hashCtx, hashID); - cpHashUpdate(pMsg, msgLen, hashCtx, hashID); - cpHashFinal(md, hashCtx, hashID); - - /* convert hash into the integer */ - hashValLen = cpFromOctStr_BNU(hashVal, md, hashLen); - hashValLen = cpMod_BNU(hashVal, hashValLen, pModulus, elemLen); - cpGFpSet(pPoolElm, hashVal, hashValLen, pGF, USE_MONT_SPACE_REPRESENTATION); - - if( cpEcGFpMakePoint(pPoint, pPoolElm, pEC)) { - /* set y-coordinate of the point (positive or negative) */ - BNU_CHUNK_T* pY = ECP_POINT_Y(pPoint); - if(pY[0] & 1) - cpGFpNeg(pY, pY, pGF); - - /* update point if cofactor>1 */ - cpEcGFpMulPoint(pPoint, pPoint, ECP_COFACTOR(pEC), GFP_FELEN(pGF), pEC, pScratchBuffer); - - cpGFpReleasePool(1, pGF); - return ippStsNoErr; - } - } - - cpGFpReleasePool(1, pGF); - return ippStsQuadraticNonResidueErr; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpointstuff.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpointstuff.c deleted file mode 100644 index 978da1b6..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecpointstuff.c +++ /dev/null @@ -1,1227 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Intel(R) Performance Primitives. Cryptography Primitives. -// Internal EC over GF(p^m) basic Definitions & Function Prototypes -// -// Context: -// cpEcGFpMakePoint() -// cpEcGFpGetAffinePoint -// -// cpEcGFpIsPointEquial() -// cpEcGFpIsPointOnCurve() -// -// cpEcGFpNegPoint() -// cpEcGFpDblPoint() -// cpEcGFpAddPoint() -// cpEcGFpMulPoint() -// -// -// -*/ - -#include "owncpepid.h" - -#include "pcpgfpecstuff.h" -//#include "pcptool.h" - - -int cpEcGFpMakePoint(IppsGFpECPoint* pPoint, const BNU_CHUNK_T* pElm, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - BNU_CHUNK_T* pX = ECP_POINT_X(pPoint); - BNU_CHUNK_T* pY = ECP_POINT_Y(pPoint); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pPoint); - - /* set x-coordinate */ - cpGFpElementCopy(pX, pElm, elemLen); - - /* T = X^3 + A*X + B */ - cpGFpxSqr(pY, pX, pGF); - pGF->mul(pY, pY, pX, pGF); - if(!EPID_PARAMS(pEC)) { - pGF->mul(pZ, ECP_A(pEC), pX, pGF); - pGF->add(pY, pY, pZ, pGF); - } - pGF->add(pY, pY, ECP_B(pEC), pGF); - - /* set z-coordinate =1 */ - cpGFpElementCopyPadd(pZ, elemLen, MNT_1(GFP_MONT(pGF)), GFP_FELEN(pGF)); - - /* Y = sqrt(Y) */ - if( cpGFpSqrt(pY, pY, pGF) ) { - ECP_POINT_FLAGS(pPoint) = ECP_AFFINE_POINT | ECP_FINITE_POINT; - return 1; - } - else { - cpEcGFpSetProjectivePointAtInfinity(pPoint, elemLen); - //ECP_POINT_FLAGS(pPoint) = 0; - return 0; - } -} - -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -int cpEcGFpGetAffinePoint(BNU_CHUNK_T* pX, BNU_CHUNK_T* pY, const IppsGFpECPoint* pPoint, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - if( !IS_ECP_FINITE_POINT(pPoint) ) { - //GFP_ZERO(pX, elemLen); - //if( GFP_IS_ZERO(ECP_B(pEC), elemLen) ) - // GFP_ONE(pY, elemLen); - //else - // GFP_ZERO(pY, elemLen); - //return; - return 0; - } - - /* case Z == 1 */ - if( IS_ECP_AFFINE_POINT(pPoint) ) { - if(pX) - cpGFpElementCopy(pX, ECP_POINT_X(pPoint), elemLen); - if(pY) - cpGFpElementCopy(pY, ECP_POINT_Y(pPoint), elemLen); - } - - /* case Z != 1 */ - else { - /* T = (1/Z)*(1/Z) */ - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pZinv = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pU = cpGFpGetPool(1, pGF); - cpGFpxInv(pZinv, ECP_POINT_Z(pPoint), pGF); - pGF->sqr(pT, pZinv, pGF); - - if(pX) { - pGF->mul(pU, ECP_POINT_X(pPoint), pT, pGF); - cpGFpElementCopy(pX, pU, elemLen); - } - if(pY) { - pGF->mul(pT, pZinv, pT, pGF); - pGF->mul(pU, ECP_POINT_Y(pPoint), pT, pGF); - cpGFpElementCopy(pY, pU, elemLen); - } - - cpGFpReleasePool(3, pGF); - } - - return 1; -} -#endif - -#if ( ECP_PROJECTIVE_COORD == HOMOGENEOUS ) -int cpEcGFpGetAffinePoint(BNU_CHUNK_T* pX, BNU_CHUNK_T* pY, const IppsGFpECPoint* pPoint, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - if( !IS_ECP_FINITE_POINT(pPoint) ) { - return 0; - } - - /* case Z == 1 */ - if( IS_ECP_AFFINE_POINT(pPoint) ) { - if(pX) - cpGFpElementCopy(pX, ECP_POINT_X(pPoint), elemLen); - if(pY) - cpGFpElementCopy(pY, ECP_POINT_Y(pPoint), elemLen); - } - - /* case Z != 1 */ - else { - /* T = (1/Z) */ - BNU_CHUNK_T* pZinv = cpGFpGetPool(1, pGF); - cpGFpxInv(pZinv, ECP_POINT_Z(pPoint), pGF); - - if(pX) { - pGF->mul(pX, ECP_POINT_X(pPoint), pZinv, pGF); - } - if(pY) { - pGF->mul(pY, ECP_POINT_Y(pPoint), pZinv, pGF); - } - - cpGFpReleasePool(1, pGF); - } - - return 1; -} -#endif - -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -int cpEcGFpIsPointEquial(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* P or/and Q at Infinity */ - if( !IS_ECP_FINITE_POINT(pP) ) - return !IS_ECP_FINITE_POINT(pQ)? 1:0; - if( !IS_ECP_FINITE_POINT(pQ) ) - return !IS_ECP_FINITE_POINT(pP)? 1:0; - - /* Px==Qx && Py==Qy && Pz==Qz */ - if( GFP_EQ(ECP_POINT_Z(pP), ECP_POINT_Z(pQ), elemLen) - &&GFP_EQ(ECP_POINT_X(pP), ECP_POINT_X(pQ), elemLen) - &&GFP_EQ(ECP_POINT_Y(pP), ECP_POINT_Y(pQ), elemLen)) - return 1; - - else { - int isEqu = 1; - - BNU_CHUNK_T* pPtmp = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pQtmp = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pPz = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pQz = cpGFpGetPool(1, pGF); - - if(isEqu) { - /* Px*Qz^2 ~ Qx*Pz^2 */ - if( IS_ECP_AFFINE_POINT(pQ) ) /* Ptmp = Px * Qz^2 */ - cpGFpElementCopy(pPtmp, ECP_POINT_X(pP), elemLen); - else { - pGF->sqr(pQz, ECP_POINT_Z(pQ), pGF); - pGF->mul(pPtmp, ECP_POINT_X(pP), pQz, pGF); - } - if( IS_ECP_AFFINE_POINT(pP) ) /* Qtmp = Qx * Pz^2 */ - cpGFpElementCopy(pQtmp, ECP_POINT_X(pQ), elemLen); - else { - pGF->sqr(pPz, ECP_POINT_Z(pP), pGF); - pGF->mul(pQtmp, ECP_POINT_X(pQ), pPz, pGF); - } - isEqu = GFP_EQ(pPtmp, pQtmp, elemLen); - } - - if(isEqu) { - /* Py*Qz^3 ~ Qy*Pz^3 */ - if( IS_ECP_AFFINE_POINT(pQ) ) /* Ptmp = Py * Qz^3 */ - cpGFpElementCopy(pPtmp, ECP_POINT_Y(pP), elemLen); - else { - pGF->mul(pQz, ECP_POINT_Z(pQ), pQz, pGF); - pGF->mul(pPtmp, pQz, ECP_POINT_Y(pP), pGF); - } - if( IS_ECP_AFFINE_POINT(pP) ) /* Qtmp = Qy * Pz^3 */ - cpGFpElementCopy(pQtmp, ECP_POINT_Y(pQ), elemLen); - else { - pGF->mul(pPz, ECP_POINT_Z(pP), pPz, pGF); - pGF->mul(pQtmp, pPz, ECP_POINT_Y(pQ), pGF); - } - isEqu = GFP_EQ(pPtmp, pQtmp, elemLen); - } - - cpGFpReleasePool(4, pGF); - return isEqu; - } -} -#endif - -#if ( ECP_PROJECTIVE_COORD == HOMOGENEOUS ) -int cpEcGFpIsPointEquial(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* P or/and Q at Infinity */ - if( !IS_ECP_FINITE_POINT(pP) ) - return !IS_ECP_FINITE_POINT(pQ)? 1:0; - if( !IS_ECP_FINITE_POINT(pQ) ) - return !IS_ECP_FINITE_POINT(pP)? 1:0; - - /* Px==Qx && Py==Qy && Pz==Qz */ - if( GFP_EQ(ECP_POINT_Z(pP), ECP_POINT_Z(pQ), elemLen) - &&GFP_EQ(ECP_POINT_X(pP), ECP_POINT_X(pQ), elemLen) - &&GFP_EQ(ECP_POINT_Y(pP), ECP_POINT_Y(pQ), elemLen)) - return 1; - - else { - int isEqu = 1; - - BNU_CHUNK_T* pPtmp = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pQtmp = cpGFpGetPool(1, pGF); - - if(isEqu) { - /* Px*Qz ~ Qx*Pz */ - if( IS_ECP_AFFINE_POINT(pQ) ) /* Ptmp = Px * Qz */ - cpGFpElementCopy(pPtmp, ECP_POINT_X(pP), elemLen); - else { - pGF->mul(pPtmp, ECP_POINT_X(pP), ECP_POINT_Z(pQ), pGF); - } - if( IS_ECP_AFFINE_POINT(pP) ) /* Qtmp = Qx * Pz */ - cpGFpElementCopy(pQtmp, ECP_POINT_X(pQ), elemLen); - else { - pGF->mul(pQtmp, ECP_POINT_X(pQ), ECP_POINT_Z(pP), pGF); - } - isEqu = GFP_EQ(pPtmp, pQtmp, elemLen); - } - - if(isEqu) { - /* Py*Qz ~ Qy*Pz */ - if( IS_ECP_AFFINE_POINT(pQ) ) /* Ptmp = Py * Qz */ - cpGFpElementCopy(pPtmp, ECP_POINT_Y(pP), elemLen); - else { - pGF->mul(pPtmp, ECP_POINT_Y(pP), ECP_POINT_Z(pQ), pGF); - } - if( IS_ECP_AFFINE_POINT(pP) ) /* Qtmp = Qy * Pz */ - cpGFpElementCopy(pQtmp, ECP_POINT_Y(pQ), elemLen); - else { - pGF->mul(pQtmp, ECP_POINT_Y(pQ), ECP_POINT_Z(pP), pGF); - } - isEqu = GFP_EQ(pPtmp, pQtmp, elemLen); - } - - cpGFpReleasePool(2, pGF); - return isEqu; - } -} -#endif - -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -int cpEcGFpIsPointOnCurve(const IppsGFpECPoint* pPoint, IppsGFpECState* pEC) -{ - /* point at infinity belongs curve */ - if( !IS_ECP_FINITE_POINT(pPoint) ) - return 1; - - /* test that 0 == R = (Y^2) - (X^3 + A*X*(Z^4) + B*(Z^6)) */ - else { - int isOnCurve = 0; - - IppsGFpState* pGF = ECP_GFP(pEC); - - BNU_CHUNK_T* pX = ECP_POINT_X(pPoint); - BNU_CHUNK_T* pY = ECP_POINT_Y(pPoint); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pPoint); - - BNU_CHUNK_T* pR = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - - pGF->sqr(pR, pY, pGF); /* R = Y^2 */ - pGF->sqr(pT, pX, pGF); /* T = X^3 */ - pGF->mul(pT, pX, pT, pGF); - pGF->sub(pR, pR, pT, pGF); /* R -= T */ - - if( IS_ECP_AFFINE_POINT(pPoint) ) { - pGF->mul(pT, pX, ECP_A(pEC), pGF); /* T = A*X */ - pGF->sub(pR, pR, pT, pGF); /* R -= T */ - pGF->sub(pR, pR, ECP_B(pEC), pGF); /* R -= B */ - } - else { - BNU_CHUNK_T* pZ4 = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pZ6 = cpGFpGetPool(1, pGF); - - pGF->sqr(pZ6, pZ, pGF); /* Z^2 */ - pGF->sqr(pZ4, pZ6, pGF); /* Z^4 */ - pGF->mul(pZ6, pZ6, pZ4, pGF); /* Z^6 */ - - pGF->mul(pZ4, pZ4, pX, pGF); /* X*(Z^4) */ - pGF->mul(pZ4, pZ4, ECP_A(pEC), pGF); /* A*X*(Z^4) */ - pGF->mul(pZ6, pZ6, ECP_B(pEC), pGF); /* B*(Z^4) */ - - pGF->sub(pR, pR, pZ4, pGF); /* R -= A*X*(Z^4) */ - pGF->sub(pR, pR, pZ6, pGF); /* R -= B*(Z^6) */ - - cpGFpReleasePool(2, pGF); - } - - isOnCurve = GFP_IS_ZERO(pR, GFP_FELEN(pGF)); - cpGFpReleasePool(2, pGF); - return isOnCurve; - } -} -#endif - -#if ( ECP_PROJECTIVE_COORD == HOMOGENEOUS ) -int cpEcGFpIsPointOnCurve(const IppsGFpECPoint* pPoint, IppsGFpECState* pEC) -{ - /* point at infinity belongs curve */ - if( !IS_ECP_FINITE_POINT(pPoint) ) - return 1; - - /* test that 0 == R = ((Y^2)*Z) - (X^3 + A*X*(Z^2) + B*(Z^3)) */ - else { - int isOnCurve = 0; - - IppsGFpState* pGF = ECP_GFP(pEC); - - BNU_CHUNK_T* pX = ECP_POINT_X(pPoint); - BNU_CHUNK_T* pY = ECP_POINT_Y(pPoint); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pPoint); - - BNU_CHUNK_T* pR = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pU = cpGFpGetPool(1, pGF); - - /* Right = X^3 + A*X*(Z^2) + B*(Z^3) = x^3 +(A*X + B*Z)*Z^2 */ - pGF->sqr(pR, pZ, pGF); /* R = Z^2 */ - pGF->mul(pT, pZ, ECP_B(pEC), pGF); /* T = Z*B */ - if(!EPID_PARAMS(pEC)) { - pGF->mul(pU, pX, ECP_A(pEC), pGF); /* U = X*A */ - pGF->add(pT, pT, pU, pGF); /* T = (A*X + B*Z) * Z^2 */ - } - pGF->mul(pT, pT, pR, pGF); - - pGF->sqr(pR, pX, pGF); /* R = X^3 */ - pGF->mul(pR, pR, pX, pGF); - - pGF->add(pR, pR, pT, pGF); /* R = X^3 + (A*X + B*Z) * Z^2 */ - - /* Left = (Y^2)*Z */ - pGF->sqr(pT, pY, pGF); - pGF->mul(pT, pT, pZ, pGF); - - pGF->sub(pR, pR, pT, pGF); /* Left - Right */ - - isOnCurve = GFP_IS_ZERO(pR, GFP_FELEN(pGF)); - - cpGFpReleasePool(3, pGF); - return isOnCurve; - } -} -#endif - -IppsGFpECPoint* cpEcGFpNegPoint (IppsGFpECPoint* pR, const IppsGFpECPoint* pP, IppsGFpECState* pEC) -{ - int elemLen = GFP_FELEN(ECP_GFP(pEC)); - IppsGFpState* pGF = ECP_GFP(pEC); - - if(pP!=pR) - cpEcGFpCopyPoint(pR, pP, elemLen); - - if( IS_ECP_FINITE_POINT(pR) ) - pGF->neg(ECP_POINT_Y(pR), ECP_POINT_Y(pR), pGF); - return pR; -} - -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -/* general complexity = 6s+4m - epid complexity = 4s+3m -*/ -IppsGFpECPoint* cpEcGFpDblPoint (IppsGFpECPoint* pR, const IppsGFpECPoint* pP, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - BNU_CHUNK_T* pX = ECP_POINT_X(pP); - BNU_CHUNK_T* pY = ECP_POINT_Y(pP); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pP); - - BNU_CHUNK_T* pU = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pM = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pS = cpGFpGetPool(1, pGF); - - /* M = 3*X^2 + A*Z^4 */ - pGF->sqr(pU, pX, pGF); /* s */ - pGF->add(pM, pU, pU, pGF); - pGF->add(pM, pU, pM, pGF); - if(!EPID_PARAMS(pEC)) { - if( IS_ECP_AFFINE_POINT(pP) ) - pGF->add(pM, ECP_A(pEC), pM, pGF); - else { - pGF->sqr(pU, pZ, pGF); /* s */ - pGF->sqr(pU, pU, pGF); /* s */ - pGF->mul(pU, ECP_A(pEC), pU, pGF); /* m */ - pGF->add(pM, pM, pU, pGF); - } - } - - /* U = 2*Y */ - pGF->add(pU, pY, pY, pGF); - - /* Rz = 2*Y*Z */ - if( IS_ECP_AFFINE_POINT(pP) ) - cpGFpElementCopy(ECP_POINT_Z(pR), pU, elemLen); - else - pGF->mul(ECP_POINT_Z(pR), pU, pZ, pGF); /* m */ - - /* S = X*(U^2) = 4*X*Y^2 */ - pGF->sqr(pU, pU, pGF); /* s */ - pGF->mul(pS, pX, pU, pGF); /* m */ - - /* Rx = M^2 - 2*S */ - pGF->sqr(ECP_POINT_X(pR),pM, pGF); /* s */ - pGF->sub(ECP_POINT_X(pR), ECP_POINT_X(pR), pS, pGF); - pGF->sub(ECP_POINT_X(pR), ECP_POINT_X(pR), pS, pGF); - - /* U = (U^2)/2 = (16*Y^4)/2 = 8*Y^4 */ - pGF->sqr(pU, pU, pGF); /* s */ - //cpGFpxHalve(pU, pU, pGF); - pGF->div2(pU, pU, pGF); - - /* Ry = M*(S - Rx) - U */ - pGF->sub(pS, pS, ECP_POINT_X(pR), pGF); - pGF->mul(pS, pM, pS, pGF); /* m */ - pGF->sub(ECP_POINT_Y(pR), pS, pU, pGF); - - //ECP_POINT_FLAGS(pR) = ECP_FINITE_POINT; - ECP_POINT_FLAGS(pR) = cpEcGFpIsProjectivePointAtInfinity(pR, elemLen)? 0 : ECP_FINITE_POINT; - - - cpGFpReleasePool(3, pGF); - - return pR; -} -#endif - -#if ( ECP_PROJECTIVE_COORD == HOMOGENEOUS ) -/* -// A = 3*X^2 + A*Z^2 -// B = Y*Z -// C = X*Y*B -// D = A^2 - 8*C -// new X = 2*B*D -// new Y = A*(4*C - D) - 8*(Y*B)^2 -// new Z = 8*B^3 -// -// general complexity = 5s+8m -// epid complexity = 4s+7m -*/ -IppsGFpECPoint* cpEcGFpDblPoint (IppsGFpECPoint* pR, const IppsGFpECPoint* pP, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* P at infinity => R at infinity */ - if( !IS_ECP_FINITE_POINT(pP) ) - cpEcGFpSetProjectivePointAtInfinity(pR, elemLen); - - else { - BNU_CHUNK_T* pA = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pB = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pC = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pD = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - - BNU_CHUNK_T* pX = ECP_POINT_X(pR); - BNU_CHUNK_T* pY = ECP_POINT_Y(pR); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pR); - if(pR!=pP) { - cpGFpElementCopy(pX, ECP_POINT_X(pP), elemLen); - cpGFpElementCopy(pY, ECP_POINT_Y(pP), elemLen); - cpGFpElementCopy(pZ, ECP_POINT_Z(pP), elemLen); - } - - /* A = 3*X^2 + A*Z^2 */ - pGF->sqr(pC, pX, pGF); /* s */ - pGF->add(pA, pC, pC, pGF); - pGF->add(pA, pA, pC, pGF); - if(!EPID_PARAMS(pEC)) { - pGF->sqr(pB, pZ, pGF); /* s */ - pGF->mul(pB, pB, ECP_A(pEC), pGF); /* m */ - pGF->add(pA, pA, pB, pGF); - } - - /* B = Y*Z */ - pGF->mul(pB, pY, pZ, pGF); /* m */ - - /* C = X*Y*B */ - pGF->mul(pC, pX, pY, pGF); /* m */ - pGF->mul(pC, pC, pB, pGF); /* m */ - - /* D = A^2 - 8*C */ - pGF->sqr(pT, pA, pGF); /* s */ - pGF->add(pD, pC, pC, pGF); - pGF->add(pD, pD, pD, pGF); - pGF->add(pD, pD, pD, pGF); - pGF->sub(pD, pT, pD, pGF); - - /* X = 2*B*D */ - pGF->mul(pX, pB, pD, pGF); /* m */ - pGF->add(pX, pX, pX, pGF); - - pGF->add(pB, pB, pB, pGF); /* B = 2*B */ - - /* Y = A*(4*C-D)-8(Y*B)^2 */ - pGF->mul(pT, pY, pB, pGF); /* m */ - pGF->sqr(pT, pT, pGF); /* s */ /* T = 4*(Y*B)^2 */ - pGF->add(pY, pC, pC, pGF); - pGF->add(pY, pY, pY, pGF); - pGF->sub(pY, pY, pD, pGF); - pGF->mul(pY, pY, pA, pGF); /* m */ - pGF->sub(pY, pY, pT, pGF); - pGF->sub(pY, pY, pT, pGF); - - /* Z = 8*B^3 = (2*B)^3 */ - pGF->sqr(pZ, pB, pGF); /* s */ - pGF->mul(pZ, pZ, pB, pGF); /* m */ - - ECP_POINT_FLAGS(pR) = ECP_FINITE_POINT; - - cpGFpReleasePool(5, pGF); - } - - return pR; -} -#endif - -#if 0 -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -/* -// initial k-Doubling routine: -// -// for(i=0; i R at infinity */ - if( !IS_ECP_FINITE_POINT(pP) ) - return cpEcGFpSetProjectivePointAtInfinity(pR, elemLen); - - else { - BNU_CHUNK_T* pW = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pM = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pS = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pT = cpGFpGetPool(1, pGF); - - BNU_CHUNK_T* pX = ECP_POINT_X(pR); - BNU_CHUNK_T* pY = ECP_POINT_Y(pR); - BNU_CHUNK_T* pZ = ECP_POINT_Z(pR); - if(pR!=pP) { - cpGFpElementCopy(pX, ECP_POINT_X(pP), elemLen); - cpGFpElementCopy(pY, ECP_POINT_Y(pP), elemLen); - cpGFpElementCopy(pZ, ECP_POINT_Z(pP), elemLen); - } - - /* M = 3*X^2 + A*Z^4 */ - pGF->sqr(pS, pX, pGF); /* s */ - pGF->add(pM, pS, pS, pGF); - pGF->add(pM, pM, pS, pGF); - if(!EPID_PARAMS(pEC)) { /* W = A*Z^4 */ - pGF->sqr(pW, pZ, pGF); /* s */ - pGF->sqr(pW, pW, pGF); /* s */ - pGF->mul(pW, pW, ECP_A(pEC), pGF); /* m */ - - pGF->add(pM, pM, pW, pGF); - } - - /* T = 2*Y */ - pGF->add(pT, pY, pY, pGF); - - /* new Z = 2*Y*Z */ - pGF->mul(pZ, pT, pZ, pGF); /* m */ - - /* S = X*(T^2) = 4*X*Y^2 */ - pGF->sqr(pT, pT, pGF); /* s */ - pGF->mul(pS, pX, pT, pGF); /* m */ - - /* T = (T^2)/2 = (16*Y^4)/2 = 8*Y^4 */ - pGF->sqr(pT, pT, pGF); /* s */ - //cpGFpxHalve(pT, pT, pGF); - cpGF->div2(pT, pT, pGF); - - /* new X = M^2 - 2*S */ - pGF->sqr(pX, pM, pGF); /* s */ - pGF->sub(pX, pX, pS, pGF); - pGF->sub(pX, pX, pS, pGF); - - /* new Y = M*(S - new X) - T */ - pGF->sub(pY, pS, pX, pGF); - pGF->mul(pY, pY, pM, pGF); /* m */ - pGF->sub(pY, pY, pT, pGF); - - for(k--; k>0; k--) { - /* new W = 2*T*W */ - if(!EPID_PARAMS(pEC)) { - pGF->mul(pW, pW, pT, pGF); /* m */ - pGF->add(pW, pW, pW, pGF); - } - - /* M = 3*X^2 + new W */ - pGF->sqr(pS, pX, pGF); /* s */ - pGF->add(pM, pS, pS, pGF); - pGF->add(pM, pM, pS, pGF); - if(!EPID_PARAMS(pEC)) { - pGF->add(pM, pM, pW, pGF); - } - - /* T = 2*Y */ - pGF->add(pT, pY, pY, pGF); - - /* new Z = 2*Y*Z */ - pGF->mul(pZ, pT, pZ, pGF); /* m */ - - /* S = X*(T^2) = 4*X*Y^2 */ - pGF->sqr(pT, pT, pGF); /* s */ - pGF->mul(pS, pX, pT, pGF); /* m */ - - /* T = (T^2)/2 = (16*Y^4)/2 = 8*Y^4 */ - pGF->sqr(pT, pT, pGF); /* s */ - //cpGFpxHalve(pT, pT, pGF); - cpGF->div2(pT, pT, pGF); - - /* new X = M^2 - 2*S */ - pGF->sqr(pX, pM, pGF); /* s */ - pGF->sub(pX, pX, pS, pGF); - pGF->sub(pX, pX, pS, pGF); - - /* new Y = M*(S - new X) - T */ - pGF->sub(pY, pS, pX, pGF); - pGF->mul(pY, pY, pM, pGF); /* m */ - pGF->sub(pY, pY, pT, pGF); - } - - ECP_POINT_FLAGS(pR) = ECP_FINITE_POINT; - - cpGFpReleasePool(4, pGF); - return pR; - } -} -#endif -#endif - - -IppsGFpECPoint* cpEcGFpDblPoint_k(IppsGFpECPoint* pR, const IppsGFpECPoint* pP,int k, IppsGFpECState* pEC) -{ - cpEcGFpDblPoint(pR, pP, pEC); - k--; - for(; k>0; k--) - cpEcGFpDblPoint(pR, pR, pEC); - - return pR; -} - - -#if ( ECP_PROJECTIVE_COORD == JACOBIAN ) -/* complexity = 4s+12m */ -IppsGFpECPoint* cpEcGFpAddPoint (IppsGFpECPoint* pPointR, const IppsGFpECPoint* pPointP, const IppsGFpECPoint* pPointQ, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - int inftyP = cpEcGFpIsProjectivePointAtInfinity(pPointP, elemLen); - int inftyQ = cpEcGFpIsProjectivePointAtInfinity(pPointQ, elemLen); - - /* - // addition - */ - BNU_CHUNK_T* pA = cpEcGFpGetPool(3, pEC); - BNU_CHUNK_T* pB = pA + elemLen; - BNU_CHUNK_T* pC = pB + elemLen; - BNU_CHUNK_T* pD = pC + elemLen; - BNU_CHUNK_T* pW = pD + elemLen; - BNU_CHUNK_T* pV = pW + elemLen; - - BNU_CHUNK_T* pRx = pV + elemLen; /* temporary result */ - BNU_CHUNK_T* pRy = pRx+ elemLen; - BNU_CHUNK_T* pRz = pRy+ elemLen; - - /* coordinates of P */ - BNU_CHUNK_T* px1 = ECP_POINT_X(pPointP); - BNU_CHUNK_T* py1 = ECP_POINT_Y(pPointP); - BNU_CHUNK_T* pz1 = ECP_POINT_Z(pPointP); - - /* coordinates of Q */ - BNU_CHUNK_T* px2 = ECP_POINT_X(pPointQ); - BNU_CHUNK_T* py2 = ECP_POINT_Y(pPointQ); - BNU_CHUNK_T* pz2 = ECP_POINT_Z(pPointQ); - - /* coordinates of R */ - //BNU_CHUNK_T* px3 = ECP_POINT_X(pPointR); - //BNU_CHUNK_T* py3 = ECP_POINT_Y(pPointR); - //BNU_CHUNK_T* pz3 = ECP_POINT_Z(pPointR); - - /* A = X1 * Z2^2 */ - /* C = Y1 * Z2^3 */ - if( IS_ECP_AFFINE_POINT(pPointQ) ) { - cpGFpElementCopy(pA, px1, elemLen); - cpGFpElementCopy(pC, py1, elemLen); - } - else { - pGF->sqr(pA, pz2, pGF); /* s */ - pGF->mul(pC, pz2, pA, pGF); /* m */ - pGF->mul(pA, pA, px1, pGF); /* m */ - pGF->mul(pC, pC, py1, pGF); /* m */ - } - - /* B = X2 * Z1^2 */ - /* D = Y2 * Z1^3 */ - if( IS_ECP_AFFINE_POINT(pPointP) ) { - cpGFpElementCopy(pB, px2, elemLen); - cpGFpElementCopy(pD, py2, elemLen); - } - else { - pGF->sqr(pB, pz1, pGF); /* s */ - pGF->mul(pD, pz1, pB, pGF); /* m */ - pGF->mul(pB, pB, px2, pGF); /* m */ - pGF->mul(pD, pD, py2, pGF); /* m */ - } - - /* W = B-A */ - /* V = D-C */ - pGF->sub(pW, pB, pA, pGF); - pGF->sub(pV, pD, pC, pGF); - - if( GFP_IS_ZERO(pW, elemLen) && !inftyP && !inftyQ ) { - cpEcGFpReleasePool(3, pEC); - if( GFP_IS_ZERO(pV, elemLen) ) - return cpEcGFpDblPoint(pPointR, pPointP, pEC); - else - return cpEcGFpSetProjectivePointAtInfinity(pPointR, elemLen); - } - - /* Z3 = Z1*Z2*W */ - if( IS_ECP_AFFINE_POINT(pPointP) && IS_ECP_AFFINE_POINT(pPointQ) ) - cpGFpElementCopy(pRz, pW, elemLen); - else { - if( IS_ECP_AFFINE_POINT(pPointQ) ) - cpGFpElementCopy(pB, pz1, elemLen); - else if ( IS_ECP_AFFINE_POINT(pPointP) ) - cpGFpElementCopy(pB, pz2, elemLen); - else - pGF->mul(pB, pz1, pz2, pGF); /* m */ - pGF->mul(pRz, pB, pW, pGF); /* m */ - } - - /* B = W^2 */ - pGF->sqr(pB, pW, pGF); /* s */ - /* A = A*W^2 */ - pGF->mul(pA, pB, pA, pGF); /* m */ - /* W = W^3 */ - pGF->mul(pW, pB, pW, pGF); /* m */ - - /* X3 = V^2 - W^3 -2*A*W^2 */ - pGF->sqr(pRx, pV, pGF); /* s */ - pGF->sub(pRx, pRx, pW, pGF); - pGF->sub(pRx, pRx, pA, pGF); - pGF->sub(pRx, pRx, pA, pGF); - - /* Y3 = V*(A*W^2 - X3) -C*W^3 */ - pGF->sub(pRy, pA, pRx, pGF); - pGF->mul(pC, pC, pW, pGF); /* m */ - pGF->mul(pRy, pRy, pV, pGF); /* m */ - pGF->sub(pRy, pRy, pC, pGF); - - cpMaskMove(pRx, px2, elemLen, inftyP); - cpMaskMove(pRy, py2, elemLen, inftyP); - cpMaskMove(pRz, pz2, elemLen, inftyP); - - cpMaskMove(pRx, px1, elemLen, inftyQ); - cpMaskMove(pRy, py1, elemLen, inftyQ); - cpMaskMove(pRz, pz1, elemLen, inftyQ); - - cpGFpElementCopy(ECP_POINT_DATA(pPointR), pRx, 3*elemLen); - ECP_POINT_FLAGS(pPointR) = cpEcGFpIsProjectivePointAtInfinity(pPointR, elemLen)? 0 : ECP_FINITE_POINT; - - cpEcGFpReleasePool(3, pEC); - return pPointR; -} -#endif - -#if ( ECP_PROJECTIVE_COORD == HOMOGENEOUS ) -/* -// A = Y2 * Z1 - Y1 * Z2 -// B = X2 * Z1 - X1 * Z2 -// C = A^2*Z1*Z2 -B^3 -2*B^2*X1*Z2 = A^2*Z1*Z2 -B^2*(B+2*X1*Z2) = A^2*Z1*Z2 -B^2*(X2*Z1+X1*Z2) -// new X = B*C -// new Y = A*(B^2*X1*Z2 -C) -B^3*Y1*Z2 -// new Z = B^3*Z1*Z2 -// -// note: Y1*Z2, X2*Z1, X1*Z2, Z1*Z2 are using several times -// (T1), (T2), (T3) (T4) -// -// complexity = 2s+13m -*/ -IppsGFpECPoint* cpEcGFpAddPoint (IppsGFpECPoint* pPointR, const IppsGFpECPoint* pP1, const IppsGFpECPoint* pP2, IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* test stupid call */ - if( pP1 == pP2) - return cpEcGFpDblPoint(pPointR, pP1, pEC); - - /* prevent operation with point at Infinity */ - if( !IS_ECP_FINITE_POINT(pP1) ) - return cpEcGFpCopyPoint(pPointR, pP2, elemLen); - if( !IS_ECP_FINITE_POINT(pP2) ) - return cpEcGFpCopyPoint(pPointR, pP1, elemLen); - - /* - // addition - */ - { - BNU_CHUNK_T* pT1 = cpEcGFpGetPool(3, pEC); - BNU_CHUNK_T* pT2 = pT1 + elemLen; - BNU_CHUNK_T* pT3 = pT2 + elemLen; - BNU_CHUNK_T* pT4 = pT3 + elemLen; - BNU_CHUNK_T* pA = pT4 + elemLen; - BNU_CHUNK_T* pB = pA + elemLen; - BNU_CHUNK_T* pC = pB + elemLen; - BNU_CHUNK_T* pB2 = pC + elemLen; - BNU_CHUNK_T* pB3 = pB2 + elemLen; - - /* coordinates of P1 */ - BNU_CHUNK_T* pX1 = ECP_POINT_X(pP1); - BNU_CHUNK_T* pY1 = ECP_POINT_Y(pP1); - BNU_CHUNK_T* pZ1 = ECP_POINT_Z(pP1); - - /* coordinates of P2 */ - BNU_CHUNK_T* pX2 = ECP_POINT_X(pP2); - BNU_CHUNK_T* pY2 = ECP_POINT_Y(pP2); - BNU_CHUNK_T* pZ2 = ECP_POINT_Z(pP2); - - /* A = Y2 * Z1 - Y1 * Z2 */ - pGF->mul(pA, pY2, pZ1, pGF); /* m */ - pGF->mul(pT1,pY1, pZ2, pGF); /* m */ - pGF->sub(pA, pA, pT1, pGF); - - /* B = X2 * Z1 - X1 * Z2 */ - pGF->mul(pT2,pX2, pZ1, pGF); /* m */ - pGF->mul(pT3,pX1, pZ2, pGF); /* m */ - pGF->sub(pB, pT2, pT3, pGF); - - if( GFP_IS_ZERO(pB, elemLen) ) { - cpEcGFpReleasePool(3, pEC); - if( GFP_IS_ZERO(pA, elemLen) ) - return cpEcGFpDblPoint(pPointR, pP1, pEC); - else - return cpEcGFpSetProjectivePointAtInfinity(pPointR, elemLen); - } - - /* C = A^2*Z1*Z2 -B^2*(X2*Z1+X1*Z2) */ - pGF->sqr(pB2, pB, pGF); /* s */ - pGF->add(pT2,pT2, pT3, pGF); - pGF->mul(pT2,pT2, pB2, pGF); /* m */ - pGF->mul(pT4,pZ1, pZ2, pGF); /* m */ - pGF->sqr(pC, pA, pGF); /* s */ - pGF->mul(pC, pC, pT4, pGF); /* m */ - pGF->sub(pC, pC, pT2, pGF); - - /* new X = B*C */ - pGF->mul(ECP_POINT_X(pPointR), pB, pC, pGF); /* m */ - - /* new Y = A*(B^2*X1*Z2 -C) -B^3*Y1*Z2 */ - pGF->mul(pT3, pT3, pB2, pGF); /* m */ /* T3 = (X1*Z2)*B^2 */ - pGF->sub(pT3, pT3, pC, pGF); - pGF->mul(pT3, pT3, pA, pGF); /* m */ /* T3 = A*(B^2*X1*Z2 -C) */ - pGF->mul(pB3, pB2, pB, pGF); /* m */ /* B3 = B^3 */ - pGF->mul(pT1, pT1, pB3, pGF); /* m */ /* T1 = B^3*Y1*Z2 */ - pGF->sub(ECP_POINT_Y(pPointR), pT3, pT1, pGF); - - /* new Z = B^3*Z1*Z2 */ - pGF->mul(ECP_POINT_Z(pPointR), pB3, pT4, pGF); /* m */ - - ECP_POINT_FLAGS(pPointR) = ECP_FINITE_POINT; - - cpEcGFpReleasePool(3, pEC); - return pPointR; - } -} -#endif - -#if 0 -/* non-sscm version */ -IppsGFpECPoint* cpEcGFpMulPoint(IppsGFpECPoint* pPointR, const IppsGFpECPoint* pPointP, const BNU_CHUNK_T* pN, int nsN, IppsGFpECState* pEC, Ipp8u* pScratchBuffer) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - UNREFERENCED_PARAMETER(pScratchBuffer); - - /* test scalar and input point */ - if( GFP_IS_ZERO(pN, nsN) || !IS_ECP_FINITE_POINT(pPointP) ) - return cpEcGFpSetProjectivePointAtInfinity(pPointR, elemLen); - - /* remove leding zeros */ - FIX_BNU(pN, nsN); - - /* case N==1 => R = P */ - if( GFP_IS_ONE(pN, nsN) ) { - cpEcGFpCopyPoint(pPointR, pPointP, elemLen); - return pPointR; - } - - /* - // scalar multiplication - */ - else { - int i; - - BNU_CHUNK_T* pH = cpGFpGetPool(1, pGF); - BNU_CHUNK_T* pK = cpGFpGetPool(1, pGF); - - IppsGFpECPoint T, U; - cpEcGFpInitPoint(&T, cpEcGFpGetPool(1, pEC),0, pEC); - cpEcGFpInitPoint(&U, cpEcGFpGetPool(1, pEC),0, pEC); - - /* H = 3*N */ - cpGFpElementCopy(pK, pN, nsN); - pK[nsN] = 0; - i = cpAdd_BNU(pH, pK, pK, nsN+1); - i = cpAdd_BNU(pH, pK, pH, nsN+1); - - /* T = affine(P) */ - if( IS_ECP_AFFINE_POINT(pPointP) ) - cpEcGFpCopyPoint(&T, pPointP, elemLen); - else { - cpEcGFpGetAffinePoint(ECP_POINT_X(&T), ECP_POINT_Y(&T), pPointP, pEC); - cpEcGFpSetAffinePoint(&T, ECP_POINT_X(&T), ECP_POINT_Y(&T), pEC); - } - /* U = affine(-P) */ - cpEcGFpNegPoint(&U, &T, pEC); - - /* R = T = affine(P) */ - cpEcGFpCopyPoint(pPointR, &T, elemLen); - - /* - // point multiplication - */ - for(i=MSB_BNU(pH, nsN+1)-1; i>0; i--) { - Ipp32u hBit = TST_BIT(pH, i); - Ipp32u kBit = TST_BIT(pK, i); - cpEcGFpDblPoint(pPointR, pPointR, pEC); - if( hBit && !kBit ) - cpEcGFpAddPoint(pPointR, &T, pPointR, pEC); - if(!hBit && kBit ) - cpEcGFpAddPoint(pPointR, &U, pPointR, pEC); - } - - cpEcGFpReleasePool(2, pEC); - cpGFpReleasePool(2, pGF); - - return pPointR; - } -} -#endif - -static int div_upper(int a, int d) -{ return (a+d-1)/d; } - -#if 0 -static int getNumOperations(int bitsize, int w) -{ - int n_overhead = (1<=n_opt) break; - w_opt = w_trial; - n_opt = n_trial; - } - return w_opt; -#undef LIMIT -} - -static int cpEcGFpConverRepresentation(BNU_CHUNK_T* pInput, int inpBits, int w) -{ - Ipp32u* pR = (Ipp32u*)pInput; - Ipp16u* pR16 = (Ipp16u*)pInput; - - int outBits = 0; - Ipp32u base = (BNU_CHUNK_T)1<>digitShift) &digitMask; - - Ipp32u delta = (base-digit) & ~digitMask; - delta <<= digitShift; - cpDec_BNU32((Ipp32u*)(pR16+chunkIdx), (Ipp32u*)(pR16+chunkIdx), (2*nsR-chunkIdx+1)/2, delta); - - inpBits = BITSIZE_BNU32(pR, nsR); - outBits += w; - } - - return outBits; -} -#endif - -/* sscm version */ -IppsGFpECPoint* cpEcGFpMulPoint(IppsGFpECPoint* pPointR, const IppsGFpECPoint* pPointP, const BNU_CHUNK_T* pN, int nsN, IppsGFpECState* pEC, Ipp8u* pScratchBuffer) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - - /* test scalar and input point */ - if( GFP_IS_ZERO(pN, nsN) || !IS_ECP_FINITE_POINT(pPointP) ) - return cpEcGFpSetProjectivePointAtInfinity(pPointR, elemLen); - - /* remove leding zeros */ - FIX_BNU(pN, nsN); - - /* case N==1 => R = P */ - if( GFP_IS_ONE(pN, nsN) ) { - cpEcGFpCopyPoint(pPointR, pPointP, elemLen); - return pPointR; - } - - { - Ipp8u* pScratchAligned; /* aligned scratch buffer */ - int nAllocation = 0; /* points from the pool */ - - /* size of point (dwords) */ - int pointDataSize = ECP_FELEN(pEC)*sizeof(BNU_CHUNK_T); - int pointDataSize32 = ECP_FELEN(pEC)*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u); - - /* scalar bitsize */ - int scalarBitSize = BITSIZE_BNU(pN, nsN); - /* optimal size of window */ - int window_size = (NULL==pScratchBuffer)? 1 : 5; - /* number of table entries */ - int nPrecomputed = 1<<(window_size-1); - - IppsGFpECPoint T; - cpEcGFpInitPoint(&T, cpEcGFpGetPool(1, pEC),0, pEC); - cpEcGFpCopyPoint(&T, pPointP, elemLen); - - if(NULL==pScratchBuffer) { - nAllocation = 1 + div_upper(CACHE_LINE_SIZE, pointDataSize); - pScratchBuffer = (Ipp8u*)cpEcGFpGetPool(nAllocation, pEC); - } - pScratchAligned = IPP_ALIGNED_PTR(pScratchBuffer, CACHE_LINE_SIZE); - - /* pre-compute auxiliary table t[] = {1*P, 2*P, ..., nPrecomputed*P} */ - { - int n; - cpScatter32((Ipp32u*)pScratchAligned, nPrecomputed, 0, (Ipp32u*)ECP_POINT_DATA(&T), pointDataSize32); - for(n=1; n> ((bit-1)%8)) & dmask; - booth_recode(&sign, &digit, (Ipp8u)wvalue, window_size); - - cpGather32((Ipp32u*)ECP_POINT_DATA(pPointR), pointDataSize32, (Ipp32u*)pScratchAligned, nPrecomputed, digit); - ECP_POINT_FLAGS(pPointR) = 0; - - for(bit-=window_size; bit>=window_size; bit-=window_size) { - /* window_size times doubling */ - cpEcGFpDblPoint_k(pPointR, pPointR, window_size, pEC); - - /* extract next window value */ - wvalue = *((Ipp16u*)&pScalar8[(bit-1)/8]); - wvalue = (wvalue>> ((bit-1)%8)) & dmask; - booth_recode(&sign, &digit, (Ipp8u)wvalue, window_size); - - /* extract value from the pre-computed table */ - cpGather32((Ipp32u*)ECP_POINT_DATA(&T), pointDataSize32, (Ipp32u*)pScratchAligned, nPrecomputed, digit); - - pGF->neg(pNegY, ECP_POINT_Y(&T), pGF); - cpMaskMove(ECP_POINT_Y(&T), pNegY, elemLen, sign); - - /* and add it */ - cpEcGFpAddPoint(pPointR, pPointR, &T, pEC); - } - - /* last window */ - cpEcGFpDblPoint_k(pPointR, pPointR, window_size, pEC); - - wvalue = *((Ipp16u*)&pScalar8[0]); - wvalue = (wvalue <<1) & dmask; - booth_recode(&sign, &digit, (Ipp8u)wvalue, window_size); - - cpGather32((Ipp32u*)ECP_POINT_DATA(&T), pointDataSize32, (Ipp32u*)pScratchAligned, nPrecomputed, digit); - - pGF->neg(pNegY, ECP_POINT_Y(&T), pGF); - cpMaskMove(ECP_POINT_Y(&T), pNegY, elemLen, sign); - - cpEcGFpAddPoint(pPointR, pPointR, &T, pEC); - } - - cpGFpReleasePool(2+1, pGF); - } - - cpEcGFpReleasePool(nAllocation+1, pEC); - - return pPointR; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecstuff.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecstuff.h deleted file mode 100644 index f312e537..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpecstuff.h +++ /dev/null @@ -1,320 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// -// Purpose: -// Intel(R) Performance Primitives. Cryptography Primitives. -// Internal EC over GF(p^m) basic Definitions & Function Prototypes -// -// -*/ - -#if !defined(_CP_ECGFP_H_) -#define _CP_ECGFP_H_ - -#include "pcpgfpstuff.h" -#include "pcpgfpxstuff.h" - - -/* -// EC over GF(p) Point context -*/ -typedef struct _cpGFpECPoint { - IppCtxId idCtx; /* EC Point identifier */ - int flags; /* flags: affine */ - int elementSize; /* size of each coordinate */ - BNU_CHUNK_T* pData; /* coordinatex X, Y, Z */ -} cpGFPECPoint; - -/* -// Contetx Access Macros -*/ -#define ECP_POINT_ID(ctx) ((ctx)->idCtx) -#define ECP_POINT_FLAGS(ctx) ((ctx)->flags) -#define ECP_POINT_FELEN(ctx) ((ctx)->elementSize) -#define ECP_POINT_DATA(ctx) ((ctx)->pData) -#define ECP_POINT_X(ctx) ((ctx)->pData) -#define ECP_POINT_Y(ctx) ((ctx)->pData+(ctx)->elementSize) -#define ECP_POINT_Z(ctx) ((ctx)->pData+(ctx)->elementSize*2) -#define ECP_POINT_TEST_ID(ctx) (ECP_POINT_ID((ctx))==idCtxGFPPoint) - -/* point flags */ -#define ECP_AFFINE_POINT (1) -#define ECP_FINITE_POINT (2) - -#define IS_ECP_AFFINE_POINT(ctx) (ECP_POINT_FLAGS((ctx))&ECP_AFFINE_POINT) -#define SET_ECP_AFFINE_POINT(ctx) (ECP_POINT_FLAGS((ctx))|ECP_AFFINE_POINT) -#define SET_ECP_PROJECTIVE_POINT(ctx) (ECP_POINT_FLAGS((ctx))&~ECP_AFFINE_POINT) - -#define IS_ECP_FINITE_POINT(ctx) (ECP_POINT_FLAGS((ctx))&ECP_FINITE_POINT) -#define SET_ECP_FINITE_POINT(ctx) (ECP_POINT_FLAGS((ctx))|ECP_FINITE_POINT) -#define SET_ECP_INFINITE_POINT(ctx) (ECP_POINT_FLAGS((ctx))&~ECP_FINITE_POINT) - -/* -// define using projective coordinates -*/ -#define JACOBIAN (0) -#define HOMOGENEOUS (1) -#define ECP_PROJECTIVE_COORD JACOBIAN -//#define ECP_PROJECTIVE_COORD HOMOGENEOUS - -#if (ECP_PROJECTIVE_COORD== JACOBIAN) - #pragma message ("ECP_PROJECTIVE_COORD = JACOBIAN") -#elif (ECP_PROJECTIVE_COORD== HOMOGENEOUS) - #pragma message ("ECP_PROJECTIVE_COORD = HOMOGENEOUS") -#else - #error ECP_PROJECTIVE_COORD should be either JACOBIAN or HOMOGENEOUS type -#endif - -#define _EPID20_EC_PARAM_SPECIFIC_ - -#if defined(_EPID20_EC_PARAM_SPECIFIC_) -#pragma message ("_EPID20_EC_PARAM_SPECIFIC_") -#endif - - -/* EC over GF(p) context */ -typedef struct _cpGFpEC { - IppCtxId idCtx; /* EC identifier */ - - IppsGFpState* pGF; /* arbitrary GF(p^d)*/ - - int elementSize; /* size of point's coordinate */ - int orderBitSize; /* base_point order bitsize */ -// int cofactor; /* cofactor = #E/base_point order */ - int epidParams; /* Intel(R) EPID 2.0 specific parameters */ - BNU_CHUNK_T* pA; /* EC parameter A */ - BNU_CHUNK_T* pB; /* B */ - BNU_CHUNK_T* pG; /* base_point */ - BNU_CHUNK_T* pR; /* base_point order */ - BNU_CHUNK_T* cofactor; /* cofactor = #E/base_point order */ - BNU_CHUNK_T* pPool; /* pool of points */ -} cpGFPEC; - -#define ECGFP_ALIGNMENT ((int)(sizeof(void*))) - -/* Local definitions */ -#define EC_POOL_SIZE (8) /* num of points into the pool */ - -#define ECP_ID(pCtx) ((pCtx)->idCtx) -#define ECP_GFP(pCtx) ((pCtx)->pGF) -#define ECP_FELEN(pCtx) ((pCtx)->elementSize) -#define ECP_ORDBITSIZE(pCtx) ((pCtx)->orderBitSize) -#define ECP_COFACTOR(pCtx) ((pCtx)->cofactor) -#define EPID_PARAMS(pCtx) ((pCtx)->epidParams) -#define ECP_A(pCtx) ((pCtx)->pA) -#define ECP_B(pCtx) ((pCtx)->pB) -#define ECP_G(pCtx) ((pCtx)->pG) -#define ECP_R(pCtx) ((pCtx)->pR) -#define ECP_POOL(pCtx) ((pCtx)->pPool) - -#define ECP_TEST_ID(pCtx) (ECP_ID((pCtx))==idCtxGFPEC) - -/* -// get/release n points from/to the pool -*/ -__INLINE BNU_CHUNK_T* cpEcGFpGetPool(int n, IppsGFpECState* pEC) -{ - BNU_CHUNK_T* pPool = ECP_POOL(pEC); - ECP_POOL(pEC) += n*GFP_FELEN(ECP_GFP(pEC))*3; - return pPool; -} -__INLINE void cpEcGFpReleasePool(int n, IppsGFpECState* pEC) -{ - ECP_POOL(pEC) -= n*GFP_FELEN(ECP_GFP(pEC))*3; -} - -__INLINE IppsGFpECPoint* cpEcGFpInitPoint(IppsGFpECPoint* pPoint, BNU_CHUNK_T* pData, int flags, const IppsGFpECState* pEC) -{ - ECP_POINT_ID(pPoint) = idCtxGFPPoint; - ECP_POINT_FLAGS(pPoint) = flags; - ECP_POINT_FELEN(pPoint) = GFP_FELEN(ECP_GFP(pEC)); - ECP_POINT_DATA(pPoint) = pData; - return pPoint; -} - -/* -// copy one point into another -*/ -__INLINE IppsGFpECPoint* cpEcGFpCopyPoint(IppsGFpECPoint* pPointR, const IppsGFpECPoint* pPointA, int elemLen) -{ - cpGFpElementCopy(ECP_POINT_DATA(pPointR), ECP_POINT_DATA(pPointA), 3*elemLen); - ECP_POINT_FLAGS(pPointR) = ECP_POINT_FLAGS(pPointA); - return pPointR; -} - -/* -// set point (convert into inside representation) -// SetProjectivePoint -// SetProjectivePointAtInfinity -// SetAffinePoint -*/ -__INLINE IppsGFpECPoint* cpEcGFpSetProjectivePoint(IppsGFpECPoint* pPoint, - const BNU_CHUNK_T* pX, const BNU_CHUNK_T* pY, const BNU_CHUNK_T* pZ, - IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - int elemLen = GFP_FELEN(pGF); - int pointFlag = 0; - - cpGFpxSet(ECP_POINT_X(pPoint), pX, elemLen, pGF, USE_MONT_SPACE_REPRESENTATION); - cpGFpxSet(ECP_POINT_Y(pPoint), pY, elemLen, pGF, USE_MONT_SPACE_REPRESENTATION); - cpGFpxSet(ECP_POINT_Z(pPoint), pZ, elemLen, pGF, USE_MONT_SPACE_REPRESENTATION); - - if(!GFP_IS_ZERO(pZ, elemLen)) pointFlag |= ECP_FINITE_POINT; - if(GFP_IS_ONE(pZ, elemLen)) pointFlag |= ECP_AFFINE_POINT; - ECP_POINT_FLAGS(pPoint) = pointFlag; - return pPoint; -} -__INLINE IppsGFpECPoint* cpEcGFpSetProjectivePointAtInfinity(IppsGFpECPoint* pPoint, int elemLen) -{ - cpGFpElementPadd(ECP_POINT_X(pPoint), elemLen, 0); - cpGFpElementPadd(ECP_POINT_Y(pPoint), elemLen, 0); - cpGFpElementPadd(ECP_POINT_Z(pPoint), elemLen, 0); - ECP_POINT_FLAGS(pPoint) = 0; - return pPoint; -} -__INLINE IppsGFpECPoint* cpEcGFpSetAffinePoint(IppsGFpECPoint* pPoint, - const BNU_CHUNK_T* pX, const BNU_CHUNK_T* pY, - IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - IppsGFpState* pBasicGF = cpGFpBasic(pGF); - - cpGFpElementCopy(ECP_POINT_X(pPoint), pX, GFP_FELEN(pGF)); - cpGFpElementCopy(ECP_POINT_Y(pPoint), pY, GFP_FELEN(pGF)); - cpGFpElementCopyPadd(ECP_POINT_Z(pPoint), GFP_FELEN(pGF), MNT_1(GFP_MONT(pBasicGF)), GFP_FELEN(pBasicGF)); - ECP_POINT_FLAGS(pPoint) = ECP_AFFINE_POINT | ECP_FINITE_POINT; - return pPoint; -} - -/* -// test infinity: -// IsProjectivePointAtInfinity -*/ -__INLINE int cpEcGFpIsProjectivePointAtInfinity(const IppsGFpECPoint* pPoint, Ipp32u elemLen) -{ - return GFP_IS_ZERO( ECP_POINT_Z(pPoint), elemLen ); -} - -/* -// get point (convert from inside representation) -// GetProjectivePoint -// GetAffinePointAtInfinity0 (B==0) -// GetAffinePointAtInfinity1 (B!=0) -// GetAffinePoint -*/ -__INLINE void cpEcGFpGetProjectivePoint(BNU_CHUNK_T* pX, BNU_CHUNK_T* pY, BNU_CHUNK_T* pZ, - const IppsGFpECPoint* pPoint, - IppsGFpECState* pEC) -{ - IppsGFpState* pGF = ECP_GFP(pEC); - cpGFpxGet(pX, GFP_FELEN(pGF), ECP_POINT_X(pPoint), pGF, USE_MONT_SPACE_REPRESENTATION); - cpGFpxGet(pY, GFP_FELEN(pGF), ECP_POINT_Y(pPoint), pGF, USE_MONT_SPACE_REPRESENTATION); - cpGFpxGet(pZ, GFP_FELEN(pGF), ECP_POINT_Z(pPoint), pGF, USE_MONT_SPACE_REPRESENTATION); -} -#if 0 -__INLINE void cpEcGFpGetAffinePointAtInfinity0(BNU_CHUNK_T* pX, BNU_CHUNK_T* pY, int elemLen) -{ - GFP_ZERO(pX, elemLen); - GFP_ONE(pY, elemLen); -} -__INLINE void cpEcGFpGetAffinePointAtInfinity1(BNU_CHUNK_T* pX, BNU_CHUNK_T* pY, int elemLen) -{ - GFP_ZERO(pX, elemLen); - GFP_ZERO(pY, elemLen); -} -#endif - - -/* signed encode */ -__INLINE void booth_recode(Ipp8u* sign, Ipp8u* digit, Ipp8u in, int w) -{ - Ipp8u s = ~((in >> w) - 1); - int d = (1 << (w+1)) - in - 1; - d = (d & s) | (in & ~s); - d = (d >> 1) + (d & 1); - *sign = s & 1; - *digit = (Ipp8u)d; -} - -/* mask of the argument: - if x==0 returns 0 - if x!=0 returns BNU_CHUNK_T(-1) -*/ -__INLINE BNU_CHUNK_T cpIsNonZeroMask(BNU_CHUNK_T x) -{ - #if(_IPP_ARCH==_IPP_ARCH_EM64T) - x |= x>>32; - #endif - x |= x>>16; - x |= x>>8; - x |= x>>4; - x |= x>>2; - x |= x>>1; - return 0-(x&1); -} - -/* dst[] = src[], iif moveFlag!=0 */ -__INLINE void cpMaskMove(BNU_CHUNK_T* dst, const BNU_CHUNK_T* src, int len, int moveFlag) -{ - BNU_CHUNK_T mask1 = cpIsNonZeroMask(moveFlag); - BNU_CHUNK_T mask2 = ~mask1; - int n; - for(n=0; n= _IPP32E_M7) -BNU_CHUNK_T* cp256pNeg(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - return gf256_neg(pR, pA, GFP_MODULUS(pGF)); -} -#endif - - -BNU_CHUNK_T* cpGFpInv(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - int poolelementLen= GFP_PELEN(pGF); - - BNU_CHUNK_T* tmpM = cpGFpGetPool(4, pGF); - BNU_CHUNK_T* tmpX1= tmpM +poolelementLen; - BNU_CHUNK_T* tmpX2= tmpX1+poolelementLen; - BNU_CHUNK_T* tmpX3= tmpX2+poolelementLen; - int nsR; - - cpGFpElementCopy(tmpM, pModulus, elemLen); - nsR = cpModInv_BNU(pR, pA,elemLen, tmpM, elemLen, tmpX1,tmpX2,tmpX3); - cpGFpReleasePool(4, pGF); - - cpGFpElementPadd(pR+nsR, elemLen-nsR, 0); - return cpGFpMul(pR, pR, MNT_CUBE_R(GFP_MONT(pGF)), pGF); -} - - -/* sscm version */ -BNU_CHUNK_T* cpGFpHalve(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - - BNU_CHUNK_T mask = 0 - (pA[0]&1); /* set mask iif A is odd */ - /* t = if(isOdd(A))? modulus : 0 */ - int i; - BNU_CHUNK_T* t = cpGFpGetPool(1, pGF); - for(i=0; i= _IPP32E_M7) -BNU_CHUNK_T* cp256pHalve(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - return gf256_div2(pR, pA, GFP_MODULUS(pGF)); -} -#endif - - -/* sscm version */ -BNU_CHUNK_T* cpGFpAdd(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pTmpR = cpGFpGetPool(1, pGF); - - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - - BNU_CHUNK_T e = cpAdd_BNU(pR, pA, pB, elemLen); - e -= cpSub_BNU(pTmpR, pR, pModulus, elemLen); - MASKED_COPY(pR, e, pR, pTmpR, elemLen); - - cpGFpReleasePool(1, pGF); - - return pR; -} - -#if(_IPP32E >= _IPP32E_M7) -BNU_CHUNK_T* cp256pAdd(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - return gf256_add(pR, pA, pB, GFP_MODULUS(pGF)); -} -#endif - - -/* sscm version */ -BNU_CHUNK_T* cpGFpSub(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pTmpR = cpGFpGetPool(1, pGF); - - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - - BNU_CHUNK_T e = cpSub_BNU(pR, pA, pB, elemLen); - cpAdd_BNU(pTmpR, pR, pModulus, elemLen); - MASKED_COPY(pR, (0-e), pTmpR, pR, elemLen); - - cpGFpReleasePool(1, pGF); - - return pR; -} - -#if(_IPP32E >= _IPP32E_M7) -BNU_CHUNK_T* cp256pSub(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - return gf256_sub(pR, pA, pB, GFP_MODULUS(pGF)); -} -#endif - - -BNU_CHUNK_T* cpGFpMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - - IppsMontState* pMont = GFP_MONT(pGF); - BNU_CHUNK_T* pBuffer = MNT_PRODUCT(pMont); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - - cpMontMul_BNU(pR, pA,elemLen, pB,elemLen, pModulus,elemLen, m0, pBuffer, NULL); - return pR; -} - -#if(_IPP32E >= _IPP32E_M7) -BNU_CHUNK_T* cp256pMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - IppsMontState* pMont = GFP_MONT(pGF); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - return gf256_mulm(pR, pA, pB, pModulus, m0); -} -#endif - -BNU_CHUNK_T* cpGFpSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - int elemLen = GFP_FELEN(pGF); - - IppsMontState* pMont = GFP_MONT(pGF); - BNU_CHUNK_T* pBuffer = MNT_PRODUCT(pMont); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - - cpMontSqr_BNU(pR, pA,elemLen, pModulus,elemLen, m0, pBuffer, NULL); - return pR; -} - -#if(_IPP32E >= _IPP32E_M7) -BNU_CHUNK_T* cp256pSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pModulus = GFP_MODULUS(pGF); - IppsMontState* pMont = GFP_MONT(pGF); - BNU_CHUNK_T m0 = MNT_HELPER(pMont); - return gf256_sqrm(pR, pA, pModulus, m0); -} -#endif - - -BNU_CHUNK_T* cpGFpExp(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pE, int nsE, IppsGFpState* pGF) -{ - IppsBigNumState A; - IppsBigNumState E; - IppsBigNumState R; - - BNU_CHUNK_T* pPool = cpGFpGetPool(3, pGF); - int poolElemLen = GFP_PELEN(pGF); - int elemLen = GFP_FELEN(pGF); - - cpGFpSetBigNum(&A, elemLen, pA, pPool+0*poolElemLen); - cpGFpSetBigNum(&E, nsE, pE, pPool+1*poolElemLen); - cpGFpInitBigNum(&R,elemLen, pR, pPool+2*poolElemLen); - - cpMontExpBin_BN(&R, &A, &E, GFP_MONT(pGF)); - - cpGFpReleasePool(3, pGF); - return pR; -} - - -static int factor2(BNU_CHUNK_T* pA, int nsA) -{ - int factor = 0; - int bits; - - int i; - for(i=0; i= BITSIZE(BNU_CHUNK_T)) { - int nchunk = bits/BITSIZE(BNU_CHUNK_T); - cpGFpElementCopyPadd(pA, nsA, pA+nchunk, nsA-nchunk); - bits %= BITSIZE(BNU_CHUNK_T); - } - if(bits) - cpLSR_BNU(pA, pA, nsA, bits); - - return factor; -} -static BNU_CHUNK_T* cpGFpExp2(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, int e, IppsGFpState* pGF) -{ - cpGFpElementCopy(pR, pA, GFP_FELEN(pGF)); - while(e--) { - pGF->sqr(pR, pR, pGF); - } - return pR; -} - -/* returns: - 0, if a - qnr - 1, if sqrt is found -*/ -int cpGFpSqrt(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF) -{ - int elemLen = GFP_FELEN(pGF); - int poolelementLen = GFP_PELEN(pGF); - int resultFlag = 1; - - /* case A==0 */ - if( GFP_IS_ZERO(pA, elemLen) ) - cpGFpElementPadd(pR, elemLen, 0); - - /* general case */ - else { - BNU_CHUNK_T* q = cpGFpGetPool(4, pGF); - BNU_CHUNK_T* x = q + poolelementLen; - BNU_CHUNK_T* y = x + poolelementLen; - BNU_CHUNK_T* z = y + poolelementLen; - - int s; - - /* z=1 */ - GFP_ONE(z, elemLen); - - /* (modulus-1) = 2^s*q */ - cpSub_BNU(q, GFP_MODULUS(pGF), z, elemLen); - s = factor2(q, elemLen); - - /* - // initialization - */ - - /* y = qnr^q */ - cpGFpExp(y, GFP_QNR(pGF), q,elemLen, pGF); - /* x = a^((q-1)/2) */ - cpSub_BNU(q, q, z, elemLen); - cpLSR_BNU(q, q, elemLen, 1); - cpGFpExp(x, pA, q, elemLen, pGF); - /* z = a*x^2 */ - pGF->mul(z, x, x, pGF); - pGF->mul(z, pA, z, pGF); - /* R = a*x */ - pGF->mul(pR, pA, x, pGF); - - while( !GFP_EQ(z, MNT_1(GFP_MONT(pGF)), elemLen) ) { - int m = 0; - cpGFpElementCopy(q, z, elemLen); - - for(m=1; mmul(q, q, q, pGF); - if( GFP_EQ(q, MNT_1(GFP_MONT(pGF)), elemLen) ) - break; - } - - if(m==s) { - /* A is quadratic non-residue */ - resultFlag = 0; - break; - } - else { - /* exponent reduction */ - cpGFpExp2(q, y, (s-m-1), pGF); /* q = y^(2^(s-m-1)) */ - pGF->mul(y, q, q, pGF); /* y = q^2 */ - pGF->mul(pR, q, pR, pGF); /* R = q*R */ - pGF->mul(z, y, z, pGF); /* z = z*y */ - s = m; - } - } - - /* choose smallest between R and (modulus-R) */ - cpGFpMontDecode(q, pR, elemLen, GFP_MONT(pGF)); - if(GFP_GT(q, GFP_HMODULUS(pGF), elemLen)) - pGF->neg(pR, pR, pGF); - - cpGFpReleasePool(4, pGF); - } - - return resultFlag; -} - - -BNU_CHUNK_T* cpGFpRand(BNU_CHUNK_T* pR, IppsGFpState* pGF, IppBitSupplier rndFunc, void* pRndParam, int montSpace) -{ - int elemLen = GFP_FELEN(pGF); - int reqBitSize = GFP_FEBITSIZE(pGF)+GF_RAND_ADD_BITS; - int nsR = (reqBitSize +BITSIZE(BNU_CHUNK_T)-1)/BITSIZE(BNU_CHUNK_T); - - BNU_CHUNK_T* pPool = cpGFpGetPool(2, pGF); - cpGFpElementPadd(pPool, nsR, 0); - rndFunc((Ipp32u*)pPool, reqBitSize, pRndParam); - - nsR = cpMod_BNU(pPool, nsR, GFP_MODULUS(pGF), elemLen); - cpGFpElementPadd(pPool+nsR, elemLen-nsR, 0); - if(montSpace) - cpGFpMontEncode(pR, pPool, elemLen, GFP_MONT(pGF)); - else - cpGFpElementCopy(pR, pPool, elemLen); - - cpGFpReleasePool(2, pGF); - return pR; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpstuff.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpstuff.h deleted file mode 100644 index d9b9d8b2..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpstuff.h +++ /dev/null @@ -1,212 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Purpose: -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives -// Internal GF(p) basic Definitions & Function Prototypes -// -// -*/ - -#if !defined(_PCP_GFP_H_) -#define _PCP_GFP_H_ - -#include "pcpbn.h" -#include "pcpmontgomery.h" - -/* GF element */ -typedef struct _cpElementGFp { - IppCtxId idCtx; /* GF() element ident */ - int length; /* length of element (in BNU_CHUNK_T) */ - BNU_CHUNK_T* pData; -} cpElementGFp; - -#define GFPE_ID(pCtx) ((pCtx)->idCtx) -#define GFPE_ROOM(pCtx) ((pCtx)->length) -#define GFPE_DATA(pCtx) ((pCtx)->pData) - -#define GFPE_TEST_ID(pCtx) (GFPE_ID((pCtx))==idCtxGFPE) - -/* basic GF arithmetic */ -typedef BNU_CHUNK_T* (*addm) (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -typedef BNU_CHUNK_T* (*subm) (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -typedef BNU_CHUNK_T* (*negm) (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -typedef BNU_CHUNK_T* (*mulm) (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -typedef BNU_CHUNK_T* (*sqrm) (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -typedef BNU_CHUNK_T* (*div2m)(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); - -/* GF(p) context */ -typedef struct _cpGFp cpGF_T; - -typedef struct _cpGFp { - IppCtxId idCtx; /* GFp spec ident */ - int gfdegree; /* degree of extension (==1 means basic GF(p)) */ - int elemLen; /* size of field element (in BNU_CHUNK_T) */ - int elemLen32; /* sizeof of field element (in Ipp32u) */ - int pelemLen; /* sizeof pool element (in BNU_CHUNK_T) */ - int modulusTypeSpc;/* modulus type specific */ - int epidParams; /* Intel(R) EPID 2.0 specific parameters */ - cpGF_T* pGroundGF; /* ground GF (refference on itself if basic GF(p)) */ - /* = methods: = */ - addm add; /* - gf add */ - subm sub; /* - gf sub */ - negm neg; /* - gf neg */ - mulm mul; /* - gf mul */ - sqrm sqr; /* - gf sqr */ - div2m div2; /* - gf div by 2 */ - /* ============ */ - BNU_CHUNK_T* pModulus; /* modulus or irreducible polypomial (without hight order term ==1) */ - BNU_CHUNK_T* pHalfModulus; /* modulus/2 if basic, NULL if extension */ - BNU_CHUNK_T* pQnr; /* quadratic non-residue if basic, NULL if extension */ - IppsMontState* pMontState; /* montgomery engine if basic, NULL if extension */ - BNU_CHUNK_T* pElemPool; /* pool of temporary field elements */ -} cpGFp; - -#define GFP_ALIGNMENT ((int)(sizeof(void*))) - -/* Local definitions */ -#define GF_MAX_BITSIZE (4096) /* max bitsize for GF element */ -#define GF_POOL_SIZE (8)//(10) /* num of elements into the pool */ -#define GF_RAND_ADD_BITS (128) /* parameter of random element generation */ - -#define GFP_ID(pCtx) ((pCtx)->idCtx) -#define GFP_DEGREE(pCtx) ((pCtx)->gfdegree) -#define GFP_FELEN(pCtx) ((pCtx)->elemLen) -#define GFP_FELEN32(pCtx) ((pCtx)->elemLen32) /////????!!!! -#define GFP_PELEN(pCtx) ((pCtx)->pelemLen) -#define FIELD_POLY_TYPE(pCtx) ((pCtx)->modulusTypeSpc) -#define EPID_PARAMS(pCtx) ((pCtx)->epidParams) -#define GFP_GROUNDGF(pCtx) ((pCtx)->pGroundGF) -#define GFP_MODULUS(pCtx) ((pCtx)->pModulus) -#define GFP_HMODULUS(pCtx) ((pCtx)->pHalfModulus) /* for Sqrt() function only */ -#define GFP_QNR(pCtx) ((pCtx)->pQnr) -#define GFP_POOL(pCtx) ((pCtx)->pElemPool) -#define GFP_MONT(pCtx) ((pCtx)->pMontState) - -/* type of field polynomial: */ -#define ARBITRARY (0) /* arbitrary */ -#define BINOMIAL (1) /* binomial */ - -#define GFP_FEBITSIZE(pCtx) (BITSIZE_BNU(GFP_MODULUS((pCtx)),GFP_FELEN((pCtx)))) -#define GFP_IS_BASIC(pCtx) (GFP_GROUNDGF((pCtx))==(pCtx)) -#define GFP_TEST_ID(pCtx) (GFP_ID((pCtx))==idCtxGFP) - -#define USE_MONT_SPACE_REPRESENTATION (1) - -/* -// get/release n element from/to the pool -*/ -__INLINE BNU_CHUNK_T* cpGFpGetPool(int n, IppsGFpState* pGF) -{ - BNU_CHUNK_T* pPool = GFP_POOL(pGF); - GFP_POOL(pGF) += n*GFP_PELEN(pGF); - return pPool; -} -__INLINE void cpGFpReleasePool(int n, IppsGFpState* pGF) -{ - GFP_POOL(pGF) -= n*GFP_PELEN(pGF); -} - - - -__INLINE int cpGFpElementLen(const BNU_CHUNK_T* pE, int nsE) -{ - for(; nsE>1 && 0==pE[nsE-1]; nsE--) ; - return nsE; -} -__INLINE BNU_CHUNK_T* cpGFpElementCopy(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pE, int nsE) -{ - int n; - for(n=0; n1 && pE[nsE-1]==pX[nsE-1]; nsE--) - ; - return pE[nsE-1]==pX[nsE-1]? 0 : pE[nsE-1]>pX[nsE-1]? 1:-1; -} -__INLINE int cpGFpElementIsEquChunk(const BNU_CHUNK_T* pE, int nsE, BNU_CHUNK_T x) -{ - int isEqu = (pE[0] == x); - return isEqu && (1==cpGFpElementLen(pE, nsE)); -} -__INLINE BNU_CHUNK_T* cpGFpElementSetChunk(BNU_CHUNK_T* pR, int nsR, BNU_CHUNK_T x) -{ - return cpGFpElementCopyPadd(pR, nsR, &x, 1); -} - - -#define GFP_LT(a,b,size) (-1==cpGFpElementCmp((a),(b),(size))) -#define GFP_EQ(a,b,size) ( 0==cpGFpElementCmp((a),(b),(size))) -#define GFP_GT(a,b,size) ( 1==cpGFpElementCmp((a),(b),(size))) - -#define GFP_IS_ZERO(a,size) cpGFpElementIsEquChunk((a),(size), 0) -#define GFP_IS_ONE(a,size) cpGFpElementIsEquChunk((a),(size), 1) - -#define GFP_ZERO(a,size) cpGFpElementSetChunk((a),(size), 0) -#define GFP_ONE(a,size) cpGFpElementSetChunk((a),(size), 1) - -#define GFP_IS_EVEN(a) (0==((a)[0]&1)) -#define GFP_IS_ODD(a) (1==((a)[0]&1)) - - -int cpGFpCompare(const IppsGFpState* pGFp1, const IppsGFpState* pGFp2); - -BNU_CHUNK_T* cpGFpRand(BNU_CHUNK_T* pR, IppsGFpState* pGF, IppBitSupplier rndFunc, void* pRndParam, int montSpace); -BNU_CHUNK_T* cpGFpSet (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pDataA, int nsA, IppsGFpState* pGF, int montSpace); -BNU_CHUNK_T* cpGFpGet (BNU_CHUNK_T* pDataA, int nsA, const BNU_CHUNK_T* pR, IppsGFpState* pGF, int montSpace); -BNU_CHUNK_T* cpGFpSetOctString(BNU_CHUNK_T* pR, const Ipp8u* pStr, int strSize, IppsGFpState* pGF, int montSpace); -Ipp8u* cpGFpGetOctString(Ipp8u* pStr, int strSize, const BNU_CHUNK_T* pA, IppsGFpState* pGF, int montSpace); - -BNU_CHUNK_T* cpGFpNeg (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpInv (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpHalve(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpAdd (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpSub (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpMul (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpSqr (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cpGFpExp (BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pE, int nsE, IppsGFpState* pGF); - int cpGFpSqrt(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); - -#if(_IPP32E >= _IPP32E_M7) -BNU_CHUNK_T* cp256pAdd(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cp256pSub(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cp256pNeg(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cp256pMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGF); -BNU_CHUNK_T* cp256pSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -BNU_CHUNK_T* cp256pHalve(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGF); -#endif - -IppsBigNumState* cpGFpInitBigNum(IppsBigNumState* pBN, int len, BNU_CHUNK_T* pNumBuffer, BNU_CHUNK_T* pTmpBuffer); -IppsBigNumState* cpGFpSetBigNum(IppsBigNumState* pBN, int len, const BNU_CHUNK_T* pBNU, BNU_CHUNK_T* pTmpBuffer); - -#endif /* _PCP_GFP_H_ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpx.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpx.c deleted file mode 100644 index be978bc1..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpx.c +++ /dev/null @@ -1,202 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Performance Primitives. Cryptography Primitives. -// Operations over GF(p) ectension. -// -// Context: -// ippsGFpxGetSize -// ippsGFpxInit -// ippsGFpGetInfo -// -*/ - -#include "owncpepid.h" - -#include "pcpgfpstuff.h" -#include "pcpgfpxstuff.h" - -/* Get context size */ -IPPFUN(IppStatus, ippsGFpxGetSize, (const IppsGFpState* pGroundGF, int deg, int* pSizeInBytes)) -{ - IPP_BAD_PTR2_RET(pGroundGF, pSizeInBytes); - IPP_BADARG_RET( deg<2, ippStsBadArgErr); - pGroundGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGroundGF, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGroundGF), ippStsContextMatchErr ); - - { - int elemGroundLen = GFP_FELEN(pGroundGF); - int elemLen = elemGroundLen * deg; - *pSizeInBytes = sizeof(IppsGFpState) - +elemLen * sizeof(BNU_CHUNK_T) /* field polynomial coeff. excluding leading 1 */ - +elemLen * sizeof(BNU_CHUNK_T) * GFPX_POOL_SIZE /* pool of temporary variables */ - +GFP_ALIGNMENT-1; - return ippStsNoErr; - } -} - -static void InitGFpxCtx(const IppsGFpState* pGroundGF, int deg, IppsGFpState* pGFpx) -{ - int elemLen = deg * GFP_FELEN(pGroundGF); - int elemLen32 = deg* GFP_FELEN32(pGroundGF); - - Ipp8u* ptr = (Ipp8u*)pGFpx + sizeof(IppsGFpState); - - /* context identifier */ - GFP_ID(pGFpx) = idCtxGFP; - /* extension degree */ - GFP_DEGREE(pGFpx) = deg; - /* length of element */ - GFP_FELEN(pGFpx)= elemLen; - GFP_FELEN32(pGFpx) = elemLen32; - GFP_PELEN(pGFpx) = elemLen; - FIELD_POLY_TYPE(pGFpx) = ARBITRARY; - EPID_PARAMS(pGFpx) = 0; - - pGFpx->add = cpGFpxAdd; - pGFpx->sub = cpGFpxSub; - pGFpx->neg = cpGFpxNeg; - pGFpx->mul = cpGFpxMul; - pGFpx->sqr = cpGFpxSqr; - pGFpx->div2= cpGFpxHalve; - - /* save ground GF() context address */ - GFP_GROUNDGF(pGFpx) = (IppsGFpState*)pGroundGF; - /* coefficients of field polynomial */ - GFP_MODULUS(pGFpx) = (BNU_CHUNK_T*)(ptr); ptr += elemLen * sizeof(BNU_CHUNK_T); - /* 1/2 modulus: no matter */ - GFP_HMODULUS(pGFpx) = NULL; - /* quadratic non-residue: no matter */ - GFP_QNR(pGFpx) = NULL; - /* montgomery engine: no matter */ - GFP_MONT(pGFpx) = NULL; - /* pool addresses */ - GFP_POOL(pGFpx) = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(ptr, (int)sizeof(BNU_CHUNK_T))); - - cpGFpElementPadd(GFP_MODULUS(pGFpx), elemLen, 0); -} - - -/* Init context by arbitrary irreducible polynomial */ -IPPFUN(IppStatus, ippsGFpxInit, (const IppsGFpState* pGroundGF, - const Ipp32u* pIrrPolynomial, int deg, - IppsGFpState* pGFpx)) -{ - IPP_BAD_PTR3_RET(pGFpx, pGroundGF, pIrrPolynomial); - pGroundGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGroundGF, GFP_ALIGNMENT) ); - pGFpx = (IppsGFpState*)( IPP_ALIGNED_PTR(pGFpx, GFP_ALIGNMENT) ); - pGroundGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGroundGF, GFP_ALIGNMENT) ); - - /* init context */ - InitGFpxCtx(pGroundGF, deg, pGFpx); - - { - BNU_CHUNK_T* pTmp = cpGFpGetPool(1, pGFpx); - - /* copy coefficients of irresucible (except high-order 1) */ - COPY_BNU((Ipp32u*)pTmp, pIrrPolynomial, GFP_FELEN32(pGFpx)); - /* convert coefficients of irresucible into internal representation and store */ - cpGFpxSet(GFP_MODULUS(pGFpx), pTmp, GFP_FELEN(pGFpx), pGFpx, USE_MONT_SPACE_REPRESENTATION); - - cpGFpReleasePool(1, pGFpx); - return ippStsNoErr; - } -} - -/* Init context by arbitrary irreducible binimial */ -IPPFUN(IppStatus, ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, - const IppsGFpElement* pGroundElm, int deg, - IppsGFpState* pGFpx)) -{ - IPP_BAD_PTR3_RET(pGFpx, pGroundGF, pGroundElm); - pGroundGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGroundGF, GFP_ALIGNMENT) ); - pGFpx = (IppsGFpState*)( IPP_ALIGNED_PTR(pGFpx, GFP_ALIGNMENT) ); - pGroundGF = (IppsGFpState*)( IPP_ALIGNED_PTR(pGroundGF, GFP_ALIGNMENT) ); - - /* init context */ - InitGFpxCtx(pGroundGF, deg, pGFpx); - - /* store low-order coefficient of irresucible into the context */ - cpGFpElementCopy(GFP_MODULUS(pGFpx), GFPE_DATA(pGroundElm), GFP_FELEN(pGroundGF)); - FIELD_POLY_TYPE(pGFpx) = BINOMIAL; - - /* test if field polynomial is match to Intel(R) EPID specific */ - { - int isEpidParam = 0; - - BNU_CHUNK_T* g0 = cpGFpGetPool(1, (IppsGFpState*)pGroundGF); - int elmLen = GFP_FELEN(pGroundGF); - - int basicExt = cpGFpBasicDegreeExtension(pGFpx); - int basicTermLen = GFP_FELEN(cpGFpBasic(pGroundGF)); - - /* convert g0 into regular representation */ - cpGFpxGet(g0, elmLen, GFPE_DATA(pGroundElm), (IppsGFpState*)pGroundGF, USE_MONT_SPACE_REPRESENTATION); - - switch(basicExt) { - case 2: - /* expected polynomial is g() = t^2 + (-beta), - beta =q-1 */ - isEpidParam = cpGFpElementIsEquChunk(g0,basicTermLen, 1); - break; - case 6: - /* expected polynomial is g() = t^3 + (-xi), - xi = 2+1*t, coeffs belongs to Fq */ - cpGFpxNeg(g0, g0, (IppsGFpState*)pGroundGF); - isEpidParam = EPID_PARAMS(pGroundGF) - && cpGFpElementIsEquChunk(g0,basicTermLen, 2) - && cpGFpElementIsEquChunk(g0+basicTermLen,basicTermLen, 1); - break; - case 12: - /* expected polynomial is g() = t^2 + (-vi), - vi = (0+0*t) + (1*t^2+0*t^3) + (0*t^4+0*t^5), coeffs belongs to Fq */ - cpGFpxNeg(g0, g0, (IppsGFpState*)pGroundGF); - isEpidParam = EPID_PARAMS(pGroundGF) - && cpGFpElementIsEquChunk(g0,basicTermLen, 0) - && cpGFpElementIsEquChunk(g0+basicTermLen, basicTermLen, 0) - && cpGFpElementIsEquChunk(g0+basicTermLen*2,basicTermLen, 1) - && cpGFpElementIsEquChunk(g0+basicTermLen*3,basicTermLen, 0) - && cpGFpElementIsEquChunk(g0+basicTermLen*4,basicTermLen, 0) - && cpGFpElementIsEquChunk(g0+basicTermLen*5,basicTermLen, 0); - break; - default: - isEpidParam = 0; - break; - } - EPID_PARAMS(pGFpx) = isEpidParam; - - cpGFpReleasePool(1, (IppsGFpState*)pGroundGF); - } - - return ippStsNoErr; -} - -/* get general info */ -IPPFUN(IppStatus, ippsGFpGetInfo,(const IppsGFpState* pGFpx, IppsGFpInfo* pInfo)) -{ - IPP_BAD_PTR2_RET(pGFpx, pInfo); - pGFpx = (IppsGFpState*)( IPP_ALIGNED_PTR(pGFpx, GFP_ALIGNMENT) ); - IPP_BADARG_RET( !GFP_TEST_ID(pGFpx), ippStsContextMatchErr ); - - pInfo->pBasicGF = cpGFpBasic(pGFpx); - pInfo->pGroundGF = GFP_GROUNDGF(pGFpx); - pInfo->basicGFdegree = cpGFpBasicDegreeExtension(pGFpx); - pInfo->groundGFdegree = GFP_DEGREE(pGFpx); - pInfo->elementLen = GFP_FELEN32(pGFpx); - - return ippStsNoErr; -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.c b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.c deleted file mode 100644 index ae9a1f49..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.c +++ /dev/null @@ -1,1307 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Performance Primitives. Cryptography Primitives. -// Internal operations over GF(p) extension. -// -// Context: -// cpGFpxCmpare -// cpGFpxSet -// cpGFpxRand -// cpGFpxGet -// -// cpGFpxHalve -// cpGFpxAdd, cpGFpxAdd_GFE -// cpGFpxSub, cpGFpxSub_GFE -// cpGFpxMul, cpGFpxMul_GFE -// cpGFp2biMul, cpGFp3biMul, cpGFpxMul_G0 -// cpGFpxSqr -// cpGFp2biSqr, cpGFp3biSqr -// cpGFpxNeg -// cpGFpxInv -// cpGFpxExp -// cpGFpxMultiExp -// cpGFpxConj -// -// -*/ - -#include "owncpepid.h" - -#include "pcpgfpxstuff.h" -//#include "pcptool.h" - - -/* -// compare GF. -// returns: -// 0 - are equial -// 1 - are different -// 2 - different structure -*/ -int cpGFpxCompare(const IppsGFpState* pGFpx1, const IppsGFpState* pGFpx2) -{ - while( !GFP_IS_BASIC(pGFpx1) && !GFP_IS_BASIC(pGFpx2) ) { - if( GFP_DEGREE(pGFpx1) != GFP_DEGREE(pGFpx2) ) - return 2; - if( GFP_FELEN(pGFpx1) != GFP_FELEN(pGFpx2) ) - return 1; - if(0 != cpGFpElementCmp(GFP_MODULUS(pGFpx1), GFP_MODULUS(pGFpx1), GFP_FELEN(pGFpx1)) ) - return 1; - pGFpx1 = GFP_GROUNDGF(pGFpx1); - pGFpx2 = GFP_GROUNDGF(pGFpx2); - } - - return (GFP_IS_BASIC(pGFpx1) && GFP_IS_BASIC(pGFpx2))? cpGFpCompare(pGFpx1, pGFpx2) : 2; -} - -BNU_CHUNK_T* cpGFpxRand(BNU_CHUNK_T* pR, IppsGFpState* pGFpx, IppBitSupplier rndFunc, void* pRndParam, int montSpace) -{ - if( GFP_IS_BASIC(pGFpx) ) - return cpGFpRand(pR, pGFpx, rndFunc, pRndParam, montSpace); - - else { - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicDeg = cpGFpBasicDegreeExtension(pGFpx); - - BNU_CHUNK_T* pTmp = pR; - int deg; - for(deg=0; deg0; deg++) { - int pieceA = IPP_MIN(nsA, basicElemLen); - - cpGFpGet(pTmp, pieceA, pE, pBasicGF, montSpace); - pE += basicElemLen; - pTmp += pieceA; - nsA -= pieceA; - } - - return pDataA; - } -} - -BNU_CHUNK_T* cpGFpxGetPolyTerm(BNU_CHUNK_T* pDataA, int nsA, const BNU_CHUNK_T* pE, int deg, IppsGFpState* pGFpx, int montSpace) -{ - pE += deg * GFP_FELEN(pGFpx); - return cpGFpxGet(pDataA, nsA, pE, pGFpx, montSpace); -} - -BNU_CHUNK_T* cpGFpxHalve(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicDeg = cpGFpBasicDegreeExtension(pGFpx); - - BNU_CHUNK_T* pTmp = pR; - int deg; - for(deg=0; degdiv2(pTmp, pA, pBasicGF); - pTmp += basicElemLen; - pA += basicElemLen; - } - return pR; -} - -BNU_CHUNK_T* cpGFpxAdd(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicDeg = cpGFpBasicDegreeExtension(pGFpx); - - BNU_CHUNK_T* pTmp = pR; - int deg; - for(deg=0; degadd(pTmp, pA, pB, pBasicGF); - pTmp += basicElemLen; - pA += basicElemLen; - pB += basicElemLen; - } - return pR; -} - -BNU_CHUNK_T* cpGFpxSub(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicDeg = cpGFpBasicDegreeExtension(pGFpx); - - BNU_CHUNK_T* pTmp = pR; - int deg; - for(deg=0; degsub(pTmp, pA, pB, pBasicGF); - pTmp += basicElemLen; - pA += basicElemLen; - pB += basicElemLen; - } - return pR; -} - -BNU_CHUNK_T* cpGFpxConj(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int groundElemLen = GFP_FELEN(pGroundGF); - - if(pR != pA) - cpGFpElementCopy(pR, pA, groundElemLen); - //cpGFpxNeg(pR+groundElemLen, pA+groundElemLen, pGroundGF); - pGroundGF->neg(pR+groundElemLen, pA+groundElemLen, pGroundGF); - - return pR; -} - - -/* -// multiplication like GF(()^d).mul(a, g0), -// where: -// a, g0 belongs to ground GF() -// and g0 is low-order term of GF(()^d) generationg binominal g(t) = t^d + g0 -// is very important for Intel(R) EPID 2.0. -// -// Thus, this kind of multiplication is using -// 1) in iplementation of GF(p^2) multiplication -// 2) in iplementation of GF((p^6)^2) multiplication too -*/ -#if defined(_EPID20_GF_PARAM_SPECIFIC_) -#pragma message ("_EPID20_GF_PARAM_SPECIFIC_") - -__INLINE BNU_CHUNK_T* cpFqMul_beta(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - if(pR != pA) - cpGFpElementCopy(pR, pA, GFP_FELEN(pGFpx)); - return pR; -} - -__INLINE BNU_CHUNK_T* cpFq2Mul_xi(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - BNU_CHUNK_T* t0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t1 = cpGFpGetPool(1, pGroundGF); - - int termLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+termLen; - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+termLen; - pGroundGF->add(t0, pA0, pA0, pGroundGF); - pGroundGF->add(t1, pA0, pA1, pGroundGF); - pGroundGF->sub(pR0, t0, pA1, pGroundGF); - pGroundGF->add(pR1, t1, pA1, pGroundGF); - - cpGFpReleasePool(2, pGroundGF); - return pR; -} - -__INLINE BNU_CHUNK_T* cpFq6Mul_vi(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int termLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+termLen; - const BNU_CHUNK_T* pA2 = pA+termLen*2; - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+termLen; - BNU_CHUNK_T* pR2 = pR+termLen*2; - - BNU_CHUNK_T* t = cpGFpGetPool(1, pGroundGF); - - cpFq2Mul_xi(t, pA2, pGroundGF); - cpGFpElementCopy(pR2, pA1, termLen); - cpGFpElementCopy(pR1, pA0, termLen); - cpGFpElementCopy(pR0, t, termLen); - - cpGFpReleasePool(1, pGroundGF); - - return pR; -} -#endif - -#if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) || defined(_EXTENSION_3_BINOMIAL_SUPPORT_) -static BNU_CHUNK_T* cpGFpxMul_G0(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - BNU_CHUNK_T* pGFpolynomial = GFP_MODULUS(pGFpx); /* g(x) = t^d + g0 */ - return pGroundGF->mul(pR, pA, pGFpolynomial, GFP_GROUNDGF(pGFpx)); -} -#endif - -/* -// field polynomial: g(x) = t^2 + beta - binominal -// extension degree: 2 -*/ -#if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) -static BNU_CHUNK_T* cpGFp2biMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+groundElemLen; - - const BNU_CHUNK_T* pB0 = pB; - const BNU_CHUNK_T* pB1 = pB+groundElemLen; - - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+groundElemLen; - - BNU_CHUNK_T* t0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t1 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t2 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t3 = cpGFpGetPool(1, pGroundGF); - - pGroundGF->mul(t0, pA0, pB0, pGroundGF); /* t0 = a[0]*b[0] */ - pGroundGF->mul(t1, pA1, pB1, pGroundGF); /* t1 = a[1]*b[1] */ - pGroundGF->add(t2, pA0, pA1,pGroundGF); /* t2 = a[0]+a[1] */ - pGroundGF->add(t3, pB0, pB1,pGroundGF); /* t3 = b[0]+b[1] */ - - pGroundGF->mul(pR1, t2, t3, pGroundGF); /* r[1] = (a[0]+a[1]) * (b[0]+b[1]) */ - pGroundGF->sub(pR1, pR1, t0, pGroundGF); /* r[1] -= a[0]*b[0]) + a[1]*b[1] */ - pGroundGF->sub(pR1, pR1, t1, pGroundGF); - - #if defined(_EPID20_GF_PARAM_SPECIFIC_) /* r[0] = t0 - t1*beta */ - { - int basicExtDegree = cpGFpBasicDegreeExtension(pGFpx); - if(basicExtDegree==2 && EPID_PARAMS(pGFpx)) { - //cpFqMul_beta(t1, t1, pGroundGF); - pGroundGF->sub(pR0, t0, t1, pGroundGF); - } - else if(basicExtDegree==12 && EPID_PARAMS(pGFpx)) { - cpFq6Mul_vi(t1, t1, pGroundGF); - pGroundGF->add(pR0, t0, t1, pGroundGF); - } - else { - cpGFpxMul_G0(t1, t1, pGFpx); - pGroundGF->sub(pR0, t0, t1, pGroundGF); - } - } - #else - cpGFpxMul_G0(t1, t1, pGFpx); - pGroundGF->sub(pR0, t0, t1, pGroundGF); - #endif - - cpGFpReleasePool(4, pGroundGF); - return pR; -} -#endif - -/* -// field polynomial: g(x) = t^3 + beta - binominal -// extension degree: 3 -*/ -#if defined(_EXTENSION_3_BINOMIAL_SUPPORT_) -static BNU_CHUNK_T* cpGFp3biMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+groundElemLen; - const BNU_CHUNK_T* pA2 = pA+groundElemLen*2; - - const BNU_CHUNK_T* pB0 = pB; - const BNU_CHUNK_T* pB1 = pB+groundElemLen; - const BNU_CHUNK_T* pB2 = pB+groundElemLen*2; - - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+groundElemLen; - BNU_CHUNK_T* pR2 = pR+groundElemLen*2; - - BNU_CHUNK_T* t0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t1 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t2 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* u0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* u1 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* u2 = cpGFpGetPool(1, pGroundGF); - - pGroundGF->add(u0 ,pA0, pA1, pGroundGF); /* u0 = a[0]+a[1] */ - pGroundGF->add(t0 ,pB0, pB1, pGroundGF); /* t0 = b[0]+b[1] */ - pGroundGF->mul(u0, u0, t0, pGroundGF); /* u0 = (a[0]+a[1])*(b[0]+b[1]) */ - pGroundGF->mul(t0, pA0, pB0, pGroundGF); /* t0 = a[0]*b[0] */ - - pGroundGF->add(u1 ,pA1, pA2, pGroundGF); /* u1 = a[1]+a[2] */ - pGroundGF->add(t1 ,pB1, pB2, pGroundGF); /* t1 = b[1]+b[2] */ - pGroundGF->mul(u1, u1, t1, pGroundGF); /* u1 = (a[1]+a[2])*(b[1]+b[2]) */ - pGroundGF->mul(t1, pA1, pB1, pGroundGF); /* t1 = a[1]*b[1] */ - - pGroundGF->add(u2 ,pA2, pA0, pGroundGF); /* u2 = a[2]+a[0] */ - pGroundGF->add(t2 ,pB2, pB0, pGroundGF); /* t2 = b[2]+b[0] */ - pGroundGF->mul(u2, u2, t2, pGroundGF); /* u2 = (a[2]+a[0])*(b[2]+b[0]) */ - pGroundGF->mul(t2, pA2, pB2, pGroundGF); /* t2 = a[2]*b[2] */ - - pGroundGF->sub(u0, u0, t0, pGroundGF); /* u0 = a[0]*b[1]+a[1]*b[0] */ - pGroundGF->sub(u0, u0, t1, pGroundGF); - pGroundGF->sub(u1, u1, t1, pGroundGF); /* u1 = a[1]*b[2]+a[2]*b[1] */ - pGroundGF->sub(u1, u1, t2, pGroundGF); - pGroundGF->sub(u2, u2, t2, pGroundGF); /* u2 = a[2]*b[0]+a[0]*b[2] */ - pGroundGF->sub(u2, u2, t0, pGroundGF); - - #if defined(_EPID20_GF_PARAM_SPECIFIC_) - { - int basicExtDegree = cpGFpBasicDegreeExtension(pGFpx); - if(basicExtDegree==6 && EPID_PARAMS(pGFpx)) { - cpFq2Mul_xi(u1, u1, pGroundGF); - cpFq2Mul_xi(t2, t2, pGroundGF); - pGroundGF->add(pR0, t0, u1, pGroundGF); /* r[0] = a[0]*b[0] - (a[2]*b[1]+a[1]*b[2])*beta */ - pGroundGF->add(pR1, u0, t2, pGroundGF); /* r[1] = a[1]*b[0] + a[0]*b[1] - a[2]*b[2]*beta */ - } - else { - cpGFpxMul_G0(u1, u1, pGFpx); /* u1 = (a[1]*b[2]+a[2]*b[1]) * beta */ - cpGFpxMul_G0(t2, t2, pGFpx); /* t2 = a[2]*b[2] * beta */ - pGroundGF->sub(pR0, t0, u1, pGroundGF); /* r[0] = a[0]*b[0] - (a[2]*b[1]+a[1]*b[2])*beta */ - pGroundGF->sub(pR1, u0, t2, pGroundGF); /* r[1] = a[1]*b[0] + a[0]*b[1] - a[2]*b[2]*beta */ - } - } - #else - cpGFpxMul_G0(u1, u1, pGFpx); /* u1 = (a[1]*b[2]+a[2]*b[1]) * beta */ - cpGFpxMul_G0(t2, t2, pGFpx); /* t2 = a[2]*b[2] * beta */ - - pGroundGF->sub(pR0, t0, u1, pGroundGF); /* r[0] = a[0]*b[0] - (a[2]*b[1]+a[1]*b[2])*beta */ - pGroundGF->sub(pR1, u0, t2, pGroundGF); /* r[1] = a[1]*b[0] + a[0]*b[1] - a[2]*b[2]*beta */ - #endif - - pGroundGF->add(pR2, u2, t1, pGroundGF); /* r[2] = a[2]*b[0] + a[1]*b[1] + a[0]*b[2] */ - - cpGFpReleasePool(6, pGroundGF); - return pR; -} -#endif - -BNU_CHUNK_T* cpGFpxMul(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, IppsGFpState* pGFpx) -{ - int extDegree = GFP_DEGREE(pGFpx); - - #if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) - #pragma message ("_EXTENSION_2_BINOMIAL_SUPPORT_") - if(BINOMIAL==FIELD_POLY_TYPE(pGFpx) && extDegree==2) - return cpGFp2biMul(pR, pA, pB, pGFpx); - #endif - - #if defined(_EXTENSION_3_BINOMIAL_SUPPORT_) - #pragma message ("_EXTENSION_3_BINOMIAL_SUPPORT_") - if(BINOMIAL==FIELD_POLY_TYPE(pGFpx) && extDegree==3) - return cpGFp3biMul(pR, pA, pB, pGFpx); - #endif - - { - BNU_CHUNK_T* pGFpolynomial = GFP_MODULUS(pGFpx); - int degR = extDegree-1; - int elemLen= GFP_FELEN(pGFpx); - - int degB = degR; - BNU_CHUNK_T* pTmpProduct = cpGFpGetPool(2, pGFpx); - BNU_CHUNK_T* pTmpResult = pTmpProduct + GFP_PELEN(pGFpx); - - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - BNU_CHUNK_T* r = cpGFpGetPool(1, pGroundGF); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pTmpB = GFPX_IDX_ELEMENT(pB, degB, groundElemLen); - - /* clear temporary */ - cpGFpElementPadd(pTmpProduct, elemLen, 0); - - /* R = A * B[degB-1] */ - cpGFpxMul_GFE(pTmpResult, pA, pTmpB, pGFpx); - - for(degB-=1; degB>=0; degB--) { - /* save R[degR-1] */ - cpGFpElementCopy(r, GFPX_IDX_ELEMENT(pTmpResult, degR, groundElemLen), groundElemLen); - - { /* R = R * x */ - int j; - for (j=degR; j>=1; j--) - cpGFpElementCopy(GFPX_IDX_ELEMENT(pTmpResult, j, groundElemLen), GFPX_IDX_ELEMENT(pTmpResult, j-1, groundElemLen), groundElemLen); - cpGFpElementPadd(pTmpResult, groundElemLen, 0); - } - - cpGFpxMul_GFE(pTmpProduct, pGFpolynomial, r, pGFpx); - pGFpx->sub(pTmpResult, pTmpResult, pTmpProduct, pGFpx); - - /* B[degB-i] */ - pTmpB -= groundElemLen; - cpGFpxMul_GFE(pTmpProduct, pA, pTmpB, pGFpx); - pGFpx->add(pTmpResult, pTmpResult, pTmpProduct, pGFpx); - } - - /* copy result */ - cpGFpElementCopy(pR, pTmpResult, elemLen); - - /* release pools */ - cpGFpReleasePool(1, pGroundGF); - cpGFpReleasePool(2, pGFpx); - - return pR; - } -} - -/* -// field polynomial: binominal -// extension degree: 2 -*/ -#if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) -static BNU_CHUNK_T* cpGFp2biSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+groundElemLen; - - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+groundElemLen; - - BNU_CHUNK_T* t0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* t1 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* u0 = cpGFpGetPool(1, pGroundGF); - - pGroundGF->mul(u0, pA0, pA1, pGroundGF); /* u0 = a[0]*a[1] */ - - #if defined(_EPID20_GF_PARAM_SPECIFIC_) /* r[0] = t0 - t1*beta */ - { - int basicExtDegree = cpGFpBasicDegreeExtension(pGFpx); - if(basicExtDegree==2 && EPID_PARAMS(pGFpx)) { - pGroundGF->add(t0, pA0, pA1, pGroundGF); - pGroundGF->sub(t1, pA0, pA1, pGroundGF); - pGroundGF->mul(pR0, t0, t1, pGroundGF); - pGroundGF->add(pR1, u0, u0, pGroundGF); /* r[1] = 2*a[0]*a[1] */ - } - else if(basicExtDegree==12 && EPID_PARAMS(pGFpx)) { - pGroundGF->sub(t0, pA0, pA1, pGroundGF); - cpFq6Mul_vi(t1, pA1, pGroundGF); - pGroundGF->sub(t1, pA0, t1, pGroundGF); - pGroundGF->mul(t0, t0, t1, pGroundGF); - pGroundGF->add(t0, t0, u0, pGroundGF); - cpFq6Mul_vi(t1, u0, pGroundGF); - pGroundGF->add(pR0, t0, t1, pGroundGF); - pGroundGF->add(pR1, u0, u0, pGroundGF); - } - else { - pGroundGF->sqr(t0, pA0, pGroundGF); /* t0 = a[0]*a[0] */ - pGroundGF->sqr(t1, pA1, pGroundGF); /* t1 = a[1]*a[1] */ - cpGFpxMul_G0(t1, t1, pGFpx); - pGroundGF->sub(pR0, t0, t1, pGroundGF); - pGroundGF->add(pR1, u0, u0, pGroundGF); /* r[1] = 2*a[0]*a[1] */ - } - } - #else - pGroundGF->sqr(t0, pA0, pGroundGF); /* t0 = a[0]*a[0] */ - pGroundGF->sqr(t1, pA1, pGroundGF); /* t1 = a[1]*a[1] */ - cpGFpxMul_G0(t1, t1, pGFpx); - pGroundGF->sub(pR0, t0, t1, pGroundGF); - pGroundGF->add(pR1, u0, u0, pGroundGF); /* r[1] = 2*a[0]*a[1] */ - #endif - - cpGFpReleasePool(3, pGroundGF); - return pR; -} -#endif - -/* -// field polynomial: binominal -// extension degree: 3 -*/ -#if defined(_EXTENSION_3_BINOMIAL_SUPPORT_) -static BNU_CHUNK_T* cpGFp3biSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pA0 = pA; - const BNU_CHUNK_T* pA1 = pA+groundElemLen; - const BNU_CHUNK_T* pA2 = pA+groundElemLen*2; - - BNU_CHUNK_T* pR0 = pR; - BNU_CHUNK_T* pR1 = pR+groundElemLen; - BNU_CHUNK_T* pR2 = pR+groundElemLen*2; - - BNU_CHUNK_T* s0 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* s1 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* s2 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* s3 = cpGFpGetPool(1, pGroundGF); - BNU_CHUNK_T* s4 = cpGFpGetPool(1, pGroundGF); - - pGroundGF->add(s2, pA0, pA2, pGroundGF); - pGroundGF->sub(s2, s2, pA1, pGroundGF); - pGroundGF->sqr(s2, s2, pGroundGF); - pGroundGF->sqr(s0, pA0, pGroundGF); - pGroundGF->sqr(s4, pA2, pGroundGF); - pGroundGF->mul(s1, pA0, pA1, pGroundGF); - pGroundGF->mul(s3, pA1, pA2, pGroundGF); - pGroundGF->add(s1, s1, s1, pGroundGF); - pGroundGF->add(s3, s3, s3, pGroundGF); - - pGroundGF->add(pR2, s1, s2, pGroundGF); - pGroundGF->add(pR2, pR2, s3, pGroundGF); - pGroundGF->sub(pR2, pR2, s0, pGroundGF); - pGroundGF->sub(pR2, pR2, s4, pGroundGF); - - #if defined(_EPID20_GF_PARAM_SPECIFIC_) - { - int basicExtDegree = cpGFpBasicDegreeExtension(pGFpx); - if(basicExtDegree==6 && EPID_PARAMS(pGFpx)) { - cpFq2Mul_xi(s4, s4, pGroundGF); - cpFq2Mul_xi(s3, s3, pGroundGF); - pGroundGF->add(pR1, s1, s4, pGroundGF); - pGroundGF->add(pR0, s0, s3, pGroundGF); - } - else { - cpGFpxMul_G0(s4, s4, pGFpx); - cpGFpxMul_G0(s3, s3, pGFpx); - pGroundGF->sub(pR1, s1, s4, pGroundGF); - pGroundGF->sub(pR0, s0, s3, pGroundGF); - } - } - - #else - cpGFpxMul_G0(s4, s4, pGFpx); - pGroundGF->sub(pR1, s1, s4, pGroundGF); - - cpGFpxMul_G0(s3, s3, pGFpx); - pGroundGF->sub(pR0, s0, s3, pGroundGF); - #endif - - cpGFpReleasePool(5, pGroundGF); - return pR; -} -#endif - -BNU_CHUNK_T* cpGFpxSqr(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - int extDegree = GFP_DEGREE(pGFpx); - - #if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) - #pragma message ("_EXTENSION_2_BINOMIAL_SUPPORT_") - if(BINOMIAL==FIELD_POLY_TYPE(pGFpx) && extDegree==2) - return cpGFp2biSqr(pR, pA, pGFpx); - #endif - - #if defined(_EXTENSION_3_BINOMIAL_SUPPORT_) - #pragma message ("_EXTENSION_3_BINOMIAL_SUPPORT_") - if(BINOMIAL==FIELD_POLY_TYPE(pGFpx) && extDegree==3) - return cpGFp3biSqr(pR, pA, pGFpx); - #endif - - { - BNU_CHUNK_T* pGFpolynomial = GFP_MODULUS(pGFpx); - int degR = extDegree-1; - int elemLen= GFP_FELEN(pGFpx); - - int degA = degR; - BNU_CHUNK_T* pTmpProduct = cpGFpGetPool(2, pGFpx); - BNU_CHUNK_T* pTmpResult = pTmpProduct + GFP_PELEN(pGFpx); - - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - BNU_CHUNK_T* r = cpGFpGetPool(1, pGroundGF); - int groundElemLen = GFP_FELEN(pGroundGF); - - const BNU_CHUNK_T* pTmpA = GFPX_IDX_ELEMENT(pA, degA, groundElemLen); - - /* clear temporary */ - cpGFpElementPadd(pTmpProduct, elemLen, 0); - - /* R = A * A[degA-1] */ - cpGFpxMul_GFE(pTmpResult, pA, pTmpA, pGFpx); - - for(degA-=1; degA>=0; degA--) { - /* save R[degR-1] */ - cpGFpElementCopy(r, GFPX_IDX_ELEMENT(pTmpResult, degR, groundElemLen), groundElemLen); - - { /* R = R * x */ - int j; - for (j=degR; j>=1; j--) - cpGFpElementCopy(GFPX_IDX_ELEMENT(pTmpResult, j, groundElemLen), GFPX_IDX_ELEMENT(pTmpResult, j-1, groundElemLen), groundElemLen); - cpGFpElementPadd(pTmpResult, groundElemLen, 0); - } - - cpGFpxMul_GFE(pTmpProduct, pGFpolynomial, r, pGFpx); - pGFpx->sub(pTmpResult, pTmpResult, pTmpProduct, pGFpx); - - /* A[degA-i] */ - pTmpA -= groundElemLen; - cpGFpxMul_GFE(pTmpProduct, pA, pTmpA, pGFpx); - pGFpx->add(pTmpResult, pTmpResult, pTmpProduct, pGFpx); - } - - /* copy result */ - cpGFpElementCopy(pR, pTmpResult, elemLen); - - /* release pools */ - cpGFpReleasePool(1, pGroundGF); - cpGFpReleasePool(2, pGFpx); - - return pR; - } -} - -BNU_CHUNK_T* cpGFpxAdd_GFE(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pGroundB, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - - if(pR != pA) { - int groundElemLen = GFP_FELEN(pGroundGF); - int deg = GFP_DEGREE(pGFpx); - cpGFpElementCopy(pR+groundElemLen, pA+groundElemLen, groundElemLen*(deg-1)); - } - return pGroundGF->add(pR, pA, pGroundB, pGroundGF); -} - -BNU_CHUNK_T* cpGFpxSub_GFE(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pGroundB, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - - if(pR != pA) { - int groundElemLen = GFP_FELEN(pGroundGF); - int deg = GFP_DEGREE(pGFpx); - cpGFpElementCopy(pR+groundElemLen, pA+groundElemLen, groundElemLen*(deg-1)); - } - return pGroundGF->sub(pR, pA, pGroundB, pGroundGF); -} - -BNU_CHUNK_T* cpGFpxMul_GFE(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pGroundB, IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - int grounfElemLen = GFP_FELEN(pGroundGF); - - BNU_CHUNK_T* pTmp = pR; - - int deg; - for(deg=0; degmul(pTmp, pA, pGroundB, pGroundGF); - pTmp += grounfElemLen; - pA += grounfElemLen; - } - return pR; -} - -BNU_CHUNK_T* cpGFpxNeg(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicElemLen = GFP_FELEN(pBasicGF); - int basicDeg = cpGFpBasicDegreeExtension(pGFpx); - - BNU_CHUNK_T* pTmp = pR; - int deg; - for(deg=0; degneg(pTmp, pA, pBasicGF); - pTmp += basicElemLen; - pA += basicElemLen; - } - return pR; -} - -////////////////////////////////////////////////////////////////// -BNU_CHUNK_T* gfpolyDiv_v0(BNU_CHUNK_T* pQ, BNU_CHUNK_T* pR, - const BNU_CHUNK_T* pA, - const BNU_CHUNK_T* pB, - IppsGFpState* pGFpx) -{ - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFpx); - - if( GFP_IS_BASIC(pGroundGF) ) { - int elemLen = GFP_FELEN(pGFpx); - int termLen = GFP_FELEN(pGroundGF); - - int degA = degree(pA, pGFpx); - int degB = degree(pB, pGFpx); - - if(degB==0) { - if( GFP_IS_ZERO(pB, termLen) ) - return NULL; - else { - cpGFpInv(pR, pB, pGroundGF); - cpGFpElementPadd(pQ, elemLen, 0); - cpGFpxMul_GFE(pQ, pA, pR, pGFpx); - cpGFpElementPadd(pR, elemLen, 0); - return pR; - } - } - - if(degA < degB) { - cpGFpElementPadd(pQ, elemLen, 0); - cpGFpElementCopyPadd(pR, elemLen, pA, (degA+1)*termLen); - return pR; - } - - else { - int i, j; - BNU_CHUNK_T* pProduct = cpGFpGetPool(2, pGroundGF); - BNU_CHUNK_T* pInvB = pProduct + GFP_PELEN(pGroundGF); - - cpGFpElementCopyPadd(pR, elemLen, pA, (degA+1)*termLen); - cpGFpElementPadd(pQ, elemLen, 0); - - cpGFpInv(pInvB, GFPX_IDX_ELEMENT(pB, degB, termLen), pGroundGF); - - for(i=0; i<=degA-degB && !GFP_IS_ZERO(GFPX_IDX_ELEMENT(pR, degA-i, termLen), termLen); i++) { - /* compute q term */ - cpGFpMul(GFPX_IDX_ELEMENT(pQ, degA-degB-i, termLen), - GFPX_IDX_ELEMENT(pR, degA-i, termLen), - pInvB, - pGroundGF); - - /* R -= B * q */ - cpGFpElementPadd(GFPX_IDX_ELEMENT(pR, degA-i, termLen), termLen, 0); - for(j=0; j 0) { - gfpxPolyDiv(quo, temp, lastrem, rem, pGFpx); - SWAP_PTR(BNU_CHUNK_T, rem, lastrem); // - SWAP_PTR(BNU_CHUNK_T, temp, rem); - - cpGFpxNeg(quo, quo, pGFpx); - cpGFpxMul(temp, quo, aux, pGFpx); - cpGFpxAdd(temp, lastaux, temp, pGFpx); - SWAP_PTR(BNU_CHUNK_T, aux, lastaux); - SWAP_PTR(BNU_CHUNK_T, temp, aux); - } - if (GFP_IS_ZERO(rem, elemLen)) { /* gcd != 1 */ - cpGFpReleasePool(pxVars, pGFpx); - return NULL; - } - - { - BNU_CHUNK_T* invRem = cpGFpGetPool(1, pGroundGF); - - cpGFpxInv(invRem, rem, pGroundGF); - cpGFpxMul_GFE(pR, aux, invRem, pGFpx); - - cpGFpReleasePool(1, pGroundGF); - } - - cpGFpReleasePool(pxVars, pGFpx); - - return pR; - } -} - - -static int div_upper(int a, int d) -{ return (a+d-1)/d; } - -static int getNumOperations(int bitsize, int w) -{ - int n_overhead = (1<=n_opt) break; - w_opt = w_trial; - n_opt = n_trial; - } - return w_opt; -#undef LIMIT -} - - -/* sscm version */ -BNU_CHUNK_T* cpGFpxExp(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pE, int nsE, - IppsGFpState* pGFpx, Ipp8u* pScratchBuffer) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - - /* remove leding zeros */ - FIX_BNU(pE, nsE); - - { - Ipp8u* pScratchAligned; /* aligned scratch buffer */ - int nAllocation = 0; /* points from the pool */ - - /* size of element (bytes) */ - int elmDataSize = GFP_FELEN(pGFpx)*sizeof(BNU_CHUNK_T); - - /* exponent bitsize */ - int expBitSize = BITSIZE_BNU(pE, nsE); - /* optimal size of window */ - int w = (NULL==pScratchBuffer)? 1 : cpGFpGetOptimalWinSize(expBitSize); - /* number of table entries */ - int nPrecomputed = 1<mul(pTmp, pTmp, pA, pGFpx); - cpScramblePut(pScratchAligned+n, nPrecomputed, (Ipp8u*)pTmp, elmDataSize); - } - } - - { - /* copy exponent value */ - cpGFpElementCopy(pExpandedE, pE, nsE); - - /* expand exponent value */ - ((Ipp32u*)pExpandedE)[BITS2WORD32_SIZE(expBitSize)] = 0; - expBitSize = ((expBitSize+w-1)/w)*w; - - /* - // exponentiation - */ - { - /* digit mask */ - BNU_CHUNK_T dmask = nPrecomputed-1; - - /* position (bit number) of the leftmost window */ - int wPosition = expBitSize-w; - - /* extract leftmost window value */ - Ipp32u eChunk = *((Ipp32u*)((Ipp16u*)pExpandedE+ wPosition/BITSIZE(Ipp16u))); - int shift = wPosition & 0xF; - Ipp32u windowVal = (eChunk>>shift) & dmask; - - /* initialize result */ - cpScrambleGet((Ipp8u*)pR, elmDataSize, pScratchAligned+windowVal, nPrecomputed); - - for(wPosition-=w; wPosition>=0; wPosition-=w) { - int k; - /* w times squaring */ - for(k=0; ksqr(pR, pR, pGFpx); - - /* extract next window value */ - eChunk = *((Ipp32u*)((Ipp16u*)pExpandedE+ wPosition/BITSIZE(Ipp16u))); - shift = wPosition & 0xF; - windowVal = (eChunk>>shift) & dmask; - - /* extract value from the pre-computed table */ - cpScrambleGet((Ipp8u*)pTmp, elmDataSize, pScratchAligned+windowVal, nPrecomputed); - - /* and multiply */ - pGFpx->mul(pR, pR, pTmp, pGFpx); - } - } - - } - - cpGFpReleasePool(nAllocation+2, pGFpx); - - return pR; - } -} - - -static void cpPrecomputeMultiExp(Ipp8u* pTable, const BNU_CHUNK_T* ppA[], int nItems, IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - - int nPrecomputed = 1<=0; k--) { - int tblIdx = baseIdx; - - int n; - for(n=0; nmul(pT, pT, ppA[k], pGFpx); - cpScramblePut(pTable+tblIdx+step, nPrecomputed, (Ipp8u*)pT, elmDataSize); - } - - nPasses *= 2; - step /= 2; - } - } - } - } - - /* release resourse */ - cpGFpReleasePool(1, pGFpx); -} - -static int cpGetMaxBitsizeExponent(const BNU_CHUNK_T* ppE[], int nsE[], int nItems) -{ - int n; - /* find out the longest exponent */ - int expBitSize = BITSIZE_BNU(ppE[0], nsE[0]); - for(n=1; n0; n--) { - const Ipp8u* pE = ((Ipp8u*)ppE[n-1]) + offset; - Ipp8u e = pE[0]; - index <<= 1; - index += (e>>shift) &1; - } - return index; -} - -/* sscm version */ -BNU_CHUNK_T* cpGFpxMultiExp(BNU_CHUNK_T* pR, const BNU_CHUNK_T* ppA[], const BNU_CHUNK_T* ppE[], int nsE[], int nItems, - IppsGFpState* pGFpx, Ipp8u* pScratchBuffer) -{ - /* align scratch buffer */ - Ipp8u* pScratchAligned = IPP_ALIGNED_PTR(pScratchBuffer, CACHE_LINE_SIZE); - /* pre-compute table */ - cpPrecomputeMultiExp(pScratchAligned, ppA, nItems, pGFpx); - - { - /* find out the longest exponent */ - int expBitSize = cpGetMaxBitsizeExponent(ppE, nsE, nItems); - - /* allocate resource and copy expanded exponents into */ - const BNU_CHUNK_T* ppExponent[LOG2_CACHE_LINE_SIZE]; - { - int n; - for(n=0; n=0; expBitSize--) { - pGFpx->sqr(pR, pR, pGFpx); - tblIdx = GetIndex(ppExponent, nItems, expBitSize); - cpScrambleGet((Ipp8u*)pT, elmDataSize, pScratchAligned+tblIdx, nPrecomputed); - pGFpx->mul(pR, pR, pT, pGFpx); - } - - /* release resourse */ - cpGFpReleasePool(1, pGFpx); - } - - /* release resourse */ - cpGFpReleasePool(nItems, pGFpx); - - return pR; - } -} diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.h b/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.h deleted file mode 100644 index e887034a..00000000 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcpepid/src/pcpgfpxstuff.h +++ /dev/null @@ -1,174 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/* -// Intel(R) Integrated Performance Primitives -// Cryptographic Primitives (ippCP) -// GF(p) extension internal -// -*/ - -#if !defined(_PCP_GFPEXT_H_) -#define _PCP_GFPEXT_H_ - -#include "pcpgfpstuff.h" - - -#define _EXTENSION_2_BINOMIAL_SUPPORT_ -#define _EXTENSION_3_BINOMIAL_SUPPORT_ - -#if defined(_EXTENSION_2_BINOMIAL_SUPPORT_) && defined(_EXTENSION_3_BINOMIAL_SUPPORT_) - /* Intel(R) EPID specific: - (Fq2) GF(q^2) generating polynomial is g(t) = t^2 + beta, beta = 1 - - */ - #define _EPID20_GF_PARAM_SPECIFIC_ -#endif - -/* GF(p^d) pool */ -#define GFPX_PESIZE(pGF) GFP_FELEN((pGF)) -#define GFPX_POOL_SIZE (14) //(8) /* Number of temporary variables in pool */ - -/* address of ground field element inside expanded field element */ -#define GFPX_IDX_ELEMENT(pxe, idx, eleSize) ((pxe)+(eleSize)*(idx)) - -#if 0 -/* internal function prototypes */ -__INLINE BNU_CHUNK_T* cpGFpxGetPool(int n, IppsGFpState* pGFpx) -{ - BNU_CHUNK_T* pPool = GFP_POOL(pGFpx); - GFP_POOL(pGFpx) += n*GFPX_PESIZE(pGFpx); - return pPool; -} -__INLINE void cpGFpxReleasePool(int n, IppsGFpState* pGFpx) -{ - GFP_POOL(pGFpx) -= n * GFPX_PESIZE(pGFpx); -} -#endif - -__INLINE int degree(const BNU_CHUNK_T* pE, const IppsGFpState* pGFpx) -{ - int groundElemLen = GFP_FELEN( (IppsGFpState*)GFP_GROUNDGF(pGFpx) ); - int deg; - for(deg=GFP_DEGREE(pGFpx)-1; deg>=0; deg-- ) { - if(!GFP_IS_ZERO(pE+groundElemLen*deg, groundElemLen)) break; - } - return deg; -} - -__INLINE IppsGFpState* cpGFpBasic(const IppsGFpState* pGFp) -{ - while( !GFP_IS_BASIC(pGFp) ) { - pGFp = GFP_GROUNDGF(pGFp); - } - return (IppsGFpState*)pGFp; -} -__INLINE int cpGFpBasicDegreeExtension(const IppsGFpState* pGFp) -{ - int degree = GFP_DEGREE(pGFp); - while( !GFP_IS_BASIC(pGFp) ) { - IppsGFpState* pGroundGF = GFP_GROUNDGF(pGFp); - degree *= GFP_DEGREE(pGroundGF); - pGFp = pGroundGF; - } - return degree; -} - -/* convert external data (Ipp32u) => internal element (BNU_CHUNK_T) representation - returns length of element (in BNU_CHUNK_T) -*/ -__INLINE int cpGFpxCopyToChunk(BNU_CHUNK_T* pElm, const Ipp32u* pA, int nsA, const IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicExtension = cpGFpBasicDegreeExtension(pGFpx); - int basicElmLen32 = GFP_FELEN32(pBasicGF); - int basicElmLen = GFP_FELEN(pBasicGF); - int deg; - for(deg=0; deg0; deg++, nsA -= basicElmLen32) { - int srcLen = IPP_MIN(nsA, basicElmLen32); - ZEXPAND_COPY_BNU((Ipp32u*)pElm, basicElmLen*(int)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)), pA,srcLen); - pElm += basicElmLen; - pA += basicElmLen32; - } - return basicElmLen*deg; -} - -/* convert internal element (BNU_CHUNK_T) => external data (Ipp32u) representation - returns length of data (in Ipp32u) -*/ -__INLINE int cpGFpxCopyFromChunk(Ipp32u* pA, const BNU_CHUNK_T* pElm, const IppsGFpState* pGFpx) -{ - IppsGFpState* pBasicGF = cpGFpBasic(pGFpx); - int basicExtension = cpGFpBasicDegreeExtension(pGFpx); - int basicElmLen32 = GFP_FELEN32(pBasicGF); - int basicElmLen = GFP_FELEN(pBasicGF); - int deg; - for(deg=0; deg -#include -#include -#include - -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "util/buffutil.h" -#include "util/strutil.h" -#include "epid/common/types.h" -#include "epid/common/file_parser.h" - -#define PROGRAM_NAME "extractgrps" - -#pragma pack(1) -/// EPID Key Output File Entry -typedef struct EpidBinaryGroupCertificate { - EpidFileHeader header; ///< EPID binary file header - GroupPubKey pubkey; ///< EPID 2.0 group public key - EcdsaSignature signature; ///< ECDSA Signature on SHA-256 of above values -} EpidBinaryGroupCertificate; -#pragma pack() - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_SUCCESS; - - size_t keyfile_size = 0; - size_t num_keys_extracted = 0; - size_t num_keys_in_file = 0; - - char* end = NULL; - FILE* file = NULL; - - unsigned int i = 0; - size_t bytes_read = 0; - - // File to extract keys from - static char* keyfile_name = NULL; - - // Number of keys to extract - static size_t num_keys_to_extract = 0; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - dropt_option options[] = { - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - // set program name for logging - set_prog_name(PROGRAM_NAME); - do { - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - ret_value = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]... [FILE] [NUM]\n" - "Extract the first NUM group certs from FILE to current " - "directory\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else { - // number of arguments rest - size_t rest_count = 0; - - if (verbose) { - verbose = ToggleVerbosity(); - } - - // count number of arguments rest - while (rest[rest_count]) rest_count++; - - if (2 != rest_count) { - log_error("unexpected number of arguments", *rest); - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } - - keyfile_name = rest[0]; - - num_keys_to_extract = strtoul(rest[1], &end, 10); - if ('\0' != *end) { - log_error("input '%s' is invalid: not a valid number of group keys", - rest[1]); - ret_value = EXIT_FAILURE; - break; - } - } - } - - // check file existence - if (!FileExists(keyfile_name)) { - log_error("cannot access '%s'", keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - - keyfile_size = GetFileSize(keyfile_name); - if (0 != keyfile_size % sizeof(EpidBinaryGroupCertificate)) { - log_error( - "input file '%s' is invalid: does not contain integral number of " - "group keys", - keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - num_keys_in_file = keyfile_size / sizeof(EpidBinaryGroupCertificate); - - if (num_keys_to_extract > num_keys_in_file) { - log_error("can not extract %d keys: only %d in file", num_keys_to_extract, - num_keys_in_file); - ret_value = EXIT_FAILURE; - break; - } - - file = fopen(keyfile_name, "rb"); - if (!file) { - log_error("failed read from '%s'", keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - - // start extraction - for (i = 0; i < num_keys_to_extract; i++) { - EpidBinaryGroupCertificate temp; - int seek_failed = 0; - seek_failed = fseek(file, i * sizeof(temp), SEEK_SET); - bytes_read = fread(&temp, 1, sizeof(temp), file); - if (seek_failed || bytes_read != sizeof(temp)) { - log_error("failed to extract key #%lu from '%s'", i, keyfile_name); - } else { - // ulong max = 4294967295 - char outkeyname[256] = {0}; - if (memcmp(&kEpidVersionCode[kEpid2x], &temp.header.epid_version, - sizeof(temp.header.epid_version)) || - memcmp(&kEpidFileTypeCode[kGroupPubKeyFile], &temp.header.file_type, - sizeof(temp.header.file_type))) { - log_error("failed to extract key #%lu from '%s': file is invalid", i, - keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - snprintf(outkeyname, sizeof(outkeyname), "pubkey%010u.bin", i); - if (FileExists(outkeyname)) { - log_error("file '%s' already exists", outkeyname); - ret_value = EXIT_FAILURE; - break; - } - if (0 != WriteLoud(&temp, sizeof(temp), outkeyname)) { - log_error("failed to write key #%lu from '%s'", i, keyfile_name); - } else { - num_keys_extracted++; - } - } - } - if (EXIT_FAILURE == ret_value) { - break; - } - - log_msg("extracted %lu of %lu keys", num_keys_extracted, num_keys_in_file); - } while (0); - - if (file) { - fclose(file); - file = NULL; - } - - dropt_free_context(dropt_ctx); - - return ret_value; -} diff --git a/external/epid-sdk-3.0.0/tools/extractkeys/extractkeys.parts b/external/epid-sdk-3.0.0/tools/extractkeys/extractkeys.parts deleted file mode 100644 index 89e3f0d9..00000000 --- a/external/epid-sdk-3.0.0/tools/extractkeys/extractkeys.parts +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("extractkeys") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() - -parts_file = ['extractkeys.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='tools/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='tools/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('common'), - Component('util'), - Component('dropt') - ]) - - if env['TARGET_PLATFORM']['OS'] == 'win32': - env.Append(CPPDEFINES='_CRT_SECURE_NO_WARNINGS') - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_TOOLS_BIN}') diff --git a/external/epid-sdk-3.0.0/tools/extractkeys/src/main.c b/external/epid-sdk-3.0.0/tools/extractkeys/src/main.c deleted file mode 100644 index 6754a6db..00000000 --- a/external/epid-sdk-3.0.0/tools/extractkeys/src/main.c +++ /dev/null @@ -1,252 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Extract member private keys from EPID key output file - * - * Not validating SHA hashes in key file - */ - -#include -#include - -#include -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "util/buffutil.h" -#include "util/strutil.h" -#include "epid/common/types.h" - -#define PROGRAM_NAME "extractkeys" -#define MANDATORY_PARAM_COUNT 2 - -#pragma pack(1) -/// EPID Key Output File Entry -typedef struct EpidKeyOutputFileKey { - unsigned char product_id[2]; ///< 2-byte Product ID (Big Endian) - unsigned char key_id[8]; ///< 8-byte Key Unique Id(Big Endian) - unsigned char svn[4]; ///< 4-byte Security Version Number (SVN) (Big Endian) - PrivKey privkey; ///< EPID 2.0 Private Key - unsigned char hash[20]; ///< 20-byte SHA-1 of above -} EpidKeyOutputFileKey; - -/// EPID Compressed Key Output File Entry -typedef struct EpidCompressedKeyOutputFileKey { - unsigned char product_id[2]; ///< 2-byte Product ID (Big Endian) - unsigned char key_id[8]; ///< 8-byte Key Unique Id(Big Endian) - unsigned char svn[4]; ///< 4-byte Security Version Number (SVN) (Big Endian) - CompressedPrivKey privkey; ///< EPID 2.0 Compressed Private Key - unsigned char hash[20]; ///< 20-byte SHA-1 of above -} EpidCompressedKeyOutputFileKey; -#pragma pack() - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_SUCCESS; - // Buffer to store read key - uint8_t temp[sizeof(EpidKeyOutputFileKey)] = {0}; - - // Private key to extract - void* privkey = 0; - size_t privkey_size = 0; - - size_t keyfile_size = 0; - size_t keyfile_entry_size = 0; - size_t num_keys_extracted = 0; - size_t num_keys_in_file = 0; - - char* end = NULL; - FILE* file = NULL; - - // File to extract keys from - static char* keyfile_name = NULL; - - // Number of keys to extract - static size_t num_keys_to_extract = 0; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - // Compressed flag parameter - static bool compressed = false; - - unsigned int i = 0; - size_t bytes_read = 0; - - dropt_option options[] = { - {'c', "compressed", "extract compressed keys", NULL, dropt_handle_bool, - &compressed}, - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - (void)argc; - // set program name for logging - set_prog_name(PROGRAM_NAME); - - do { - dropt_ctx = dropt_new_context(options); - - if (dropt_ctx && argc > 0) { - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]... [FILE] [NUM]\n" - - "Extract the first NUM private keys from FILE to current " - "directory.\n\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else { - size_t rest_count = 0; - if (verbose) verbose = ToggleVerbosity(); - - // count number of arguments rest - while (rest[rest_count]) rest_count++; - if (rest_count != MANDATORY_PARAM_COUNT) { - log_error( - "%s arguments: found %i positional arguments, expected %i", - (rest_count < MANDATORY_PARAM_COUNT) ? "missing" : "too many", - rest_count, MANDATORY_PARAM_COUNT); - - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } - - keyfile_name = *(rest); - - num_keys_to_extract = strtoul(*(rest + 1), &end, 10); - if ('\0' != *end) { - log_error("input '%s' is invalid: not a valid number of keys", - *(rest + 1)); - ret_value = EXIT_FAILURE; - break; - } - } - - } else { - ret_value = EXIT_FAILURE; - break; - } - - // check file existence - if (!FileExists(keyfile_name)) { - log_error("cannot access '%s'", keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - - keyfile_size = GetFileSize(keyfile_name); - if (compressed) { - privkey_size = sizeof(CompressedPrivKey); - privkey = &(((EpidCompressedKeyOutputFileKey*)&temp[0])->privkey); - keyfile_entry_size = sizeof(EpidCompressedKeyOutputFileKey); - } else { - privkey_size = sizeof(PrivKey); - privkey = &(((EpidKeyOutputFileKey*)&temp[0])->privkey); - keyfile_entry_size = sizeof(EpidKeyOutputFileKey); - } - - if (0 != keyfile_size % keyfile_entry_size) { - log_error( - "input file '%s' is invalid: does not contain integral number of " - "keys", - keyfile_name); - ret_value = EXIT_FAILURE; - break; - } - num_keys_in_file = keyfile_size / keyfile_entry_size; - - if (num_keys_to_extract > num_keys_in_file) { - log_error("can not extract %d keys: only %d in file", num_keys_to_extract, - num_keys_in_file); - ret_value = EXIT_FAILURE; - break; - } - - file = fopen(keyfile_name, "rb"); - if (!file) { - log_error("failed read from '%s'", keyfile_name); - - ret_value = EXIT_FAILURE; - break; - } - - // start extraction - for (i = 0; i < num_keys_to_extract; ++i) { - int seek_failed = 0; - seek_failed = fseek(file, (int)(i * keyfile_entry_size), SEEK_SET); - bytes_read = fread(&temp, 1, keyfile_entry_size, file); - if (seek_failed || bytes_read != keyfile_entry_size) { - log_error("failed to extract key #%lu from '%s'", i, keyfile_name); - } else { - char outkeyname[256] = {0}; - snprintf(outkeyname, sizeof(outkeyname), "mprivkey%010u.dat", i); - - if (FileExists(outkeyname)) { - log_error("file '%s' already exists", outkeyname); - ret_value = EXIT_FAILURE; - break; - } - if (0 != WriteLoud(privkey, privkey_size, outkeyname)) { - log_error("failed to write key #%lu from '%s'", i, keyfile_name); - } else { - num_keys_extracted++; - } - } - } - if (EXIT_FAILURE == ret_value) { - break; - } - - log_msg("extracted %lu of %lu keys", num_keys_extracted, num_keys_in_file); - } while (0); - - if (file) { - fclose(file); - file = NULL; - } - - dropt_free_context(dropt_ctx); - dropt_ctx = NULL; - - return ret_value; -} diff --git a/external/epid-sdk-3.0.0/tools/revokegrp/revokegrp.parts b/external/epid-sdk-3.0.0/tools/revokegrp/revokegrp.parts deleted file mode 100644 index 053c88fe..00000000 --- a/external/epid-sdk-3.0.0/tools/revokegrp/revokegrp.parts +++ /dev/null @@ -1,46 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("revokegrp") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() - -parts_file = ['revokegrp.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='tools/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='tools/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('common'), - Component('util'), - Component('dropt') - ]) - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_TOOLS_BIN}') diff --git a/external/epid-sdk-3.0.0/tools/revokegrp/src/main.c b/external/epid-sdk-3.0.0/tools/revokegrp/src/main.c deleted file mode 100644 index 72131507..00000000 --- a/external/epid-sdk-3.0.0/tools/revokegrp/src/main.c +++ /dev/null @@ -1,382 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Create group revocation list request - * - */ - -#include -#include -#include -#include "util/buffutil.h" -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "epid/common/file_parser.h" - -const OctStr16 kEpidFileVersion = {2, 0}; - -// Defaults -#define PROGRAM_NAME "revokegrp" -#define PUBKEYFILE_DEFAULT "pubkey.bin" -#define REQFILE_DEFAULT "grprlreq.dat" -#define REASON_DEFAULT 0 -#define GROUP_PUB_KEY_SIZE \ - (sizeof(EpidFileHeader) + sizeof(GroupPubKey) + sizeof(EcdsaSignature)) -#define STRINGIZE(a) #a - -#pragma pack(1) -/// Group revocation request entry -typedef struct GrpInfo { - GroupId gid; ///< EPID Group ID - uint8_t reason; ///< Revocation reason -} GrpInfo; -/// Group Revocation request -typedef struct GrpRlRequest { - EpidFileHeader header; ///< EPID File Header - uint32_t count; ///< Revoked count (big endian) - GrpInfo groups[1]; ///< Revoked group count (flexible array) -} GrpRlRequest; -#pragma pack() - -/// convert host to network byte order -static uint32_t htonl(uint32_t hostlong) { - return (((hostlong & 0xFF) << 24) | ((hostlong & 0xFF00) << 8) | - ((hostlong & 0xFF0000) >> 8) | ((hostlong & 0xFF000000) >> 24)); -} -/// convert network to host byte order -static uint32_t ntohl(uint32_t netlong) { - return (((netlong & 0xFF) << 24) | ((netlong & 0xFF00) << 8) | - ((netlong & 0xFF0000) >> 8) | ((netlong & 0xFF000000) >> 24)); -} - -/// Makes a request and appends it to file. -/*! -\param[in] cacert_file -Issuing CA certificate used to sign group public key file. -\param[in] pubkey_file -File containing group public key. -\param[in] req_file -File to write a request. -\param[in] reason -Revokation reason. -\param[in] verbose -If true function would print debug information to stdout. -*/ -int MakeRequest(char const* cacert_file, char const* pubkey_file, - char const* req_file, uint8_t reason, bool verbose); - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_FAILURE; - - // User Settings - - // Group revocation request file name parameter - static char* req_file = NULL; - - // Group public key file name parameter - static char* pubkey_file = NULL; - - // CA certificate file name parameter - static char* cacert_file = NULL; - - // Revocation reason - static uint32_t reason = REASON_DEFAULT; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - dropt_option options[] = { - {'\0', "gpubkey", - "load group public key from FILE (default: " PUBKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &pubkey_file}, - {'\0', "capubkey", "load IoT Issuing CA public key from FILE", "FILE", - dropt_handle_string, &cacert_file}, - {'\0', "reason", - "revocation reason (default: " STRINGIZE(REASON_DEFAULT) ")", "FILE", - dropt_handle_uint, &reason}, - {'\0', "req", - "append signature revocation request to FILE (default: " REQFILE_DEFAULT - ")", - "FILE", dropt_handle_string, &req_file}, - - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - dropt_context* dropt_ctx = NULL; - // set program name for logging - set_prog_name(PROGRAM_NAME); - do { - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - ret_value = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]...\n" - "Revoke Intel(R) EPID group\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else if (*rest) { - // we have unparsed (positional) arguments - log_error("invalid argument: %s", *rest); - fprintf(stderr, "Try '%s --help' for more information\n", PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } else { - if (reason > UCHAR_MAX) { - log_error( - "unexpected reason value. Value of the reason must be lesser or " - "equal to %d", - UCHAR_MAX); - ret_value = EXIT_FAILURE; - break; - } - if (verbose) { - verbose = ToggleVerbosity(); - } - if (!pubkey_file) { - pubkey_file = PUBKEYFILE_DEFAULT; - } - if (!cacert_file) { - log_error("issuing CA public key must be specified"); - ret_value = EXIT_FAILURE; - break; - } - if (!req_file) { - req_file = REQFILE_DEFAULT; - } - if (verbose) { - log_msg("\nOption values:"); - log_msg(" pubkey_file : %s", pubkey_file); - log_msg(" cacert_file : %s", cacert_file); - log_msg(" reason : %d", reason); - log_msg(" req_file : %s", req_file); - log_msg(""); - } - } - } - - ret_value = MakeRequest(cacert_file, pubkey_file, req_file, (uint8_t)reason, - verbose); - } while (0); - dropt_free_context(dropt_ctx); - return ret_value; -} - -int MakeRequest(char const* cacert_file, char const* pubkey_file, - char const* req_file, uint8_t reason, bool verbose) { - // Group index and count - uint32_t grp_index = 0; - uint32_t grp_count = 0; - - // Buffers and computed values - // Group public key file - unsigned char* pubkey_file_data = NULL; - size_t pubkey_file_size = 0; - - // Group public key buffer - GroupPubKey pubkey = {0}; - - // CA certificate - EpidCaCertificate cacert = {0}; - - // Request buffer - uint8_t* req_buf = NULL; - size_t req_size = 0; - size_t req_file_size = 0; - GrpRlRequest* request = NULL; - size_t req_extra_space = sizeof(GroupId) + sizeof(uint8_t); - - int ret_value = EXIT_FAILURE; - do { - if (!cacert_file || !pubkey_file || !req_file) { - log_error("internal error: badarg to MakeRequest()"); - ret_value = EXIT_FAILURE; - break; - } - - // convert command line args to usable formats - // CA certificate - if (0 != ReadLoud(cacert_file, &cacert, sizeof(cacert))) { - ret_value = EXIT_FAILURE; - break; - } - - // Group public key file - pubkey_file_data = NewBufferFromFile(pubkey_file, &pubkey_file_size); - if (!pubkey_file_data) { - ret_value = EXIT_FAILURE; - break; - } - - // Security note: - // Application must confirm group public key is - // authorized by the issuer, e.g., signed by the issuer. - if (GROUP_PUB_KEY_SIZE != pubkey_file_size) { - log_error("unexpected file size for '%s'. Expected: %d; got: %d", - pubkey_file, (int)GROUP_PUB_KEY_SIZE, pubkey_file_size); - ret_value = EXIT_FAILURE; - break; - } - if (kEpidNoErr != EpidParseGroupPubKeyFile(pubkey_file_data, - pubkey_file_size, &cacert, - &pubkey)) { - log_error("group public key is not authorized"); - ret_value = EXIT_FAILURE; - break; - } - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Input settings:"); - log_msg(""); - log_msg(" [in] Group ID: "); - PrintBuffer(&pubkey.gid, sizeof(pubkey.gid)); - log_msg(""); - log_msg(" [in] Reason: %d", reason); - log_msg("=============================================="); - } - - // Calculate request size - req_size = sizeof(EpidFileHeader) + sizeof(uint32_t); - - if (FileExists(req_file)) { - req_file_size = GetFileSize_S(req_file, SIZE_MAX - req_extra_space); - - if (req_file_size < req_size) { - log_error("output file smaller then size of empty request"); - ret_value = EXIT_FAILURE; - break; - } - - req_size = req_file_size; - } else { - log_msg("request file does not exsist, create new"); - } - - req_size += req_extra_space; - - // Allocate request buffer - req_buf = AllocBuffer(req_size); - if (!req_buf) { - ret_value = EXIT_FAILURE; - break; - } - - request = (GrpRlRequest*)req_buf; - - // Load existing request file - if (req_file_size > 0) { - if (0 != ReadLoud(req_file, req_buf, req_file_size)) { - ret_value = EXIT_FAILURE; - break; - } - - // Check EPID and file versions - if (0 != memcmp(&request->header.epid_version, &kEpidFileVersion, - sizeof(kEpidFileVersion))) { - ret_value = EXIT_FAILURE; - break; - } - - if (0 != memcmp(&request->header.file_type, - &kEpidFileTypeCode[kGroupRlRequestFile], - sizeof(kEpidFileTypeCode[kGroupRlRequestFile]))) { - ret_value = EXIT_FAILURE; - break; - } - - grp_count = ntohl(request->count); - - // Update the reason if the group is in the request - for (grp_index = 0; grp_index < grp_count; grp_index++) { - if (0 == memcmp(&request->groups[grp_index].gid, &pubkey.gid, - sizeof(pubkey.gid))) { - request->groups[grp_index].reason = reason; - req_size = req_file_size; - break; - } - } - } - - // Append group to the request - if (grp_index == grp_count) { - request->header.epid_version = kEpidFileVersion; - request->header.file_type = kEpidFileTypeCode[kGroupRlRequestFile]; - request->groups[grp_count].gid = pubkey.gid; - request->groups[grp_count].reason = reason; - request->count = htonl(++grp_count); - } - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Request generated:"); - log_msg(""); - log_msg(" [in] Request Len: %d", (int)req_size); - log_msg(" [in] Request: "); - PrintBuffer(req_buf, req_size); - log_msg("=============================================="); - } - - // Store request - if (0 != WriteLoud(req_buf, req_size, req_file)) { - ret_value = EXIT_FAILURE; - break; - } - - // Success - ret_value = EXIT_SUCCESS; - } while (0); - - // Free allocated buffers - if (pubkey_file_data) free(pubkey_file_data); - if (req_buf) free(req_buf); - - return ret_value; -} diff --git a/external/epid-sdk-3.0.0/tools/revokekey/revokekey.parts b/external/epid-sdk-3.0.0/tools/revokekey/revokekey.parts deleted file mode 100644 index 55173499..00000000 --- a/external/epid-sdk-3.0.0/tools/revokekey/revokekey.parts +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("revokekey") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() - -parts_file = ['revokekey.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='tools/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='tools/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('common'), - Component('member'), - Component('util'), - Component('dropt') - ]) - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_TOOLS_BIN}') diff --git a/external/epid-sdk-3.0.0/tools/revokekey/src/main.c b/external/epid-sdk-3.0.0/tools/revokekey/src/main.c deleted file mode 100644 index 9ce068f2..00000000 --- a/external/epid-sdk-3.0.0/tools/revokekey/src/main.c +++ /dev/null @@ -1,356 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Create private key revocation list request - * - */ - -#include -#include -#include - -#include "util/buffutil.h" -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "epid/common/file_parser.h" -#include "epid/member/api.h" - -const OctStr16 kEpidFileVersion = {2, 0}; - -// Defaults -#define PROGRAM_NAME "revokekey" -#define PRIVKEY_DEFAULT "mprivkey.dat" -#define REQFILE_DEFAULT "privreq.dat" -#define PUBKEYFILE_DEFAULT "pubkey.bin" - -/// Partial signature request, includes all but message. -typedef struct PrivRlRequestTop { - EpidFileHeader header; ///< EPID File Header - PrivKey privkey; ///< EPID Private Key -} PrivRlRequestTop; - -int OpenKey(char const* privkey_file, char const* gpubkey_file, - char const* cacert_file, PrivKey* priv_key) { - int retval = EXIT_FAILURE; - size_t file_size = GetFileSize(privkey_file); - - if (0 == file_size && !FileExists(privkey_file)) { - log_error("cannot access '%s'", privkey_file); - return EXIT_FAILURE; - } - - if (file_size == sizeof(PrivKey)) { - if (0 != ReadLoud(privkey_file, priv_key, sizeof(PrivKey))) { - return EXIT_FAILURE; - } - retval = EXIT_SUCCESS; - } else if (file_size == sizeof(CompressedPrivKey)) { - void* signed_pubkey = NULL; - if (!cacert_file) { - log_error("issuing CA public key must be specified for compressed key"); - return EXIT_FAILURE; - } - if (!gpubkey_file) { - log_error("group public key must be specified for compressed key"); - return EXIT_FAILURE; - } - - do { - size_t signed_pubkey_size = 0; - CompressedPrivKey cmp_key; - EpidCaCertificate cacert; - GroupPubKey pub_key; - EpidStatus sts; - if (0 != ReadLoud(privkey_file, &cmp_key, sizeof(CompressedPrivKey))) { - retval = EXIT_FAILURE; - break; - } - signed_pubkey = NewBufferFromFile(gpubkey_file, &signed_pubkey_size); - if (!signed_pubkey) { - retval = EXIT_FAILURE; - break; - } - if (0 != ReadLoud(gpubkey_file, signed_pubkey, signed_pubkey_size)) { - retval = EXIT_FAILURE; - break; - } - if (0 != ReadLoud(cacert_file, &cacert, sizeof(cacert))) { - retval = EXIT_FAILURE; - break; - } - sts = EpidParseGroupPubKeyFile(signed_pubkey, signed_pubkey_size, &cacert, - &pub_key); - if (kEpidNoErr != sts) { - log_error("error while parsing group public key"); - retval = EXIT_FAILURE; - break; - } - sts = EpidDecompressPrivKey(&pub_key, &cmp_key, priv_key); - if (kEpidNoErr != sts) { - log_error("error while decompressing member private key"); - retval = EXIT_FAILURE; - break; - } - retval = EXIT_SUCCESS; - } while (0); - free(signed_pubkey); - } else { - log_error("unexpected file size for '%s'", privkey_file); - retval = EXIT_FAILURE; - } - return retval; -} - -int MakeRequest(PrivKey priv_key, char const* req_file, bool verbose) { - // Request buffer - uint8_t* req_buf = NULL; - size_t req_size = 0; - size_t req_extra_space = 0; - int ret_value = EXIT_FAILURE; - do { - size_t entry_size = sizeof(EpidFileHeader) + sizeof(PrivKey); - size_t req_file_size = 0; - bool duplicate = false; - size_t i = 0; - PrivRlRequestTop* req_top = NULL; - - if (!req_file) { - log_error("internal error: badarg to MakeRequest()"); - ret_value = EXIT_FAILURE; - break; - } - - // convert command line args to usable formats - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Input settings:"); - log_msg(""); - log_msg(" [in] Group ID: "); - PrintBuffer(&(priv_key.gid), sizeof(priv_key.gid)); - log_msg(""); - log_msg(" [in] Private Key Len: %d", sizeof(PrivKey)); - log_msg(" [in] Private Key: "); - PrintBuffer(&(priv_key), sizeof(PrivKey)); - log_msg(""); - log_msg("=============================================="); - } - - req_extra_space += entry_size; - if (FileExists(req_file)) { - req_file_size = GetFileSize_S(req_file, SIZE_MAX - req_extra_space); - - if (req_file_size < entry_size) { - log_error("output file smaller then size of one entry"); - ret_value = EXIT_FAILURE; - break; - } - - if (req_file_size % entry_size != 0) { - log_error("size of output file is not multiple of the entry size"); - ret_value = EXIT_FAILURE; - break; - } - } else { - log_msg("request file does not exsist, create new"); - } - - req_size = req_file_size + req_extra_space; - - req_buf = AllocBuffer(req_size); - if (!req_buf) { - ret_value = EXIT_FAILURE; - break; - } - - // Load existing request file - if (req_file_size > 0) { - if (0 != ReadLoud(req_file, req_buf, req_file_size)) { - ret_value = EXIT_FAILURE; - break; - } - - for (i = 0; i < req_file_size / entry_size; i++) { - if (0 == memcmp(req_buf + entry_size * i + sizeof(EpidFileHeader), - &(priv_key), sizeof(PrivKey))) { - duplicate = true; - break; - } - } - if (duplicate) { - log_error("this private key already exists in output file"); - ret_value = EXIT_FAILURE; - break; - } - } - - // Append to the request - req_top = (PrivRlRequestTop*)(req_buf + req_file_size); - req_top->header.epid_version = kEpidFileVersion; - req_top->header.file_type = kEpidFileTypeCode[kPrivRlRequestFile]; - req_top->privkey = priv_key; - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Request generated:"); - log_msg(""); - log_msg(" [in] Request Len: %d", sizeof(PrivRlRequestTop)); - log_msg(" [in] Request: "); - PrintBuffer(&req_top, sizeof(PrivRlRequestTop)); - log_msg("=============================================="); - } - - // Store request - if (0 != WriteLoud(req_buf, req_size, req_file)) { - ret_value = EXIT_FAILURE; - break; - } - - ret_value = EXIT_SUCCESS; - } while (0); - - // Free allocated buffers - if (req_buf) free(req_buf); - - return ret_value; -} - -/// Main entrypoint -int main(int argc, char* argv[]) { - int retval = EXIT_FAILURE; - - // User Settings - // Private key file name parameter - static char* privkey_file = NULL; - static char* gpubkey_file = NULL; - static char* capubkey_file = NULL; - - // Private key revocation request file name parameter - static char* req_file = NULL; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - // Private key - PrivKey priv_key; - - dropt_option options[] = { - {'\0', "mprivkey", - "load private key to revoke from FILE (default: " PRIVKEY_DEFAULT ")", - "FILE", dropt_handle_string, &privkey_file}, - {'\0', "req", - "append signature revocation request to FILE (default: " REQFILE_DEFAULT - ")", - "FILE", dropt_handle_string, &req_file}, - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - {'\0', '\0', "The following options are only needed for compressed keys:", - NULL, dropt_handle_string, NULL}, - {'\0', "gpubkey", - "load group public key from FILE (default: " PUBKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &gpubkey_file}, - {'\0', "capubkey", "load IoT Issuing CA public key from FILE", "FILE", - dropt_handle_string, &capubkey_file}, - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - - // set program name for logging - set_prog_name(PROGRAM_NAME); - - do { - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - retval = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - retval = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]...\n" - "Revoke Intel(R) EPID signature\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - retval = EXIT_SUCCESS; - break; - } else if (*rest) { - // we have unparsed (positional) arguments - log_error("invalid argument: %s", *rest); - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - retval = EXIT_FAILURE; - break; - } else { - if (verbose) { - verbose = ToggleVerbosity(); - } - if (!privkey_file) { - privkey_file = PRIVKEY_DEFAULT; - } - if (!gpubkey_file) { - gpubkey_file = PUBKEYFILE_DEFAULT; - } - if (!req_file) { - req_file = REQFILE_DEFAULT; - } - if (verbose) { - log_msg("\nOption values:"); - log_msg(" mprivkey : %s", privkey_file); - log_msg(" req : %s", req_file); - log_msg(" gpubkey : %s", gpubkey_file); - log_msg(" capubkey : %s", capubkey_file); - log_msg(""); - } - } - } - - retval = OpenKey(privkey_file, gpubkey_file, capubkey_file, &priv_key); - if (EXIT_SUCCESS != retval) { - break; - } - retval = MakeRequest(priv_key, req_file, verbose); - } while (0); - - dropt_free_context(dropt_ctx); - - return retval; -} diff --git a/external/epid-sdk-3.0.0/tools/revokesig/revokesig.parts b/external/epid-sdk-3.0.0/tools/revokesig/revokesig.parts deleted file mode 100644 index 5dc108de..00000000 --- a/external/epid-sdk-3.0.0/tools/revokesig/revokesig.parts +++ /dev/null @@ -1,46 +0,0 @@ -############################################################################ -# Copyright 2016 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -############################################################################ - -Import('*') - -env.PartName("revokesig") - -src_files = Pattern(src_dir='src/', - includes=['*.c'], - recursive=True).files() - -parts_file = ['revokesig.parts'] - -if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='tools/${PART_SHORT_NAME}/src') - env.InstallTopLevel(parts_file, sub_dir='tools/${PART_SHORT_NAME}') -else: - env.DependsOn([ - Component('common'), - Component('util'), - Component('dropt') - ]) - - if env['TARGET_PLATFORM']['OS'] == 'win32': - if env.isConfigBasedOn('debug'): - env['PDB'] = '${PART_NAME}.pdb' - - outputs = env.Program('${PART_NAME}', src_files, - no_import_lib=True) - - env.InstallBin(outputs, - no_pkg=False, - INSTALL_BIN='${INSTALL_TOOLS_BIN}') diff --git a/external/epid-sdk-3.0.0/tools/revokesig/src/main.c b/external/epid-sdk-3.0.0/tools/revokesig/src/main.c deleted file mode 100644 index 861e3895..00000000 --- a/external/epid-sdk-3.0.0/tools/revokesig/src/main.c +++ /dev/null @@ -1,455 +0,0 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ - -/*! - * \file - * - * \brief Create signature based revocation list request - * - */ - -#include -#include -#include -#include "util/buffutil.h" -#include "util/envutil.h" -#include "util/stdtypes.h" -#include "epid/common/file_parser.h" - -// Defaults -#define PROGRAM_NAME "revokesig" -#define PUBKEYFILE_DEFAULT "pubkey.bin" -#define REQFILE_DEFAULT "sigrlreq.dat" -#define SIG_DEFAULT "sig.dat" -#define GROUP_PUB_KEY_SIZE \ - (sizeof(EpidFileHeader) + sizeof(GroupPubKey) + sizeof(EcdsaSignature)) - -#pragma pack(1) -/// Partial signature request, includes components through sig. -typedef struct SigRlRequestTop { - EpidFileHeader header; ///< EPID File Header - GroupId gid; ///< EPID Group ID - EpidSignature sig; ///< EPID Signature -} SigRlRequestTop; - -/// Partial signature request, includes components after. -typedef struct SigRlRequestMid { - uint32_t be_msg_size; ///< size of message in bytes (big endian) - uint8_t msg[1]; ///< message used to create signature (flexible array) -} SigRlRequestMid; -#pragma pack() - -/// convert host to network byte order -static uint32_t htonl(uint32_t hostlong) { - return (((hostlong & 0xFF) << 24) | ((hostlong & 0xFF00) << 8) | - ((hostlong & 0xFF0000) >> 8) | ((hostlong & 0xFF000000) >> 24)); -} - -/// Fill a single SigRlRequest structure -/*! -\param[in] pubkey -Group public key. -\param[in] sig -Signature to append to request. -\param[in] sig_size -Size of the signature. -\param[in] msg_str -Message used to generate signature to revoke. -\param[in] msg_size -Length of the message. -\param[in out] req_buf -Pointer to request buffer. -\param[in] req_size -Size of request buffer. -\param[in out] req_top -Pointer to top structure of request. -*/ -void FillRequest(GroupPubKey const* pubkey, EpidSignature const* sig, - size_t sig_size, char const* msg_str, size_t msg_size, - uint8_t* req_buf, size_t req_size, SigRlRequestTop* req_top); - -/// Makes a request and appends it to file. -/*! -\param[in] cacert_file -Issuing CA certificate used to sign group public key file. -\param[in] sig_file -File containing signature to add to request. -\param[in] pubkey_file -File containing group public key. -\param[in] req_file -File to write a request. -\param[in] msg_str -Message used to generate signature to revoke. -\param[in] msg_size -Length of the message. -\param[in] verbose -If true function would print debug information to stdout. -*/ -int MakeRequest(char const* cacert_file, char const* sig_file, - char const* pubkey_file, char const* req_file, - char const* msg_str, size_t msg_size, bool verbose); - -/// Main entrypoint -int main(int argc, char* argv[]) { - // intermediate return value for C style functions - int ret_value = EXIT_FAILURE; - - // Signature file name parameter - static char* sig_file = NULL; - - // Message string parameter - static char* msg_str = NULL; - size_t msg_size = 0; - static char* msg_file = NULL; - char* msg_buf = NULL; // message loaded from msg_file - - // Signature revocation request file name parameter - static char* req_file = NULL; - - // Group public key file name parameter - static char* pubkey_file = NULL; - - // CA certificate file name parameter - static char* cacert_file = NULL; - - // help flag parameter - static bool show_help = false; - - // Verbose flag parameter - static bool verbose = false; - - dropt_option options[] = { - {'\0', "sig", - "load signature to revoke from FILE (default: " SIG_DEFAULT ")", "FILE", - dropt_handle_string, &sig_file}, - {'\0', "msg", "MESSAGE used to generate signature to revoke", "MESSAGE", - dropt_handle_string, &msg_str}, - {'\0', "msgfile", - "FILE containing message used to generate signature to revoke", "FILE", - dropt_handle_string, &msg_file}, - {'\0', "gpubkey", - "load group public key from FILE (default: " PUBKEYFILE_DEFAULT ")", - "FILE", dropt_handle_string, &pubkey_file}, - {'\0', "capubkey", "load IoT Issuing CA public key from FILE", "FILE", - dropt_handle_string, &cacert_file}, - {'\0', "req", - "append signature revocation request to FILE (default: " REQFILE_DEFAULT - ")", - "FILE", dropt_handle_string, &req_file}, - - {'h', "help", "display this help and exit", NULL, dropt_handle_bool, - &show_help, dropt_attr_halt}, - {'v', "verbose", "print status messages to stdout", NULL, - dropt_handle_bool, &verbose}, - - {0} /* Required sentinel value. */ - }; - - dropt_context* dropt_ctx = NULL; - // set program name for logging - set_prog_name(PROGRAM_NAME); - do { - dropt_ctx = dropt_new_context(options); - if (!dropt_ctx) { - ret_value = EXIT_FAILURE; - break; - } else if (argc > 0) { - /* Parse the arguments from argv. - * - * argv[1] is always safe to access since argv[argc] is guaranteed - * to be NULL and since we've established that argc > 0. - */ - char** rest = dropt_parse(dropt_ctx, -1, &argv[1]); - if (dropt_get_error(dropt_ctx) != dropt_error_none) { - log_error(dropt_get_error_message(dropt_ctx)); - if (dropt_error_invalid_option == dropt_get_error(dropt_ctx)) { - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - } - ret_value = EXIT_FAILURE; - break; - } else if (show_help) { - log_fmt( - "Usage: %s [OPTION]...\n" - "Revoke Intel(R) EPID signature\n" - "\n" - "Options:\n", - PROGRAM_NAME); - dropt_print_help(stdout, dropt_ctx, NULL); - ret_value = EXIT_SUCCESS; - break; - } else if (*rest) { - // we have unparsed (positional) arguments - log_error("invalid argument: %s", *rest); - fprintf(stderr, "Try '%s --help' for more information.\n", - PROGRAM_NAME); - ret_value = EXIT_FAILURE; - break; - } else { - if (verbose) { - verbose = ToggleVerbosity(); - } - if (!sig_file) { - sig_file = SIG_DEFAULT; - } - - if (msg_str && msg_file) { - log_error("--msg and --msgfile cannot be used together"); - ret_value = EXIT_FAILURE; - break; - } else if (msg_str) { - msg_size = strlen(msg_str); - } else if (msg_file) { - msg_buf = NewBufferFromFile(msg_file, &msg_size); - if (!msg_buf) { - ret_value = EXIT_FAILURE; - break; - } - msg_str = msg_buf; - } else { - msg_size = 0; - } - - if (!pubkey_file) { - pubkey_file = PUBKEYFILE_DEFAULT; - } - if (!cacert_file) { - log_error("issuing CA public key must be specified"); - ret_value = EXIT_FAILURE; - break; - } - if (!req_file) { - req_file = REQFILE_DEFAULT; - } - if (verbose) { - log_msg("\nOption values:"); - log_msg(" sig_file : %s", sig_file); - log_msg(" msg_str : %s", msg_str); - log_msg(" pubkey_file : %s", pubkey_file); - log_msg(" cacert_file : %s", cacert_file); - log_msg(" req_file : %s", req_file); - log_msg(""); - } - } - } - - ret_value = MakeRequest(cacert_file, sig_file, pubkey_file, req_file, - msg_str, msg_size, verbose); - } while (0); - - if (msg_buf) { - free(msg_buf); - msg_buf = NULL; - } - - dropt_free_context(dropt_ctx); - - return ret_value; -} - -/// Fill a single SigRlRequest structure -/*! - - | Field | Size | - |:--------------------------------|--------------:| - | EPID Version (0x0200) | 2 bytes | - | File Type (0x000B) | 2 bytes | - | Group ID Number | 16 bytes | - | Basic Signature | 52 bytes | - | SigRL Version | 4 bytes | - | Number of Non-Revoked Proofs | 4 bytes | - | nNRP * Non-Revoked Proofs | 160 * nNRP | - | Message Size in Bytes (msgSize) | 4 bytes | - | Message | msgSize bytes | - - */ -void FillRequest(GroupPubKey const* pubkey, EpidSignature const* sig, - size_t sig_size, char const* msg_str, size_t msg_size, - uint8_t* req_buf, size_t req_size, SigRlRequestTop* req_top) { - const OctStr16 kEpidFileVersion = {2, 0}; - size_t i = 0; - size_t req_mid_size = sizeof(((SigRlRequestMid*)0)->be_msg_size) + msg_size; - SigRlRequestMid* req_mid = - (SigRlRequestMid*)(req_buf + req_size - req_mid_size); - - if (!pubkey || !sig || !req_buf || !req_top || (!msg_str && 0 != msg_size)) { - log_error("internal error: badarg to FillRequest()"); - return; - } - - req_top->header.epid_version = kEpidFileVersion; - req_top->header.file_type = kEpidFileTypeCode[kSigRlRequestFile]; - req_top->gid = pubkey->gid; - // copy signature - for (i = 0; i < sig_size; i++) { - ((uint8_t*)&req_top->sig)[i] = ((uint8_t*)sig)[i]; - } - req_mid->be_msg_size = htonl((uint32_t)msg_size); - // copy msg - for (i = 0; i < msg_size; i++) { - req_mid->msg[i] = msg_str[i]; - } -} - -int MakeRequest(char const* cacert_file, char const* sig_file, - char const* pubkey_file, char const* req_file, - char const* msg_str, size_t msg_size, bool verbose) { - // Buffers and computed values - // Signature buffer - EpidSignature* sig = NULL; - size_t sig_size = 0; - - // Group public key file - unsigned char* pubkey_file_data = NULL; - size_t pubkey_file_size = 0; - - // CA certificate - EpidCaCertificate cacert = {0}; - - // Group public key buffer - GroupPubKey pubkey = {0}; - - // Request buffer - uint8_t* req_buf = NULL; - size_t req_size = 0; - - size_t req_extra_space = (sizeof(EpidFileHeader) + sizeof(GroupId)); - - int ret_value = EXIT_FAILURE; - do { - SigRlRequestTop* req_top = NULL; - size_t req_file_size = 0; - const size_t kMsgSizeSize = sizeof(((SigRlRequestMid*)0)->be_msg_size); - - if (!cacert_file || !sig_file || !pubkey_file || !req_file || - (!msg_str && 0 != msg_size)) { - log_error("internal error: badarg to MakeRequest()"); - ret_value = EXIT_FAILURE; - break; - } - - // convert command line args to usable formats - // CA certificate - if (0 != ReadLoud(cacert_file, &cacert, sizeof(cacert))) { - ret_value = EXIT_FAILURE; - break; - } - - // Signature - sig = NewBufferFromFile(sig_file, &sig_size); - if (!sig) { - ret_value = EXIT_FAILURE; - break; - } - - // Group public key file - pubkey_file_data = NewBufferFromFile(pubkey_file, &pubkey_file_size); - if (!pubkey_file_data) { - ret_value = EXIT_FAILURE; - break; - } - - // Security note: - // Application must confirm group public key is - // authorized by the issuer, e.g., signed by the issuer. - if (GROUP_PUB_KEY_SIZE != pubkey_file_size) { - log_error("unexpected file size for '%s'. Expected: %d; got: %d", - pubkey_file, (int)GROUP_PUB_KEY_SIZE, (int)pubkey_file_size); - ret_value = EXIT_FAILURE; - break; - } - if (kEpidNoErr != EpidParseGroupPubKeyFile(pubkey_file_data, - pubkey_file_size, &cacert, - &pubkey)) { - log_error("group public key is not authorized"); - ret_value = EXIT_FAILURE; - break; - } - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Creating SigRL revocation request:"); - log_msg(""); - log_msg(" [in] Group ID: "); - PrintBuffer(&pubkey.gid, sizeof(pubkey.gid)); - log_msg(""); - log_msg(" [in] Signature Len: %d", (int)sig_size); - log_msg(" [in] Signature: "); - PrintBuffer(&sig, sig_size); - log_msg(""); - log_msg(" [in] Message Len: %d", (int)msg_size); - log_msg(" [in] Message: "); - PrintBuffer(msg_str, msg_size); - log_msg("=============================================="); - } - - req_extra_space += sig_size + kMsgSizeSize + msg_size; - - if (FileExists(req_file)) { - req_file_size = GetFileSize_S(req_file, SIZE_MAX - req_extra_space); - } else { - log_msg("request file does not exsist, create new"); - } - - req_size = req_file_size + req_extra_space; - - req_buf = AllocBuffer(req_size); - if (!req_buf) { - ret_value = EXIT_FAILURE; - break; - } - - if (req_file_size > 0) { - if (0 != ReadLoud(req_file, req_buf, req_file_size)) { - ret_value = EXIT_FAILURE; - break; - } - } - - req_top = (SigRlRequestTop*)(req_buf + req_file_size); - - FillRequest(&pubkey, sig, sig_size, msg_str, msg_size, req_buf, req_size, - req_top); - - // Report Settings - if (verbose) { - log_msg("=============================================="); - log_msg("Reqest generated:"); - log_msg(""); - log_msg(" [in] Request Len: %d", sizeof(SigRlRequestTop)); - log_msg(" [in] Request: "); - PrintBuffer(&req_top, sizeof(SigRlRequestTop)); - log_msg("=============================================="); - } - - // Store request - if (0 != WriteLoud(req_buf, req_size, req_file)) { - ret_value = EXIT_FAILURE; - break; - } - - // Success - ret_value = EXIT_SUCCESS; - } while (0); - - // Free allocated buffers - if (pubkey_file_data) free(pubkey_file_data); - if (sig) free(sig); - if (req_buf) free(req_buf); - - return ret_value; -} diff --git a/external/epid-sdk/CHANGELOG.md b/external/epid-sdk/CHANGELOG.md new file mode 100644 index 00000000..a1bc22ae --- /dev/null +++ b/external/epid-sdk/CHANGELOG.md @@ -0,0 +1,241 @@ +# Intel(R) EPID SDK ChangeLog {#ChangeLog} + +## [6.0.0] - 2017-12-15 + +### Added + +- The member can now be built with a substantially reduced code size + using a compilation option. + +- New context lifetime management APIs have been added to member to + give callers more control of memory allocation. + +- New member API `EpidClearRegisteredBasenames` has been added to + clear registered basenames without recreating the member. + +### Changed + +- `EpidRegisterBaseName` was renamed to `EpidRegisterBasename` because + basename is a single word. + +- Command-line parsing library used by samples and tools has been + replaced by Argtable3. + + +### Deprecated + +- `EpidMemberCreate` has been deprecated. This API has been superseded + by `EpidMemberGetSize` and `EpidMemberInit`. + +- `EpidMemberDelete` has been deprecated. This API has been superseded + by `EpidMemberDeinit`. + +### Removed + +- `size_optimized_release` build configuration has been removed. + Use the compilation option to build member with reduced code size. + +### Known Issues + +- Only the SHA-256 hash algorithm is supported when using the SDK with + the IBM TPM simulator due to a defect in version 532 of the + simulator. + +- Basenames are limited to 124 bytes in TPM mode. + +- Scons build will not work natively on ARM. You can still build using + `make` or cross compile. + + +## [5.0.0] - 2017-09-15 + +### Added + +- The member implementation now has the option to support signing + using a TPM, using the ECDAA capabilities of TPM 2.0. + + +### Changed + +- Member API updated to unify HW and SW use cases. + - Added + - `ProvisionKey` + - `ProvisionCompressed` + - `ProvisionCredential` + - `Startup` + - Parameters changed + - `MemberCreate` + - `RequestJoin` + - Removed or made private + - `WritePrecomp` + - `SignBasic` + - `NrProve` + - `AssemblePrivKey` + +- `EpidRequestJoin` was renamed to `EpidCreateJoinRequest` to make it + clear that it is not directly communicating with the issuer. + + +### Fixed + +- `EpidCreateJoinRequest` creates valid join requests. This fixes a + regression in `EpidRequestJoin` introduced in 4.0.0. + + +### Known Issues + +- Only the SHA-256 hash algorithm is supported when using the + SDK with the IBM TPM simulator due to a defect in version + 532 of the simulator. + +- Basenames are limited to 124 bytes in TPM mode. + + +## [4.0.0] - 2017-04-25 + +### Added + +- The member implementation now provides an internal interface that + gives guidance on partitioning member operations between highly + sensitive ones that use f value of the private key, and less + sensitive operations that can be performed in a host environment. + +- New member API `EpidAssemblePrivKey` was added to help assemble and + validate the new member private key that is created when a member + either joins a group (using the join protocol) or switches to a new + group (as the result of a performance rekey). + + +### Changed + +- Updated Intel(R) IPP Cryptography library to version 2017 (Update 2). + +- The mechanism to set the signature based revocation list (SigRL) + used for signing was changed. `EpidMemberSetSigRl` must be used to + set the SigRL. The SigRL is no longer a parameter to `EpidSign`. + This better models typical use case where a device stores a + revocation list and updates it independently of signing operations. + + +### Removed + +- Removed `EpidWritePreSigs` API. Serialization of pre-computed + signatures is a risky capability to provide, and simply expanding + the internal pool via `EpidAddPreSigs` still provides most of the + optimization benefits. + +- The `EpidIsPrivKeyInGroup` API is no longer exposed to clients. It + is no longer needed because the new member API `EpidAssemblePrivKey` + performs this check. + + +### Fixed + +- When building with commercial version of the Intel(R) IPP + Cryptography library, optimized functions are now properly invoked, + making signing and verification operations ~2 times faster + +- SHA-512/256 hash algorithm is now supported. + +- README for compressed data now correctly documents the number of + entries in revocation lists. + +- The `verifysig` sample now reports a more clear error message for + mismatched SigRLs. + +- The default scons build will now build for a 32-bit target on a + 32-bit platform. + + +### Known Issues + +- Scons build will not work natively on ARM. You can still build using + `make` or cross compile. + + +## [3.0.0] - 2016-11-22 + +### Added + +- Support for verification of Intel(R) EPID 1.1 members. + +- Make-based build system support. + +- Sample material includes compressed keys. + +- Enhanced documentation, including step-by-step walkthroughs of + example applications. + +- Validated on additional IoT platforms. + + - Ostro Linux + + - Snappy Ubuntu Core + + +### Changes + +- A new verifier API has been added to set the basename to be used for + verification. Verifier APIs that used to accept basenames now use + the basename set via `EpidVerifierSetBasename`. + +- The verifier pre-computation structure has been changed to include + the group ID to allow detection of errors that result from providing + a pre-computation blob from a different group to + `EpidVerifierCreate`. + + +### Fixes + +- The kEpidxxxRevoked enums have been renamed to be consistent with + other result return values. + + +### Known Issues + +- SHA-512/256 hash algorithm is not supported. + + +## [2.0.0] - 2016-07-20 + +### Added + +- Signed binary issuer material support. + + - Binary issuer material validation APIs. + + - Updated sample issuer material. + + - Updated samples that parse signed binary issuer material. + +- Compressed member private key support. + +- Validated on additional IoT platforms. + + - Windows 10 IoT Core + + - WindRiver IDP + + +### Changed + +- The default hash algorithm has changed. It is now SHA-512. + +- Functions that returned `EpidNullPtrErr` now return `EpidBadArgErr` + instead. + + +### Fixed + +- Updated build flags to work around GCC 4.8.5 defect. + + +## [1.0.0] - 2016-03-03 + +### Added + +- Basic sign and verify functionality + +- Dynamic join support for member + +- Apache 2.0 License diff --git a/external/epid-sdk-3.0.0/LICENSE.txt b/external/epid-sdk/LICENSE.txt similarity index 97% rename from external/epid-sdk-3.0.0/LICENSE.txt rename to external/epid-sdk/LICENSE.txt index 2afcf387..6af60009 100644 --- a/external/epid-sdk-3.0.0/LICENSE.txt +++ b/external/epid-sdk/LICENSE.txt @@ -203,22 +203,26 @@ ======================================================================= -Intel(R) Enhanced Privacy ID (Intel(R) EPID) SDK Subcomponents: +SDK Subcomponents: -The Intel(R) EPID SDK contains subcomponents with separate copyright notices -and license terms. Your use of the source code for these subcomponents -is subject to the terms and conditions of the following licenses. +The Intel(R) EPID SDK contains subcomponents with separate copyright +notices and license terms. Your use of the source code for these +subcomponents is subject to the terms and conditions of the following +licenses. ----------------------------------------------------------------------- The BSD 3-Clause License ----------------------------------------------------------------------- -The Intel(R) EPID SDK bundles portions of the following under the BSD 3-Clause -License: +The Intel(R) EPID SDK bundles portions of the following under the BSD +3-Clause License: - Google Test (https://github.com/google/googletest) Copyright 2008, Google Inc. + - Argtable3 (https://github.com/argtable/argtable3) + Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + All rights reserved. diff --git a/external/epid-sdk/Makefile b/external/epid-sdk/Makefile new file mode 100644 index 00000000..45f45c3d --- /dev/null +++ b/external/epid-sdk/Makefile @@ -0,0 +1,184 @@ +#!/usr/bin/make -f + +#variables are set by configure +prefix = /usr/local +installdir = $(prefix)/ +epidinstalldir = $(installdir)/epid-sdk +CC = gcc +CXX = g++ +CFLAGS = +LDFLAGS = +RANLIB = ranlib +TSS_PATH = +TINY = + +#set performance affecting flags +SIZE_CFLAGS := -O2 + +#gcc flags +CC_FLAGS := $(CFLAGS) $(SIZE_CFLAGS) -Werror -Wall -Wextra -Wno-missing-braces \ + -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-unused-function \ + -fno-strict-aliasing -Wno-unused-but-set-variable -Wno-comment -Wformat \ + -Wformat-security -fstack-protector -DNDEBUG -D_FORTIFY_SOURCE=2 + +#intel c compiler flags +ICC_FLAGS := $(CFLAGS) $(SIZE_CFLAGS) -Werror -Wall -Wextra -DNDEBUG \ + -fstack-protector -D_FORTIFY_SOURCE=2 \ + -Wformat -Wformat-security + +ifneq ($(OS),Windows_NT) + CC_FLAGS += -fPIC + ICC_FLAGS += -fPIC + CXX11_FLAG = -std=c++0x + EXE_EXTENSION = +else + CC_FLAGS += -D__int64='long long' + CXX11_FLAG = -std=gnu++11 + EXE_EXTENSION = .exe +endif + +#g++ flags +CXX_FLAGS := $(CC_FLAGS) $(CXX11_FLAG) + +#intel c++ compiler flags +ICPC_FLAGS := $(ICC_FLAGS) $(CXX11_FLAG) + +#check if architecture was specified +#or take it by shell command +ifeq ($(findstring -m32,$(CFLAGS)),-m32) + ARCH = x86 + CXXFLAGS += -m32 + LDFLAGS += -m32 +else ifeq ($(findstring -m64,$(CFLAGS)),-m64) + ARCH = x86_64 + CXXFLAGS += -m64 + LDFLAGS += -m64 +else + ifeq ($(findstring arm-,$(CC)),arm-) + ARCH = arm + + ifneq (,$(findstring gnueabihf,$(CC))) + ARCH := $(addsuffix hf,$(ARCH)) + endif + + else + ARCH := $(shell uname -m) + endif +endif + +#set tools and flags depending on specified compiler +ifeq ($(findstring icc,$(CC)),icc) + CFLAGS := $(ICC_FLAGS) + CXXFLAGS := $(ICPC_FLAGS) + AR = $(subst icc,xiar,$(CC)) +else + CFLAGS := $(CC_FLAGS) + CXXFLAGS := $(CXX_FLAGS) +endif + +# ld flags +LDFLAGS += -fstack-protector +ifneq ($(OS),Windows_NT) + LDFLAGS += -z noexecstack -z relro -z now -pie +endif + +#gtest defines +GTEST_DEFINES := -DGTEST_HAS_PTHREAD=0 -D_VARIADIC_MAX=10 + +#set flags for unit tests executables +GTEST_FLAGS = --gtest_color=yes \ + --gtest_print_time=1 \ + --gtest_output=xml + +export CC LDFLAGS ARCH CFLAGS +export CXX CXXFLAGS +export AR RANLIB +export epidinstalldir +export GTEST_FLAGS GTEST_DEFINES +export EXE_EXTENSION +export TSS_PATH +export TINY + +#output of the main parameters +$(info $$ccompiler is [${CC}]) +$(info $$cxxcompiler is [${CXX}]) +$(info $$architecture is [${ARCH}]) +#targets part +all: + $(MAKE) common member verifier argtable3 + +clean: + $(MAKE) -C ./epid/common/ clean + $(MAKE) -C ./epid/member/ clean + $(MAKE) -C ./epid/verifier/ clean + $(MAKE) -C ./ext/gtest/ clean + $(MAKE) -C ./epid/common-testhelper/ clean + $(MAKE) -C ./ext/argtable3/ clean +ifneq ("$(wildcard ./ext/google_benchmark)","") + $(MAKE) -C ./ext/google_benchmark/ clean +endif + +install: + $(MAKE) -C ./epid/common/ install + $(MAKE) -C ./epid/member/ install + $(MAKE) -C ./epid/verifier/ install + $(MAKE) -C ./epid/common-testhelper/ install + +uninstall: + rm -rf $(epidinstalldir) + +common-testhelper: + $(MAKE) -C ./epid/common-testhelper/ all + +common-testhelper_utest: + $(MAKE) -C ./epid/common-testhelper/ utest + +common: + $(MAKE) -C ./epid/common/ all + +common_utest: + $(MAKE) -C ./epid/common/ utest + +member: + $(MAKE) -C ./epid/member/ all + +member_utest: + $(MAKE) -C ./epid/member/ utest + +verifier: + $(MAKE) -C ./epid/verifier/ all + +verifier_utest: + $(MAKE) -C ./epid/verifier/ utest + +gtest: + $(MAKE) -C ./ext/gtest/ all + +argtable3: + $(MAKE) -C ./ext/argtable3/ all + +utest: + $(MAKE) gtest common-testhelper + $(MAKE) common-testhelper_utest common_utest member_utest verifier_utest + +run_utest: + $(MAKE) -C ./epid/common-testhelper/ run_utest + $(MAKE) -C ./epid/common/ run_utest + $(MAKE) -C ./epid/member/ run_utest + $(MAKE) -C ./epid/verifier/ run_utest + +check: + $(MAKE) utest + $(MAKE) run_utest + +perf: +ifneq ("$(wildcard ./ext/google_benchmark/)","") + $(MAKE) -C ./ext/google_benchmark/ all + $(MAKE) -C ./ext/google_benchmark/ utest + $(MAKE) -C ./ext/google_benchmark/ run_utest +endif + +build: + $(MAKE) all + $(MAKE) check + $(MAKE) install diff --git a/external/epid-sdk/Makefile.in b/external/epid-sdk/Makefile.in new file mode 100644 index 00000000..79a881b7 --- /dev/null +++ b/external/epid-sdk/Makefile.in @@ -0,0 +1,184 @@ +#!/usr/bin/make -f + +#variables are set by configure +prefix = @prefix@ +installdir = $(prefix)/ +epidinstalldir = $(installdir)/epid-sdk +CC = @CC@ +CXX = @CXX@ +CFLAGS = @CFLAGS@ +LDFLAGS = @LDFLAGS@ +RANLIB = @RANLIB@ +TSS_PATH = @TSS_PATH@ +TINY = @TINY@ + +#set performance affecting flags +SIZE_CFLAGS := -O2 + +#gcc flags +CC_FLAGS := $(CFLAGS) $(SIZE_CFLAGS) -Werror -Wall -Wextra -Wno-missing-braces \ + -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-unused-function \ + -fno-strict-aliasing -Wno-unused-but-set-variable -Wno-comment -Wformat \ + -Wformat-security -fstack-protector -DNDEBUG -D_FORTIFY_SOURCE=2 + +#intel c compiler flags +ICC_FLAGS := $(CFLAGS) $(SIZE_CFLAGS) -Werror -Wall -Wextra -DNDEBUG \ + -fstack-protector -D_FORTIFY_SOURCE=2 \ + -Wformat -Wformat-security + +ifneq ($(OS),Windows_NT) + CC_FLAGS += -fPIC + ICC_FLAGS += -fPIC + CXX11_FLAG = -std=c++0x + EXE_EXTENSION = +else + CC_FLAGS += -D__int64='long long' + CXX11_FLAG = -std=gnu++11 + EXE_EXTENSION = .exe +endif + +#g++ flags +CXX_FLAGS := $(CC_FLAGS) $(CXX11_FLAG) + +#intel c++ compiler flags +ICPC_FLAGS := $(ICC_FLAGS) $(CXX11_FLAG) + +#check if architecture was specified +#or take it by shell command +ifeq ($(findstring -m32,$(CFLAGS)),-m32) + ARCH = x86 + CXXFLAGS += -m32 + LDFLAGS += -m32 +else ifeq ($(findstring -m64,$(CFLAGS)),-m64) + ARCH = x86_64 + CXXFLAGS += -m64 + LDFLAGS += -m64 +else + ifeq ($(findstring arm-,$(CC)),arm-) + ARCH = arm + + ifneq (,$(findstring gnueabihf,$(CC))) + ARCH := $(addsuffix hf,$(ARCH)) + endif + + else + ARCH := $(shell uname -m) + endif +endif + +#set tools and flags depending on specified compiler +ifeq ($(findstring icc,$(CC)),icc) + CFLAGS := $(ICC_FLAGS) + CXXFLAGS := $(ICPC_FLAGS) + AR = $(subst icc,xiar,$(CC)) +else + CFLAGS := $(CC_FLAGS) + CXXFLAGS := $(CXX_FLAGS) +endif + +# ld flags +LDFLAGS += -fstack-protector +ifneq ($(OS),Windows_NT) + LDFLAGS += -z noexecstack -z relro -z now -pie +endif + +#gtest defines +GTEST_DEFINES := -DGTEST_HAS_PTHREAD=0 -D_VARIADIC_MAX=10 + +#set flags for unit tests executables +GTEST_FLAGS = --gtest_color=yes \ + --gtest_print_time=1 \ + --gtest_output=xml + +export CC LDFLAGS ARCH CFLAGS +export CXX CXXFLAGS +export AR RANLIB +export epidinstalldir +export GTEST_FLAGS GTEST_DEFINES +export EXE_EXTENSION +export TSS_PATH +export TINY + +#output of the main parameters +$(info $$ccompiler is [${CC}]) +$(info $$cxxcompiler is [${CXX}]) +$(info $$architecture is [${ARCH}]) +#targets part +all: + $(MAKE) common member verifier argtable3 + +clean: + $(MAKE) -C ./epid/common/ clean + $(MAKE) -C ./epid/member/ clean + $(MAKE) -C ./epid/verifier/ clean + $(MAKE) -C ./ext/gtest/ clean + $(MAKE) -C ./epid/common-testhelper/ clean + $(MAKE) -C ./ext/argtable3/ clean +ifneq ("$(wildcard ./ext/google_benchmark)","") + $(MAKE) -C ./ext/google_benchmark/ clean +endif + +install: + $(MAKE) -C ./epid/common/ install + $(MAKE) -C ./epid/member/ install + $(MAKE) -C ./epid/verifier/ install + $(MAKE) -C ./epid/common-testhelper/ install + +uninstall: + rm -rf $(epidinstalldir) + +common-testhelper: + $(MAKE) -C ./epid/common-testhelper/ all + +common-testhelper_utest: + $(MAKE) -C ./epid/common-testhelper/ utest + +common: + $(MAKE) -C ./epid/common/ all + +common_utest: + $(MAKE) -C ./epid/common/ utest + +member: + $(MAKE) -C ./epid/member/ all + +member_utest: + $(MAKE) -C ./epid/member/ utest + +verifier: + $(MAKE) -C ./epid/verifier/ all + +verifier_utest: + $(MAKE) -C ./epid/verifier/ utest + +gtest: + $(MAKE) -C ./ext/gtest/ all + +argtable3: + $(MAKE) -C ./ext/argtable3/ all + +utest: + $(MAKE) gtest common-testhelper + $(MAKE) common-testhelper_utest common_utest member_utest verifier_utest + +run_utest: + $(MAKE) -C ./epid/common-testhelper/ run_utest + $(MAKE) -C ./epid/common/ run_utest + $(MAKE) -C ./epid/member/ run_utest + $(MAKE) -C ./epid/verifier/ run_utest + +check: + $(MAKE) utest + $(MAKE) run_utest + +perf: +ifneq ("$(wildcard ./ext/google_benchmark/)","") + $(MAKE) -C ./ext/google_benchmark/ all + $(MAKE) -C ./ext/google_benchmark/ utest + $(MAKE) -C ./ext/google_benchmark/ run_utest +endif + +build: + $(MAKE) all + $(MAKE) check + $(MAKE) install diff --git a/external/epid-sdk-3.0.0/NOTICE.txt b/external/epid-sdk/NOTICE.txt similarity index 51% rename from external/epid-sdk-3.0.0/NOTICE.txt rename to external/epid-sdk/NOTICE.txt index 3a89982c..51a62a2b 100644 --- a/external/epid-sdk-3.0.0/NOTICE.txt +++ b/external/epid-sdk/NOTICE.txt @@ -1,23 +1,21 @@ -Intel(R) Enhanced Privacy ID (Intel(R) EPID) SDK -Copyright 2016 Intel Corporation +Intel(R) EPID SDK +Copyright 2016-2017 Intel Corporation ========== -The Intel(R) EPID SDK contains subcomponents with separate copyright notices -and license terms. +The Intel(R) EPID SDK contains subcomponents with separate copyright +notices and license terms. Your use of the source code for the these subcomponents is subject to the terms and conditions of their respective licenses. -See the LICENSE.txt file for a list of subcomponents and dependencies and -their respective licenses. +See the LICENSE.txt file for a list of subcomponents and dependencies +and their respective licenses. ---------- The source code used for math primitives in the Intel(R) EPID SDK is a -subset of the Intel(R) Integrated Performance Primitives (Intel(R) IPP) -Cryptography library (v9.0.3) written in C. -For higher performance, you can use the commercial version of the -Intel(R) IPP Cryptography libraries, which are available at +subset of Intel(R) IPP Cryptography 2017 Update 2 written in C. For +higher performance, you can use the commercial version of the IPP +Cryptography libraries, which are available at https://software.intel.com/articles/download-ipp-cryptography-libraries. - diff --git a/external/epid-sdk-3.0.0/README.md b/external/epid-sdk/README.md similarity index 61% rename from external/epid-sdk-3.0.0/README.md rename to external/epid-sdk/README.md index 5cb5c5f4..2c201e0b 100644 --- a/external/epid-sdk-3.0.0/README.md +++ b/external/epid-sdk/README.md @@ -51,7 +51,13 @@ See [LICENSE.txt](LICENSE.txt). ## Math Primitives The source code used for math primitives in the Intel(R) EPID SDK is a -subset of the Intel(R) IPP Cryptography library (v9.0.3) written in -C. For higher performance, you can use the commercial version of the -IPP Cryptography libraries, which are available at -https://software.intel.com/articles/download-ipp-cryptography-libraries. +subset of the Intel(R) IPP Cryptography library (version 2017 Update +2) written in pure C and not optimized for performance. For higher +performance, you can use the commercial version of the IPP +Cryptography library, which is available at +[https://software.intel.com/articles/download-ipp-cryptography-libraries](https://software.intel.com/articles/download-ipp-cryptography-libraries). + +More information on the optimized versions of Intel(R) IPP +Cryptography library, including mitigations for a potential +side-channel issue are available at +[https://security-center.intel.com/advisory.aspx?intelid=INTEL-SA-00060&languageid=en-fr](https://security-center.intel.com/advisory.aspx?intelid=INTEL-SA-00060&languageid=en-fr). diff --git a/external/epid-sdk/SConstruct b/external/epid-sdk/SConstruct new file mode 100644 index 00000000..08ac78dd --- /dev/null +++ b/external/epid-sdk/SConstruct @@ -0,0 +1,566 @@ +############################################################################ +# Copyright 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ + +"""use scons -k to invoke all builds regardless of unit test failures +""" +import string +import sys +import SCons.Script +import os.path +import subprocess +from subprocess import Popen, PIPE +from parts import * +import re +import tempfile +import shutil +from collections import OrderedDict + +def get_parts_versions(env): + """Get Parts related versions given SCons environment env""" + return OrderedDict({'python': string.split(sys.version, " ", 1)[0], + 'scons': str(SCons.__version__), + 'parts': str(PartsExtensionVersion())}) + +def get_toolchain_versions(env): + """Get version of compilation toolchain given SCons environment env""" + versions = OrderedDict() + if 'MSVC_VERSION' in env: + versions['compiler'] = 'MSVC ' + env['MSVC_VERSION'] + cmd = env.subst('echo int main(){return 0;} > a.cpp' + ' | $CXX $CCFLAGS a.cpp /link /verbose') + defaultlib_regexp = r'.*Searching (.*\.lib).*' + elif 'GCC_VERSION' in env: + versions['compiler'] = 'GCC ' + env['GCC_VERSION'] + if 'GXX_VERSION' in env: + versions['compiler'] += ' and GXX ' + env['GXX_VERSION'] + if os.name == 'nt': + cmd = env.subst('echo int main(){return 0;}' + ' | $CXX $CCFLAGS -xc++ -Wl,--verbose -') + else: + cmd = env.subst('echo "int main(){return 0;}"' + ' | $CXX $CCFLAGS -xc++ -Wl,--verbose -') + else: + if os.name == 'nt': + cmd = env.subst('echo int main(){return 0;}' + ' | $CXX $CCFLAGS -xc++ -Wl,--verbose -') + else: + cmd = env.subst('echo "int main(){return 0;}"' + ' | $CC $CCFLAGS -xc -Wl,--verbose -') + if os.name == 'nt': + defaultlib_regexp = r'\n.* open (.*) succeeded' + else: + defaultlib_regexp = r'[\n(](/.*\.so[-.\da-fA-F]*).*' + + # Intel C compiler always depends from base toolchain + if 'INTELC_VERSION' in env: + versions['compiler'] = 'INTELC {0} with {1}'.format( + env['INTELC_VERSION'], + versions['compiler']) + + env['ENV']['PATH'] = str(env['ENV']['PATH']) + temp_dir = tempfile.mkdtemp() + try: + proc = subprocess.Popen(cmd, + cwd=temp_dir, + env=env['ENV'], + shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, _ = proc.communicate() + if proc.returncode != 0: + versions['default_libs'] = 'failure executing: "{0}"'.format(cmd) + else: + default_libs = list( + set(re.findall(defaultlib_regexp, stdout, re.M))) + if 'MSVC_VERSION' in env: + # for windows additionally report versions of Windows Kit used + runtime_version_set = set() + for lib_path in default_libs: + path_components = os.path.realpath(lib_path).split(os.sep) + if 'Windows Kits' in path_components: + i = path_components.index('Windows Kits') + runtime_version_set.add( + 'Windows Kits {0} {1}'.format(path_components[i + 1], + path_components[i + 3])) + versions['sdk_or_libc'] = '; '.join(list(runtime_version_set)) + else: + # for posix additionally report versions of libc used + versions['sdk_or_libc'] = os.path.split(os.path.realpath( + next((lib for lib in default_libs if + 'libc' in lib.lower() and 'libcilk' not in lib.lower()), None)))[1] + versions['default_libs'] = default_libs + finally: + shutil.rmtree(temp_dir) + + return versions + + +def log_versions(env, include_toolchain=True): + """Log tools and libraries versions given SCons environment env + + Args: + env: Scons environment. + include_toolchain: Log version of compilation toolchain if True. + """ + + versions = get_parts_versions(env) + if include_toolchain: + versions.update(get_toolchain_versions(env)) + + print "**************** VERSIONS *************" + long_names = { + 'python': 'Python Version', + 'scons': 'SCons Version', + 'parts': 'Parts Version', + 'compiler': 'Compiler Version', + 'sdk_or_libc': 'Libc/SDK', + 'default_libs': 'Default Libs' + } + for name, value in versions.iteritems(): + if not isinstance(value, list): + print '* {0}: {1}'.format(long_names.get(name, name), value) + else: + print '* {0}:\n* \t{1}'.format(long_names.get(name, name), + '\n* \t'.join(sorted(value))) + print "***************************************" + + +def include_parts(part_list, **kwargs): + for parts_file in part_list: + if os.path.isfile(DefaultEnvironment().subst(parts_file)): + Part(parts_file=parts_file, **kwargs) + + +######## Part groups #################################################### +ipp_parts = ['ext/ipp/ippcp.parts'] +utest_parts = ['ext/gtest/gtest.parts', + 'epid/common-testhelper/common-testhelper.parts'] +common_parts = ['epid/common/common.parts'] +member_parts = ['epid/member/member.parts'] +verifier_parts = ['epid/verifier/verifier.parts'] +util_parts = ['example/util/util.parts'] +example_parts = ['ext/argtable3/argtable3.parts', + 'example/verifysig/verifysig.parts', + 'example/signmsg/signmsg.parts', + 'example/data/data.parts', + 'example/compressed_data/compressed_data.parts'] +sizing_parts = ['example/util/util_static.parts', + 'example/signmsg/signmsg_shared.parts', + 'example/verifysig/verifysig_shared.parts', + 'example/verifysig/verifysig11_shared.parts'] +example_static_parts = ['example/util/util_static.parts', + 'example/signmsg/signmsg_static.parts', + 'example/verifysig/verifysig_static.parts'] +tools_parts = ['tools/revokegrp/revokegrp.parts', + 'tools/revokekey/revokekey.parts', + 'tools/revokesig/revokesig.parts', + 'tools/extractkeys/extractkeys.parts', + 'tools/extractgrps/extractgrps.parts'] +testbot_test_parts = ['test/testbot/testbot.parts', + 'test/testbot/signmsg/signmsg_testbot.parts', + 'test/testbot/verifysig/verifysig_testbot.parts', + 'test/testbot/integration/integration_testbot.parts', + 'test/testbot/ssh_remote/ssh_remote_testbot.parts', + 'test/testbot/revokegrp/revokegrp_testbot.parts', + 'test/testbot/revokekey/revokekey_testbot.parts', + 'test/testbot/revokesig/revokesig_testbot.parts', + 'test/testbot/extractkeys/extractkeys_testbot.parts', + 'test/testbot/extractgrps/extractgrps_testbot.parts', + 'tools/reports/reports.parts'] +tss_test_parts = ['test/tss/tss.parts'] +package_parts = ['ext/gtest/gtest.parts', + 'ext/ipp/ippcp.parts', + 'package.parts'] +memory_profiler_parts = ['tools/memory_profiler/memory_profiler.parts'] +internal_tools_parts = ['ext/argtable3/argtable3.parts', + 'tools/ikgfwrapper/ikgfwrapper.parts'] +epid_data = ['test/epid_data/epid_data.parts'] +perf_benchmark_parts = ['ext/google_benchmark/google_benchmark.parts', + 'test/performance/performance.parts'] +memory_benchmark_parts = ['test/dynamic_memory/dynamic_memory.parts'] +######## End Part groups ############################################### +######## Commandline option setup ####################################### +product_variants = [ + 'production', + 'internal-test', + 'package-epid-sdk', + 'internal-tools', + 'benchmark', + 'tiny', + 'internal-test-tiny' +] + +default_variant = 'production' + + +def is_production(): + return GetOption("product-variant") == 'production' + + +def is_internal_test(): + return GetOption("product-variant") == 'internal-test' + + +def is_internal_tools(): + return GetOption("product-variant") == 'internal-tools' + + +def is_package(): + return GetOption("product-variant") == 'package-epid-sdk' + + +def is_benchmark(): + return GetOption("product-variant") == 'benchmark' + +def is_tiny(): + return GetOption("product-variant") == 'tiny' + +def is_internal_test_tiny(): + return GetOption("product-variant") == 'internal-test-tiny' + + +def use_commercial_ipp(): + return GetOption("use-commercial-ipp") + + +def use_tss(): + return GetOption("use-tss") + + +def config_has_instrumentation(): + return any(DefaultEnvironment().isConfigBasedOn(config_name) + for config_name in ['instr_release']) + + +def variant_dirname(): + s = GetOption("product-variant") + if s == 'production': + return 'epid-sdk' + elif s == 'package-epid-sdk': + return 'epid-sdk' + elif s == 'tiny': + return 'epid-sdk' + else: + return s + + +AddOption("--product-variant", "--prod-var", nargs=1, + help=("Select product variant to build. Possible " + "options are: {0}. The default is {1} if no option " + "is specified").format(", ".join(product_variants), + default_variant), + action='store', dest='product-variant', type='choice', + choices=product_variants, default=default_variant) + +AddOption("--use-commercial-ipp", + help=("Link with commercial IPP. The IPPROOT environment variable " + "must be set."), + action='store_true', dest='use-commercial-ipp', + default=False) + +AddOption("--use-tss", + help=("Link with TPM TSS. The TSSROOT environment variable " + "must be set."), + action='store_true', dest='use-tss', + default=False) + +AddOption("--ipp-shared", + help=("Build /ext/ipp as shared library."), + action='store_true', dest='ipp-shared', + default=False) + +AddOption("--enable-sanitizers", + help=("Build with sanitizers (https://github.com/google/sanitizers)."), + action='store_true', dest='sanitizers', + default=False) + +AddOption("--sanitizers-recover", + help=("Configure sanititzers to recover and continue execution " + "on error found. Only applicable when sanitizers are enabled." + "See --enable-sanitizers option."), + action='store_true', dest='sanitizers-recover', + default=False) + + +SetOptionDefault("PRODUCT_VARIANT", variant_dirname()) + +######## End Commandline option setup ################################### + + +# fix for parts 0.10.8 until we get better logic to extract ${CC} +SetOptionDefault('PARTS_USE_SHORT_TOOL_NAMES', 1) + + +def enable_sanitizers(recover): + """ + Configures compiler to enable sanitizers. + Adds sanitizer options to default scons environment such + that it affects all parts. + Args: + recover: Enable sanitizers recovery from errors found when True. + """ + env = DefaultEnvironment() + error_msg = None + try: + major = int(env.subst('$GCC_VERSION').partition('.')[0]) + except ValueError: + major = 0 + + if major >= 6 and env['TARGET_OS'] == 'posix': + if 'INTELC_VERSION' not in env: + ccflags = ['-fsanitize=address,undefined', '-fno-sanitize=alignment', + '-fno-sanitize=shift', '-fno-omit-frame-pointer'] + if recover: + ccflags = ccflags + ['-fsanitize-recover=all', '-fsanitize-recover=address'] + else: + ccflags = ccflags + ['-fno-sanitize-recover'] + # Extends default flags with sanitizer options + SetOptionDefault('CCFLAGS', ccflags) + SetOptionDefault('LIBS', ['asan', 'ubsan']) + else: + error_msg = """ + Build with sanitizers is not supported for Intel(R) C++ Compiler. + Try scons --toolchain=gcc_6 --target=posix + """ + else: + # User experience with sanitizers in GCC 4.8 is not great. Use at least GCC 6.x. + error_msg = """ + Build with sanitizers is only supported for GCC version greater than + 6.x targeting posix OS. Current GCC version is "{0}" and OS target is "{1}". + Try scons --toolchain=gcc_6 --target=posix + """.format(env.get('GCC_VERSION', 'unknown'), env.get('TARGET_OS', 'unknown')) + if error_msg is not None: + env.PrintError(error_msg) + + +def set_default_production_options(): + SetOptionDefault('CONFIG', 'release') + + SetOptionDefault('TARGET_VARIANT', '${TARGET_OS}-${TARGET_ARCH}') + + SetOptionDefault('INSTALL_ROOT', + '#_install/${PRODUCT_VARIANT}') + + SetOptionDefault('INSTALL_TOOLS_BIN', + '$INSTALL_ROOT/tools') + + SetOptionDefault('INSTALL_SAMPLE_BIN', + '$INSTALL_ROOT/example') + + SetOptionDefault('INSTALL_EPID_INCLUDE', + '$INSTALL_ROOT/include/epid') + + SetOptionDefault('INSTALL_IPP_INCLUDE', + '$INSTALL_ROOT/include/ext/ipp/include') + + SetOptionDefault('INSTALL_TEST_BIN', + '$INSTALL_ROOT/test') + + SetOptionDefault('INSTALL_LIB', + '$INSTALL_ROOT/lib/${TARGET_VARIANT}') + + SetOptionDefault('INSTALL_SAMPLE_DATA', + '$INSTALL_ROOT/example') + + SetOptionDefault('INSTALL_TOOLS_DATA', + '$INSTALL_ROOT/tools') + + SetOptionDefault('PACKAGE_DIR', + '#_package') + + SetOptionDefault('PACKAGE_ROOT', + '#_package/${PRODUCT_VARIANT}') + + SetOptionDefault('ROOT', + '#') + + SetOptionDefault('PACKAGE_NAME', + '{PRODUCT_VARIANT}') + + +if GetOption("sanitizers"): + enable_sanitizers(GetOption("sanitizers-recover")) + +if is_production(): + set_default_production_options() + ipp_mode = ['install_lib'] + if use_commercial_ipp(): + ipp_mode.append('use_commercial_ipp') + sdk_mode = ['install_lib'] + if use_tss(): + sdk_mode.append('use_tss') + if GetOption('ipp-shared'): + ipp_mode.append('build_ipp_shared') + include_parts(ipp_parts, mode=ipp_mode, + INSTALL_INCLUDE='${INSTALL_IPP_INCLUDE}') + include_parts(utest_parts + common_parts + + member_parts + verifier_parts, + mode=sdk_mode, + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}') + include_parts(util_parts + example_parts, + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}', + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + include_parts(tools_parts, + INSTALL_BIN='${INSTALL_TOOLS_BIN}', + INSTALL_DATA='${INSTALL_TOOLS_DATA}') + Default('all') + Default('utest::') + if not use_tss(): + Default('run_utest::') + +if is_internal_test(): + set_default_production_options() + sdk_mode = [] + if use_tss(): + sdk_mode.append('use_tss') + include_parts(tss_test_parts) + include_parts(ipp_parts) + include_parts(utest_parts + common_parts + + member_parts + verifier_parts, + mode=sdk_mode) + include_parts(util_parts + example_parts, + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + include_parts(sizing_parts, + INSTALL_BIN='${INSTALL_SAMPLE_BIN}') + include_parts(tools_parts, INSTALL_BIN='${INSTALL_TOOLS_BIN}') + include_parts(testbot_test_parts) + Default('all') + +if is_internal_tools(): + set_default_production_options() + include_parts(ipp_parts + utest_parts + common_parts + verifier_parts + member_parts + util_parts) + include_parts(internal_tools_parts + memory_profiler_parts, + INSTALL_BIN='${INSTALL_TOOLS_BIN}') + Default('ikgfwrapper', 'memory_profiler') + Default('run_utest::memory_profiler::') + +if is_benchmark(): + set_default_production_options() + MODE = [] + if config_has_instrumentation(): + MODE.append('use_memory_profiler') + ipp_mode = [] + if use_commercial_ipp(): + ipp_mode.append('use_commercial_ipp') + + # install ipp static and ipp shared builds into separate locations + if GetOption('ipp-shared'): + ipp_mode.append('build_ipp_shared') + SetOptionDefault('INSTALL_TEST_BIN', + '$INSTALL_ROOT/test_ipp_shared') + SetOptionDefault('INSTALL_LIB', + '$INSTALL_ROOT/lib_ipp_shared') + else: + SetOptionDefault('INSTALL_LIB', + '$INSTALL_ROOT/lib') + + # do not allow file links to keep previous builds intact + SetOptionDefault('CCOPY_LOGIC', 'copy') + + include_parts(ipp_parts, config_independent=True, mode=MODE + ipp_mode, + INSTALL_BIN='${INSTALL_TEST_BIN}') + include_parts(example_static_parts + utest_parts + perf_benchmark_parts + + common_parts + verifier_parts + + sizing_parts + epid_data, + config_independent=True, + mode=MODE, + INSTALL_BIN='${INSTALL_TEST_BIN}') + + member_mode = ['install_lib'] + member_cfg = ('embedded' if not DefaultEnvironment().isConfigBasedOn( + 'debug') and not config_has_instrumentation() else DefaultEnvironment().subst('$CONFIG')) + Part(parts_file='epid/common/tinycommon.parts', CONFIG=member_cfg) + Part(parts_file='epid/member/tinymember.parts', CONFIG=member_cfg, + config_independent=True, mode=MODE + member_mode, INSTALL_BIN='${INSTALL_TEST_BIN}') + + if config_has_instrumentation(): + include_parts(memory_benchmark_parts + memory_profiler_parts, + config_independent=True, + mode=MODE, + INSTALL_BIN='${INSTALL_TEST_BIN}') + + Default('build::') + +if is_package(): + set_default_production_options() + include_parts(package_parts, + mode=['install_package'], + INSTALL_TOP_LEVEL='${PACKAGE_ROOT}') + Default('package') + +if is_tiny(): + set_default_production_options() + ### Member + Part(parts_file='ext/gtest/gtest.parts') + member_mode = ['install_lib'] + member_cfg = ('embedded' + if not DefaultEnvironment().isConfigBasedOn('debug') + else DefaultEnvironment().subst('$CONFIG')) + Part(parts_file='epid/common/tinycommon.parts', CONFIG=member_cfg) + Part(parts_file='epid/member/tinymember.parts', CONFIG=member_cfg, + config_independent=True, mode=member_mode) + Default('member::') + Default('run_utest::member::') + ### Verifier, samples and tools + verifier_mode = ['install_lib'] + ipp_mode = ['install_lib'] + if use_commercial_ipp(): + ipp_mode.append('use_commercial_ipp') + if GetOption('ipp-shared'): + ipp_mode.append('build_ipp_shared') + include_parts(ipp_parts, mode=ipp_mode, + INSTALL_INCLUDE='${INSTALL_IPP_INCLUDE}') + Part(parts_file='epid/common-testhelper/common-testhelper.parts', + config_independent=True) + include_parts(common_parts + verifier_parts, + mode=verifier_mode, + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}') + include_parts(util_parts + example_parts, + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}', + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + include_parts(tools_parts, + INSTALL_BIN='${INSTALL_TOOLS_BIN}', + INSTALL_DATA='${INSTALL_TOOLS_DATA}') + Default('all') + Default('utest::') + +if is_internal_test_tiny(): + set_default_production_options() + sdk_mode = [] + ### Member + Part(parts_file='ext/gtest/gtest.parts') + member_cfg = ('embedded' + if not DefaultEnvironment().isConfigBasedOn('debug') + else DefaultEnvironment().subst('$CONFIG')) + Part(parts_file='epid/common/tinycommon.parts', CONFIG=member_cfg) + Part(parts_file='epid/member/tinymember.parts', CONFIG=member_cfg, + config_independent=True, mode=sdk_mode) + ### Verifier, samples and tools + include_parts(ipp_parts) + Part(parts_file='epid/common-testhelper/common-testhelper.parts', + config_independent=True) + include_parts(common_parts + verifier_parts, + mode=sdk_mode) + include_parts(util_parts + example_parts, + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + include_parts(tools_parts, INSTALL_BIN='${INSTALL_TOOLS_BIN}') + include_parts(testbot_test_parts) + Default('build::') + +log_versions(DefaultEnvironment(), not is_package()) diff --git a/external/epid-sdk-3.0.0/configure b/external/epid-sdk/configure similarity index 96% rename from external/epid-sdk-3.0.0/configure rename to external/epid-sdk/configure index 02a6d411..a288104a 100755 --- a/external/epid-sdk-3.0.0/configure +++ b/external/epid-sdk/configure @@ -584,6 +584,9 @@ PACKAGE_URL='' ac_default_prefix=`pwd`/_install ac_subst_vars='LTLIBOBJS LIBOBJS +TINY +TSS_PATH +RANLIB ac_ct_CXX CXXFLAGS CXX @@ -635,6 +638,8 @@ SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking +with_tss +enable_tiny ' ac_precious_vars='build_alias host_alias @@ -1253,6 +1258,19 @@ if test -n "$ac_init_help"; then esac cat <<\_ACEOF +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-tiny Build size optimized member. Mutually exclusive with + '--with-tss' + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-tss Link with TPM TSS. The TSSROOT environment variable + must be set. + Some influential environment variables: CC C compiler command CFLAGS C compiler flags @@ -2632,11 +2650,162 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu +#define ranlib +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi # restore flags CFLAGS="$CFLAGS_OLD" CPPFLAGS="$CPPFLAGS_OLD" + +# Check whether --with-tss was given. +if test "${with_tss+set}" = set; then : + withval=$with_tss; +else + with_tss=no + +fi + + + + +if test "x$with_tss" != "xno"; then : + as_ac_File=`$as_echo "ac_cv_file_$TSSROOT" | $as_tr_sh` +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $TSSROOT" >&5 +$as_echo_n "checking for $TSSROOT... " >&6; } +if eval \${$as_ac_File+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "$TSSROOT"; then + eval "$as_ac_File=yes" +else + eval "$as_ac_File=no" +fi +fi +eval ac_res=\$$as_ac_File + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +if eval test \"x\$"$as_ac_File"\" = x"yes"; then : + TSS_PATH=$TSSROOT +else + + as_fn_error $? "Necessary environment variable not set or set incorrectly: 'TSSROOT'" "$LINENO" 5 + +fi + +fi + + +# Check whether --enable-tiny was given. +if test "${enable_tiny+set}" = set; then : + enableval=$enable_tiny; +else + enable_tiny=no + +fi + + + +if test "x$enable_tiny" != "xno"; then : + if test "x$with_tss" != "xno"; then : + + as_fn_error $? "Size optimized member can not link with TPM TSS" "$LINENO" 5 + +fi + TINY=yes +fi # default install path is current directory ac_config_files="$ac_config_files Makefile" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.cc b/external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.cc similarity index 67% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.cc index f1be7e9e..46aa850f 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ #include #include "epid/common-testhelper/1.1/epid_params-testhelper.h" +#include "epid/common-testhelper/bignum_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/bignum_wrapper-testhelper.h" extern "C" { #include "epid/common/math/src/ecgroup-internal.h" @@ -98,9 +98,9 @@ Epid11ParamsObj::Epid11ParamsObj() { // cofactor is 1 for G2 const BigNumStr h2_str_ = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; // Create G2 // Set G2 = E(Fqd).init(orderG2, param(Fqd), twista, twistb, g2.x, g2.y). @@ -111,42 +111,42 @@ Epid11ParamsObj::Epid11ParamsObj() { } const BigNumStr Epid11ParamsObj::p_str_ = { - {{0x00, 0x00, 0x89, 0x57, 0x3F, 0x17, 0x47, 0x30, 0x8C, 0x43, 0xD5, 0xEE, - 0x41, 0x97, 0x96, 0x19, 0x72, 0xBB, 0x86, 0x88, 0xED, 0x4B, 0xEF, 0x04, - 0xAB, 0xAE, 0xC3, 0x8E, 0xEC, 0x51, 0xC3, 0xD3}}}; + {{0x00, 0x00, 0x89, 0x57, 0x3F, 0x17, 0x47, 0x30, 0x8C, 0x43, 0xD5, + 0xEE, 0x41, 0x97, 0x96, 0x19, 0x72, 0xBB, 0x86, 0x88, 0xED, 0x4B, + 0xEF, 0x04, 0xAB, 0xAE, 0xC3, 0x8E, 0xEC, 0x51, 0xC3, 0xD3}}}; const BigNumStr Epid11ParamsObj::q_str_ = { - {{0x09, 0xF9, 0x24, 0xE5, 0xD9, 0xBC, 0x67, 0x7F, 0x81, 0x0D, 0xF0, 0x25, - 0x58, 0xF7, 0x53, 0x13, 0xA9, 0x8A, 0xA6, 0x10, 0x47, 0x65, 0x5D, 0x73, - 0x9E, 0xF1, 0x94, 0xEB, 0x05, 0xB1, 0xA7, 0x11}}}; + {{0x09, 0xF9, 0x24, 0xE5, 0xD9, 0xBC, 0x67, 0x7F, 0x81, 0x0D, 0xF0, + 0x25, 0x58, 0xF7, 0x53, 0x13, 0xA9, 0x8A, 0xA6, 0x10, 0x47, 0x65, + 0x5D, 0x73, 0x9E, 0xF1, 0x94, 0xEB, 0x05, 0xB1, 0xA7, 0x11}}}; const std::vector Epid11ParamsObj::h_str_ = {0x00, 0x00, 0x12, 0x97}; const FqElemStr Epid11ParamsObj::a_str_ = { - {{0x05, 0x53, 0xD7, 0xC8, 0x81, 0xF7, 0x78, 0xC2, 0x2C, 0x37, 0xB6, 0xC0, - 0x16, 0x3E, 0x68, 0x24, 0x3A, 0x84, 0x78, 0x1C, 0x0A, 0xDF, 0x9B, 0xB3, - 0xED, 0x21, 0xC4, 0x46, 0xE5, 0xA7, 0xA3, 0x92}}}; + {{0x05, 0x53, 0xD7, 0xC8, 0x81, 0xF7, 0x78, 0xC2, 0x2C, 0x37, 0xB6, + 0xC0, 0x16, 0x3E, 0x68, 0x24, 0x3A, 0x84, 0x78, 0x1C, 0x0A, 0xDF, + 0x9B, 0xB3, 0xED, 0x21, 0xC4, 0x46, 0xE5, 0xA7, 0xA3, 0x92}}}; const FqElemStr Epid11ParamsObj::b_str_ = { - {{0x00, 0x3A, 0x2E, 0x39, 0x0E, 0x10, 0xD8, 0xAC, 0x47, 0xCB, 0x29, 0xC8, - 0xF1, 0x2C, 0x7F, 0x11, 0x99, 0x2A, 0x18, 0xB7, 0xEF, 0x73, 0x48, 0xA6, - 0xBE, 0x70, 0xA6, 0x8B, 0x97, 0x34, 0x8A, 0xB1}}}; + {{0x00, 0x3A, 0x2E, 0x39, 0x0E, 0x10, 0xD8, 0xAC, 0x47, 0xCB, 0x29, + 0xC8, 0xF1, 0x2C, 0x7F, 0x11, 0x99, 0x2A, 0x18, 0xB7, 0xEF, 0x73, + 0x48, 0xA6, 0xBE, 0x70, 0xA6, 0x8B, 0x97, 0x34, 0x8A, 0xB1}}}; const BigNumStr Epid11ParamsObj::coeffs_str_[3] = { - {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, 0x94, - 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, 0x43, 0x89, - 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, + {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, + 0x94, 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, + 0x43, 0x89, 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, - {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, 0x0E, - 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, 0x85, 0x7A, - 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, + {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, + 0x0E, 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, + 0x85, 0x7A, 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, - {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, 0x4B, - 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, 0x24, 0xA4, - 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; + {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, + 0x4B, 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, + 0x24, 0xA4, 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; const FqElemStr Epid11ParamsObj::qnr_str = { - {0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, 0x52, 0x94, - 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, 0x2B, 0x6E, - 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}}; + {0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, 0x52, + 0x94, 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, + 0x2B, 0x6E, 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}}; const std::vector Epid11ParamsObj::orderG2_str = { 0x00, 0x03, 0xDF, 0xFC, 0xBE, 0x2F, 0x5C, 0x2E, 0x45, 0x49, 0x7A, 0x2A, @@ -159,58 +159,58 @@ const std::vector Epid11ParamsObj::orderG2_str = { 0xF4, 0xD0, 0x37, 0x74, 0x93, 0x56, 0x62, 0x7B, 0x95, 0xCC, 0x2C, 0xB0}; const BigNumStr Epid11ParamsObj::p1_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, - 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, + 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}}}; const BigNumStr Epid11ParamsObj::q1_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}}; const std::vector Epid11ParamsObj::h1_str_ = {0x00, 0x00, 0x00, 0x01}; const FqElemStr Epid11ParamsObj::a1_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}}}; const FqElemStr Epid11ParamsObj::b1_str_ = { - {{0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55, - 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, - 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}}}; + {{0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, + 0x55, 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, + 0xB0, 0xF6, 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}}}; const Epid11G1ElemStr Epid11ParamsObj::g1_str_ = { - {{{0x07, 0x78, 0x3B, 0x0D, 0xFE, 0x4A, 0xA3, 0x19, 0x49, 0xB0, 0xCE, 0xAF, - 0x3F, 0x74, 0x0F, 0x32, 0x16, 0x0C, 0x8B, 0x46, 0x94, 0x5B, 0xA5, 0xB0, - 0xE4, 0x8A, 0xDA, 0xD8, 0x88, 0x32, 0x90, 0x53}}}, - {{{0x08, 0xF7, 0xA2, 0xAA, 0xBA, 0x62, 0xB3, 0xFE, 0x29, 0x80, 0xC9, 0x5B, - 0x63, 0x53, 0xC8, 0x24, 0x3C, 0x7C, 0x1F, 0x4C, 0xDA, 0xCD, 0xE5, 0x5F, - 0xA2, 0x36, 0x93, 0x04, 0x3C, 0x3A, 0xBC, 0x2E}}}}; + {{{0x07, 0x78, 0x3B, 0x0D, 0xFE, 0x4A, 0xA3, 0x19, 0x49, 0xB0, 0xCE, + 0xAF, 0x3F, 0x74, 0x0F, 0x32, 0x16, 0x0C, 0x8B, 0x46, 0x94, 0x5B, + 0xA5, 0xB0, 0xE4, 0x8A, 0xDA, 0xD8, 0x88, 0x32, 0x90, 0x53}}}, + {{{0x08, 0xF7, 0xA2, 0xAA, 0xBA, 0x62, 0xB3, 0xFE, 0x29, 0x80, 0xC9, + 0x5B, 0x63, 0x53, 0xC8, 0x24, 0x3C, 0x7C, 0x1F, 0x4C, 0xDA, 0xCD, + 0xE5, 0x5F, 0xA2, 0x36, 0x93, 0x04, 0x3C, 0x3A, 0xBC, 0x2E}}}}; const Fq3ElemStr Epid11ParamsObj::g2x_str_ = { - {{{{0x02, 0x10, 0x9A, 0xF4, 0x06, 0x32, 0x30, 0x89, 0xCB, 0x95, 0xE9, 0x55, - 0x0E, 0x9D, 0xAF, 0x0E, 0x98, 0xCD, 0xCA, 0xDC, 0xB1, 0xFF, 0xFC, 0xD1, - 0x45, 0x66, 0xBB, 0x86, 0x46, 0x1E, 0x8C, 0x30}}}, - {{{0x04, 0x78, 0x53, 0xE1, 0x3F, 0x96, 0xC5, 0xE4, 0x15, 0x23, 0x7B, 0x1F, - 0x3F, 0x2C, 0xD3, 0x95, 0x40, 0xBC, 0x7A, 0x31, 0x1F, 0x14, 0x38, 0x9E, - 0x1A, 0xA5, 0xD6, 0x63, 0x10, 0x91, 0xE4, 0xD3}}}, - {{{0x00, 0xB4, 0x02, 0xBC, 0x47, 0xFA, 0xA6, 0x29, 0x82, 0x0B, 0xB1, 0xD5, - 0xFF, 0xF2, 0xE6, 0xB0, 0xC6, 0xAE, 0xE8, 0x7B, 0x91, 0xD9, 0xEE, 0x66, - 0x07, 0x1F, 0xFD, 0xA2, 0xE7, 0x02, 0x66, 0xDD}}}}}; + {{{{0x02, 0x10, 0x9A, 0xF4, 0x06, 0x32, 0x30, 0x89, 0xCB, 0x95, 0xE9, + 0x55, 0x0E, 0x9D, 0xAF, 0x0E, 0x98, 0xCD, 0xCA, 0xDC, 0xB1, 0xFF, + 0xFC, 0xD1, 0x45, 0x66, 0xBB, 0x86, 0x46, 0x1E, 0x8C, 0x30}}}, + {{{0x04, 0x78, 0x53, 0xE1, 0x3F, 0x96, 0xC5, 0xE4, 0x15, 0x23, 0x7B, + 0x1F, 0x3F, 0x2C, 0xD3, 0x95, 0x40, 0xBC, 0x7A, 0x31, 0x1F, 0x14, + 0x38, 0x9E, 0x1A, 0xA5, 0xD6, 0x63, 0x10, 0x91, 0xE4, 0xD3}}}, + {{{0x00, 0xB4, 0x02, 0xBC, 0x47, 0xFA, 0xA6, 0x29, 0x82, 0x0B, 0xB1, + 0xD5, 0xFF, 0xF2, 0xE6, 0xB0, 0xC6, 0xAE, 0xE8, 0x7B, 0x91, 0xD9, + 0xEE, 0x66, 0x07, 0x1F, 0xFD, 0xA2, 0xE7, 0x02, 0x66, 0xDD}}}}}; const Fq3ElemStr Epid11ParamsObj::g2y_str_ = { - {{{{0x05, 0x2E, 0xF8, 0xC6, 0xC1, 0x6A, 0xEF, 0x3C, 0xC1, 0x95, 0xF6, 0x26, - 0xCE, 0x5E, 0x55, 0xD1, 0x64, 0x13, 0x28, 0xB1, 0x18, 0x57, 0xD8, 0x1B, - 0x84, 0xFA, 0xEC, 0x7E, 0x5D, 0x99, 0x06, 0x49}}}, - {{{0x05, 0x73, 0x35, 0xA9, 0xA7, 0xF2, 0xA1, 0x92, 0x5F, 0x3E, 0x7C, 0xDF, - 0xAC, 0xFE, 0x0F, 0xF5, 0x08, 0xD0, 0x3C, 0xAE, 0xCD, 0x58, 0x00, 0x5F, - 0xD0, 0x84, 0x7E, 0xEA, 0x63, 0x57, 0xFE, 0xC6}}}, - {{{0x01, 0x56, 0xDA, 0xF3, 0x72, 0x61, 0xDA, 0xC6, 0x93, 0xB0, 0xAC, 0xEF, - 0xAA, 0xD4, 0x51, 0x6D, 0xCA, 0x71, 0x1E, 0x06, 0x73, 0xEA, 0x83, 0xB2, - 0xB1, 0x99, 0x4A, 0x4D, 0x4A, 0x0D, 0x35, 0x07}}}}}; + {{{{0x05, 0x2E, 0xF8, 0xC6, 0xC1, 0x6A, 0xEF, 0x3C, 0xC1, 0x95, 0xF6, + 0x26, 0xCE, 0x5E, 0x55, 0xD1, 0x64, 0x13, 0x28, 0xB1, 0x18, 0x57, + 0xD8, 0x1B, 0x84, 0xFA, 0xEC, 0x7E, 0x5D, 0x99, 0x06, 0x49}}}, + {{{0x05, 0x73, 0x35, 0xA9, 0xA7, 0xF2, 0xA1, 0x92, 0x5F, 0x3E, 0x7C, + 0xDF, 0xAC, 0xFE, 0x0F, 0xF5, 0x08, 0xD0, 0x3C, 0xAE, 0xCD, 0x58, + 0x00, 0x5F, 0xD0, 0x84, 0x7E, 0xEA, 0x63, 0x57, 0xFE, 0xC6}}}, + {{{0x01, 0x56, 0xDA, 0xF3, 0x72, 0x61, 0xDA, 0xC6, 0x93, 0xB0, 0xAC, + 0xEF, 0xAA, 0xD4, 0x51, 0x6D, 0xCA, 0x71, 0x1E, 0x06, 0x73, 0xEA, + 0x83, 0xB2, 0xB1, 0x99, 0x4A, 0x4D, 0x4A, 0x0D, 0x35, 0x07}}}}}; const Epid11G3ElemStr Epid11ParamsObj::g3_str_ = { - {{{0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5, - 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, - 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}}}, - {{{0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, - 0x7C, 0x0F, 0x9E, 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, - 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}}}}; + {{{0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, + 0xE5, 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, + 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}}}, + {{{0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, + 0x4A, 0x7C, 0x0F, 0x9E, 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, + 0x5E, 0xCE, 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}}}}; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.h b/external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.h similarity index 98% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.h rename to external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.h index 82b80d3c..17923929 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/epid_params-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/1.1/epid_params-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,16 +25,16 @@ #include extern "C" { -#include "epid/common/math/bignum.h" -#include "epid/common/math/finitefield.h" -#include "epid/common/math/ecgroup.h" #include "epid/common/1.1/types.h" +#include "epid/common/math/bignum.h" +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" } -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" class Epid11ParamsObj { public: diff --git a/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp01/member0/sig_bsn0_msg_0_255_sha256.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp01/member0/sig_bsn0_msg_0_255_sha256.inc new file mode 100644 index 00000000..b8639f5f --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp01/member0/sig_bsn0_msg_0_255_sha256.inc @@ -0,0 +1,89 @@ + /*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 1.1 Signature + * Group : groupA + * Signer : member0 + * HashAlg : Sha512 + * Message : bytes [0, 255] + * Basename: Random + * SigRl : SigRl of group + */ +0x8d, 0x1c, 0x17, 0x76, 0x00, 0x19, 0xe0, 0xdd, +0xd7, 0xf3, 0xad, 0x12, 0xf0, 0x68, 0xd2, 0xa4, 0x45, 0xfb, 0xfb, 0x79, +0x4d, 0x8d, 0xef, 0x13, 0x62, 0x19, 0x12, 0x7a, 0x5f, 0xfb, 0xdb, 0x49, +0x6a, 0x73, 0x37, 0x9e, 0xe7, 0x9f, 0x91, 0x3b, 0xba, 0x77, 0xac, 0xae, +0x10, 0x91, 0xb0, 0xa5, 0xab, 0x3d, 0xc8, 0x69, 0x07, 0x9a, 0x73, 0xdd, +0x64, 0x3b, 0xed, 0x0b, 0x26, 0x63, 0x28, 0xc7, 0x5b, 0x84, 0xb9, 0x94, +0xdb, 0xac, 0xfc, 0xcc, 0x7c, 0x46, 0xd7, 0x12, 0xee, 0xb2, 0x49, 0x8e, +0xb9, 0x9f, 0xf7, 0x96, 0xf9, 0x83, 0xf3, 0xfb, 0xb5, 0xd6, 0x26, 0x3b, +0xde, 0x99, 0xa3, 0x97, 0x7e, 0xe8, 0x57, 0x93, 0xe2, 0xd9, 0xa3, 0x8c, +0xc6, 0xb0, 0x74, 0xfd, 0x2d, 0x2d, 0xe7, 0x9f, 0xe3, 0xf0, 0xf5, 0x4c, +0xe5, 0xb3, 0xdc, 0xfc, 0xac, 0xac, 0xe7, 0x83, 0x2c, 0xe7, 0x8a, 0xe1, +0x03, 0x6c, 0xfd, 0xa5, 0x46, 0xab, 0xe0, 0x50, 0xd4, 0x86, 0x5e, 0xbf, +0x03, 0xfb, 0xac, 0xca, 0x4f, 0x89, 0x2c, 0x7c, 0xeb, 0xad, 0x43, 0x19, +0x21, 0x7d, 0x00, 0x2a, 0x2c, 0x14, 0x20, 0x4d, 0x06, 0xc0, 0x28, 0x96, +0x1c, 0x3a, 0x3c, 0x81, 0x01, 0x9b, 0x38, 0xd1, 0x4c, 0x00, 0xe8, 0x6c, +0x44, 0xe6, 0x3a, 0xeb, 0x72, 0x94, 0x06, 0xd4, 0x06, 0x46, 0xc0, 0xf3, +0xd3, 0xc5, 0xdf, 0x5e, 0x02, 0x13, 0x72, 0x81, 0x96, 0x2c, 0x98, 0x19, +0x9c, 0x61, 0xc1, 0xe7, 0xf8, 0x94, 0x24, 0x33, 0x7b, 0xea, 0x97, 0x9a, +0x2f, 0x99, 0x46, 0x0e, 0xd6, 0x0f, 0x3a, 0x66, 0xf0, 0xb9, 0xa6, 0xa7, +0x03, 0xee, 0xb1, 0xfc, 0x8b, 0xa8, 0xf4, 0xad, 0x77, 0xc1, 0x26, 0x63, +0x47, 0x81, 0x5c, 0x01, 0x67, 0xf5, 0x43, 0xfb, 0xec, 0x58, 0xd7, 0x20, +0xd8, 0xe2, 0xba, 0xdb, 0x95, 0x74, 0xd5, 0x18, 0xda, 0x7d, 0xf7, 0xf6, +0xa8, 0x4d, 0x0f, 0x82, 0x60, 0xe7, 0x21, 0x38, 0x11, 0x4b, 0x81, 0x40, +0x63, 0x08, 0x5c, 0x9c, 0x86, 0xbe, 0x2a, 0x53, 0x69, 0x54, 0xbe, 0x0f, +0x4f, 0xb6, 0x60, 0x88, 0xd0, 0x28, 0x83, 0xf7, 0xea, 0xaa, 0xcb, 0xdb, +0xdf, 0x89, 0x00, 0x00, 0x56, 0xac, 0x9e, 0x51, 0x7d, 0xc0, 0xe1, 0x77, +0x93, 0xb8, 0x18, 0x2a, 0x1a, 0x95, 0xe4, 0x7c, 0x21, 0x14, 0x5a, 0xa7, +0x35, 0x8d, 0xb9, 0xcd, 0x0c, 0xc8, 0x33, 0x93, 0x47, 0x87, 0x00, 0x00, +0x5a, 0xf8, 0x3f, 0x82, 0x6a, 0x6f, 0x85, 0x75, 0x83, 0xfe, 0x50, 0x3d, +0xeb, 0x68, 0xbd, 0x6d, 0xe6, 0x14, 0xb9, 0x16, 0xab, 0x84, 0x76, 0x59, +0x42, 0x4a, 0x9f, 0x61, 0xac, 0xa7, 0x00, 0x80, 0xbb, 0x20, 0xfe, 0xb1, +0x3e, 0xee, 0x68, 0x07, 0xc7, 0xcf, 0x2d, 0x2d, 0x98, 0x18, 0xa0, 0x8d, +0x91, 0xd5, 0x7f, 0x23, 0x05, 0x2e, 0x35, 0x06, 0xdd, 0xe0, 0xab, 0xd7, +0x90, 0x2e, 0x53, 0xcc, 0xa1, 0xfd, 0x17, 0x28, 0xbf, 0x91, 0xd6, 0x32, +0xc8, 0x48, 0xdc, 0x97, 0xae, 0xe2, 0xf4, 0x22, 0x4d, 0xb0, 0x7c, 0xc4, +0x14, 0xb6, 0x6f, 0x02, 0x54, 0xc3, 0x9a, 0x89, 0xec, 0xbf, 0x41, 0x5f, +0xda, 0x16, 0x34, 0xd3, 0x1f, 0x77, 0x50, 0x44, 0xb6, 0x00, 0x00, 0x19, +0xa9, 0x7e, 0xc9, 0x58, 0x95, 0x9d, 0xc7, 0x3e, 0x25, 0x78, 0x75, 0xa1, +0x1a, 0x68, 0x61, 0x42, 0x94, 0x1a, 0xdc, 0x73, 0xee, 0x23, 0x2e, 0x85, +0xa1, 0x3e, 0xe8, 0xdc, 0x9d, 0x00, 0x00, 0x65, 0x16, 0x55, 0x42, 0xbc, +0x48, 0xdc, 0x13, 0xf5, 0xd9, 0x77, 0x89, 0x25, 0x4a, 0x1f, 0x12, 0xf0, +0x7a, 0xce, 0x98, 0xd8, 0xbe, 0x96, 0x08, 0x04, 0x75, 0x45, 0xc1, 0x63, +0xd6, 0x00, 0x00, 0x21, 0xdb, 0x1d, 0x9f, 0xe5, 0xbc, 0x64, 0x2c, 0x3c, +0x37, 0xac, 0xd4, 0x18, 0xf6, 0xf5, 0x52, 0xae, 0xe6, 0x54, 0x19, 0x6e, +0xac, 0x83, 0x28, 0x43, 0xa7, 0x49, 0xea, 0x94, 0x6f, 0x00, 0x00, 0x72, +0x8d, 0x9d, 0x41, 0x1d, 0x81, 0x24, 0x13, 0xe4, 0x92, 0x3e, 0x1d, 0x94, +0x1a, 0x79, 0x04, 0x33, 0xd1, 0x9a, 0xe5, 0x17, 0xf4, 0x7f, 0xf8, 0xd0, +0x23, 0x2f, 0x15, 0x20, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, +0x01, 0x79, 0xc4, 0x6e, 0xb2, 0xb9, 0x0d, 0x82, 0x0e, 0x43, 0x6b, 0x62, +0xdd, 0xaa, 0xf4, 0xe5, 0x60, 0x60, 0xa0, 0xf6, 0x0f, 0x0a, 0x3a, 0xd4, +0x10, 0xfb, 0x3d, 0x9e, 0x65, 0x3d, 0xf8, 0xf2, 0x6b, 0x9e, 0x4f, 0xb1, +0xe1, 0xad, 0x06, 0x71, 0xc1, 0xe2, 0xb8, 0x9b, 0xcd, 0x56, 0x2b, 0xca, +0xa7, 0x0a, 0x44, 0x9a, 0xdb, 0xa6, 0x4d, 0x7d, 0xb5, 0xe0, 0x76, 0x9d, +0x24, 0x45, 0x87, 0x5f, 0x01, 0x79, 0xce, 0xb3, 0xc1, 0x34, 0xa3, 0xab, +0x7f, 0x86, 0x95, 0x19, 0x02, 0xa4, 0xdc, 0xb0, 0x47, 0xd6, 0x69, 0x21, +0x22, 0x00, 0xc5, 0x82, 0xc6, 0x70, 0x1d, 0x5d, 0xaf, 0xe4, 0x20, 0xa3, +0x71, 0xf3, 0x29, 0x5a, 0xe1, 0x59, 0x3a, 0x66, 0x02, 0x0d, 0xe1, 0x01, +0x10, 0xab, 0x17, 0x17, 0x30, 0x8e, 0x1d, 0xb2, 0x1b, 0x71, 0x92, 0x02, +0xe1, 0x91, 0xa9, 0xd5, 0xdb, 0xc7, 0x20, 0x72, 0x09, 0x93, 0xe8, 0x64, +0x63, 0x3a, 0x6a, 0x4a, 0xc9, 0x4e, 0x20, 0x19, 0x6f, 0xb5, 0x5e, 0x37, +0x01, 0x38, 0x82, 0x7a, 0x74, 0x87, 0x29, 0xbb, 0xd2, 0xca, 0x24, 0xf5, +0x75, 0x17, 0xdc, 0xd3, 0x60 diff --git a/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/corrupted_privrl.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/corrupted_privrl.inc new file mode 100644 index 00000000..6972ab7b --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/corrupted_privrl.inc @@ -0,0 +1,35 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 1.1 private-key based revocation list + * Group : grpX + */ +//unsigned char privrl_dat[] = { + // Group ID + 0x00, 0x00, 0x00, 0x7b, + // RLver + 0x00, 0x00, 0x00, 0x03, + // n1 + 0x00, 0x00, 0x00, 0x01, + // f[1] + 0x00, 0x00, 0x89, 0x57, 0x3F, 0x17, 0x47, 0x30, 0x8C, 0x43, 0xD5, 0xEE, + 0x41, 0x97, 0x96, 0x19, 0x72, 0xBB, 0x86, 0x88, 0xED, 0x4B, 0xEF, 0x04, + 0xAB, 0xAE, 0xC3, 0x8E, 0xEC, 0x51, 0xC3, 0xD3 +//}; +// unsigned int privrl_dat_len = 44; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/epid_grpcrt.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/epid_grpcrt.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/epid_grpcrt.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/epid_grpcrt.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_single_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_single_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_three_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_three_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_three_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0_three_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrl.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrl.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sig_sha256_bsnrnd_msg0.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sig_sha256_bsnrnd_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sig_sha256_bsnrnd_msg0.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sig_sha256_bsnrnd_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_first_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_first_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_first_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_first_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_last_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_last_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_last_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_last_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_middle_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_middle_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_middle_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_middle_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_single_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_single_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grp_x/sigrl_member0_sig_bsn0_msg0_revoked_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_first_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_first_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_first_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_first_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_last_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_last_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_last_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_last_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_middle_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_middle_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_middle_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_middle_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_single_entry.inc b/external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_single_entry.inc rename to external/epid-sdk/epid/common-testhelper/1.1/testdata/grprl_revoked_grp_x_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc index cea2e06d..ea95b075 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/1.1/verifier_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ * \brief EcGroup C++ wrapper implementation. */ #include -#include #include +#include #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/1.1/verifier_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/1.1/verifier_wrapper-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/1.1/verifier_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/1.1/verifier_wrapper-testhelper.h diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/Makefile b/external/epid-sdk/epid/common-testhelper/Makefile similarity index 74% rename from external/epid-sdk-3.0.0/epid/common-testhelper/Makefile rename to external/epid-sdk/epid/common-testhelper/Makefile index 74e97490..1b9559b1 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/Makefile +++ b/external/epid-sdk/epid/common-testhelper/Makefile @@ -9,34 +9,37 @@ COMMON_TESTHELPER_11_INCLUDE_DIR = ../../1.1 COMMON_TESTHELPER_SRC = $(wildcard ./*.cc) COMMON_TESTHELPER_SRC += $(wildcard ./1.1/*.cc) COMMON_TESTHELPER_UTEST_SRC = $(wildcard ./unittests/*.cc) -COMMON_TESTHELPER_OBJ = $(sort $(COMMON_TESTHELPER_SRC:.cc=.o)) -COMMON_TESTHELPER_UTEST_OBJ = $(sort $(COMMON_TESTHELPER_UTEST_SRC:.cc=.o)) +COMMON_TESTHELPER_OBJ = $(COMMON_TESTHELPER_SRC:.cc=.o) +COMMON_TESTHELPER_UTEST_OBJ = $(COMMON_TESTHELPER_UTEST_SRC:.cc=.o) COMMON_TESTHELPER_LIB = ./libcommon-testhelper.a -COMMON_TESTHELPER_UTEST_EXE = ./unittests/common-testhelper-utest +COMMON_TESTHELPER_UTEST_EXE = ./unittests/common-testhelper-utest$(EXE_EXTENSION) LIB_COMMON_TESTHELPER_DIR = . LIB_COMMON_DIR = ../common LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src -LIB_IPPCPEPID_DIR = ../../ext/ipp/sources/ippcpepid/src #set flags for linker LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \ - -L$(LIB_COMMON_DIR) -L$(LIB_IPPCPEPID_DIR) -L$(LIB_IPPCP_DIR) \ - -lgtest -lcommon-testhelper -lcommon -lippcpepid -lippcp + -L$(LIB_COMMON_DIR) -L$(LIB_IPPCP_DIR) \ + -lgtest -lcommon-testhelper -lcommon -lippcp + +ifneq ($(TSS_PATH),) + CXXFLAGS += -DTPM_TSS +endif #target part $(COMMON_TESTHELPER_LIB): $(COMMON_TESTHELPER_OBJ) $(AR) rc $(COMMON_TESTHELPER_LIB) $(COMMON_TESTHELPER_OBJ) - ranlib $(COMMON_TESTHELPER_LIB) + $(RANLIB) $(COMMON_TESTHELPER_LIB) $(COMMON_TESTHELPER_OBJ): %.o: %.cc $(CXX) -o $@ $(CXXFLAGS) -I$(COMMON_TESTHELPER_INCLUDE_DIR) -c $^ $(COMMON_TESTHELPER_UTEST_EXE): $(COMMON_TESTHELPER_UTEST_OBJ) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) + $(CXX) -o $@ $^ $(LDFLAGS) $(COMMON_TESTHELPER_UTEST_OBJ): %.o: %.cc - $(CXX) -o $@ $(CXXFLAGS) -I$(COMMON_TESTHELPER_INCLUDE_DIR) \ + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(COMMON_TESTHELPER_INCLUDE_DIR) \ -I$(COMMON_TESTHELPER_11_INCLUDE_DIR) -I$(GTEST_INCLUDE_DIR) -c $^ build: all @@ -50,11 +53,13 @@ ifneq (,$(wildcard $(COMMON_TESTHELPER_UTEST_EXE))) cp $(COMMON_TESTHELPER_UTEST_EXE) '$(TEST_INSTALL_DIR)' endif -check: $(COMMON_TESTHELPER_UTEST_EXE) run +utest: $(COMMON_TESTHELPER_UTEST_EXE) -run: +run_utest: $(COMMON_TESTHELPER_UTEST_EXE) $(GTEST_FLAGS) +check: utest run_utest + clean: rm -f $(COMMON_TESTHELPER_OBJ) \ $(COMMON_TESTHELPER_LIB) \ diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/bignum_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/bignum_wrapper-testhelper.cc similarity index 98% rename from external/epid-sdk-3.0.0/epid/common-testhelper/bignum_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/bignum_wrapper-testhelper.cc index 75585e2a..680dd599 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/bignum_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/bignum_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ * \file * \brief Bignum C++ wrapper implementation. */ -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common/math/bignum.h" /// bignum deleter type diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/bignum_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/bignum_wrapper-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/bignum_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/bignum_wrapper-testhelper.h diff --git a/external/epid-sdk/epid/common-testhelper/common-testhelper.parts b/external/epid-sdk/epid/common-testhelper/common-testhelper.parts new file mode 100644 index 00000000..c0b6a414 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/common-testhelper.parts @@ -0,0 +1,86 @@ +############################################################################ +# Copyright 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +Import('*') +env.PartName('common-testhelper') + +src_files = Pattern( + src_dir='.', includes=['*-testhelper.cc'], excludes=[], + recursive=False).files() +inc_files = Pattern( + src_dir='.', includes=['*-testhelper.h'], excludes=[], + recursive=False).files() +epid11_src_files = Pattern( + src_dir='1.1', includes=['*-testhelper.cc'], excludes=[], + recursive=False).files() +epid11_inc_files = Pattern( + src_dir='1.1', includes=['*-testhelper.h'], excludes=[], + recursive=False).files() +test_data_files = Pattern( + src_dir='testdata', includes=['*'], excludes=[], recursive=True) +epid11_test_data_files = Pattern( + src_dir='1.1/testdata', includes=['*'], excludes=[], recursive=True) + +# unit tests +utest_files = Pattern( + src_dir='.', includes=['*-test.cc'], excludes=[], recursive=True).files() + +if 'use_tss' in env['MODE']: + env.Append(CPPDEFINES=['TPM_TSS']) + +if 'install_package' in env['MODE']: + env.InstallTopLevel(src_files, sub_dir='epid/${PART_SHORT_NAME}') + env.InstallTopLevel(inc_files, sub_dir='epid/${PART_SHORT_NAME}') + env.InstallTopLevel( + utest_files, sub_dir='epid/${PART_SHORT_NAME}/unittests') + env.InstallTopLevel( + test_data_files, sub_dir='epid/${PART_SHORT_NAME}/testdata') + + env.InstallTopLevel( + epid11_src_files, sub_dir='epid/${PART_SHORT_NAME}/1.1') + env.InstallTopLevel( + epid11_inc_files, sub_dir='epid/${PART_SHORT_NAME}/1.1') + env.InstallTopLevel( + epid11_test_data_files, sub_dir='epid/${PART_SHORT_NAME}/1.1/testdata') + + parts_file = ['common-testhelper.parts'] + env.InstallTopLevel(parts_file, sub_dir='epid/${PART_SHORT_NAME}') + makefile = ['Makefile'] + env.InstallTopLevel(makefile, sub_dir='epid/${PART_SHORT_NAME}') +else: + env.DependsOn([ + Component('common'), + ]) + + env.Append(CPPPATH='#') + + testenv = env.Clone() + + outputs = env.Library('${PART_NAME}', src_files + epid11_src_files) + env.Sdk(outputs) + + testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}" + testenv.UnitTest( + "utest", + utest_files, + command_args=[ + '--gtest_color=yes', + '--gtest_print_time=1', + '--gtest_output=xml', + '--gtest_filter=**', + ], + make_pdb=(env.isConfigBasedOn('debug')), + depends=[Component('gtest'), Component('common-testhelper')], + INSTALL_BIN='${INSTALL_TEST_BIN}') diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ecgroup_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/ecgroup_wrapper-testhelper.cc similarity index 85% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ecgroup_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/ecgroup_wrapper-testhelper.cc index 3ce59595..34dfd7e7 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/ecgroup_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/ecgroup_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ * \file * \brief EcGroup C++ wrapper implementation. */ -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common/math/bignum.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common/math/bignum.h" /// ecgroup deleter type struct EcGroupDeleter { @@ -58,28 +58,28 @@ struct EcGroupObj::State { EcGroupObj::EcGroupObj() : state_(new State()) { const BigNumStr q_str = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; const FqElemStr b_str = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; const BigNumStr p_str = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; const BigNumStr h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; const G1ElemStr g1_str = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; FiniteFieldObj fq(q_str); EcGroup* temp = nullptr; NewEcGroup(fq, FfElementObj(&fq), FfElementObj(&fq, b_str), diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ecgroup_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/ecgroup_wrapper-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ecgroup_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/ecgroup_wrapper-testhelper.h diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.cc similarity index 98% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.cc index f1aa18ce..354338b1 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ * \file * \brief EcPoint C++ wrapper implementation. */ -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common/math/bignum.h" /// ecpoint deleter type diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.h similarity index 98% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.h index 87b3af24..6e75df46 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/ecpoint_wrapper-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/ecpoint_wrapper-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,9 +25,9 @@ #include extern "C" { +#include "epid/common/1.1/types.h" #include "epid/common/math/bignum.h" #include "epid/common/math/ecgroup.h" -#include "epid/common/1.1/types.h" } class EcGroupObj; diff --git a/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.cc new file mode 100644 index 00000000..b9636f81 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.cc @@ -0,0 +1,49 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Epid2Params C++ wrapper implementation. +/*! \file */ + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" + +#include +#include +#include + +extern "C" { +#include "epid/common/src/epid2params.h" +} + +Epid2ParamsObj::Epid2ParamsObj() : params_(nullptr) { + EpidStatus sts = kEpidNoErr; + sts = CreateEpid2Params(¶ms_); + if (kEpidNoErr != sts) { + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "CreateEpid2Params()"); + } +} + +Epid2ParamsObj::~Epid2ParamsObj() { DeleteEpid2Params(¶ms_); } + +Epid2Params_* Epid2ParamsObj::ctx() const { return params_; } + +Epid2ParamsObj::operator Epid2Params_*() const { return params_; } + +Epid2ParamsObj::operator const Epid2Params_*() const { return params_; } + +FiniteField* Epid2ParamsObj::Fp() const { return params_->Fp; } + +EcGroup* Epid2ParamsObj::G1() const { return params_->G1; } diff --git a/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.h new file mode 100644 index 00000000..90ddcee7 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/epid2params_wrapper-testhelper.h @@ -0,0 +1,55 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Epid2Params C++ wrapper interface. +/*! \file */ + +#ifndef EPID_COMMON_TESTHELPER_EPID2PARAMS_WRAPPER_TESTHELPER_H_ +#define EPID_COMMON_TESTHELPER_EPID2PARAMS_WRAPPER_TESTHELPER_H_ + +typedef struct Epid2Params_ Epid2Params_; +typedef struct FiniteField FiniteField; +typedef struct EcGroup EcGroup; + +/// C++ Wrapper to manage memory for Epid2Params via RAII +class Epid2ParamsObj { + public: + /// Create a Epid2Params + Epid2ParamsObj(); + + // This class instances are not meant to be copied. + // Explicitly delete copy constructor and assignment operator. + Epid2ParamsObj(const Epid2ParamsObj&) = delete; + Epid2ParamsObj& operator=(const Epid2ParamsObj&) = delete; + + /// Destroy the Epid2Params + ~Epid2ParamsObj(); + /// get a pointer to the stored Epid2Params + Epid2Params_* ctx() const; + /// cast operator to get the pointer to the stored Epid2Params + operator Epid2Params_*() const; + /// const cast operator to get the pointer to the stored Epid2Params + operator const Epid2Params_*() const; + /// get a pointer to the prime field Fp + FiniteField* Fp() const; + /// get a pointer to elliptic curve group G1 + EcGroup* G1() const; + + private: + /// The stored parameters + Epid2Params_* params_; +}; + +#endif // EPID_COMMON_TESTHELPER_EPID2PARAMS_WRAPPER_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.cc b/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.cc new file mode 100644 index 00000000..d19e8225 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.cc @@ -0,0 +1,69 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Implementation of Intel(R) EPID specific predicates for gtest + */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include + +/// Record mapping status code to string +struct EpidStatusTextEntry { + /// error code + EpidStatus value; + /// name of error code + const char* value_name; +}; +#define EPID_STATUS_TEXT_ENTRY_VALUE(sts) \ + { sts, #sts } +/// Mapping of status codes to strings +static const struct EpidStatusTextEntry kEnumToText[] = { + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNoErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigInvalid), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInGroupRl), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInPrivRl), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInSigRl), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInVerifierRl), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNotImpl), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidBadArgErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNoMemErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMemAllocErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMathErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidDivByZeroErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidUnderflowErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidHashAlgorithmNotSupported), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidRandMaxIterErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidDuplicateErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidInconsistentBasenameSetErr), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMathQuadraticNonResidueError), + EPID_STATUS_TEXT_ENTRY_VALUE(kEpidOutOfSequenceError)}; + +const char* EpidStatusToName(EpidStatus e) { + size_t i = 0; + const size_t num_entries = sizeof(kEnumToText) / sizeof(kEnumToText[0]); + for (i = 0; i < num_entries; i++) { + if (e == kEnumToText[i].value) { + return kEnumToText[i].value_name; + } + } + return "unknown"; +} +std::ostream& operator<<(std::ostream& os, EpidStatus e) { + const char* enum_name = EpidStatusToName(e); + return os << enum_name << " (" << std::to_string(e) << ")"; +} diff --git a/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.h b/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.h new file mode 100644 index 00000000..3831f3d3 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/epid_gtest-testhelper.h @@ -0,0 +1,30 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Intel(R) EPID specific predicates for gtest + */ +#ifndef EPID_COMMON_TESTHELPER_EPID_GTEST_TESTHELPER_H_ +#define EPID_COMMON_TESTHELPER_EPID_GTEST_TESTHELPER_H_ +#include +extern "C" { +#include "epid/common/errors.h" +} + +std::ostream& operator<<(std::ostream& os, EpidStatus e); + +#endif // EPID_COMMON_TESTHELPER_EPID_GTEST_TESTHELPER_H_ diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.cc b/external/epid-sdk/epid/common-testhelper/epid_params-testhelper.cc similarity index 64% rename from external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/epid_params-testhelper.cc index 57fa53bc..1991db95 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/epid_params-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ * \brief Intel(R) EPID parameters C++ wrapper implementation. */ +#include #include +#include +#include #include #include "epid/common-testhelper/epid_params-testhelper.h" @@ -31,9 +34,13 @@ extern "C" { #include "epid/common/math/src/ecgroup-internal.h" #include "epid/common/math/src/finitefield-internal.h" #include "epid/common/math/src/pairing-internal.h" +#include "epid/common/src/epid2params.h" } Epid20Params::Epid20Params() { + // construct Fp finite field + fp = FiniteFieldObj(p_str_); + // construct Fq finite field fq = FiniteFieldObj(q_str_); @@ -53,9 +60,9 @@ Epid20Params::Epid20Params() { GT = FiniteFieldObj(fq6, neg_v, 2); const BigNumStr h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; // Create G1 // G1 is an elliptic curve group E(Fq).It can be initialized as follows : @@ -66,20 +73,20 @@ Epid20Params::Epid20Params() { // set h = 2q - p, aka cofactor std::vector cofactor_str( - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, 0xee, 0x71, 0xa4, 0xa0, - 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, 0xea, 0xb0, 0x25, 0x08, 0x4a, - 0x8c, 0x9b, 0x10, 0x19}); + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, + 0xee, 0x71, 0xa4, 0xa0, 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, + 0xea, 0xb0, 0x25, 0x08, 0x4a, 0x8c, 0x9b, 0x10, 0x19}); // set n = p * h, AKA order std::vector order_str( - {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, 0xc7, - 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, 0xe8, 0x54, - 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, 0x70, 0x21, 0xdc, - 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, 0x4e, 0x84, 0xcd, 0x19, - 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, 0xa0, 0x2e, 0x7f, 0x40, 0x13, - 0xb2, 0xfa, 0xa1, 0x45}); + {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, + 0xc7, 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, + 0xe8, 0x54, 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, + 0x70, 0x21, 0xdc, 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, + 0x4e, 0x84, 0xcd, 0x19, 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, + 0xa0, 0x2e, 0x7f, 0x40, 0x13, 0xb2, 0xfa, 0xa1, 0x45}); // Compute xi' = Fq2.inverse(xi). FfElementObj inv_xi(&fq2); @@ -96,69 +103,69 @@ Epid20Params::Epid20Params() { } const BigNumStr Epid20Params::q_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; const FqElemStr Epid20Params::beta_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}}; const Fq6ElemStr Epid20Params::v_str_ = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; const BigNumStr Epid20Params::p_str_ = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; const FqElemStr Epid20Params::b_str_ = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; const FqElemStr Epid20Params::h_str_ = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; const G1ElemStr Epid20Params::g1_str_ = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; const Fq2ElemStr Epid20Params::xi_str_ = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; const G2ElemStr Epid20Params::g2_str_ = { - {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, 0x13, - 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, 0x47, 0x0E, - 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, - {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, 0x25, - 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, 0x53, 0xE2, - 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, - {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, 0x03, - 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, 0x68, 0x38, - 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, - {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, 0xF8, - 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, 0xD6, 0x13, - 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; + {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, + 0x13, 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, + 0x47, 0x0E, 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, + {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, + 0x25, 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, + 0x53, 0xE2, 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, + {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, + 0x03, 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, + 0x68, 0x38, 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, + {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, + 0xF8, 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, + 0xD6, 0x13, 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.h b/external/epid-sdk/epid/common-testhelper/epid_params-testhelper.h similarity index 95% rename from external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.h rename to external/epid-sdk/epid/common-testhelper/epid_params-testhelper.h index 42e2a5cf..5ed76318 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/epid_params-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/epid_params-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,15 +26,17 @@ extern "C" { #include "epid/common/math/bignum.h" -#include "epid/common/math/finitefield.h" #include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" } -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/bignum_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" -#include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" + +typedef struct Epid2Params_ Epid2Params_; class Epid20Params { public: @@ -50,6 +52,8 @@ class Epid20Params { FiniteFieldObj GT; EcGroupObj G1; EcGroupObj G2; + FiniteFieldObj fq; + FiniteFieldObj fp; private: static const BigNumStr q_str_; @@ -64,7 +68,6 @@ class Epid20Params { static const Fq2ElemStr xi_str_; static const G2ElemStr g2_str_; - FiniteFieldObj fq; FiniteFieldObj fq2; FiniteFieldObj fq6; }; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/errors-testhelper.h b/external/epid-sdk/epid/common-testhelper/errors-testhelper.h similarity index 78% rename from external/epid-sdk-3.0.0/epid/common-testhelper/errors-testhelper.h rename to external/epid-sdk/epid/common-testhelper/errors-testhelper.h index f61de1b3..9950f26a 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/errors-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/errors-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ #ifndef EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_ #define EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_ -#include #include -#include -#include #include +#include +#include +#include extern "C" { #include "epid/common/math/bignum.h" @@ -38,4 +38,11 @@ extern "C" { throw std::logic_error(std::string("Failed to call: ") + #actual); \ } +/// Macro used to indicate fatal error during unit test run +#define THROW_NE(expected, actual) \ + if (expected != actual) { \ + printf("%s(%d): error: %s\n", __FILE__, __LINE__, "test defect"); \ + throw std::logic_error(std::string("Failed to call: ") + #actual); \ + } + #endif // EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_ diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.cc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.cc index 675142e0..fcebe505 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ * \file * \brief FfElement C++ wrapper implementation. */ -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/finite_field_wrapper-testhelper.h" #include "epid/common/math/bignum.h" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.h similarity index 98% rename from external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.h index df09065b..c86a68ad 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/ffelement_wrapper-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/ffelement_wrapper-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,9 +25,9 @@ #include extern "C" { +#include "epid/common/1.1/types.h" #include "epid/common/math/bignum.h" #include "epid/common/math/finitefield.h" -#include "epid/common/1.1/types.h" } class FiniteFieldObj; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/finite_field_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/finite_field_wrapper-testhelper.cc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common-testhelper/finite_field_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/finite_field_wrapper-testhelper.cc index 12bf5d3d..6bb0ceef 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/finite_field_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/finite_field_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ * \file * \brief FiniteField C++ wrapper implementation. */ -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common/math/bignum.h" #include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common/math/bignum.h" /// finite field deleter type struct FiniteFieldDeleter { diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/finite_field_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/finite_field_wrapper-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/finite_field_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/finite_field_wrapper-testhelper.h diff --git a/external/epid-sdk-3.0.0/example/util/strutil.h b/external/epid-sdk/epid/common-testhelper/mem_params-testhelper.cc similarity index 61% rename from external/epid-sdk-3.0.0/example/util/strutil.h rename to external/epid-sdk/epid/common-testhelper/mem_params-testhelper.cc index 885fc593..621b6910 100644 --- a/external/epid-sdk-3.0.0/example/util/strutil.h +++ b/external/epid-sdk/epid/common-testhelper/mem_params-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,20 @@ /*! * \file - * \brief Buffer handling utilities interface. + * \brief Implementation of Intel(R) EPID specific predicates for Set MemParams + * strcuture */ -#ifndef EXAMPLE_UTIL_STRUTIL_H_ -#define EXAMPLE_UTIL_STRUTIL_H_ +#include "epid/common-testhelper/mem_params-testhelper.h" -#include -#include - -// Prior to version 14.0 snprintf was not supported in MSVC -#if defined(_MSC_VER) && _MSC_VER < 1900 -int vsnprintf(char* outBuf, size_t size, const char* format, va_list ap); -int snprintf(char* outBuf, size_t size, const char* format, ...); +void SetMemberParams(BitSupplier rnd_func, void* rnd_param, const FpElemStr* f, + MemberParams* params) { +#ifdef TPM_TSS + (void)rnd_func; + (void)rnd_param; + params->f = f; +#else + params->rnd_func = rnd_func; + params->rnd_param = rnd_param; + params->f = f; #endif - -#endif // EXAMPLE_UTIL_STRUTIL_H_ +} diff --git a/external/epid-sdk/epid/common-testhelper/mem_params-testhelper.h b/external/epid-sdk/epid/common-testhelper/mem_params-testhelper.h new file mode 100644 index 00000000..48277ae2 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/mem_params-testhelper.h @@ -0,0 +1,48 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Intel(R) EPID 2.0 parameters C++ wrapper interface. + */ +#ifndef EPID_COMMON_TESTHELPER_MEM_PARAMS_TESTHELPER_H_ +#define EPID_COMMON_TESTHELPER_MEM_PARAMS_TESTHELPER_H_ + +extern "C" { +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" +#ifdef TPM_TSS +#include "epid/member/tpm_member.h" +#else +#include "epid/member/software_member.h" +#endif +} +/// Implementation specific configuration parameters. +typedef struct MemberParams MemberParams; + +/// Set MemmberParams structure +/*! + +MemberParams had different structure between TPM_TSS build +and non TPM_TSS build + +\returns ::void + +*/ +void SetMemberParams(BitSupplier rnd_func, void* rnd_param, const FpElemStr* f, + MemberParams* params); + +#endif // EPID_COMMON_TESTHELPER_MEM_PARAMS_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.cc new file mode 100644 index 00000000..7dfcefe0 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.cc @@ -0,0 +1,290 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member C++ wrapper implementation. + */ + +#include "epid/common-testhelper/member_wrapper-testhelper.h" + +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include "epid/common/types.h" +} + +#include "epid/common-testhelper/mem_params-testhelper.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + BitSupplier rnd_func, void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, &priv_key.f, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidProvisionKey(ctx_, &pub_key, &priv_key, nullptr); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, + MembershipCredential const& cred, + BitSupplier rnd_func, void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, nullptr, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidProvisionCredential(ctx_, &pub_key, &cred, nullptr); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + HashAlg hash_alg, BitSupplier rnd_func, + void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, &priv_key.f, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidMemberSetHashAlg(ctx_, hash_alg); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberSetHashAlg()"); + } + sts = EpidProvisionKey(ctx_, &pub_key, &priv_key, nullptr); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(BitSupplier rnd_func, void* rnd_param) + : ctx_(nullptr) { + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, nullptr, ¶ms); + ctx_ = CreateMember(¶ms); +} + +MemberCtxObj::MemberCtxObj(MemberParams const* params) : ctx_(nullptr) { + ctx_ = CreateMember(params); +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + MemberPrecomp const& precomp, BitSupplier rnd_func, + void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, &priv_key.f, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidProvisionKey(ctx_, &pub_key, &priv_key, &precomp); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + HashAlg hash_alg, MemberPrecomp const& precomp, + BitSupplier rnd_func, void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, &priv_key.f, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidMemberSetHashAlg(ctx_, hash_alg); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidProvisionKey(ctx_, &pub_key, &priv_key, &precomp); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, + MembershipCredential const& cred, + MemberPrecomp const& precomp, BitSupplier rnd_func, + void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, nullptr, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidProvisionCredential(ctx_, &pub_key, &cred, &precomp); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionCredential()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::MemberCtxObj(GroupPubKey const& pub_key, + MembershipCredential const& cred, HashAlg hash_alg, + BitSupplier rnd_func, void* rnd_param) + : ctx_(nullptr) { + EpidStatus sts = kEpidErr; + MemberParams params = {0}; + SetMemberParams(rnd_func, rnd_param, nullptr, ¶ms); + ctx_ = CreateMember(¶ms); + sts = EpidMemberSetHashAlg(ctx_, hash_alg); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionKey()"); + } + sts = EpidProvisionCredential(ctx_, &pub_key, &cred, nullptr); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidProvisionCredential()"); + } + sts = EpidMemberStartup(ctx_); + if (kEpidNoErr != sts) { + DeleteMember(&ctx_); + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberStartup()"); + } +} + +MemberCtxObj::~MemberCtxObj() { DeleteMember(&ctx_); } + +MemberCtx* MemberCtxObj::ctx() const { return ctx_; } + +MemberCtxObj::operator MemberCtx*() const { return ctx_; } + +MemberCtxObj::operator const MemberCtx*() const { return ctx_; } + +MemberCtx* MemberCtxObj::CreateMember(MemberParams const* params) const { + size_t context_size = 0; + EpidStatus sts = kEpidErr; + MemberCtx* member_ctx = NULL; + + sts = EpidMemberGetSize(params, &context_size); + if (kEpidNoErr != sts) { + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberGetSize()"); + } + + // allocate and zero initialize, no throw on failure + member_ctx = (MemberCtx*)new (std::nothrow) uint8_t[context_size](); + if (!member_ctx) { + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + std::ostringstream err; + err << "Failed to allocate " << context_size + << "bytes after EpidMemberGetSize()"; + throw std::logic_error(err.str()); + } + + sts = EpidMemberInit(params, member_ctx); + if (kEpidNoErr != sts) { + delete[](uint8_t*) member_ctx; + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "EpidMemberInit()"); + } + return member_ctx; +} + +void MemberCtxObj::DeleteMember(MemberCtx** ctx) const { + if (ctx) { + EpidMemberDeinit(*ctx); + delete[](uint8_t*)(*ctx); + *ctx = NULL; + } +} diff --git a/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.h new file mode 100644 index 00000000..d25f1962 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/member_wrapper-testhelper.h @@ -0,0 +1,84 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member C++ wrapper interface. + */ +#ifndef EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ +#define EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ + +extern "C" { +#include "epid/member/api.h" +} + +/// C++ Wrapper to manage memory for MemberCtx via RAII +class MemberCtxObj { + public: + /// Create a MemberCtx + explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + BitSupplier rnd_func, void* rnd_param); + /// Create a MemberCtx + explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + HashAlg hash_alg, BitSupplier rnd_func, + void* rnd_param); + /// Create a MemberCtx + explicit MemberCtxObj(BitSupplier rnd_func, void* rnd_param); + /// Create a MemberCtx + explicit MemberCtxObj(MemberParams const* params); + /// Create a MemberCtx + explicit MemberCtxObj(GroupPubKey const& pub_key, + MembershipCredential const& cred, BitSupplier rnd_func, + void* rnd_param); + /// Create a MemberCtx given precomputation blob + MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + MemberPrecomp const& precomp, BitSupplier rnd_func, + void* rnd_param); + /// Create a MemberCtx given precomputation blob + MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, + HashAlg hash_alg, MemberPrecomp const& precomp, + BitSupplier rnd_func, void* rnd_param); + /// Create a MemberCtx given precomputation blob + MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred, + MemberPrecomp const& precomp, BitSupplier rnd_func, + void* rnd_param); + /// Create a MemberCtx given precomputation blob + MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred, + HashAlg hash_alg, BitSupplier rnd_func, void* rnd_param); + // This class instances are not meant to be copied. + // Explicitly delete copy constructor and assignment operator. + MemberCtxObj(const MemberCtxObj&) = delete; + MemberCtxObj& operator=(const MemberCtxObj&) = delete; + + /// Destroy the MemberCtx + ~MemberCtxObj(); + /// get a pointer to the stored MemberCtx + MemberCtx* ctx() const; + /// cast operator to get the pointer to the stored MemberCtx + operator MemberCtx*() const; + /// const cast operator to get the pointer to the stored MemberCtx + operator const MemberCtx*() const; + + private: + /// Creates and initializes new member given parameters. + MemberCtx* CreateMember(MemberParams const* params) const; + /// Deletes the member created by CreateMember(). + void DeleteMember(MemberCtx** ctx) const; + /// The stored MemberCtx + MemberCtx* ctx_; +}; + +#endif // EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/octstr-testhelper.cc b/external/epid-sdk/epid/common-testhelper/octstr-testhelper.cc similarity index 95% rename from external/epid-sdk-3.0.0/epid/common-testhelper/octstr-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/octstr-testhelper.cc index 86ce1931..18e9fff3 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/octstr-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/octstr-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,8 +22,11 @@ extern "C" { #include "epid/common/src/memory.h" } +#include "epid/common/types.h" #include "ext/ipp/include/ippcp.h" +typedef Ipp8u* IppOctStr; + /// Internal function to delete BigNum void delete_BigNum(IppsBigNumState** bn) { if (*bn) { @@ -71,7 +74,7 @@ EpidStatus create_BigNum(IppsBigNumState** bn, const OctStr256* str) { break; } - sts = ippsSetOctString_BN((Ipp8u*)str, byte_size, ipp_bn_ctx); + sts = ippsSetOctString_BN((IppOctStr)str, byte_size, ipp_bn_ctx); if (sts != ippStsNoErr) { if (sts == ippStsLengthErr) { result = kEpidBadArgErr; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/octstr-testhelper.h b/external/epid-sdk/epid/common-testhelper/octstr-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/octstr-testhelper.h rename to external/epid-sdk/epid/common-testhelper/octstr-testhelper.h diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/prng-testhelper.h b/external/epid-sdk/epid/common-testhelper/prng-testhelper.h similarity index 63% rename from external/epid-sdk-3.0.0/epid/common-testhelper/prng-testhelper.h rename to external/epid-sdk/epid/common-testhelper/prng-testhelper.h index f3008e1a..8eaae83d 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/prng-testhelper.h +++ b/external/epid-sdk/epid/common-testhelper/prng-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,7 +27,13 @@ #define __STDCALL #endif #include // for CHAR_BIT +#include #include +#include + +extern "C" { +#include "epid/common/types.h" +} /// Return status for Prng Generate function typedef enum { @@ -53,30 +59,23 @@ class Prng { static int __STDCALL Generate(unsigned int* random_data, int num_bits, void* user_data) { unsigned int num_bytes = num_bits / CHAR_BIT; - unsigned int num_words = num_bytes / sizeof(unsigned int); - unsigned int extra_bytes = num_bytes % sizeof(unsigned int); + + unsigned int extra_bits = num_bits % CHAR_BIT; + unsigned char* random_bytes = reinterpret_cast(random_data); if (!random_data) { return kPrngBadArgErr; } if (num_bits <= 0) { return kPrngBadArgErr; } - Prng* myprng = (Prng*)user_data; - std::uniform_int_distribution<> dis(0x0, 0xffff); - if (num_words > 0) { - for (unsigned int n = 0; n < num_words; n++) { - random_data[n] = - (dis(myprng->generator_) << 16) + dis(myprng->generator_); - } + if (0 != extra_bits) { + num_bytes += 1; } - if (extra_bytes > 0) { - unsigned int data = - (dis(myprng->generator_) << 16) + dis(myprng->generator_); - unsigned char* byte_data = (unsigned char*)&data; - unsigned char* random_bytes = (unsigned char*)&random_data[num_words]; - for (unsigned int n = 0; n < extra_bytes; n++) { - random_bytes[n] = byte_data[n]; - } + + Prng* myprng = (Prng*)user_data; + for (unsigned int n = 0; n < num_bytes; n++) { + random_bytes[n] = + static_cast(myprng->generator_() & 0x000000ff); } return kPrngNoErr; @@ -87,4 +86,31 @@ class Prng { std::mt19937 generator_; }; +// BitSupplier implementation returns pre-defined bytes. +class StaticPrng { + public: + StaticPrng(ConstOctStr bytes, size_t length) + : bytes_((uint8_t const*)bytes, (uint8_t const*)bytes + length) {} + ~StaticPrng() {} + /// Generates random number + static int __STDCALL Generate(unsigned int* random_data, int num_bits, + void* user_data) { + unsigned int num_bytes = num_bits / CHAR_BIT; + if (!random_data) { + return kPrngBadArgErr; + } + if (num_bits <= 0) { + return kPrngBadArgErr; + } + StaticPrng* myprng = (StaticPrng*)user_data; + for (size_t i = 0; i < num_bytes; i++) { + random_data[i] = myprng->bytes_[i % myprng->bytes_.size()]; + } + return kPrngNoErr; + } + + private: + std::vector bytes_; +}; + #endif // EPID_COMMON_TESTHELPER_PRNG_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/common-testhelper/testapp-testhelper.cc b/external/epid-sdk/epid/common-testhelper/testapp-testhelper.cc new file mode 100644 index 00000000..7fde3850 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testapp-testhelper.cc @@ -0,0 +1,74 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/*! +* \file +* \brief Main entry point helpers unit tests. +*/ +#include "epid/common-testhelper/testapp-testhelper.h" +#include +#include +#include + +void split_filter(std::vector* positive, + std::vector* negative, std::string filter_expr) { + std::istringstream f(filter_expr); + std::string s; + bool is_neg = false; + while (getline(f, s, ':')) { + if (!is_neg) { + if (s.compare(0, 1, "-") == 0) { + is_neg = true; + s = s.substr(1); + } else { + positive->push_back(s); + } + } + if (is_neg) { + negative->push_back(s); + } + } +} + +std::string join_filter(std::vector const& positive, + std::vector const& negative) { + std::ostringstream s; + bool first = true; + bool first_neg = true; + if (!positive.empty() || !negative.empty()) { + s << "--gtest_filter="; + } + for (const auto& i : positive) { + if (!first) { + s << ":"; + } else { + first = false; + } + s << i; + } + for (const auto& i : negative) { + if (!first) { + s << ":"; + } else { + first = false; + } + if (first_neg) { + s << "-"; + first_neg = false; + } + s << i; + } + return s.str(); +} diff --git a/external/epid-sdk/epid/common-testhelper/testapp-testhelper.h b/external/epid-sdk/epid/common-testhelper/testapp-testhelper.h new file mode 100644 index 00000000..4c337683 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testapp-testhelper.h @@ -0,0 +1,33 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/*! +* \file +* \brief Main entry point helpers unit tests. +*/ + +#ifndef EPID_COMMON_TESTHELPER_TESTAPP_TESTHELPER_H_ +#define EPID_COMMON_TESTHELPER_TESTAPP_TESTHELPER_H_ + +#include +#include + +void split_filter(std::vector* positive, + std::vector* negative, std::string filter_expr); + +std::string join_filter(std::vector const& positive, + std::vector const& negative); + +#endif // EPID_COMMON_TESTHELPER_TESTAPP_TESTHELPER_H_ diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/gpubkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/gpubkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/gpubkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/gpubkey.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_bsn0_msg_0_255_sha512.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_bsn0_msg_0_255_sha512.inc new file mode 100644 index 00000000..e57d201a --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_bsn0_msg_0_255_sha512.inc @@ -0,0 +1,72 @@ + /*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : groupA + * Signer : member0 + * HashAlg : Sha512 + * Message : bytes [0, 255] + * Basename: "bsn0" + * SigRl : SigRl of group + */ + 0x72, 0xed, 0x4f, 0x01, 0xf2, 0xfe, 0xc9, 0xf4, 0x56, 0x4f, 0x11, 0x31, + 0x62, 0x07, 0x02, 0x0f, 0xed, 0xd0, 0x6b, 0xe8, 0xbf, 0xa9, 0x0b, 0x55, + 0xb8, 0xf7, 0xe9, 0x6e, 0xaa, 0x13, 0x2e, 0x6f, 0xa7, 0xd5, 0xec, 0x4b, + 0x3e, 0x23, 0x5f, 0x4f, 0x61, 0x44, 0x52, 0xc1, 0x75, 0x0b, 0x13, 0xad, + 0xa1, 0x53, 0x0d, 0x6a, 0x73, 0xed, 0x5e, 0x49, 0xa9, 0xed, 0x1d, 0x88, + 0xde, 0xa6, 0x93, 0x18, 0xa4, 0xaa, 0xcc, 0x21, 0xc0, 0xbb, 0x90, 0xc1, + 0xb4, 0x1c, 0x8d, 0xf6, 0xd9, 0xb4, 0x6d, 0xd8, 0xa6, 0x66, 0xed, 0xc4, + 0x33, 0x97, 0x6d, 0xc1, 0x68, 0x44, 0x3e, 0xd1, 0x08, 0x75, 0x6e, 0x1d, + 0xf5, 0x81, 0xee, 0x39, 0xaa, 0xbf, 0xc9, 0x38, 0x14, 0x8a, 0x57, 0x93, + 0x85, 0x6a, 0x98, 0xbf, 0x1a, 0xed, 0xa5, 0x96, 0x1f, 0x97, 0x1e, 0xc6, + 0xc5, 0x28, 0x8e, 0x6f, 0xf4, 0xca, 0x2f, 0xe5, 0xc6, 0x4c, 0xc8, 0x9d, + 0xdc, 0x63, 0x46, 0x5b, 0xab, 0x79, 0xea, 0x49, 0x76, 0x47, 0x68, 0xe6, + 0x2e, 0x7d, 0x0b, 0x49, 0xc0, 0x29, 0xe4, 0xc8, 0x84, 0xb5, 0x04, 0x2d, + 0x15, 0xaa, 0x0d, 0xd4, 0x71, 0x43, 0xd0, 0x24, 0x3e, 0x00, 0xf4, 0x94, + 0xad, 0x1e, 0x1e, 0x32, 0xea, 0x21, 0x4d, 0x83, 0xae, 0x63, 0x3c, 0x5a, + 0xd4, 0xa5, 0x79, 0x9b, 0x2c, 0xad, 0x03, 0x50, 0xb6, 0x57, 0x0a, 0xbf, + 0x3f, 0xeb, 0xf5, 0x72, 0x9f, 0x5f, 0x9f, 0x95, 0x5c, 0x66, 0xc9, 0x1f, + 0xfe, 0x71, 0x50, 0xee, 0xf6, 0x09, 0xf5, 0x1f, 0x08, 0x0c, 0x78, 0xd0, + 0xc3, 0xcf, 0x4a, 0x7b, 0xba, 0xb5, 0xf7, 0xbb, 0xc4, 0x5e, 0x1f, 0x0c, + 0xc3, 0x25, 0xe3, 0x7f, 0x8d, 0x15, 0x16, 0xec, 0x6a, 0xae, 0x58, 0xf8, + 0xb9, 0x73, 0x0f, 0xa4, 0x73, 0xdb, 0xe7, 0x29, 0x72, 0x07, 0xda, 0xcc, + 0x0f, 0xc4, 0xfc, 0x9b, 0xd3, 0xe5, 0xbd, 0x26, 0xf5, 0xb6, 0x05, 0xaf, + 0x93, 0x31, 0xf5, 0x62, 0x6d, 0xf4, 0xdd, 0xea, 0x16, 0xf9, 0xe9, 0x2e, + 0x3f, 0x10, 0xa4, 0x6f, 0xfd, 0x7c, 0x06, 0x10, 0x74, 0x51, 0xf1, 0x8e, + 0x1e, 0x49, 0xd2, 0xb1, 0x4c, 0x89, 0xe1, 0x16, 0x5e, 0xbc, 0xbb, 0xfc, + 0x5f, 0xad, 0x33, 0xb9, 0x7a, 0x9b, 0xf4, 0x59, 0x0b, 0xf2, 0x0e, 0x63, + 0x39, 0xc7, 0x90, 0xce, 0x0a, 0xef, 0x5c, 0x72, 0x7a, 0x05, 0xbb, 0xe5, + 0xfe, 0xfc, 0xbe, 0x2c, 0xdf, 0xd1, 0xba, 0x0c, 0x3f, 0x40, 0xe0, 0x8c, + 0xa4, 0x25, 0xe8, 0xc3, 0x54, 0x8d, 0x32, 0xba, 0x2d, 0x96, 0x3c, 0x5e, + 0x44, 0x61, 0xd1, 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + // sigma + 0x9a, 0x8a, 0x3c, 0x2d, 0x96, 0x27, 0x84, 0xfc, 0x3f, 0x11, 0x87, 0x30, + 0x51, 0x30, 0x62, 0xba, 0x51, 0x93, 0x09, 0x87, 0x80, 0x44, 0x02, 0x10, + 0x95, 0x09, 0xe7, 0x7f, 0x27, 0x9d, 0x8f, 0xae, 0xc7, 0x06, 0xad, 0xd8, + 0xe2, 0xe4, 0x79, 0x07, 0x0c, 0xc1, 0xba, 0x5f, 0x64, 0xe2, 0xee, 0xe5, + 0xc5, 0x89, 0x6d, 0xc4, 0xde, 0x2c, 0xd3, 0x88, 0x31, 0x09, 0x47, 0x3d, + 0xd4, 0x5a, 0xe1, 0x55, 0x43, 0xbc, 0x23, 0x60, 0xdd, 0x63, 0xf9, 0x21, + 0x07, 0xde, 0x56, 0x85, 0x9f, 0x0c, 0xbe, 0x04, 0xfe, 0x35, 0x67, 0x75, + 0x23, 0x27, 0x11, 0x8e, 0x7b, 0xcd, 0x7d, 0x85, 0x2e, 0xd2, 0xfe, 0x25, + 0x6a, 0x34, 0xf2, 0xed, 0x5d, 0x2b, 0x1e, 0x63, 0x46, 0x88, 0x72, 0x47, + 0x5e, 0xf3, 0x1b, 0x70, 0x3d, 0xd7, 0x06, 0x7a, 0x07, 0xb1, 0x62, 0xd4, + 0x55, 0x6a, 0xed, 0x0b, 0x4e, 0x52, 0xcd, 0x8d, 0x5c, 0x35, 0x6b, 0x58, + 0xad, 0x69, 0x14, 0x96, 0xe7, 0x0c, 0x43, 0x14, 0xd6, 0x28, 0x33, 0xbc, + 0xe4, 0x2c, 0x23, 0x58, 0xee, 0x05, 0xa2, 0x6f, 0x7b, 0x88, 0xab, 0xc8, + 0x93, 0x6e, 0x99, 0xba, diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha384_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha384_sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha384_sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha384_sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_basename1_sha256.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_basename1_sha256.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_basename1_sha256.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_basename1_sha256.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/privrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/privrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/privrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/privrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/verrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp01/verrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp01/verrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp01/verrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/corrupted_privrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/corrupted_privrl.inc new file mode 100644 index 00000000..40471176 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/corrupted_privrl.inc @@ -0,0 +1,36 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 private-key based revocation list + * Group : grpX + */ +//unsigned char privrl_dat[] = { + // Group ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // RLver + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xee, + // n1 + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, + // f[1] + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9E, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, + 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D, +//}; +//unsigned int privrl_dat_len = 56; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/iprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/iprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/iprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/iprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0_rl_singleentry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0_rl_singleentry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0_rl_singleentry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg0_rl_singleentry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn0_msg1.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_bsn1_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_rndbase_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_rndbase_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha384_rndbase_msg0.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_bsn0_msg0.inc new file mode 100644 index 00000000..7decfdee --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_bsn0_msg0.inc @@ -0,0 +1,100 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : member0 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: "bsn0" + * SigRl : group x sigrl + */ +// unsigned char sig[] = { +0xcb, 0xc0, 0x78, 0x14, 0xbd, 0x94, 0x6f, 0xe6, 0xeb, 0x43, 0x37, 0x3b, +0x7e, 0x22, 0x79, 0xf4, 0x4d, 0xc1, 0x55, 0x93, 0x7f, 0x5c, 0x22, 0x2f, +0x87, 0x15, 0x18, 0x92, 0xbd, 0x23, 0x15, 0x83, 0x9e, 0x0d, 0x3b, 0x35, +0xe9, 0xd0, 0xdd, 0xd5, 0xd8, 0x99, 0xac, 0x22, 0xaf, 0x2a, 0xa3, 0x52, +0x25, 0xfa, 0x02, 0x50, 0x60, 0x60, 0xd3, 0x07, 0x7a, 0x59, 0xec, 0x8d, +0xb2, 0xf6, 0x6e, 0x2d, 0x98, 0x59, 0x58, 0x94, 0x34, 0xda, 0x7a, 0x0b, +0x66, 0xc4, 0xa5, 0x8f, 0x6a, 0x56, 0xf6, 0x91, 0x0b, 0xa8, 0x52, 0xde, +0xb4, 0x1c, 0x36, 0xa7, 0x93, 0x6d, 0xbf, 0xd6, 0xca, 0x0e, 0x77, 0x9a, +0xb1, 0xdf, 0xc4, 0x78, 0x61, 0x41, 0x17, 0xb2, 0x74, 0x7f, 0x92, 0xc8, +0x26, 0x17, 0x89, 0xa0, 0x1b, 0xdb, 0x6a, 0x82, 0x1b, 0x7d, 0xb0, 0x3b, +0x3e, 0x4e, 0x06, 0x81, 0x83, 0x3a, 0x79, 0x09, 0xba, 0xec, 0xaa, 0x96, +0x22, 0xa9, 0xaa, 0xb3, 0x4f, 0x19, 0x9e, 0xf3, 0xed, 0x82, 0xcc, 0xf2, +0x69, 0x4c, 0x17, 0x39, 0x27, 0xf4, 0x18, 0x98, 0x0f, 0xdc, 0xc9, 0x4e, +0x93, 0x9c, 0x5e, 0xad, 0x77, 0xbd, 0xe2, 0x74, 0x0b, 0xa9, 0x8a, 0x8a, +0xfc, 0xa6, 0x79, 0x0b, 0x72, 0x7b, 0x2a, 0x9b, 0xba, 0x25, 0x51, 0x06, +0x06, 0x14, 0xc4, 0x6d, 0xa6, 0x2f, 0xf5, 0xdd, 0x3d, 0xd6, 0x49, 0x61, +0x6c, 0x08, 0x7a, 0xff, 0x66, 0xbf, 0xf5, 0xbb, 0x08, 0x3d, 0x14, 0x89, +0x15, 0x5a, 0xcf, 0xcd, 0x50, 0xbb, 0xab, 0x4d, 0xb2, 0xda, 0x9d, 0xac, +0x6d, 0xee, 0xc3, 0xf7, 0x09, 0x9a, 0x84, 0xe1, 0x75, 0x2e, 0x1a, 0x7d, +0x50, 0xa2, 0x62, 0xaf, 0xf4, 0x0a, 0x9a, 0x7c, 0x9d, 0x13, 0x0a, 0xd6, +0x34, 0x5d, 0x97, 0xc7, 0x65, 0x2a, 0xda, 0x5e, 0xae, 0xf0, 0x6c, 0x4b, +0x7d, 0x9f, 0x10, 0x99, 0x04, 0x1b, 0xde, 0x58, 0xe7, 0xa7, 0xa5, 0x31, +0x0a, 0x5b, 0x51, 0x01, 0xc8, 0x65, 0x47, 0xf2, 0xbc, 0x19, 0xf2, 0xe0, +0x7f, 0x43, 0x9d, 0x58, 0x50, 0xf2, 0xbf, 0x47, 0x94, 0xce, 0xa9, 0x50, +0x81, 0x60, 0x72, 0x64, 0xf2, 0x6e, 0x62, 0x8b, 0x13, 0x6a, 0x95, 0x7f, +0xf1, 0xfe, 0x3e, 0x6a, 0xc1, 0x5e, 0x59, 0x98, 0x24, 0x0b, 0xc7, 0x31, +0x12, 0xe1, 0x96, 0x92, 0xdb, 0x39, 0x17, 0xcf, 0xb8, 0x0e, 0x02, 0xd5, +0x3b, 0x5e, 0x8f, 0x32, 0xee, 0x58, 0x02, 0x6f, 0x9f, 0x08, 0xe1, 0xf7, +0xe9, 0x63, 0xed, 0xae, 0xf0, 0xe5, 0x43, 0xcb, 0x31, 0x76, 0x78, 0x33, +0x06, 0x84, 0xc2, 0x87, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, +0x43, 0x04, 0xf0, 0xea, 0xe0, 0xca, 0x02, 0x65, 0x22, 0xd4, 0x68, 0x5c, +0x12, 0xfa, 0xe0, 0x39, 0x23, 0x5a, 0xde, 0x7e, 0xb2, 0xed, 0x02, 0x4f, +0xcc, 0x10, 0xe4, 0xf7, 0x5f, 0x7d, 0x69, 0xbc, 0x6d, 0xf9, 0xe9, 0x0b, +0x88, 0x1b, 0x60, 0xad, 0xee, 0xab, 0x56, 0xc1, 0x36, 0x44, 0x58, 0x92, +0x28, 0x64, 0x87, 0xdc, 0x2a, 0xfb, 0x1e, 0x59, 0x24, 0xbb, 0x07, 0xf5, +0x1c, 0x3a, 0xee, 0xe7, 0x33, 0xec, 0x48, 0xd3, 0xd3, 0x10, 0xf4, 0x0a, +0x3c, 0xb6, 0xfd, 0x80, 0x0a, 0x95, 0x91, 0x67, 0xa6, 0x53, 0x34, 0x19, +0x63, 0x4c, 0x4d, 0xff, 0x21, 0xe9, 0x0c, 0xc2, 0x53, 0x95, 0x27, 0xbd, +0x7f, 0x60, 0x5f, 0x3c, 0xa6, 0x8f, 0xcb, 0xf8, 0x67, 0x91, 0xa9, 0xb9, +0x11, 0x52, 0xa7, 0x49, 0x04, 0xde, 0x1d, 0x47, 0x4a, 0xc8, 0x9b, 0x27, +0x31, 0x03, 0xa4, 0x4c, 0x3b, 0x29, 0xfc, 0xa4, 0x35, 0x11, 0x42, 0x86, +0x3f, 0x67, 0x70, 0xac, 0x89, 0x66, 0x93, 0x39, 0x2a, 0xce, 0x34, 0x51, +0xcc, 0x7d, 0x93, 0x5b, 0x0f, 0xe4, 0xbd, 0xdf, 0x70, 0xaa, 0xf2, 0x74, +0x61, 0x2c, 0x6c, 0x63, 0x78, 0xd9, 0xf1, 0x6b, 0x41, 0x4f, 0xeb, 0xe4, +0x25, 0x00, 0x45, 0xd4, 0xab, 0xce, 0xd2, 0x01, 0xa0, 0x18, 0xd1, 0x37, +0x6c, 0xb1, 0xb4, 0x44, 0xef, 0x62, 0x18, 0x76, 0x2a, 0xd8, 0x56, 0x26, +0xee, 0x6c, 0x68, 0xd9, 0xf8, 0x91, 0xd9, 0x5a, 0x10, 0x52, 0x75, 0xb0, +0x3e, 0xe8, 0x98, 0xa9, 0x37, 0x3d, 0x18, 0x50, 0xfd, 0x7c, 0x18, 0x43, +0xbd, 0x25, 0x4e, 0x08, 0x02, 0xc0, 0x9e, 0xa5, 0x47, 0xcb, 0x3c, 0xd4, +0xb9, 0xe1, 0x7a, 0xdf, 0x70, 0x35, 0x7b, 0x61, 0x42, 0x1a, 0x86, 0xf0, +0xab, 0x64, 0xf5, 0x5c, 0x5c, 0x7f, 0xfa, 0xd5, 0x73, 0x1e, 0xd6, 0x62, +0x67, 0xad, 0xf2, 0xe7, 0x8b, 0xd0, 0xaf, 0xbb, 0x5f, 0x1f, 0xff, 0xb0, +0xc0, 0x94, 0x6e, 0x68, 0xed, 0xc3, 0xdb, 0x8f, 0x2f, 0xeb, 0x72, 0x2c, +0x65, 0xb8, 0x8b, 0x50, 0x2f, 0x28, 0xfa, 0xa0, 0xdd, 0x8a, 0x42, 0xd7, +0xeb, 0xc3, 0xd2, 0x49, 0xb7, 0x56, 0x6d, 0xc1, 0x23, 0xa5, 0x8c, 0xe1, +0x19, 0xde, 0x59, 0x46, 0xaf, 0x4e, 0x10, 0x77, 0x9c, 0x5e, 0x7f, 0x00, +0x74, 0x83, 0x57, 0x04, 0xc1, 0xee, 0x48, 0xba, 0x13, 0xab, 0x06, 0x8b, +0xb7, 0x07, 0xa0, 0x7c, 0x17, 0x1a, 0x62, 0xa3, 0xdf, 0x86, 0xcd, 0xd0, +0x3a, 0xc1, 0x4f, 0x80, 0x0d, 0x64, 0x8e, 0xf8, 0xe6, 0xf9, 0xed, 0x35, +0x26, 0xe5, 0x04, 0x3e, 0x61, 0xd9, 0x32, 0x5a, 0x5c, 0x56, 0x51, 0xb2, +0xdf, 0xab, 0x5c, 0x7e, 0xce, 0xd6, 0xb7, 0x6d, 0x10, 0xc5, 0xb4, 0xf6, +0x66, 0xe0, 0xb7, 0x1b, 0x36, 0x78, 0x05, 0xde, 0xa7, 0xdd, 0x93, 0xdd, +0x6f, 0x74, 0xa6, 0xce, 0x3e, 0xb7, 0x52, 0x32, 0xdc, 0x09, 0xba, 0x25, +0xb2, 0xc8, 0xa1, 0x6b, 0x67, 0xa3, 0xac, 0x77, 0xd9, 0xa8, 0x14, 0x09, +0x7d, 0x2a, 0x66, 0x89, 0x3f, 0xc0, 0x3a, 0xaf, 0xef, 0x79, 0xfb, 0x38, +0x59, 0x58, 0x78, 0xd1, 0x78, 0x73, 0x0d, 0xaf, 0x80, 0xe6, 0x2c, 0x90, +0x21, 0x97, 0x7c, 0xa5, 0xa6, 0xe7, 0x4c, 0x30, 0xfe, 0x96, 0xea, 0x82, +0xcd, 0x14, 0x20, 0xec, 0xc4, 0x81, 0x29, 0xec, 0x82, 0xc7, 0xfe, 0xe2, +0x79, 0x92, 0x12, 0x61, 0x3f, 0xc8, 0xa2, 0x45, 0x2e, 0xe3, 0xe9, 0x11, +0xfc, 0x22, 0xc3, 0xb4, 0x73, 0x5c, 0xcb, 0xc3, 0xd5, 0x24, 0x75, 0x9d, +// } +// unsigned int sig_len = 840; diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0.inc new file mode 100644 index 00000000..12d464ba --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0.inc @@ -0,0 +1,100 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : member0 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: None (random base) + * SigRl : group x sigrl + */ +// unsigned char sig[] = { + 0xf9, 0x71, 0x8d, 0x87, 0x0c, 0x04, 0x6a, 0x5c, 0xea, 0x61, 0xee, 0xcd, + 0x41, 0x62, 0xc6, 0xc0, 0x30, 0x88, 0x34, 0x2d, 0x37, 0xd6, 0x47, 0xa8, + 0x39, 0xe1, 0x6a, 0xa5, 0x56, 0xae, 0x1c, 0x4f, 0x62, 0x36, 0xcb, 0x59, + 0x10, 0xf5, 0x81, 0x94, 0x08, 0xe6, 0xd0, 0x62, 0xab, 0x59, 0x9f, 0x29, + 0xc9, 0xaf, 0xe5, 0x75, 0xa5, 0xee, 0x30, 0xd8, 0x0c, 0xc4, 0x63, 0x4d, + 0x2a, 0x72, 0xee, 0xd4, 0xfc, 0x3a, 0xc1, 0x2a, 0xd9, 0xad, 0xb2, 0xc0, + 0xe1, 0x62, 0x7e, 0x01, 0xb0, 0x28, 0x2b, 0x74, 0x7d, 0xba, 0xab, 0x6a, + 0x12, 0x81, 0x81, 0x51, 0xad, 0x27, 0x8d, 0xc8, 0x66, 0xba, 0x29, 0xd0, + 0xdd, 0x0f, 0xa1, 0x41, 0xd8, 0xf7, 0xc3, 0xca, 0xcf, 0x71, 0x2d, 0xaf, + 0x90, 0x7b, 0x22, 0x7b, 0x63, 0x74, 0x5a, 0x74, 0x20, 0xe8, 0xa3, 0x93, + 0x17, 0xc4, 0x4e, 0xca, 0xf0, 0x5e, 0xc1, 0x5c, 0xd1, 0x1a, 0x6c, 0xc2, + 0x22, 0xdb, 0x9f, 0xff, 0x3b, 0x0c, 0x49, 0xe0, 0x22, 0x64, 0x46, 0x7a, + 0x87, 0x0e, 0x49, 0x42, 0x53, 0xf4, 0xbb, 0xdb, 0x6e, 0xd1, 0x15, 0xd5, + 0xec, 0x70, 0x6b, 0xed, 0x8c, 0x99, 0x85, 0x88, 0x77, 0xc8, 0x09, 0xb7, + 0x2f, 0xc4, 0x35, 0xbd, 0x0a, 0xe5, 0x3d, 0x1c, 0xd3, 0x23, 0x94, 0x07, + 0x42, 0x50, 0x02, 0x48, 0x5c, 0x4f, 0x22, 0x23, 0xce, 0xb8, 0x70, 0x44, + 0x9d, 0x55, 0xae, 0x3b, 0x4c, 0xa7, 0xe9, 0x58, 0xf7, 0x83, 0x1a, 0x11, + 0x97, 0x6b, 0x2b, 0x19, 0x6a, 0xf9, 0x5d, 0x45, 0x4f, 0xae, 0x6c, 0xb2, + 0x72, 0x40, 0xb0, 0x54, 0x6c, 0x8e, 0xbc, 0x64, 0x0c, 0x7e, 0xf5, 0x32, + 0x97, 0x4e, 0x2d, 0xb4, 0x88, 0x76, 0x26, 0xc5, 0x2a, 0x28, 0x5c, 0x46, + 0xe7, 0x1f, 0x04, 0xc0, 0xad, 0xe6, 0xcd, 0x51, 0xaf, 0x25, 0x89, 0x17, + 0xff, 0x3e, 0x90, 0xba, 0x8e, 0x50, 0xe5, 0x6d, 0xe6, 0x10, 0xbf, 0x99, + 0x56, 0x61, 0x47, 0xfb, 0xa9, 0x1a, 0x77, 0xd9, 0xdf, 0xe1, 0x62, 0x51, + 0xa8, 0xe1, 0x91, 0x64, 0xf4, 0x87, 0xa0, 0x1d, 0xe8, 0x46, 0x68, 0xcb, + 0x76, 0x9f, 0x51, 0x49, 0x7b, 0xe7, 0xfe, 0xde, 0x21, 0xb6, 0xca, 0x93, + 0x8b, 0x5e, 0x8e, 0x79, 0xa0, 0x9e, 0x69, 0xf3, 0xe5, 0x4d, 0x53, 0x3a, + 0x3b, 0x6c, 0x28, 0xe1, 0x56, 0x6a, 0xb9, 0x86, 0x0a, 0xc8, 0x81, 0xb9, + 0x87, 0xee, 0xe4, 0xb0, 0x41, 0x3a, 0x4a, 0x4b, 0xde, 0x39, 0x2b, 0x63, + 0x62, 0x2a, 0x97, 0xd6, 0x9c, 0xaa, 0xc9, 0xdd, 0x09, 0x77, 0x53, 0x5f, + 0xdb, 0xfe, 0x7d, 0x51, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + 0xad, 0x09, 0xe0, 0x35, 0xf5, 0xfb, 0xc9, 0xc0, 0xf4, 0x18, 0x23, 0x31, + 0x29, 0xed, 0xbb, 0x33, 0xf7, 0x38, 0x86, 0xe2, 0xd8, 0x69, 0x0e, 0x7d, + 0xf3, 0x94, 0xbb, 0xe8, 0xfb, 0xbe, 0xcd, 0xaf, 0x51, 0xd7, 0x38, 0x6b, + 0x52, 0x0d, 0x73, 0x0e, 0x1a, 0xda, 0x2c, 0x0c, 0xa3, 0x96, 0x00, 0x47, + 0x86, 0xc9, 0x59, 0xec, 0xc0, 0xe5, 0xb3, 0x36, 0xae, 0x3b, 0xd9, 0x1a, + 0xae, 0x73, 0x34, 0x94, 0xbd, 0x69, 0x6d, 0x36, 0xa6, 0xc4, 0x82, 0x0f, + 0xfa, 0xb9, 0x6b, 0x9e, 0x59, 0xb5, 0x4e, 0xe6, 0x15, 0x4f, 0x20, 0xcc, + 0xd4, 0x2c, 0x17, 0x29, 0xd0, 0xb1, 0x17, 0x88, 0xb4, 0xc7, 0xf3, 0xdb, + 0xff, 0x20, 0xa5, 0x40, 0x4b, 0x35, 0x8e, 0x03, 0x51, 0xa2, 0x18, 0x90, + 0x27, 0x24, 0x0b, 0x57, 0x3f, 0xb5, 0x6c, 0x97, 0x0c, 0x33, 0xe1, 0xb2, + 0x84, 0xbb, 0x37, 0xfc, 0x71, 0xd4, 0xb5, 0x9f, 0x51, 0xed, 0xe1, 0x59, + 0x14, 0x51, 0xb1, 0x9a, 0x63, 0x70, 0x3e, 0x93, 0x53, 0x52, 0x02, 0x70, + 0x02, 0xde, 0x05, 0xa5, 0x51, 0x85, 0x82, 0x12, 0xd2, 0x66, 0xa0, 0x41, + 0xae, 0x93, 0x29, 0x21, 0x9c, 0x35, 0x8f, 0xea, 0x2b, 0xee, 0xcd, 0x47, + 0xa8, 0xb8, 0xc1, 0x26, 0x6c, 0x73, 0x40, 0x9d, 0xdf, 0xf0, 0x67, 0x75, + 0x9d, 0x52, 0x5a, 0x50, 0x95, 0x57, 0xd1, 0x5d, 0x9f, 0x5f, 0x8a, 0xe8, + 0x1b, 0x9d, 0x65, 0x9a, 0x36, 0xe9, 0xb1, 0x6f, 0x74, 0x03, 0x18, 0x59, + 0x95, 0x01, 0x5a, 0x90, 0xc3, 0x95, 0x7b, 0x88, 0xa0, 0xf3, 0xdc, 0x05, + 0xa3, 0x95, 0xdc, 0x4b, 0x9d, 0x77, 0x5f, 0x2c, 0x43, 0x74, 0x04, 0xb7, + 0x56, 0xc5, 0xf7, 0x46, 0x46, 0xf8, 0x84, 0x30, 0x4b, 0x7c, 0x04, 0x89, + 0x73, 0xde, 0xaf, 0xb5, 0xd2, 0xbc, 0xaf, 0x30, 0xad, 0x91, 0x2d, 0x78, + 0x5a, 0x1f, 0x09, 0x89, 0x5f, 0xd4, 0x1f, 0x1e, 0x24, 0xe5, 0xb1, 0x2f, + 0xbe, 0xc3, 0x4e, 0xf4, 0x66, 0xa4, 0x84, 0x62, 0xd6, 0xcf, 0x2e, 0x89, + 0xf0, 0x57, 0xe7, 0xbe, 0x86, 0xe0, 0x20, 0xc0, 0x9f, 0xca, 0xd4, 0x5d, + 0x2e, 0x02, 0x3f, 0x8a, 0x9f, 0x8a, 0x12, 0x2e, 0x6a, 0x6c, 0x0f, 0x71, + 0xaa, 0x27, 0x44, 0x4f, 0xca, 0xf2, 0x56, 0x28, 0x49, 0x91, 0x9b, 0xa5, + 0x24, 0x91, 0x07, 0x6a, 0xfa, 0x7f, 0xdc, 0x96, 0x83, 0x81, 0x2c, 0x36, + 0x42, 0x8f, 0xe8, 0xf6, 0xa0, 0x42, 0x59, 0xbb, 0xd8, 0xf9, 0x17, 0x3c, + 0x7d, 0xd2, 0xa4, 0x9c, 0xb6, 0xcc, 0xbe, 0x0d, 0xbf, 0xc6, 0x42, 0x34, + 0x35, 0x6c, 0x7b, 0x8e, 0x86, 0x91, 0x40, 0x44, 0xc4, 0x13, 0xa4, 0x4b, + 0x4d, 0x73, 0xaf, 0xd9, 0x2e, 0xbf, 0xd2, 0x84, 0xbc, 0x74, 0x9b, 0x4f, + 0x63, 0x50, 0x57, 0xda, 0xe8, 0x2e, 0x10, 0x6f, 0xbb, 0x3b, 0x13, 0xc4, + 0xa3, 0x22, 0x6d, 0xc7, 0x42, 0x8b, 0x0c, 0xb5, 0x18, 0xe6, 0x99, 0x31, + 0xf7, 0xbe, 0xab, 0x42, 0x70, 0xee, 0x19, 0xea, 0x79, 0xab, 0xe4, 0xbe, + 0x07, 0xe5, 0xa9, 0x67, 0x78, 0xee, 0xdd, 0xf1, 0xd6, 0x94, 0x04, 0xf4, + 0xe2, 0x7b, 0x5a, 0xb3, 0xdd, 0x4b, 0x4f, 0x1b, 0x05, 0x41, 0x6b, 0x01, + 0x11, 0xf6, 0x0e, 0xec, 0x84, 0x04, 0xce, 0x9f, 0xaa, 0x9a, 0x75, 0x48, + 0x09, 0x3c, 0xc2, 0x0a, 0x31, 0x7f, 0x13, 0x71, 0x81, 0x20, 0x93, 0xd2, + 0x53, 0xce, 0xe7, 0xc6, 0x41, 0xd3, 0xfb, 0x7c, 0xc4, 0x05, 0xc6, 0x1c, + 0x83, 0x26, 0x00, 0x78, 0x67, 0xe5, 0xb3, 0x0a, 0x41, 0xe1, 0xec, 0x42 +// }; +// unsigned int sig_len = 840; diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0_no_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0_no_sigrl.inc new file mode 100644 index 00000000..3720cba7 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0_no_sigrl.inc @@ -0,0 +1,88 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : member0 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: random + * SigRl : no sigrl + */ + // unsigned char sig[] = { + 0xc2, 0x8c, 0xa4, 0x67, 0x82, 0xb2, 0x29, 0x10, + 0xe2, 0x21, 0x20, 0xf2, 0x6c, 0x10, 0x2b, 0x10, + 0x39, 0xea, 0x4f, 0x20, 0x6a, 0xb0, 0x2a, 0xfc, + 0x12, 0xba, 0xf8, 0xf7, 0x4b, 0xa6, 0x1c, 0x87, + + 0x3e, 0x09, 0x74, 0xd1, 0x3a, 0x3f, 0x0e, 0x16, + 0x47, 0x75, 0x19, 0x2c, 0x5a, 0x90, 0xa2, 0xf3, + 0x5a, 0x3a, 0x17, 0xab, 0xeb, 0x0a, 0xe3, 0x41, + 0xd3, 0x77, 0xc2, 0xdd, 0x14, 0xcd, 0x52, 0x2c, + + 0x60, 0xca, 0x87, 0x57, 0xc9, 0x91, 0x51, 0x48, + 0x7b, 0x48, 0x4a, 0x10, 0x81, 0xb3, 0x05, 0x77, + 0xdc, 0x5e, 0x1c, 0x9d, 0xcf, 0xbc, 0x18, 0x7c, + 0x1b, 0x97, 0x58, 0x45, 0xde, 0x2e, 0xce, 0x2c, + + 0xd5, 0xa5, 0xf2, 0x79, 0x70, 0xbd, 0x72, 0x0d, + 0x11, 0x10, 0x60, 0x41, 0x01, 0x5c, 0x25, 0xd4, + 0x68, 0xa1, 0xe5, 0x86, 0x6e, 0x72, 0xa7, 0xc6, + 0x24, 0x22, 0x66, 0xe0, 0x63, 0x55, 0x07, 0xb9, + + 0xe9, 0x6c, 0xad, 0xa7, 0xdc, 0x39, 0x5e, 0xb1, + 0xec, 0x7f, 0x42, 0x55, 0x60, 0x83, 0xd8, 0xda, + 0x9d, 0xb4, 0xb0, 0xef, 0x28, 0x37, 0x6a, 0xfd, + 0x65, 0xdd, 0xce, 0x93, 0x08, 0x22, 0x01, 0x19, + + 0x22, 0x51, 0x58, 0x80, 0x27, 0x94, 0xaa, 0x15, + 0xd4, 0xff, 0xfa, 0x21, 0xd0, 0xa4, 0x07, 0x43, + 0xc5, 0x43, 0x16, 0x5a, 0x4b, 0x95, 0xfd, 0x4b, + 0xe7, 0x50, 0x7a, 0xee, 0x1e, 0x91, 0x81, 0x49, + + 0xb1, 0x89, 0x7c, 0x8f, 0xed, 0x4f, 0x02, 0x66, + 0x52, 0xbf, 0xfb, 0x4f, 0xc7, 0x9b, 0x58, 0xb1, + 0x30, 0x8a, 0x00, 0x5a, 0x39, 0x99, 0x64, 0x67, + 0xfa, 0x7a, 0xc3, 0x62, 0xf8, 0x04, 0x4a, 0x21, + + 0x9e, 0x91, 0xf9, 0x22, 0x64, 0x8c, 0x7d, 0x8e, + 0x7d, 0x9a, 0xe9, 0xb8, 0xd4, 0x95, 0xc6, 0x3e, + 0xda, 0xb3, 0xb9, 0x6b, 0x93, 0x5c, 0x21, 0x05, + 0x29, 0xb4, 0xbf, 0x16, 0x80, 0xc9, 0xba, 0xe2, + + 0xd6, 0xf2, 0x1f, 0x4e, 0xdb, 0x1b, 0x79, 0x12, + 0x02, 0xb5, 0x11, 0xdf, 0x30, 0x21, 0xf4, 0x53, + 0xda, 0x00, 0x6b, 0xc7, 0x60, 0x6a, 0x85, 0x2a, + 0xfa, 0xec, 0x03, 0x0f, 0x6a, 0x2a, 0xe1, 0x60, + + 0x94, 0x8f, 0x7e, 0x04, 0xea, 0x54, 0x06, 0x6c, + 0x0f, 0x44, 0x37, 0x89, 0xd7, 0x33, 0x76, 0x92, + 0xf9, 0xd4, 0x46, 0xd3, 0xbd, 0x93, 0xfe, 0x37, + 0x3e, 0x51, 0x0a, 0xfc, 0x8b, 0xa3, 0x2f, 0xa9, + + 0xea, 0xd7, 0x8a, 0xa5, 0x2c, 0x94, 0xbe, 0xd4, + 0x40, 0x1f, 0xe3, 0x92, 0x7d, 0x60, 0xc3, 0x76, + 0x2b, 0xeb, 0x72, 0x7e, 0x0d, 0x70, 0x6c, 0xdb, + 0x1b, 0xa8, 0xec, 0xb6, 0x37, 0xf6, 0x8f, 0x15, + + 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +// }; +// unsigned int sig_len = 360; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_huge_bsn_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_huge_bsn_msg0.inc new file mode 100644 index 00000000..6d56d48b --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_huge_bsn_msg0.inc @@ -0,0 +1,99 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : member0 + * HashAlg : Sha512 + * Message : "msg0" + * Basename: huge (1024 KB) bsn + * SigRl : group x sigrl + */ +//unsigned char sig_grpx_member0_sha512_huge_bsn_msg0_dat[] = { + 0xd8, 0xf7, 0xcd, 0x26, 0xa1, 0x86, 0x2e, 0x25, 0xa5, 0x17, 0x84, 0x98, + 0x80, 0x5b, 0xb6, 0x10, 0x1c, 0xd, 0xe1, 0xf4, 0xaa, 0x50, 0xfa, 0xdd, + 0x67, 0x2f, 0xfd, 0x96, 0x95, 0x57, 0x1d, 0xf, 0x92, 0xcd, 0xd1, 0x99, + 0x27, 0x29, 0xbe, 0x7c, 0x66, 0x27, 0x8e, 0x5b, 0xc7, 0xf, 0x9f, 0xad, + 0xd7, 0x29, 0x54, 0xf, 0xea, 0xa8, 0x1, 0x42, 0xf9, 0x47, 0x1d, 0xec, + 0x5c, 0xc, 0x2e, 0xdb, 0x56, 0xd3, 0x35, 0x74, 0xca, 0x88, 0x50, 0xc3, + 0x3, 0xdf, 0x66, 0x33, 0xe3, 0xb2, 0x70, 0xc2, 0x6b, 0x2b, 0xa3, 0xb7, + 0x7d, 0x45, 0x4f, 0xcd, 0xeb, 0x39, 0x47, 0x4b, 0x5c, 0xad, 0x60, 0x2a, + 0x9b, 0x1e, 0xeb, 0xd5, 0xfa, 0x4b, 0x0, 0x33, 0xf1, 0xbb, 0xc0, 0xbb, + 0xe6, 0xf0, 0x8b, 0xe7, 0xd9, 0xaa, 0x84, 0x44, 0x5c, 0x7f, 0x11, 0xa1, + 0x78, 0x5e, 0x45, 0xc1, 0x58, 0x85, 0x9d, 0xb7, 0xba, 0xec, 0xaa, 0x96, + 0x22, 0xa9, 0xaa, 0xb3, 0x4f, 0x19, 0x9e, 0xf3, 0xed, 0x82, 0xcc, 0xf2, + 0x69, 0x4c, 0x17, 0x39, 0x27, 0xf4, 0x18, 0x98, 0xf, 0xdc, 0xc9, 0x4e, + 0x93, 0x9c, 0x5e, 0xad, 0x77, 0xbd, 0xe2, 0x74, 0xb, 0xa9, 0x8a, 0x8a, + 0xfc, 0xa6, 0x79, 0xb, 0x72, 0x7b, 0x2a, 0x9b, 0xba, 0x25, 0x51, 0x6, + 0x6, 0x14, 0xc4, 0x6d, 0xa6, 0x2f, 0xf5, 0xdd, 0x3d, 0xd6, 0x49, 0x61, + 0x62, 0xb, 0x56, 0x28, 0xa8, 0xe9, 0xe2, 0x77, 0x6a, 0x15, 0x44, 0xb0, + 0x7a, 0xaa, 0x32, 0x5c, 0xe9, 0xbf, 0xfb, 0xaf, 0xfe, 0xca, 0x47, 0x13, + 0xe8, 0xc8, 0xfe, 0xb3, 0xd2, 0x88, 0x45, 0xcd, 0x96, 0x79, 0x2b, 0x6a, + 0x26, 0xb2, 0xd7, 0x33, 0x7e, 0x8c, 0x6b, 0xff, 0x9b, 0x49, 0x1c, 0xc2, + 0x3e, 0xff, 0x70, 0x63, 0x4a, 0x2c, 0x8a, 0x7, 0x7c, 0xe9, 0x1a, 0x92, + 0x7a, 0x53, 0xe1, 0x30, 0xf0, 0x29, 0xe6, 0xe3, 0x58, 0x5a, 0x3f, 0xa1, + 0x8b, 0x2c, 0xfe, 0x57, 0xb0, 0x2c, 0x96, 0x5e, 0xd2, 0xbd, 0xff, 0x92, + 0xaf, 0xb4, 0xb5, 0x71, 0x5c, 0x27, 0x89, 0x7f, 0x72, 0xc5, 0x2c, 0x41, + 0x2b, 0xbd, 0xf7, 0xd, 0xb8, 0xfd, 0xe4, 0x94, 0x27, 0x62, 0x7f, 0x64, + 0xb8, 0xf4, 0x47, 0x64, 0x90, 0x8b, 0x96, 0xb7, 0x59, 0xd2, 0xee, 0xee, + 0x55, 0x8e, 0x2b, 0x82, 0xde, 0x72, 0x23, 0x5, 0xdc, 0x1e, 0xa, 0xd4, + 0xc4, 0xe6, 0x7d, 0x9b, 0x96, 0xfc, 0xb4, 0x17, 0x38, 0xea, 0x7b, 0x9d, + 0xf7, 0xd8, 0x95, 0xfa, 0xfb, 0x99, 0x26, 0xa, 0x13, 0x96, 0xf3, 0x7b, + 0x20, 0xc4, 0x39, 0xb7, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x3, + 0x43, 0x4, 0xf0, 0xea, 0xe0, 0xca, 0x2, 0x65, 0x22, 0xd4, 0x68, 0x5c, + 0x12, 0xfa, 0xe0, 0x39, 0x23, 0x5a, 0xde, 0x7e, 0xb2, 0xed, 0x2, 0x4f, + 0xcc, 0x10, 0xe4, 0xf7, 0x5f, 0x7d, 0x69, 0xbc, 0x6d, 0xf9, 0xe9, 0xb, + 0x88, 0x1b, 0x60, 0xad, 0xee, 0xab, 0x56, 0xc1, 0x36, 0x44, 0x58, 0x92, + 0x28, 0x64, 0x87, 0xdc, 0x2a, 0xfb, 0x1e, 0x59, 0x24, 0xbb, 0x7, 0xf5, + 0x1c, 0x3a, 0xee, 0xe7, 0x73, 0xc2, 0x83, 0xb8, 0xd6, 0x93, 0x41, 0x78, + 0xb, 0xc2, 0xe6, 0xee, 0x8a, 0xa0, 0xc1, 0x4b, 0xc8, 0x4a, 0x89, 0x3f, + 0xc9, 0x56, 0x6d, 0x7f, 0xf3, 0x51, 0x2e, 0x9, 0x68, 0x35, 0xca, 0x45, + 0x89, 0x39, 0x2d, 0xc9, 0xa1, 0x30, 0xfb, 0xf0, 0xae, 0x90, 0x39, 0x9f, + 0x68, 0x7, 0xab, 0xea, 0x8c, 0xf1, 0x83, 0x4c, 0x5d, 0x46, 0xb9, 0xe2, + 0xc0, 0xbf, 0x1f, 0x91, 0xa5, 0xed, 0x7, 0xb8, 0x35, 0x15, 0x55, 0x19, + 0x32, 0xd5, 0x42, 0x3d, 0xea, 0x1e, 0x60, 0x37, 0x44, 0x75, 0xe0, 0x57, + 0x93, 0x58, 0x3b, 0x4f, 0xcc, 0x17, 0x97, 0x5, 0xba, 0x67, 0x3e, 0x6a, + 0xfc, 0x69, 0x1, 0x93, 0x78, 0xd9, 0xf1, 0x6b, 0x41, 0x4f, 0xeb, 0xe4, + 0x25, 0x0, 0x45, 0xd4, 0xab, 0xce, 0xd2, 0x1, 0xa0, 0x18, 0xd1, 0x37, + 0x6c, 0xb1, 0xb4, 0x44, 0xef, 0x62, 0x18, 0x76, 0x2a, 0xd8, 0x56, 0x26, + 0xee, 0x6c, 0x68, 0xd9, 0xf8, 0x91, 0xd9, 0x5a, 0x10, 0x52, 0x75, 0xb0, + 0x3e, 0xe8, 0x98, 0xa9, 0x37, 0x3d, 0x18, 0x50, 0xfd, 0x7c, 0x18, 0x43, + 0xbd, 0x25, 0x4e, 0x8, 0x2, 0xc0, 0x9e, 0xa5, 0xc0, 0xdc, 0x6b, 0xb, + 0x39, 0x7a, 0xc0, 0x6d, 0x8e, 0x59, 0x70, 0x31, 0x77, 0x88, 0xdc, 0xf1, + 0x27, 0xf4, 0x5d, 0x28, 0xed, 0x3c, 0x61, 0x24, 0x77, 0x5f, 0x3f, 0xf4, + 0x64, 0x73, 0x1a, 0x40, 0xb3, 0xab, 0xfa, 0x76, 0x7b, 0xc0, 0x1f, 0x53, + 0xd1, 0xa9, 0x28, 0xff, 0x2c, 0x24, 0xe5, 0xf3, 0x3c, 0xcc, 0x44, 0xe5, + 0x48, 0x47, 0x73, 0xd8, 0x86, 0xa8, 0x2e, 0xd7, 0xff, 0xc0, 0x5a, 0x86, + 0xde, 0xa4, 0x31, 0xe4, 0xfd, 0xe4, 0x7d, 0x62, 0x75, 0xf, 0x47, 0x62, + 0xfc, 0x56, 0xa5, 0x3f, 0x34, 0xd6, 0xf6, 0x74, 0x18, 0x93, 0xa8, 0xfd, + 0x8d, 0xfe, 0x7a, 0xc7, 0x85, 0xe, 0xbe, 0xf1, 0x13, 0xab, 0x6, 0x8b, + 0xb7, 0x7, 0xa0, 0x7c, 0x17, 0x1a, 0x62, 0xa3, 0xdf, 0x86, 0xcd, 0xd0, + 0x3a, 0xc1, 0x4f, 0x80, 0xd, 0x64, 0x8e, 0xf8, 0xe6, 0xf9, 0xed, 0x35, + 0x26, 0xe5, 0x4, 0x3e, 0x61, 0xd9, 0x32, 0x5a, 0x5c, 0x56, 0x51, 0xb2, + 0xdf, 0xab, 0x5c, 0x7e, 0xce, 0xd6, 0xb7, 0x6d, 0x10, 0xc5, 0xb4, 0xf6, + 0x66, 0xe0, 0xb7, 0x1b, 0x36, 0x78, 0x5, 0xde, 0xa7, 0xdd, 0x93, 0xdd, + 0x78, 0xe, 0xdb, 0x7f, 0x9, 0x2f, 0x4, 0x66, 0x4d, 0xe2, 0x4c, 0xe0, + 0x87, 0x66, 0x38, 0xf1, 0x7c, 0xa5, 0xce, 0xce, 0x98, 0x4d, 0x1e, 0x77, + 0xae, 0x55, 0x94, 0xa5, 0xd5, 0x32, 0xc7, 0x11, 0x2d, 0x63, 0x1a, 0x38, + 0x5f, 0xae, 0x6a, 0xd1, 0x22, 0xbd, 0xc5, 0xc4, 0x7f, 0xab, 0x98, 0xb2, + 0x9b, 0xb5, 0x72, 0x2f, 0xb4, 0x96, 0x2e, 0xdf, 0x4c, 0x83, 0x87, 0x44, + 0xc8, 0x5f, 0x41, 0x1, 0xf4, 0x55, 0xfc, 0x28, 0xa3, 0xab, 0xb0, 0xfb, + 0x2e, 0xc7, 0x98, 0xd, 0xa9, 0x6d, 0x74, 0x10, 0x2a, 0x9f, 0xd1, 0xb6, + 0x7d, 0x50, 0x81, 0x24, 0x9c, 0xba, 0x32, 0x6, 0x57, 0xeb, 0xa9, 0xca +//}; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member1/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member1/mprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member1/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member1/mprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey000.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey000.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey001.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey001.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey001.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey001.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey002.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey002.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey002.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/mprivatekey002.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey001.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrevoked/signatures/sig_sha256_bsn0_msg0_revkey002.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrl_single_entry_revoked_key000.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrl_single_entry_revoked_key000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/privrl_single_entry_revoked_key000.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/privrl_single_entry_revoked_key000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/pubkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/pubkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/pubkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/pubkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey001.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey001.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey001.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey001.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey002.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey002.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey002.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey002.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_first_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_first_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_first_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_first_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_last_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_last_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_last_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_last_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc new file mode 100644 index 00000000..9899c2b0 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc @@ -0,0 +1,77 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 signature based revocation list + * Group : grpX + * Revoked signature : Member0/sig_sha512_rndbase_msg0 middle entry + */ +//unsigned char sigrl_dat[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xee, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + 0x87, 0xe2, 0xb2, 0x6d, 0x2e, 0x6f, 0xd0, 0x1d, + 0x1f, 0x53, 0x11, 0xdb, 0x8f, 0x2c, 0x7f, 0x07, + 0xd2, 0x8b, 0x04, 0x00, 0x72, 0xae, 0x07, 0x40, + 0x95, 0x94, 0xc2, 0x7d, 0x25, 0x28, 0xd3, 0x3a, + 0x00, 0x4b, 0xa7, 0x92, 0x76, 0x3d, 0xd8, 0x51, + 0x32, 0x2d, 0x7b, 0x2e, 0x9d, 0x93, 0xd3, 0xfe, + 0x75, 0x3c, 0xf5, 0xc0, 0xbf, 0x69, 0xed, 0xc5, + 0xfa, 0x26, 0x5e, 0x4a, 0x6d, 0xea, 0x7d, 0xac, + 0x17, 0xe8, 0x8d, 0x5f, 0xcf, 0xeb, 0x35, 0x51, + 0x55, 0x1c, 0x41, 0x7e, 0xc9, 0x67, 0x0d, 0x87, + 0x25, 0x7d, 0xaa, 0x75, 0xc5, 0x2b, 0x86, 0x69, + 0xa3, 0x67, 0xf2, 0x95, 0x9c, 0xdb, 0x22, 0xb1, + 0x04, 0x0c, 0x8a, 0xae, 0x4f, 0xb3, 0xdd, 0x9b, + 0xb1, 0x6e, 0x79, 0x5f, 0x8f, 0xeb, 0x4a, 0x94, + 0x9e, 0x95, 0xf4, 0xbb, 0xb6, 0x1c, 0xe6, 0xbb, + 0x9c, 0x34, 0xc7, 0xa0, 0x61, 0x14, 0x3d, 0xfb, + 0x43, 0xa4, 0x74, 0x4b, 0xcb, 0x17, 0xfa, 0xaf, + 0xb8, 0x6e, 0xb4, 0xca, 0x94, 0x4d, 0xe8, 0x5b, + 0x40, 0x88, 0x6c, 0x9c, 0xfa, 0xba, 0x4a, 0x4c, + 0x65, 0x94, 0xd1, 0x17, 0x90, 0x5b, 0x66, 0x12, + 0x46, 0xcf, 0xcc, 0x6e, 0x47, 0x2c, 0x0c, 0xa7, + 0x4e, 0xb4, 0x62, 0x57, 0xdc, 0x70, 0xbb, 0xd0, + 0x52, 0xa7, 0x38, 0x97, 0xec, 0x34, 0x8c, 0xfd, + 0xe6, 0x5f, 0xa1, 0x8b, 0x8a, 0x1e, 0x0c, 0x41, + 0xa9, 0x86, 0x53, 0x85, 0x0e, 0xaa, 0xc2, 0x1d, + 0xe9, 0x42, 0x18, 0x2e, 0x1f, 0xca, 0xa0, 0x41, + 0x46, 0x04, 0x10, 0xb9, 0xc7, 0x15, 0x88, 0x41, + 0x92, 0x53, 0x7b, 0xb0, 0xc2, 0xf1, 0x96, 0x8f, + 0xc8, 0xe7, 0x4a, 0x43, 0x0a, 0xa2, 0x92, 0x08, + 0xd3, 0xdb, 0x09, 0xae, 0x31, 0x6c, 0xef, 0x9f, + 0xb7, 0x58, 0x4b, 0x41, 0x69, 0xf7, 0x5b, 0xbc, + 0x62, 0x3b, 0xa9, 0x9f, 0x4b, 0xcb, 0x17, 0x6f, + 0x6d, 0x5c, 0x55, 0x4b, 0xc8, 0xa4, 0x51, 0xb1, + 0xf3, 0xae, 0x18, 0x68, 0xaf, 0x45, 0x91, 0xe4, + 0x03, 0x96, 0x8c, 0x71, 0x2d, 0x7e, 0xe5, 0x96, + 0x03, 0x68, 0x4d, 0xc3, 0xb8, 0x59, 0x12, 0x41, + 0x57, 0xed, 0xcf, 0x41, 0xe4, 0xad, 0xf4, 0xcb, + 0x32, 0x38, 0x4c, 0x71, 0x8b, 0xa6, 0x5a, 0x4f, + 0x9c, 0xb7, 0x0e, 0x3c, 0x23, 0x82, 0x88, 0x95, + 0xc0, 0x5a, 0x5a, 0x28, 0xbe, 0xcd, 0xdc, 0xef, + 0x35, 0xd5, 0x83, 0x3f, 0x36, 0x88, 0x0f, 0xea, + 0x6e, 0x97, 0xab, 0xe2, 0x6f, 0x56, 0x67, 0x50, + 0x89, 0x9d, 0x40, 0xc3, 0xd9, 0x90, 0x04, 0x67, + 0xef, 0x1a, 0x38, 0x5d, 0xb6, 0xe4, 0xcb, 0xf1, + 0xf1, 0x22, 0x98, 0xb6, 0x5e, 0x4a, 0xdd, 0x71, + 0xb8, 0x98, 0xa6, 0x37, 0xfe, 0xd3, 0xdc, 0x0c, + 0x82, 0xb6, 0x6b, 0xed, 0x8b, 0x07, 0xbd, 0x0d, + 0xa3, 0x6b, 0x41, 0x9c, 0x26, 0xd0, 0xe5, 0xf9 +//}; +//unsigned int sigrl_dat_len = 408; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_ver_2.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_ver_2.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/sigrl_ver_2.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/sigrl_ver_2.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey000.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey000.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey000.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey000.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey001.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey001.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey001.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey001.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey002.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey002.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey002.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/mprivkey002.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha256bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha256bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha256bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha384bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha384bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha384bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha384bsn0msg0.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512_256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512_256bsn0msg0.inc new file mode 100644 index 00000000..916a4a1f --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512_256bsn0msg0.inc @@ -0,0 +1,100 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : verrevoked/bsn0/mprivkey000 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: "bsn0" + * SigRl : group x sigrl + */ + // unsigned char sig[] = { + 0x70, 0x91, 0x63, 0x2c, 0xbb, 0xfe, 0x06, 0x26, 0x5f, 0x20, 0xbd, 0x9e, + 0x49, 0x11, 0x31, 0xe0, 0x7c, 0x99, 0x5e, 0xa0, 0x58, 0x4f, 0x1b, 0x3f, + 0xb4, 0x6e, 0xcd, 0x17, 0x61, 0x79, 0xa0, 0xfd, 0x64, 0x60, 0xa4, 0xf8, + 0x17, 0x81, 0xc3, 0x0a, 0x4b, 0x6a, 0x72, 0x86, 0x96, 0xe3, 0xfa, 0x95, + 0x47, 0x45, 0xfb, 0x57, 0xef, 0xca, 0x82, 0x99, 0x72, 0xdc, 0xe6, 0x78, + 0xe3, 0x70, 0xa8, 0x28, 0x8b, 0xc9, 0x6e, 0xc0, 0x86, 0x04, 0x6f, 0x6c, + 0x89, 0xc2, 0x27, 0xfd, 0x61, 0x59, 0xb5, 0xd2, 0x73, 0x96, 0xfa, 0xd6, + 0xf8, 0xfa, 0x2c, 0x39, 0xfe, 0xee, 0xef, 0x3e, 0x73, 0xd2, 0x38, 0x3f, + 0x3c, 0x04, 0x07, 0x78, 0xfd, 0x32, 0x9b, 0xc3, 0x74, 0x90, 0xf2, 0xf5, + 0x50, 0xe4, 0x69, 0x5d, 0x30, 0x0c, 0x6a, 0x8a, 0x9c, 0xcf, 0xff, 0x78, + 0x28, 0x52, 0x6d, 0x20, 0x29, 0xef, 0x2d, 0x7a, 0xec, 0x31, 0x09, 0xa3, + 0x2f, 0x9a, 0x3d, 0x87, 0xa0, 0x9c, 0x7a, 0xb6, 0x25, 0x86, 0x47, 0x27, + 0x05, 0x14, 0x14, 0x2e, 0x72, 0xcd, 0x61, 0x0e, 0x2f, 0x3c, 0xb2, 0x83, + 0xdc, 0x4f, 0x3d, 0x5d, 0xa4, 0xa4, 0xcb, 0x10, 0x73, 0xf2, 0xae, 0x9f, + 0xae, 0x22, 0x90, 0x03, 0x69, 0xa4, 0x83, 0xf5, 0xf8, 0xf4, 0x2b, 0x59, + 0x50, 0xf3, 0x2a, 0x66, 0xb6, 0x2c, 0x0f, 0x23, 0x96, 0xc2, 0xee, 0x5d, + 0x42, 0xdf, 0x5b, 0xbc, 0x31, 0x76, 0xce, 0x8a, 0xce, 0xb0, 0x35, 0x82, + 0x79, 0x20, 0xee, 0xe2, 0x45, 0xf9, 0xb3, 0xc5, 0xb2, 0x59, 0xcf, 0x29, + 0x67, 0x3c, 0x80, 0xf8, 0x0c, 0xad, 0xe9, 0xdb, 0x26, 0x93, 0x42, 0xdd, + 0x9f, 0x41, 0x69, 0xd4, 0x28, 0x77, 0xfd, 0x32, 0xf3, 0x55, 0xcc, 0x10, + 0xbc, 0x49, 0xbc, 0xbf, 0xac, 0x87, 0xcb, 0xa0, 0xf3, 0x1a, 0xf4, 0xfd, + 0x28, 0xe3, 0x32, 0xee, 0xf1, 0x0c, 0x7a, 0x75, 0x20, 0xcf, 0x44, 0x17, + 0xd6, 0x9c, 0x87, 0x2f, 0xe7, 0xad, 0x8a, 0xc6, 0xa1, 0xea, 0x4a, 0x86, + 0xe0, 0x3d, 0x6f, 0x7d, 0xd1, 0xd4, 0x08, 0x9f, 0x64, 0x45, 0x7c, 0x35, + 0xe6, 0x5c, 0x97, 0x52, 0x58, 0xc4, 0x0a, 0xbc, 0x3c, 0x74, 0x56, 0x2c, + 0x2a, 0xc4, 0x4d, 0x29, 0x3d, 0xba, 0x45, 0x35, 0x55, 0x23, 0x05, 0xbf, + 0x0b, 0x95, 0xba, 0x06, 0x01, 0x9d, 0x31, 0xb4, 0x47, 0xa0, 0xe5, 0xf4, + 0xd1, 0xcd, 0x42, 0x07, 0x92, 0x60, 0x40, 0x15, 0x7d, 0x96, 0xdc, 0x1e, + 0xd5, 0x43, 0x85, 0xf3, 0x86, 0x8b, 0x98, 0xc6, 0x24, 0x44, 0x24, 0x77, + 0x54, 0x86, 0x03, 0xc4, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + 0x4d, 0xef, 0x88, 0xbf, 0xa9, 0x73, 0xfc, 0x06, 0x7e, 0x69, 0xba, 0xcc, + 0x30, 0xb5, 0x83, 0x33, 0x3a, 0xdd, 0xa8, 0x36, 0x95, 0x6c, 0xa5, 0x63, + 0xe6, 0x88, 0xbe, 0x4f, 0xa8, 0x61, 0xaf, 0x5a, 0x37, 0x48, 0x59, 0x6e, + 0xa8, 0x5f, 0x94, 0xc1, 0xae, 0x8d, 0xbf, 0xa2, 0x76, 0xa0, 0x3e, 0xb2, + 0x6b, 0x50, 0x6f, 0x84, 0x53, 0xc3, 0xd9, 0x52, 0xfc, 0x8e, 0xcb, 0x94, + 0x20, 0x10, 0x88, 0x8d, 0x8f, 0x77, 0xbb, 0x4c, 0xfa, 0x18, 0x2d, 0xa5, + 0x3e, 0x72, 0x62, 0x8f, 0x7b, 0x10, 0x99, 0x35, 0xd8, 0x9d, 0x61, 0x34, + 0xcd, 0xb7, 0x7f, 0x42, 0xe9, 0xe6, 0xaa, 0x7f, 0x7b, 0x8c, 0x1b, 0xa4, + 0xb6, 0xf7, 0xaa, 0x22, 0x2c, 0xd3, 0xff, 0x9b, 0xc0, 0xcf, 0x3e, 0x53, + 0xc6, 0x8f, 0x1d, 0x5f, 0x48, 0x4a, 0x6c, 0xec, 0x83, 0x6f, 0xf6, 0x4c, + 0xd4, 0xaf, 0x86, 0x50, 0xe2, 0x79, 0xe3, 0x64, 0xbd, 0x9d, 0xd7, 0x7b, + 0x83, 0xda, 0x98, 0x49, 0x4f, 0x70, 0xcf, 0xeb, 0xec, 0xa1, 0x3d, 0x40, + 0xc9, 0x49, 0x9a, 0x45, 0x00, 0xda, 0x7f, 0x85, 0xc1, 0x2c, 0x32, 0x5d, + 0x02, 0xa0, 0x57, 0x44, 0xc7, 0x1c, 0x7b, 0x1b, 0xa3, 0xf0, 0x9c, 0xbc, + 0xfd, 0x7d, 0x0c, 0x52, 0xc2, 0x07, 0x83, 0x9b, 0xd0, 0x26, 0x10, 0xec, + 0x9f, 0x54, 0x5d, 0xd7, 0x46, 0xb4, 0x2e, 0xe1, 0x76, 0xa1, 0x53, 0x18, + 0x06, 0x25, 0x91, 0x0a, 0xb8, 0xc2, 0x61, 0x9d, 0x0f, 0xa9, 0x5c, 0xb9, + 0x9d, 0xdd, 0x2b, 0xe3, 0x40, 0xab, 0x45, 0xd0, 0xfe, 0x9b, 0xc2, 0xa2, + 0xee, 0x19, 0xa8, 0xbb, 0xf0, 0x2b, 0x63, 0x98, 0x86, 0xc3, 0x2d, 0xbc, + 0x6c, 0x24, 0x0e, 0xd4, 0x8f, 0xca, 0x4a, 0xca, 0xa8, 0x83, 0x7f, 0x22, + 0x40, 0x54, 0x0f, 0xeb, 0x97, 0xfe, 0x4b, 0x78, 0xd9, 0xc5, 0x3f, 0x79, + 0x23, 0x5c, 0xc0, 0xd7, 0x7b, 0x0c, 0xa0, 0xce, 0x54, 0x96, 0x44, 0x81, + 0x68, 0xd2, 0x36, 0x5f, 0x56, 0x3d, 0xed, 0xaa, 0xa4, 0xff, 0x59, 0x3a, + 0x76, 0x0f, 0x9b, 0x29, 0xa8, 0x9c, 0x58, 0x1a, 0x93, 0x31, 0x3a, 0x9b, + 0xd1, 0x9c, 0xf3, 0xd1, 0x83, 0xf0, 0xb2, 0xf5, 0x4a, 0x0a, 0x24, 0xb4, + 0x60, 0x76, 0x4a, 0x11, 0x93, 0x24, 0x2e, 0xcb, 0x6d, 0x40, 0x76, 0x7f, + 0xb6, 0xd3, 0x1a, 0x12, 0x95, 0x6d, 0x47, 0xad, 0xed, 0xe7, 0x11, 0xce, + 0x13, 0x1b, 0x28, 0x5c, 0x45, 0xd1, 0x33, 0x71, 0xe8, 0x68, 0xb1, 0x45, + 0xd2, 0x56, 0x5a, 0xe0, 0xde, 0x8c, 0x60, 0x2f, 0x22, 0x29, 0x8f, 0x34, + 0x6f, 0xba, 0xf5, 0xb3, 0x00, 0x0f, 0xd9, 0xcb, 0xb5, 0x02, 0x58, 0x1a, + 0x27, 0x09, 0x8d, 0x88, 0x6e, 0x60, 0x7e, 0x89, 0x0b, 0x1d, 0xb8, 0x01, + 0x1c, 0x82, 0x2f, 0x39, 0x2c, 0x3f, 0xa0, 0x23, 0x72, 0x84, 0xb7, 0xb1, + 0x8c, 0x12, 0xd0, 0xfb, 0x4d, 0xff, 0xb9, 0x7f, 0xbc, 0x31, 0x11, 0x57, + 0xa0, 0x7e, 0x67, 0x43, 0xd8, 0x6a, 0x2c, 0x25, 0x79, 0x3f, 0x9a, 0x54, + 0xeb, 0x6f, 0x4a, 0xb9, 0xc2, 0x45, 0xfd, 0x03, 0x97, 0x14, 0x67, 0xf3, + 0x39, 0x08, 0xda, 0x92, 0x08, 0x2b, 0xe2, 0xe3, 0xc2, 0x68, 0x9b, 0x36, + 0xaf, 0xf1, 0x16, 0xde, 0x0f, 0x28, 0xd2, 0xc1, 0xeb, 0x2f, 0x99, 0x3c, + 0xa5, 0xa1, 0x54, 0x38, 0x25, 0x55, 0x1f, 0x94, 0xf1, 0xbf, 0xcd, 0x60, + 0xc0, 0x3b, 0x97, 0xbc, 0x36, 0x20, 0xd1, 0xfe, 0x61, 0xb1, 0x1a, 0x8f, + 0x56, 0xe6, 0xdf, 0xdb, 0x06, 0x4f, 0x78, 0xa9, 0xa7, 0xcb, 0x1c, 0x1c +// }; +// unsigned int sig_len = 840; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked0sha512bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha256bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha256bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha256bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha384bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha384bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha384bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha384bsn0msg0.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512_256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512_256bsn0msg0.inc new file mode 100644 index 00000000..9fe16fdc --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512_256bsn0msg0.inc @@ -0,0 +1,100 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : verrevoked/bsn0/mprivkey001 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: "bsn0" + * SigRl : group x sigrl + */ + // unsigned char sig[] = { + 0x70, 0x91, 0x63, 0x2c, 0xbb, 0xfe, 0x06, 0x26, 0x5f, 0x20, 0xbd, 0x9e, + 0x49, 0x11, 0x31, 0xe0, 0x7c, 0x99, 0x5e, 0xa0, 0x58, 0x4f, 0x1b, 0x3f, + 0xb4, 0x6e, 0xcd, 0x17, 0x61, 0x79, 0xa0, 0xfd, 0x64, 0x60, 0xa4, 0xf8, + 0x17, 0x81, 0xc3, 0x0a, 0x4b, 0x6a, 0x72, 0x86, 0x96, 0xe3, 0xfa, 0x95, + 0x47, 0x45, 0xfb, 0x57, 0xef, 0xca, 0x82, 0x99, 0x72, 0xdc, 0xe6, 0x78, + 0xe3, 0x70, 0xa8, 0x28, 0x07, 0x46, 0xed, 0xb8, 0x6a, 0x4e, 0x7f, 0x4b, + 0x9d, 0xcc, 0x18, 0x91, 0x88, 0xf6, 0x76, 0x4d, 0x74, 0x02, 0x36, 0x62, + 0xe6, 0xd4, 0xb5, 0xf0, 0x2d, 0x70, 0x91, 0x49, 0x65, 0xdf, 0x19, 0x02, + 0x30, 0x6c, 0x11, 0xaa, 0x74, 0x8c, 0x55, 0x2e, 0x4b, 0xa3, 0x00, 0x00, + 0xb0, 0x38, 0xf4, 0xcd, 0x5d, 0xc9, 0x1d, 0xaa, 0x1e, 0x44, 0x98, 0xa4, + 0xe1, 0x3f, 0x2f, 0x4f, 0x6c, 0xc9, 0x15, 0xb0, 0xe6, 0x70, 0x62, 0x2c, + 0x21, 0xf0, 0xa3, 0x7b, 0x32, 0x5f, 0x96, 0xc7, 0x19, 0xef, 0x7b, 0x14, + 0xf2, 0x52, 0xaa, 0xc8, 0x16, 0x81, 0x71, 0xdb, 0x53, 0x07, 0x1f, 0x52, + 0x5b, 0x7b, 0xa9, 0x7a, 0x4f, 0x92, 0x1e, 0xda, 0x24, 0xc0, 0xdd, 0xcb, + 0x19, 0xb0, 0x4a, 0x8c, 0x25, 0x7a, 0x18, 0x62, 0x34, 0x23, 0x93, 0xb4, + 0xeb, 0x14, 0xd4, 0x4d, 0x4d, 0xbd, 0xf1, 0x88, 0xf5, 0xb0, 0xa4, 0x8f, + 0x82, 0x03, 0x3d, 0x95, 0x58, 0x4c, 0xd8, 0x7b, 0xe9, 0xac, 0x40, 0x25, + 0x5b, 0xba, 0xa5, 0x36, 0x36, 0xf5, 0x5c, 0xff, 0xd1, 0x55, 0x89, 0x85, + 0x74, 0xf6, 0xf8, 0x0d, 0x2c, 0x3a, 0x94, 0x5e, 0x6d, 0xd6, 0x07, 0x99, + 0x07, 0x2e, 0x4f, 0x89, 0x3f, 0x33, 0x2e, 0xe8, 0x20, 0x20, 0xcf, 0xea, + 0x80, 0xbc, 0x33, 0xe4, 0x4e, 0xc6, 0xdf, 0x7f, 0xff, 0x20, 0x33, 0x2d, + 0x09, 0x29, 0x66, 0x2f, 0xf1, 0xbb, 0xea, 0xe8, 0x7a, 0x95, 0x4b, 0x35, + 0xab, 0xb4, 0x50, 0xc1, 0xdc, 0x34, 0x42, 0x49, 0x5b, 0xf4, 0x85, 0xb3, + 0xe1, 0xce, 0xf4, 0x0a, 0xbd, 0x6a, 0xde, 0xad, 0x35, 0xef, 0xef, 0x18, + 0xea, 0x89, 0x0c, 0x80, 0x7e, 0x26, 0xd8, 0xc5, 0x6e, 0x55, 0x06, 0xb0, + 0xf4, 0x25, 0x4e, 0x3e, 0x4b, 0x5a, 0xea, 0x08, 0x3b, 0xe4, 0xcc, 0x3f, + 0x87, 0x6a, 0xd3, 0xb7, 0x29, 0x54, 0xdc, 0x89, 0xf8, 0x3d, 0x4f, 0x1b, + 0xd0, 0x8d, 0xe9, 0x03, 0x4e, 0xba, 0x15, 0x3a, 0xc0, 0xf5, 0xbf, 0x47, + 0x68, 0x4b, 0x45, 0xb0, 0x7d, 0x9b, 0x57, 0x87, 0xf5, 0x07, 0x9a, 0xad, + 0x4e, 0x0d, 0xaa, 0xe9, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + 0x93, 0x28, 0xdc, 0xca, 0x44, 0xca, 0xd1, 0x3b, 0x05, 0x4e, 0x68, 0xfb, + 0x37, 0xee, 0x91, 0xf0, 0x46, 0x7e, 0x33, 0xa5, 0xae, 0x5f, 0xd9, 0x3c, + 0x37, 0x7e, 0xe2, 0x9a, 0x6e, 0xfa, 0x91, 0x9f, 0xd8, 0x43, 0x75, 0xa7, + 0x8b, 0x18, 0x0b, 0x25, 0x5d, 0x46, 0x94, 0x72, 0xc0, 0x19, 0x8c, 0x42, + 0x1c, 0xbc, 0x5f, 0xa9, 0x67, 0xbf, 0x55, 0x84, 0x6e, 0x2b, 0x4b, 0x6f, + 0xeb, 0x42, 0x67, 0xb8, 0x42, 0xcc, 0xa7, 0xa2, 0x38, 0xf8, 0x6c, 0xf9, + 0x1c, 0xe3, 0xdb, 0xa2, 0x31, 0x6d, 0xd5, 0x5e, 0xe9, 0xb6, 0xef, 0xf9, + 0x7f, 0x20, 0x51, 0x45, 0x7d, 0x8c, 0xb6, 0x47, 0xed, 0xcf, 0x9f, 0x57, + 0x61, 0x44, 0x2e, 0x25, 0xb2, 0x4e, 0xea, 0x36, 0x0d, 0x32, 0xa2, 0x46, + 0xbe, 0xf8, 0xa9, 0xbb, 0x61, 0x11, 0x56, 0xc6, 0x15, 0xf2, 0xdd, 0x35, + 0xb4, 0xa2, 0x31, 0xba, 0x04, 0xd4, 0x4d, 0x36, 0xa0, 0x79, 0x37, 0x53, + 0x94, 0x91, 0x37, 0x56, 0xe1, 0xed, 0xdb, 0x67, 0x73, 0x69, 0xad, 0xf2, + 0x0b, 0xb2, 0x37, 0xbb, 0x44, 0xd0, 0xd9, 0x19, 0x0c, 0x9b, 0xd4, 0xb0, + 0x3f, 0x16, 0x2b, 0x2f, 0x41, 0x10, 0xdf, 0xea, 0x98, 0x36, 0xc1, 0xc1, + 0xca, 0x12, 0x46, 0x30, 0xcd, 0xad, 0x07, 0x18, 0x24, 0x54, 0x55, 0xb7, + 0x85, 0x3f, 0x5a, 0x35, 0x10, 0xf8, 0xf9, 0x96, 0xca, 0x0b, 0xbb, 0xf6, + 0x37, 0x76, 0x3a, 0xd8, 0x73, 0xec, 0x86, 0xf8, 0x5b, 0xdd, 0xae, 0x01, + 0x83, 0xc8, 0x0e, 0x6e, 0x18, 0x23, 0x63, 0x34, 0x0f, 0x09, 0xf0, 0x65, + 0x35, 0xad, 0xbe, 0x88, 0x97, 0x04, 0x39, 0x45, 0x90, 0x2a, 0xbd, 0x5d, + 0x96, 0x33, 0xdb, 0x04, 0xa0, 0xa1, 0x7b, 0x79, 0x25, 0xa1, 0x8f, 0x37, + 0xfc, 0xef, 0x68, 0x2a, 0xf7, 0xa8, 0x8a, 0x26, 0x56, 0xf1, 0xf4, 0x77, + 0x11, 0xa0, 0x39, 0xf5, 0xb6, 0x02, 0x2e, 0x7e, 0xa9, 0xfe, 0x9e, 0x49, + 0xb6, 0x6d, 0xd6, 0xf4, 0x34, 0xe6, 0xe2, 0x85, 0xc5, 0x64, 0xfc, 0xa0, + 0x1a, 0xf5, 0xed, 0xed, 0xde, 0xa9, 0x67, 0xcd, 0xf4, 0x97, 0x27, 0xa9, + 0xe8, 0x30, 0xeb, 0x81, 0x85, 0xe6, 0x1f, 0x0b, 0xb5, 0x79, 0xee, 0x4b, + 0x20, 0xbb, 0x77, 0xd5, 0x45, 0x08, 0xf5, 0xb9, 0x7d, 0xbd, 0xac, 0x82, + 0x78, 0xd9, 0x07, 0xde, 0x72, 0x9c, 0xe1, 0xc9, 0x8a, 0x45, 0x15, 0xb3, + 0x6f, 0xc7, 0xc7, 0xee, 0x78, 0x4d, 0x05, 0x70, 0xd4, 0x24, 0xc5, 0x24, + 0x20, 0x0e, 0xbc, 0xfa, 0xfc, 0xa7, 0x09, 0x14, 0x5c, 0xb4, 0x8a, 0xe7, + 0x4d, 0xb0, 0xa0, 0x6a, 0xc1, 0x50, 0x87, 0xbd, 0xc9, 0x9e, 0x67, 0xcb, + 0xc9, 0xf6, 0x8d, 0xc8, 0x8d, 0xee, 0x61, 0x81, 0xf6, 0xef, 0x60, 0x68, + 0x19, 0xc5, 0x0d, 0x67, 0x55, 0x24, 0xa8, 0x12, 0x84, 0xe7, 0x70, 0x86, + 0xf2, 0x99, 0x06, 0x0e, 0xfc, 0xfe, 0x08, 0x58, 0x56, 0xd8, 0xc1, 0x6d, + 0xab, 0xda, 0x90, 0xf5, 0x53, 0xda, 0x2d, 0x72, 0xe2, 0xf7, 0xdc, 0x0c, + 0x9d, 0x61, 0x9c, 0x91, 0xff, 0xc1, 0x67, 0xe0, 0x31, 0xc3, 0xbf, 0x10, + 0x0a, 0xce, 0x6c, 0xb5, 0x7f, 0x5d, 0xcc, 0x17, 0xaa, 0x57, 0xd9, 0x36, + 0xd0, 0x50, 0xfe, 0xc8, 0x24, 0x5d, 0x6e, 0xb5, 0x91, 0xc4, 0x8c, 0xf1, + 0x08, 0x50, 0xf3, 0x76, 0x29, 0xc6, 0x94, 0x04, 0xf8, 0x97, 0xa8, 0xa5, + 0x1b, 0x52, 0x4c, 0xd9, 0xc0, 0xcc, 0xe4, 0x00, 0xe1, 0x1f, 0xba, 0x6b, + 0xf5, 0x2c, 0x61, 0x53, 0x8b, 0x12, 0x04, 0xa0, 0x4c, 0xdd, 0x93, 0xff +// }; +// unsigned int sig_len = 840; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked1sha512bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha256bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha256bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha256bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha384bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha384bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha384bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha384bsn0msg0.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512_256bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512_256bsn0msg0.inc new file mode 100644 index 00000000..82425b46 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512_256bsn0msg0.inc @@ -0,0 +1,100 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 Signature + * Group : grpX + * Signer : verrevoked/bsn0/mprivkey002 + * HashAlg : Sha512256 + * Message : "msg0" + * Basename: "bsn0" + * SigRl : group x sigrl + */ + // unsigned char sig[] = { + 0x70, 0x91, 0x63, 0x2c, 0xbb, 0xfe, 0x06, 0x26, 0x5f, 0x20, 0xbd, 0x9e, + 0x49, 0x11, 0x31, 0xe0, 0x7c, 0x99, 0x5e, 0xa0, 0x58, 0x4f, 0x1b, 0x3f, + 0xb4, 0x6e, 0xcd, 0x17, 0x61, 0x79, 0xa0, 0xfd, 0x64, 0x60, 0xa4, 0xf8, + 0x17, 0x81, 0xc3, 0x0a, 0x4b, 0x6a, 0x72, 0x86, 0x96, 0xe3, 0xfa, 0x95, + 0x47, 0x45, 0xfb, 0x57, 0xef, 0xca, 0x82, 0x99, 0x72, 0xdc, 0xe6, 0x78, + 0xe3, 0x70, 0xa8, 0x28, 0x8c, 0x10, 0x2f, 0x17, 0xa0, 0xe4, 0x1f, 0xc6, + 0xaa, 0xea, 0xd4, 0x82, 0x67, 0x61, 0x96, 0x47, 0x9b, 0x46, 0x2c, 0x31, + 0xbd, 0x29, 0x62, 0x2d, 0xd8, 0x40, 0x44, 0xbc, 0x1d, 0xf0, 0x19, 0x02, + 0x4e, 0x4c, 0x2e, 0xc1, 0x0d, 0x43, 0x59, 0x8b, 0xe0, 0x0d, 0xb4, 0x29, + 0x20, 0x35, 0x1f, 0xb6, 0x00, 0x07, 0xa3, 0xd9, 0x28, 0xd9, 0x48, 0x08, + 0x5e, 0x14, 0xca, 0x56, 0x72, 0xa4, 0xb6, 0x5a, 0xbf, 0xaa, 0xfd, 0x90, + 0x46, 0xfb, 0xac, 0x86, 0x7c, 0x1d, 0xcd, 0x22, 0x48, 0xfb, 0xca, 0xa5, + 0x88, 0xfd, 0x8c, 0x3b, 0x3a, 0x16, 0xa6, 0x98, 0x77, 0x44, 0x45, 0xcc, + 0x03, 0x50, 0xf1, 0x76, 0x8f, 0x06, 0x81, 0x12, 0x4d, 0x5c, 0x58, 0x23, + 0xdb, 0x88, 0x1c, 0x40, 0x79, 0xa8, 0x5b, 0x31, 0x72, 0x76, 0x4f, 0x9b, + 0x34, 0x6e, 0x38, 0x1a, 0x5b, 0xda, 0xac, 0x1d, 0xf4, 0x6b, 0x89, 0xd8, + 0x64, 0xd7, 0x63, 0x80, 0x47, 0x59, 0x0b, 0xd0, 0xb6, 0x0d, 0xaf, 0x83, + 0x72, 0xac, 0xb5, 0x45, 0xce, 0xaf, 0x49, 0x61, 0x24, 0xb1, 0xcc, 0x75, + 0x6b, 0x48, 0x19, 0x5f, 0x49, 0x54, 0x66, 0xa4, 0x09, 0x73, 0x0c, 0x9a, + 0x1f, 0x9c, 0x2a, 0xf0, 0x03, 0x10, 0xf1, 0x9d, 0x6f, 0xf7, 0xa4, 0xf2, + 0x19, 0x01, 0x90, 0xfa, 0x5b, 0xa0, 0x89, 0xf9, 0xc2, 0x00, 0xc2, 0xed, + 0x53, 0xca, 0x0c, 0xfc, 0x54, 0x0f, 0x09, 0xa3, 0x0c, 0x4e, 0x8d, 0xf6, + 0x81, 0x9f, 0x2b, 0x0a, 0x09, 0x09, 0x2c, 0x1d, 0xb0, 0x39, 0x72, 0xd9, + 0x46, 0xe2, 0xf3, 0xfc, 0xa1, 0xb9, 0x4a, 0x46, 0xe4, 0x6e, 0xb5, 0x55, + 0x57, 0x5a, 0x3f, 0xa3, 0x84, 0x28, 0x2f, 0x77, 0x3c, 0x90, 0x0f, 0x66, + 0xc9, 0x9f, 0xb4, 0x51, 0xe3, 0x6f, 0x27, 0x73, 0xb0, 0xf3, 0x2e, 0xdf, + 0x94, 0x0a, 0x22, 0xf5, 0xdf, 0xaf, 0xa7, 0x94, 0x0f, 0x14, 0xb5, 0x05, + 0x76, 0x05, 0x5e, 0xb5, 0x15, 0xb5, 0x34, 0x99, 0xcb, 0xff, 0xbe, 0xf7, + 0xd2, 0x12, 0xc8, 0x58, 0xdb, 0x33, 0x28, 0xa9, 0xc1, 0xc6, 0x23, 0x07, + 0xbc, 0x50, 0xc4, 0xdd, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + 0x45, 0xd2, 0xd0, 0xb3, 0x22, 0xd3, 0xf2, 0x8b, 0x01, 0x6e, 0xba, 0xfa, + 0x0f, 0xac, 0x4c, 0x80, 0x29, 0x2c, 0xd0, 0x1d, 0x48, 0x99, 0x0a, 0xd2, + 0x78, 0x2b, 0x52, 0xd4, 0xe3, 0xbf, 0x12, 0xb9, 0x95, 0x45, 0x4a, 0x47, + 0xf4, 0x20, 0xd0, 0xa3, 0xc4, 0x55, 0x82, 0x1e, 0x6a, 0xbe, 0x00, 0x86, + 0x9c, 0x94, 0xe3, 0xd6, 0xac, 0xb5, 0x51, 0x25, 0x08, 0x5d, 0x0d, 0xf2, + 0x39, 0x37, 0x95, 0x88, 0xc9, 0xeb, 0xbe, 0xd5, 0xce, 0xff, 0x9b, 0x33, + 0x4e, 0xd0, 0xcc, 0x91, 0x2e, 0xf4, 0x5f, 0x0d, 0x0b, 0x9f, 0x93, 0xb7, + 0x63, 0xd1, 0x0f, 0x32, 0xd0, 0x64, 0x37, 0x42, 0x0c, 0x08, 0xc5, 0x3c, + 0xdf, 0xc3, 0xb0, 0xec, 0x8f, 0x51, 0xdc, 0x58, 0xe9, 0x99, 0xad, 0x58, + 0x58, 0x89, 0xa4, 0x35, 0xca, 0xc8, 0x14, 0xc0, 0x93, 0x78, 0x36, 0x08, + 0x3a, 0xf0, 0xac, 0x03, 0x20, 0x51, 0x59, 0x7e, 0x4c, 0x28, 0x3c, 0xf8, + 0x48, 0x9e, 0x91, 0x3a, 0xd4, 0x3b, 0xf4, 0xa9, 0x49, 0x7c, 0x61, 0x50, + 0x9c, 0xa5, 0xf1, 0xed, 0xc7, 0xb3, 0xbe, 0xca, 0x9e, 0x9a, 0x30, 0x91, + 0x77, 0x64, 0x5d, 0xdd, 0xf6, 0x83, 0x22, 0x63, 0x79, 0x52, 0xe9, 0x88, + 0xe8, 0x92, 0x64, 0x09, 0x0f, 0xa3, 0xbf, 0x77, 0x84, 0x37, 0x8e, 0xda, + 0xa8, 0xac, 0x9e, 0xfc, 0x49, 0xcf, 0x70, 0x2e, 0xe3, 0x2b, 0xdb, 0x11, + 0x0a, 0x6b, 0x5b, 0xc2, 0xa2, 0x0b, 0x2e, 0xa3, 0xa5, 0xed, 0x77, 0x1b, + 0xb5, 0x75, 0xe1, 0x8b, 0xec, 0x59, 0xbf, 0x80, 0xbb, 0x96, 0x80, 0xc2, + 0x1a, 0x57, 0x01, 0x9e, 0x1d, 0xdf, 0xcf, 0xf6, 0x86, 0x9e, 0x38, 0xed, + 0x46, 0xfa, 0x88, 0x1c, 0xcf, 0x56, 0xcc, 0x61, 0xe3, 0x8c, 0x06, 0xbb, + 0x80, 0xd4, 0xc4, 0x40, 0x3c, 0xa8, 0xce, 0x02, 0xc8, 0xb5, 0x2b, 0x5c, + 0xd2, 0xee, 0xd6, 0xc9, 0x4e, 0x5c, 0x82, 0x40, 0x00, 0xa5, 0xa8, 0x89, + 0x77, 0x4e, 0xa7, 0xd3, 0xa2, 0x0e, 0xc0, 0xb8, 0xfa, 0xa3, 0xdd, 0x53, + 0x12, 0x1d, 0x45, 0x04, 0x87, 0xd7, 0xe3, 0xd2, 0x99, 0x6f, 0xbe, 0xb4, + 0xb3, 0xb0, 0x35, 0x99, 0x22, 0xb8, 0x91, 0x83, 0x0d, 0x0a, 0xf6, 0x2c, + 0x51, 0x4c, 0xb8, 0xe5, 0x4a, 0x75, 0xca, 0xda, 0xd7, 0x3d, 0x8f, 0x0a, + 0x04, 0x04, 0xf8, 0x55, 0xb8, 0x01, 0xb7, 0xff, 0xf7, 0xed, 0x0a, 0x4b, + 0x62, 0x94, 0x79, 0x3d, 0x29, 0x1f, 0xfc, 0x40, 0xd1, 0xd2, 0x29, 0xbe, + 0x5d, 0x99, 0x3c, 0x04, 0xee, 0xa9, 0x20, 0x08, 0xea, 0xad, 0x08, 0x3d, + 0x8d, 0x35, 0x7f, 0x7c, 0x51, 0xf2, 0xe2, 0x00, 0x3e, 0x47, 0x7a, 0x98, + 0x53, 0x70, 0x23, 0xc2, 0xa0, 0x6d, 0x81, 0xc1, 0x78, 0xb0, 0xff, 0xfb, + 0xaf, 0xe4, 0x66, 0x4e, 0x7b, 0x79, 0xcd, 0x77, 0x09, 0x7b, 0x0e, 0x64, + 0xad, 0x30, 0xe2, 0x03, 0xe1, 0xed, 0x29, 0xa0, 0xb7, 0x8f, 0xa4, 0x62, + 0xc0, 0x09, 0xa8, 0xae, 0x8e, 0xf9, 0x91, 0x74, 0x2a, 0xf2, 0x87, 0x3b, + 0x0e, 0x02, 0x4e, 0x19, 0xb7, 0xef, 0xc8, 0x7e, 0x53, 0x40, 0x59, 0x9b, + 0x6e, 0x91, 0xcb, 0xcb, 0x8e, 0x80, 0xfd, 0x8e, 0x11, 0x94, 0xd3, 0x93, + 0x22, 0x6b, 0x7d, 0xbd, 0xa5, 0x1f, 0xa8, 0xf5, 0x64, 0x55, 0x31, 0xa6, + 0xd4, 0x21, 0x38, 0xfb, 0x8c, 0xc5, 0xaa, 0x1c, 0x71, 0x5f, 0xb6, 0x3f, + 0x3c, 0x0f, 0x3b, 0x66, 0xbf, 0x18, 0x69, 0xaa, 0x98, 0x84, 0x8d, 0x8c, + 0x5d, 0xa8, 0xec, 0x6f, 0x77, 0x41, 0x48, 0xfa, 0x25, 0x7d, 0x53, 0x54 +// }; +// unsigned int sig_len = 840; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512bsn0msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512bsn0msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512bsn0msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/sig_revoked2sha512bsn0msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha384.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha384.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha384.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha384.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc diff --git a/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc new file mode 100644 index 00000000..0159bbf3 --- /dev/null +++ b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc @@ -0,0 +1,68 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Test data. + * + * Type : Intel(R) EPID 2.0 verifier revocation list + * Group : grpX + * Bsn : "bsn0" + * HashAlg : Sha512256 + * Revoked : verrevoked/mprivatekey000 + * verrevoked/mprivatekey001 + * verrevoked/mprivatekey002 + */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xee, + + // B + 0xcb, 0xc0, 0x78, 0x14, 0xbd, 0x94, 0x6f, 0xe6, + 0xeb, 0x43, 0x37, 0x3b, 0x7e, 0x22, 0x79, 0xf4, + 0x4d, 0xc1, 0x55, 0x93, 0x7f, 0x5c, 0x22, 0x2f, + 0x87, 0x15, 0x18, 0x92, 0xbd, 0x23, 0x15, 0x83, + 0x9e, 0x0d, 0x3b, 0x35, 0xe9, 0xd0, 0xdd, 0xd5, + 0xd8, 0x99, 0xac, 0x22, 0xaf, 0x2a, 0xa3, 0x52, + 0x25, 0xfa, 0x02, 0x50, 0x60, 0x60, 0xd3, 0x07, + 0x7a, 0x59, 0xec, 0x8d, 0xb2, 0xf6, 0x6e, 0x2d, + // version | n4 + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, + + 0x8b, 0xc9, 0x6e, 0xc0, 0x86, 0x04, 0x6f, 0x6c, + 0x89, 0xc2, 0x27, 0xfd, 0x61, 0x59, 0xb5, 0xd2, + 0x73, 0x96, 0xfa, 0xd6, 0xf8, 0xfa, 0x2c, 0x39, + 0xfe, 0xee, 0xef, 0x3e, 0x73, 0xd2, 0x38, 0x3f, + 0x3c, 0x04, 0x07, 0x78, 0xfd, 0x32, 0x9b, 0xc3, + 0x74, 0x90, 0xf2, 0xf5, 0x50, 0xe4, 0x69, 0x5d, + 0x30, 0x0c, 0x6a, 0x8a, 0x9c, 0xcf, 0xff, 0x78, + 0x28, 0x52, 0x6d, 0x20, 0x29, 0xef, 0x2d, 0x7a, + + 0x07, 0x46, 0xed, 0xb8, 0x6a, 0x4e, 0x7f, 0x4b, + 0x9d, 0xcc, 0x18, 0x91, 0x88, 0xf6, 0x76, 0x4d, + 0x74, 0x02, 0x36, 0x62, 0xe6, 0xd4, 0xb5, 0xf0, + 0x2d, 0x70, 0x91, 0x49, 0x65, 0xdf, 0x19, 0x02, + 0x30, 0x6c, 0x11, 0xaa, 0x74, 0x8c, 0x55, 0x2e, + 0x4b, 0xa3, 0x00, 0x00, 0xb0, 0x38, 0xf4, 0xcd, + 0x5d, 0xc9, 0x1d, 0xaa, 0x1e, 0x44, 0x98, 0xa4, + 0xe1, 0x3f, 0x2f, 0x4f, 0x6c, 0xc9, 0x15, 0xb0, + + 0x8c, 0x10, 0x2f, 0x17, 0xa0, 0xe4, 0x1f, 0xc6, + 0xaa, 0xea, 0xd4, 0x82, 0x67, 0x61, 0x96, 0x47, + 0x9b, 0x46, 0x2c, 0x31, 0xbd, 0x29, 0x62, 0x2d, + 0xd8, 0x40, 0x44, 0xbc, 0x1d, 0xf0, 0x19, 0x02, + 0x4e, 0x4c, 0x2e, 0xc1, 0x0d, 0x43, 0x59, 0x8b, + 0xe0, 0x0d, 0xb4, 0x29, 0x20, 0x35, 0x1f, 0xb6, + 0x00, 0x07, 0xa3, 0xd9, 0x28, 0xd9, 0x48, 0x08, + 0x5e, 0x14, 0xca, 0x56, 0x72, 0xa4, 0xb6, 0x5a, diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey003.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey003.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey003.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey003.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey004.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey004.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey004.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey004.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey005.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey005.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey005.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/mprivkey005.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/sig_revoked3sha256bsn1msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/sig_revoked3sha256bsn1msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/sig_revoked3sha256bsn1msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/sig_revoked3sha256bsn1msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl_012revoked.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl_012revoked.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl_012revoked.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_x/verrevoked/bsn1/verrl_012revoked.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.dat b/external/epid-sdk/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.dat rename to external/epid-sdk/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.dat diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/iprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_y/iprivkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/iprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_y/iprivkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/pubkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/grp_y/pubkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grp_y/pubkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grp_y/pubkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl.inc b/external/epid-sdk/epid/common-testhelper/testdata/grprl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grprl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_first_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_first_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_first_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_first_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_last_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_last_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_last_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_last_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_middle_entry.inc b/external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_middle_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_revoked_grp_x_middle_entry.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grprl_revoked_grp_x_middle_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_single_entry_revoked_grp_x.inc b/external/epid-sdk/epid/common-testhelper/testdata/grprl_single_entry_revoked_grp_x.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/grprl_single_entry_revoked_grp_x.inc rename to external/epid-sdk/epid/common-testhelper/testdata/grprl_single_entry_revoked_grp_x.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc index 21957978..0fae8b7e 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc +++ b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -103,4 +103,4 @@ 0x32, 0x8d, 0xac, 0x7b, 0x8f, 0x2a, 0x8a, 0x5f, 0xf1, 0xea, 0xbb, 0x8e, 0x6d, 0xbf, 0xe0, 0x59, 0x90, 0xc2, 0xd3, 0x3d, 0x8a, 0x03, 0x64, 0x11, 0xdd, 0xf1, 0xfc, 0x2d, 0x26, 0x8a, 0x6f, 0x39, 0x25, 0xa9, 0xaa, 0x61, - 0x45, 0x5b, 0x7b, 0x36, 0xfd, 0x82, 0xd2, 0x6a, 0x8c, 0x9a, 0xf1, 0xc2 \ No newline at end of file + 0x45, 0x5b, 0x7b, 0x36, 0xfd, 0x82, 0xd2, 0x6a, 0x8c, 0x9a, 0xf1, 0xc2 diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc index 2017fa0d..44de32ae 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc +++ b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,4 +33,4 @@ 0x0e, 0x2f, 0x12, 0xac, 0x95, 0xb9, 0x26, 0x6d, 0x1d, 0xe2, 0xcf, 0x64, 0x4a, 0x09, 0xdd, 0x4f, 0x15, 0x9d, 0x08, 0x6b, 0x93, 0xbf, 0x95, 0x89, 0x11, 0xb8, 0x31, 0x11, 0xb1, 0x36, 0x76, 0x4d, 0x0a, 0xbe, 0x5a, 0x42, - 0xe7, 0x44, 0xbb, 0x17, 0x6d, 0x36, 0x7b, 0x80, 0x0b, 0x10, 0x1e, 0xc6 \ No newline at end of file + 0xe7, 0x44, 0xbb, 0x17, 0x6d, 0x36, 0x7b, 0x80, 0x0b, 0x10, 0x1e, 0xc6 diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/privrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/privrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/privrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/privrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_empty_sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_empty_sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_empty_sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_empty_sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_nosigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_nosigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_nosigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_nosigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_revkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_revkey.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_revkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_bsn0_msg0_revkey.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_rndbase_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_rndbase_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_rndbase_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sha256_rndbase_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sigrevoked_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sigrevoked_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_sigrevoked_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_sigrevoked_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_test1_basename1_sha256.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_test1_basename1_sha256.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sig_test1_basename1_sha256.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sig_test1_basename1_sha256.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc index e8059b8d..08b48b91 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc +++ b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,4 +33,4 @@ 0x96, 0xfd, 0xdc, 0x71, 0x8a, 0x88, 0x5c, 0x13, 0x55, 0x1b, 0x22, 0xbd, 0x42, 0x0e, 0xc2, 0x49, 0x48, 0x5b, 0xa0, 0x03, 0xea, 0x4b, 0x79, 0x0b, 0xb5, 0xed, 0x1a, 0x81, 0x6d, 0xb2, 0xe8, 0x41, 0xca, 0x1b, 0xb1, 0xc0, - 0xf7, 0x11, 0x42, 0x3f, 0x24, 0xea, 0x55, 0x02, 0x82, 0x4d, 0x11, 0x48 \ No newline at end of file + 0xf7, 0x11, 0x42, 0x3f, 0x24, 0xea, 0x55, 0x02, 0x82, 0x4d, 0x11, 0x48 diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc index 33408c97..1ff48eea 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc +++ b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupb/member0/mprivkey.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,4 +33,4 @@ 0x9f, 0xe1, 0xb0, 0x93, 0x74, 0x58, 0xdd, 0x13, 0x8f, 0xc8, 0xce, 0x87, 0x76, 0x80, 0x02, 0x8b, 0x8f, 0xb9, 0x5d, 0x46, 0x25, 0xcb, 0x20, 0x43, 0xda, 0x66, 0xd3, 0x50, 0x6e, 0x10, 0xf2, 0x32, 0x6a, 0x39, 0x36, 0xd2, - 0x97, 0x01, 0x08, 0x6c, 0x8e, 0x9e, 0x25, 0xa7, 0x7c, 0x86, 0xd4, 0xad \ No newline at end of file + 0x97, 0x01, 0x08, 0x6c, 0x8e, 0x9e, 0x25, 0xa7, 0x7c, 0x86, 0xd4, 0xad diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupb/sig_grouprevoked_sha256_bsn0_msg0.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupb/sig_grouprevoked_sha256_bsn0_msg0.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/groupb/sig_grouprevoked_sha256_bsn0_msg0.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/groupb/sig_grouprevoked_sha256_bsn0_msg0.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/grprl.inc b/external/epid-sdk/epid/common-testhelper/testdata/ikgf/grprl.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/testdata/ikgf/grprl.inc rename to external/epid-sdk/epid/common-testhelper/testdata/ikgf/grprl.inc diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/bignum_wrapper-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/bignum_wrapper-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/bignum_wrapper-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/bignum_wrapper-test.cc index 83dba24f..2f4db3fd 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/bignum_wrapper-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/bignum_wrapper-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,10 +19,11 @@ * \brief Bignum C++ wrapper unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" extern "C" { #include "epid/common/math/bignum.h" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc similarity index 85% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc index 4cc399c7..fc9ba853 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/ecgroup_wrapper-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,14 +19,15 @@ * \brief EcGroup C++ wrapper unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" extern "C" { #include "epid/common/math/bignum.h" @@ -45,28 +46,28 @@ class EcGroupObjTest : public ::testing::Test { static const G1ElemStr g1_str; }; const BigNumStr EcGroupObjTest::q_str = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; const FqElemStr EcGroupObjTest::b_str = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; const BigNumStr EcGroupObjTest::p_str = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; const BigNumStr EcGroupObjTest::h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; const G1ElemStr EcGroupObjTest::g1_str = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; TEST_F(EcGroupObjTest, ObjDefaultConstructedIsNotNull) { EcGroupObj group; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc similarity index 83% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc index 780b70fe..db77afc5 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/ecpoint_wrapper-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,12 @@ * \brief EcPoint C++ wrapper unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" +#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" extern "C" { #include "epid/common/math/bignum.h" @@ -40,20 +41,20 @@ class EcPointObjTest : public ::testing::Test { }; const G1ElemStr EcPointObjTest::group_str_1 = { - {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, - {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, 0x30, - 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, 0xF7, 0xCD, - 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; + {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, + 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, + 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; const G1ElemStr EcPointObjTest::group_str_2 = { - {{{0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, 0x67, - 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, 0xD9, 0x98, - 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}}}, - {{{0x63, 0xB0, 0xAD, 0xB8, 0x2C, 0xE8, 0x14, 0xFD, 0xA2, 0x39, 0x0E, 0x66, - 0xB7, 0xD0, 0x6A, 0xAB, 0xEE, 0xFA, 0x2E, 0x24, 0x9B, 0xB5, 0x14, 0x35, - 0xFE, 0xB6, 0xB0, 0xFF, 0xFD, 0x5F, 0x73, 0x19}}}}; + {{{0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, + 0x67, 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, + 0xD9, 0x98, 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}}}, + {{{0x63, 0xB0, 0xAD, 0xB8, 0x2C, 0xE8, 0x14, 0xFD, 0xA2, 0x39, 0x0E, + 0x66, 0xB7, 0xD0, 0x6A, 0xAB, 0xEE, 0xFA, 0x2E, 0x24, 0x9B, 0xB5, + 0x14, 0x35, 0xFE, 0xB6, 0xB0, 0xFF, 0xFD, 0x5F, 0x73, 0x19}}}}; EcGroupObj EcPointObjTest::group; diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ffelement_wrapper-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/ffelement_wrapper-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ffelement_wrapper-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/ffelement_wrapper-test.cc index 6f835ca4..c9e13613 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/ffelement_wrapper-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/ffelement_wrapper-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * \brief FfElement C++ wrapper unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" #include "epid/common-testhelper/errors-testhelper.h" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/finite_field_wrapper-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/finite_field_wrapper-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/finite_field_wrapper-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/finite_field_wrapper-test.cc index 1ce59d0c..62a29c67 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/finite_field_wrapper-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/finite_field_wrapper-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,12 @@ * \brief FiniteField C++ wrapper unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" #include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" extern "C" { #include "epid/common/math/bignum.h" diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/main-test.cc b/external/epid-sdk/epid/common-testhelper/unittests/main-test.cc similarity index 90% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/main-test.cc rename to external/epid-sdk/epid/common-testhelper/unittests/main-test.cc index 70f2d3a1..a8bb2fa9 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/main-test.cc +++ b/external/epid-sdk/epid/common-testhelper/unittests/main-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * \brief Main entry point for unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" int main(int argc, char** argv) { diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/verifier_wrapper-testhelper.cc b/external/epid-sdk/epid/common-testhelper/verifier_wrapper-testhelper.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/common-testhelper/verifier_wrapper-testhelper.cc rename to external/epid-sdk/epid/common-testhelper/verifier_wrapper-testhelper.cc index ef9ba8b2..943d3083 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/verifier_wrapper-testhelper.cc +++ b/external/epid-sdk/epid/common-testhelper/verifier_wrapper-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ * \brief Verifier C++ wrapper implementation. */ #include -#include #include +#include #include "epid/common-testhelper/verifier_wrapper-testhelper.h" diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/verifier_wrapper-testhelper.h b/external/epid-sdk/epid/common-testhelper/verifier_wrapper-testhelper.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common-testhelper/verifier_wrapper-testhelper.h rename to external/epid-sdk/epid/common-testhelper/verifier_wrapper-testhelper.h diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/file_parser.h b/external/epid-sdk/epid/common/1.1/file_parser.h similarity index 94% rename from external/epid-sdk-3.0.0/epid/common/1.1/file_parser.h rename to external/epid-sdk/epid/common/1.1/file_parser.h index d6d5c893..70ccfdcb 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/file_parser.h +++ b/external/epid-sdk/epid/common/1.1/file_parser.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ -/// Epid 1.1 issuer material parsing utilities. +/// Intel(R) EPID 1.1 issuer material parsing utilities. /*! * \file */ @@ -28,13 +28,13 @@ /// Parser for 1.1 issuer material /*! - \defgroup Epid11FileParserModule EPID 1.1 support + \defgroup Epid11FileParserModule Intel(R) EPID 1.1 support Defines the APIs needed to parse Intel(R) EPID 1.1 issuer material. \ingroup FileParser - \see EPID 1.1 -support + \see Intel(R) + EPID 1.1 support @{ */ @@ -68,7 +68,8 @@ support
      \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. - \see EPID 1.1 + \see Intel(R) + EPID 1.1 support */ @@ -113,8 +114,8 @@ EpidStatus Epid11ParseGroupPubKeyFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. - \see EPID 1.1 - support + \see Intel(R) + EPID 1.1 support */ EpidStatus Epid11ParsePrivRlFile(void const* buf, size_t len, @@ -159,8 +160,8 @@ EpidStatus Epid11ParsePrivRlFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. - \see EPID 1.1 - support + \see Intel(R) + EPID 1.1 support */ EpidStatus Epid11ParseSigRlFile(void const* buf, size_t len, @@ -204,8 +205,8 @@ EpidStatus Epid11ParseSigRlFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. - \see EPID 1.1 - support + \see Intel(R) + EPID 1.1 support */ EpidStatus Epid11ParseGroupRlFile(void const* buf, size_t len, diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.c b/external/epid-sdk/epid/common/1.1/src/commitment.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.c rename to external/epid-sdk/epid/common/1.1/src/commitment.c index 7749fa65..cf161449 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.c +++ b/external/epid-sdk/epid/common/1.1/src/commitment.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,13 +18,13 @@ * \file * \brief Commitment hash implementation. */ -#include -#include #include "epid/common/1.1/src/commitment.h" -#include "epid/common/src/memory.h" +#include +#include #include "epid/common/math/bignum.h" #include "epid/common/math/src/bignum-internal.h" #include "epid/common/src/endian_convert.h" +#include "epid/common/src/memory.h" EpidStatus SetKeySpecificEpid11CommitValues(Epid11GroupPubKey const* pub_key, Epid11CommitValues* values) { diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.h b/external/epid-sdk/epid/common/1.1/src/commitment.h similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.h rename to external/epid-sdk/epid/common/1.1/src/commitment.h index b6065905..ee3d9b1e 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/src/commitment.h +++ b/external/epid-sdk/epid/common/1.1/src/commitment.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ * \addtogroup EpidCommon * @{ */ -#include "epid/common/errors.h" #include "epid/common/1.1/types.h" +#include "epid/common/errors.h" #include "epid/common/math/ecgroup.h" #include "epid/common/math/finitefield.h" #include "epid/common/math/hash.h" diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params.c b/external/epid-sdk/epid/common/1.1/src/epid11params.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params.c rename to external/epid-sdk/epid/common/1.1/src/epid11params.c index 0a1e620d..8692f0ef 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params.c +++ b/external/epid-sdk/epid/common/1.1/src/epid11params.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ * \brief Intel(R) EPID 1.1 constant parameters implementation. */ #include "epid/common/1.1/src/epid11params.h" -#include "epid/common/src/memory.h" #include "epid/common/math/tatepairing.h" +#include "epid/common/src/memory.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params.h b/external/epid-sdk/epid/common/1.1/src/epid11params.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params.h rename to external/epid-sdk/epid/common/1.1/src/epid11params.h diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params_tate.inc b/external/epid-sdk/epid/common/1.1/src/epid11params_tate.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/epid11params_tate.inc rename to external/epid-sdk/epid/common/1.1/src/epid11params_tate.inc diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/file_parser.c b/external/epid-sdk/epid/common/1.1/src/file_parser.c similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/file_parser.c rename to external/epid-sdk/epid/common/1.1/src/file_parser.c index bf3d79d0..a9716324 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/src/file_parser.c +++ b/external/epid-sdk/epid/common/1.1/src/file_parser.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ #include #include "epid/common/math/ecdsa.h" -#include "epid/common/src/memory.h" #include "epid/common/src/file_parser-internal.h" +#include "epid/common/src/memory.h" /// Intel(R) EPID 1.1 Group Public Key binary format typedef struct Epid11GroupPubKeyCertificate { @@ -134,7 +134,7 @@ EpidStatus Epid11ParseGroupPubKeyFile(void const* buf, size_t len, return kEpidBadArgErr; } - if (sizeof(Epid11GroupPubKeyCertificate) > len) { + if (len == 0 || len % sizeof(Epid11GroupPubKeyCertificate) != 0) { return kEpidBadArgErr; } diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/grouppubkey.c b/external/epid-sdk/epid/common/1.1/src/grouppubkey.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/grouppubkey.c rename to external/epid-sdk/epid/common/1.1/src/grouppubkey.c diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/src/grouppubkey.h b/external/epid-sdk/epid/common/1.1/src/grouppubkey.h similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/1.1/src/grouppubkey.h rename to external/epid-sdk/epid/common/1.1/src/grouppubkey.h index 49db3302..3cb83a35 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/src/grouppubkey.h +++ b/external/epid-sdk/epid/common/1.1/src/grouppubkey.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ * \addtogroup EpidCommon * @{ */ +#include "epid/common/1.1/types.h" #include "epid/common/errors.h" #include "epid/common/math/ecgroup.h" -#include "epid/common/1.1/types.h" /// Internal representation of Epid11GroupPubKey typedef struct Epid11GroupPubKey_ { diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/types.h b/external/epid-sdk/epid/common/1.1/types.h similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/1.1/types.h rename to external/epid-sdk/epid/common/1.1/types.h index dba9d082..a83f824c 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/types.h +++ b/external/epid-sdk/epid/common/1.1/types.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,13 +27,13 @@ /// Intel(R) EPID 1.1 specific data types. /*! -\defgroup Epid11Types EPID 1.1 specific types +\defgroup Epid11Types Intel(R) EPID 1.1 specific types Defines serialized data types used by the SDK. These data types are only used by components that need to do Intel(R) EPID 1.1 verification. \ingroup EpidTypes -\see EPID 1.1 +\see Intel(R) EPID 1.1 support @{ */ @@ -123,7 +123,7 @@ typedef struct Epid11GroupPubKey { * Basic signature: (B, K, T1, T2, c, nd, sx, sy, sf, sa, sb, salpha, sbeta) */ typedef struct Epid11BasicSignature { - OctStr32 bv; ///For backward compatibility only + OctStr32 bv; Epid11G3ElemStr B; ///< an element in G3 Epid11G3ElemStr K; ///< an element in G3 Epid11G1ElemStr T1; ///< an element in G1 diff --git a/external/epid-sdk-3.0.0/epid/common/1.1/unittests/file_parser-test.cc b/external/epid-sdk/epid/common/1.1/unittests/file_parser-test.cc similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/1.1/unittests/file_parser-test.cc rename to external/epid-sdk/epid/common/1.1/unittests/file_parser-test.cc index 59d1541c..a2bf2449 100644 --- a/external/epid-sdk-3.0.0/epid/common/1.1/unittests/file_parser-test.cc +++ b/external/epid-sdk/epid/common/1.1/unittests/file_parser-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/common/1.1/file_parser.h" @@ -68,9 +69,9 @@ class Epid11FileParser : public ::testing::Test { static const std::vector kShortGroupRl; }; const EpidCaCertificate Epid11FileParser::kCert = { - // EpidFileHeader::epid_version + // Intel(R) EPID Version 0x02, 0x00, - // EpidFileHeader::file_type + // File type 0x00, 0x11, // pubkey 0x24, 0x42, 0xa5, 0xcc, 0x0e, 0xcd, 0x01, 0x5f, 0xa3, 0xca, 0x31, 0xdc, @@ -113,9 +114,9 @@ const EpidCaCertificate Epid11FileParser::kCert = { 0x1c, 0x01, 0x5b, 0xc9, 0x08, 0xce, 0x3e, 0x68}; const std::vector Epid11FileParser::kGroupPublicKeyFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0c, // GID 0x00, 0x00, 0x00, 0x7b, @@ -193,9 +194,9 @@ const std::vector Epid11FileParser::kGroupPublicKey = { 0xa5, 0xfd, 0x6b, 0xc4, 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd}; const std::vector Epid11FileParser::kGroupMultiPublicKeyFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0c, // GID 0x00, 0x00, 0x00, 0x7b, @@ -237,9 +238,9 @@ const std::vector Epid11FileParser::kGroupMultiPublicKeyFile = { 0x68, 0x6f, 0x9e, 0x3b, 0xcf, 0xfd, 0x98, 0xcc, 0xae, 0x92, 0xcc, 0x94, 0x23, 0xb6, 0xbd, 0x57, 0xac, 0x06, 0x3c, 0xa1, 0xe5, 0x3e, 0xe9, 0xf5, 0x0e, 0x55, 0xb4, 0xe5, - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0c, // GID 0x00, 0x00, 0x04, 0xd2, @@ -283,9 +284,9 @@ const std::vector Epid11FileParser::kGroupMultiPublicKeyFile = { 0xfb, 0x79, 0xa0, 0xa5}; const std::vector Epid11FileParser::kEmptyPrivRlFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0d, // GID 0x00, 0x00, 0x00, 0x7b, @@ -310,9 +311,9 @@ const std::vector Epid11FileParser::kEmptyPrivRl = { 0x00, 0x00, 0x00, 0x00}; const std::vector Epid11FileParser::kShortPrivRlFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0d, // GID 0x00, 0x00, 0x00, 0x7b, @@ -346,9 +347,9 @@ const std::vector Epid11FileParser::kShortPrivRl = { }; const std::vector Epid11FileParser::kEmptySigRlFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0e, // GID 0x00, 0x00, 0x00, 0x7b, @@ -372,9 +373,9 @@ const std::vector Epid11FileParser::kEmptySigRl = { 0x00, 0x00, 0x00, 0x00}; const std::vector Epid11FileParser::kShortSigRlFile = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0e, // GID 0x00, 0x00, 0x00, 0x7b, @@ -467,9 +468,9 @@ const std::vector Epid11FileParser::kShortSigRl = { 0x48, 0xc2, 0x89, 0xb6, 0x27, 0x3b, 0x95, 0x89}; const std::vector Epid11FileParser::kEmptyGroupRlFile = { - // Epid version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0f, // RL ver 0x00, 0x00, 0x00, 0x00, @@ -489,9 +490,9 @@ const std::vector Epid11FileParser::kEmptyGroupRl = { 0x00, 0x00, 0x00, 0x00}; const std::vector Epid11FileParser::kShortGroupRlFile = { - // Epid version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0f, // RL ver 0x00, 0x00, 0x00, 0x03, @@ -606,6 +607,14 @@ TEST_F(Epid11FileParser, RejectsGroupPubKeyFileWithInvalidSize) { Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size() - 1, &this->kCert, &pubkey)); + EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupPubKeyFile( + (void*)this->kGroupMultiPublicKeyFile.data(), + this->kGroupMultiPublicKeyFile.size() - 1, + &this->kCert, &pubkey)); + EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupPubKeyFile( + (void*)this->kGroupMultiPublicKeyFile.data(), + this->kGroupMultiPublicKeyFile.size() + 1, + &this->kCert, &pubkey)); } TEST_F(Epid11FileParser, RejectsInvalidGroupPubKeyFileType) { @@ -852,9 +861,9 @@ TEST_F(Epid11FileParser, PrivRlParseParsesLongPrivRl) { }; std::vector long_privrl_file = { - // Epid Version + // Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0d, // GID 0x00, 0x00, 0x00, 0x7b, @@ -1110,9 +1119,9 @@ TEST_F(Epid11FileParser, SigRlParseParsesLongSigRl) { 0x23, 0x1d, 0x31, 0x17, 0x88, 0x49, 0x13, 0x47, 0xe7, 0xda, 0xfe, 0x8d, 0x67, 0xba, 0x16, 0x1d, 0x0a, 0xd3, 0x4a, 0x2d, 0xd1, 0xf8, 0x60, 0x21, 0xa5, 0x00, 0x9a, 0x0d, 0x4d, 0xc4, 0xbd}; - std::vector long_sigrl_file = {// EPID Version + std::vector long_sigrl_file = {// Intel(R) EPID Version 0x01, 0x00, - // Epid type + // File type 0x00, 0x0e, // GID 0x00, 0x00, 0x00, 0x7b, @@ -1353,7 +1362,7 @@ TEST_F(Epid11FileParser, ParsesLongGroupRl) { 0x30, 0x90, 0x53, 0x8f, 0x55, 0x50, 0xcf, 0xed, 0x9e, 0xaa, 0x31, 0x4f, 0x7f, 0xb2, 0x27, 0xf9, 0xbb, 0xfa, 0x52, 0x70}; std::vector long_grouprl_file = { - /// EPID version + /// Intel(R) EPID version 0x01, 0x00, // File type 0x00, 0x0f, diff --git a/external/epid-sdk-3.0.0/epid/common/Makefile b/external/epid-sdk/epid/common/Makefile similarity index 79% rename from external/epid-sdk-3.0.0/epid/common/Makefile rename to external/epid-sdk/epid/common/Makefile index be705d4a..4dfe984a 100644 --- a/external/epid-sdk-3.0.0/epid/common/Makefile +++ b/external/epid-sdk/epid/common/Makefile @@ -18,23 +18,22 @@ COMMON_MATH_INCLUDE_DIR = ./math COMMON_SRC = $(wildcard ./src/*.c) COMMON_SRC += $(wildcard ./math/src/*.c) COMMON_SRC += $(wildcard ./1.1/src/*.c) -COMMON_OBJ = $(sort $(COMMON_SRC:.c=.o)) +COMMON_OBJ = $(COMMON_SRC:.c=.o) COMMON_LIB = ./libcommon.a -COMMON_UTEST_EXE = ./common-utest +COMMON_UTEST_EXE = ./common-utest$(EXE_EXTENSION) COMMON_UTEST_SRC = $(wildcard ./math/unittests/*.cc) COMMON_UTEST_SRC += $(wildcard ./unittests/*.cc) COMMON_UTEST_SRC += $(wildcard ./1.1/unittests/*.cc) -COMMON_UTEST_OBJ = $(sort $(COMMON_UTEST_SRC:.cc=.o)) +COMMON_UTEST_OBJ = $(COMMON_UTEST_SRC:.cc=.o) LIB_COMMON_DIR = . LIB_COMMON_TESTHELPER_DIR = ../common-testhelper LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src -LIB_IPPCPEPID_DIR = ../../ext/ipp/sources/ippcpepid/src #set flags for linker LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \ - -L$(LIB_COMMON_DIR) -L$(LIB_IPPCPEPID_DIR) -L$(LIB_IPPCP_DIR) \ - -lgtest -lcommon-testhelper -lcommon -lippcpepid -lippcp + -L$(LIB_COMMON_DIR) -L$(LIB_IPPCP_DIR) \ + -lgtest -lcommon-testhelper -lcommon -lippcp #target part $(COMMON_OBJ): %.o: %.c @@ -42,13 +41,13 @@ $(COMMON_OBJ): %.o: %.c $(COMMON_LIB): $(COMMON_OBJ) $(AR) rc $(COMMON_LIB) $(COMMON_OBJ) - ranlib $(COMMON_LIB) + $(RANLIB) $(COMMON_LIB) $(COMMON_UTEST_EXE): $(COMMON_UTEST_OBJ) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) + $(CXX) -o $@ $^ $(LDFLAGS) $(COMMON_UTEST_OBJ): %.o: %.cc - $(CXX) -o $@ $(CXXFLAGS) -I$(COMMON_INCLUDE_DIR) -I$(GTEST_INCLUDE_DIR) -c $^ + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(COMMON_INCLUDE_DIR) -I$(GTEST_INCLUDE_DIR) -c $^ build: all @@ -67,11 +66,13 @@ ifneq (,$(wildcard $(COMMON_UTEST_EXE))) cp $(COMMON_UTEST_EXE) '$(TEST_INSTALL_DIR)' endif -check: $(COMMON_UTEST_EXE) run +utest: $(COMMON_UTEST_EXE) -run: +run_utest: $(COMMON_UTEST_EXE) $(GTEST_FLAGS) +check: utest run_utest + clean: rm -f $(COMMON_OBJ) \ $(COMMON_LIB) \ diff --git a/external/epid-sdk-3.0.0/epid/common/bitsupplier.h b/external/epid-sdk/epid/common/bitsupplier.h similarity index 57% rename from external/epid-sdk-3.0.0/epid/common/bitsupplier.h rename to external/epid-sdk/epid/common/bitsupplier.h index 7abee2d0..fb544a13 100644 --- a/external/epid-sdk-3.0.0/epid/common/bitsupplier.h +++ b/external/epid-sdk/epid/common/bitsupplier.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,13 +28,27 @@ /// Generates random data. /*! - It is the responsibility of the caller of the SDK interfaces to - implement a function of this prototype and to then pass a pointer - to this function into methods that require it. + The SDK provides the ::BitSupplier as a function + prototype so that you will know the requirements for your + own implementation of a random number generator. - \param[out] rand_data destination buffer - \param[in] num_bits size of rand_data in bits - \param[in] user_data user data passed through from api call. + You need to pass a pointer to your + implementation of the random number generator into + methods that require it. + + For an example of how a BitSupplier is created, see + the `signmsg` example. + + \param[out] rand_data destination buffer for random data + generated by BitSupplier. The buffer will receive + `num_bits` of random data. + \param[in] num_bits specifies the size of the random + data, in bits, to be generated. + \param[in] user_data user data that will be passed to the + random number generator. The usage of this data is specific + to the implementation of the BitSupplier. For example, this + could be used to pass a pointer to a data structure + that maintains state across calls to your BitSupplier. \returns zero on success and non-zero value on error. diff --git a/external/epid-sdk-3.0.0/epid/common/common.parts b/external/epid-sdk/epid/common/common.parts similarity index 97% rename from external/epid-sdk-3.0.0/epid/common/common.parts rename to external/epid-sdk/epid/common/common.parts index 3886d8c8..dfa80b4d 100644 --- a/external/epid-sdk-3.0.0/epid/common/common.parts +++ b/external/epid-sdk/epid/common/common.parts @@ -1,5 +1,5 @@ ############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -83,8 +83,9 @@ if 'install_package' in env['MODE']: else: env.DependsOn([ Component('ippcp'), - Component('ippcpepid'), ]) + if 'use_memory_profiler' in env['MODE']: + env.DependsOn([Component('memory_profiler')]) env.Append(CPPPATH='#') diff --git a/external/epid-sdk/epid/common/epiddefs.h b/external/epid-sdk/epid/common/epiddefs.h new file mode 100644 index 00000000..1ff76730 --- /dev/null +++ b/external/epid-sdk/epid/common/epiddefs.h @@ -0,0 +1,39 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Common SDK macro definitions +/*! \file */ +#ifndef EPID_COMMON_EPIDDEFS_H_ +#define EPID_COMMON_EPIDDEFS_H_ + +#if defined(SHARED) +#if defined(_WIN32) +#ifdef EXPORT_EPID_APIS +#define EPID_API __declspec(dllexport) +#else +#define EPID_API __declspec(dllimport) +#endif +#else // defined(_WIN32) +#if __GNUC__ >= 4 +#define EPID_API __attribute__((visibility("default"))) +#else +#define EPID_API +#endif +#endif // defined(_WIN32) +#else // defined(SHARED) +#define EPID_API +#endif // defined(SHARED) + +#endif // EPID_COMMON_EPIDDEFS_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/errors.h b/external/epid-sdk/epid/common/errors.h similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/errors.h rename to external/epid-sdk/epid/common/errors.h index 15a29d0d..7f4f4850 100644 --- a/external/epid-sdk-3.0.0/epid/common/errors.h +++ b/external/epid-sdk/epid/common/errors.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -58,6 +58,7 @@ typedef enum { kEpidDuplicateErr, //!< argument would add duplicate entry kEpidInconsistentBasenameSetErr, //!< set basename conflicts with arguments kEpidMathQuadraticNonResidueError, //!< quadratic Non-Residue Error + kEpidOutOfSequenceError, //!< operation was performed out of sequence } EpidStatus; /// Returns string representation of error code. diff --git a/external/epid-sdk-3.0.0/epid/common/file_parser.h b/external/epid-sdk/epid/common/file_parser.h similarity index 92% rename from external/epid-sdk-3.0.0/epid/common/file_parser.h rename to external/epid-sdk/epid/common/file_parser.h index a920b3b2..0cc7b3b0 100644 --- a/external/epid-sdk-3.0.0/epid/common/file_parser.h +++ b/external/epid-sdk/epid/common/file_parser.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ /*! * \file - * \brief Epid issuer material parsing utilities. + * \brief Intel(R) EPID issuer material parsing utilities. */ #ifndef EPID_COMMON_FILE_PARSER_H_ #define EPID_COMMON_FILE_PARSER_H_ #include -#include "epid/common/types.h" #include "epid/common/errors.h" +#include "epid/common/types.h" /// Parser for issuer material /*! @@ -32,6 +32,8 @@ Provides an API for parsing buffers formatted according to the various IoT Intel(R) EPID binary file formats. + To use this module, include the header epid/common/file_parser.h. + \ingroup EpidCommon @{ */ @@ -40,7 +42,7 @@ typedef enum EpidVersion { kEpid1x, ///< Intel(R) EPID version 1.x kEpid2x, ///< Intel(R) EPID version 2.x - kNumEpidVersions, ///< Maximum number of EPID versions + kNumEpidVersions, ///< Maximum number of versions } EpidVersion; /// Encoding of issuer material Intel(R) EPID versions @@ -92,12 +94,12 @@ typedef struct EpidCaCertificate { The size of buf in bytes. \param[out] epid_version - The extracted EPID version or kNumEpidVersions if EPID version is unknown. - Pass NULL to not extract. + The extracted Intel(R) EPID version or kNumEpidVersions if Intel(R) EPID + version is unknown. Pass NULL to not extract. \param[out] file_type - The extracted EPID file type or kNumFileTypes if file type is unknown. - Pass NULL to not extract. + The extracted Intel(R) EPID file type or kNumFileTypes if file type is + unknown. Pass NULL to not extract. \returns ::EpidStatus @@ -136,6 +138,9 @@ EpidStatus EpidParseFileHeader(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. + \b Examples + + \ref UserManual_GeneratingAnIntelEpidSignature */ EpidStatus EpidParseGroupPubKeyFile(void const* buf, size_t len, EpidCaCertificate const* cert, @@ -178,6 +183,9 @@ EpidStatus EpidParseGroupPubKeyFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidParsePrivRlFile(void const* buf, size_t len, EpidCaCertificate const* cert, PrivRl* rl, @@ -220,6 +228,9 @@ EpidStatus EpidParsePrivRlFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. + \b Examples + + \ref UserManual_GeneratingAnIntelEpidSignature */ EpidStatus EpidParseSigRlFile(void const* buf, size_t len, EpidCaCertificate const* cert, SigRl* rl, @@ -262,6 +273,9 @@ EpidStatus EpidParseSigRlFile(void const* buf, size_t len, \retval ::kEpidSigInvalid Parsing failed due to data authentication failure. + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidParseGroupRlFile(void const* buf, size_t len, EpidCaCertificate const* cert, GroupRl* rl, diff --git a/external/epid-sdk-3.0.0/epid/common/math/bignum.h b/external/epid-sdk/epid/common/math/bignum.h similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/math/bignum.h rename to external/epid-sdk/epid/common/math/bignum.h index e9e9df4d..000d2a19 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/bignum.h +++ b/external/epid-sdk/epid/common/math/bignum.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ #include #include -#include "epid/common/stdtypes.h" #include "epid/common/errors.h" +#include "epid/common/stdtypes.h" #include "epid/common/types.h" /// Big number operations @@ -84,7 +84,7 @@ void DeleteBigNum(BigNum** bignum); \returns ::EpidStatus */ -EpidStatus ReadBigNum(void const* bn_str, size_t strlen, BigNum* bn); +EpidStatus ReadBigNum(ConstOctStr bn_str, size_t strlen, BigNum* bn); /// Serializes a BigNum to a string. /*! @@ -97,7 +97,7 @@ EpidStatus ReadBigNum(void const* bn_str, size_t strlen, BigNum* bn); \returns ::EpidStatus */ -EpidStatus WriteBigNum(BigNum const* bn, size_t strlen, void* bn_str); +EpidStatus WriteBigNum(BigNum const* bn, size_t strlen, OctStr bn_str); /// Adds two BigNum values. /*! diff --git a/external/epid-sdk-3.0.0/epid/common/math/ecdsa.h b/external/epid-sdk/epid/common/math/ecdsa.h similarity index 95% rename from external/epid-sdk-3.0.0/epid/common/math/ecdsa.h rename to external/epid-sdk/epid/common/math/ecdsa.h index faeca4db..92567f76 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/ecdsa.h +++ b/external/epid-sdk/epid/common/math/ecdsa.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,9 +24,9 @@ #include +#include "epid/common/bitsupplier.h" #include "epid/common/errors.h" #include "epid/common/types.h" -#include "epid/common/bitsupplier.h" /// Elliptic Curve Digital Signature Algorithm Primitives /*! @@ -69,7 +69,7 @@ \see EcdsaSignBuffer */ -EpidStatus EcdsaVerifyBuffer(void const* buf, size_t buf_len, +EpidStatus EcdsaVerifyBuffer(ConstOctStr buf, size_t buf_len, EcdsaPublicKey const* pubkey, EcdsaSignature const* sig); @@ -103,7 +103,7 @@ EpidStatus EcdsaVerifyBuffer(void const* buf, size_t buf_len, \see EcdsaSignBuffer */ -EpidStatus EcdsaSignBuffer(void const* buf, size_t buf_len, +EpidStatus EcdsaSignBuffer(ConstOctStr buf, size_t buf_len, EcdsaPrivateKey const* privkey, BitSupplier rnd_func, void* rnd_param, EcdsaSignature* sig); diff --git a/external/epid-sdk-3.0.0/epid/common/math/ecgroup.h b/external/epid-sdk/epid/common/math/ecgroup.h similarity index 93% rename from external/epid-sdk-3.0.0/epid/common/math/ecgroup.h rename to external/epid-sdk/epid/common/math/ecgroup.h index 3f21d881..85e90b92 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/ecgroup.h +++ b/external/epid-sdk/epid/common/math/ecgroup.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ #ifndef EPID_COMMON_MATH_ECGROUP_H_ #define EPID_COMMON_MATH_ECGROUP_H_ -#include "epid/common/stdtypes.h" #include "epid/common/errors.h" #include "epid/common/math/bignum.h" #include "epid/common/math/finitefield.h" +#include "epid/common/stdtypes.h" #include "epid/common/types.h" /// Elliptic curve group operations @@ -72,6 +72,9 @@ typedef struct EcGroup EcGroup; \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ff exists + for the entire lifetime of the new EcGroup. + \see DeleteEcGroup */ EpidStatus NewEcGroup(FiniteField const* ff, FfElement const* a, @@ -106,6 +109,9 @@ typedef struct EcPoint EcPoint; \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that g exists + for the entire lifetime of the new EcPoint. + \see NewEcGroup \see DeleteEcPoint */ @@ -138,7 +144,7 @@ void DeleteEcPoint(EcPoint** p); \see NewEcPoint */ -EpidStatus ReadEcPoint(EcGroup* g, void const* p_str, size_t strlen, +EpidStatus ReadEcPoint(EcGroup* g, ConstOctStr p_str, size_t strlen, EcPoint* p); /// Serializes an EcPoint to a string. @@ -156,7 +162,7 @@ EpidStatus ReadEcPoint(EcGroup* g, void const* p_str, size_t strlen, \see NewEcPoint */ -EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, +EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, OctStr p_str, size_t strlen); /// Multiplies two elements in an elliptic curve group. @@ -355,7 +361,7 @@ EpidStatus EcGetRandom(EcGroup* g, BitSupplier rnd_func, void* rnd_func_param, \see NewEcPoint */ -EpidStatus EcInGroup(EcGroup* g, void const* p_str, size_t strlen, +EpidStatus EcInGroup(EcGroup* g, ConstOctStr p_str, size_t strlen, bool* in_group); /// Hashes an arbitrary message to an Intel(R) EPID 1.1 element in an elliptic @@ -375,7 +381,7 @@ The hashed value. \see NewEcGroup \see NewEcPoint */ -EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, +EpidStatus Epid11EcHash(EcGroup* g, ConstOctStr msg, size_t msg_len, EcPoint* r); /// Hashes an arbitrary message to an element in an elliptic curve group. @@ -390,14 +396,16 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, The hash algorithm. \param[out] r The hashed value. + \param[out] iterations + The number of hash iterations needed to find a valid hash. Can be NULL. \returns ::EpidStatus \see NewEcGroup \see NewEcPoint */ -EpidStatus EcHash(EcGroup* g, void const* msg, size_t msg_len, HashAlg hash_alg, - EcPoint* r); +EpidStatus EcHash(EcGroup* g, ConstOctStr msg, size_t msg_len, HashAlg hash_alg, + EcPoint* r, uint32_t* iterations); /// Sets an EcPoint variable to a point on a curve. /*! diff --git a/external/epid-sdk-3.0.0/epid/common/math/finitefield.h b/external/epid-sdk/epid/common/math/finitefield.h similarity index 95% rename from external/epid-sdk-3.0.0/epid/common/math/finitefield.h rename to external/epid-sdk/epid/common/math/finitefield.h index 3754ef31..6a8d5a22 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/finitefield.h +++ b/external/epid-sdk/epid/common/math/finitefield.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ #ifndef EPID_COMMON_MATH_FINITEFIELD_H_ #define EPID_COMMON_MATH_FINITEFIELD_H_ -#include "epid/common/stdtypes.h" #include "epid/common/bitsupplier.h" #include "epid/common/errors.h" #include "epid/common/math/bignum.h" +#include "epid/common/stdtypes.h" #include "epid/common/types.h" /// Finite field operations @@ -86,6 +86,9 @@ EpidStatus NewFiniteField(BigNumStr const* prime, FiniteField** ff); \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ground_field + exists for the entire lifetime of the new FiniteField. + \see DeleteFiniteField */ EpidStatus NewFiniteFieldViaBinomalExtension(FiniteField const* ground_field, @@ -112,6 +115,9 @@ EpidStatus NewFiniteFieldViaBinomalExtension(FiniteField const* ground_field, \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ground_field + exists for the entire lifetime of the new FiniteField. + \see DeleteFiniteField */ EpidStatus NewFiniteFieldViaPolynomialExtension(FiniteField const* ground_field, @@ -143,6 +149,9 @@ The Newly constructed finite field element. \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ff + exists for the entire lifetime of the new FfElement. + \see NewFiniteField \see DeleteFfElement */ @@ -175,7 +184,7 @@ void DeleteFfElement(FfElement** ff_elem); \see NewFfElement \see WriteFfElement */ -EpidStatus ReadFfElement(FiniteField* ff, void const* ff_elem_str, +EpidStatus ReadFfElement(FiniteField* ff, ConstOctStr ff_elem_str, size_t strlen, FfElement* ff_elem); /// Initializes an existing FfElement from a BigNum. @@ -213,7 +222,7 @@ EpidStatus InitFfElementFromBn(FiniteField* ff, BigNum* bn, FfElement* ff_elem); \see GtElemStr */ EpidStatus WriteFfElement(FiniteField* ff, FfElement const* ff_elem, - void* ff_elem_str, size_t strlen); + OctStr ff_elem_str, size_t strlen); /// Calculates the additive inverse of a finite field element. /*! @@ -454,7 +463,7 @@ EpidStatus FfIsEqual(FiniteField* ff, FfElement const* a, FfElement const* b, \see NewFiniteField \see NewFfElement */ -EpidStatus FfHash(FiniteField* ff, void const* msg, size_t msg_len, +EpidStatus FfHash(FiniteField* ff, ConstOctStr msg, size_t msg_len, HashAlg hash_alg, FfElement* r); /// Generate random finite field element. diff --git a/external/epid-sdk-3.0.0/epid/common/math/hash.h b/external/epid-sdk/epid/common/math/hash.h similarity index 97% rename from external/epid-sdk-3.0.0/epid/common/math/hash.h rename to external/epid-sdk/epid/common/math/hash.h index 30e8e200..014f6a54 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/hash.h +++ b/external/epid-sdk/epid/common/math/hash.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ #ifndef EPID_COMMON_MATH_HASH_H_ #define EPID_COMMON_MATH_HASH_H_ +#include // for CHAR_BIT #include #include -#include // for CHAR_BIT #include "epid/common/errors.h" /// Hash primitives diff --git a/external/epid-sdk-3.0.0/epid/common/math/pairing.h b/external/epid-sdk/epid/common/math/pairing.h similarity index 90% rename from external/epid-sdk-3.0.0/epid/common/math/pairing.h rename to external/epid-sdk/epid/common/math/pairing.h index 5aab91af..ff41a766 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/pairing.h +++ b/external/epid-sdk/epid/common/math/pairing.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ #define EPID_COMMON_MATH_PAIRING_H_ #include "epid/common/errors.h" -#include "epid/common/types.h" -#include "epid/common/math/finitefield.h" #include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/types.h" /// Pairing operations /*! @@ -62,6 +62,9 @@ typedef struct PairingState PairingState; \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ga, gb, and + ff exist for the entire lifetime of the new PairingState. + \see DeletePairingState */ EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb, @@ -83,17 +86,17 @@ void DeletePairingState(PairingState** ps); /*! \param[in] ps The pairing state. - \param[out] d - The result of the pairing. Will be in ff used to create the pairing state. \param[in] a The first value to pair. Must be in ga used to create ps. \param[in] b The second value to pair. Must be in gb used to create ps + \param[out] d + The result of the pairing. Will be in ff used to create the pairing state. \returns ::EpidStatus */ -EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, - EcPoint const* b); +EpidStatus Pairing(PairingState* ps, EcPoint const* a, EcPoint const* b, + FfElement* d); /*! @} diff --git a/external/epid-sdk-3.0.0/epid/common/math/printutils.h b/external/epid-sdk/epid/common/math/printutils.h similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/math/printutils.h rename to external/epid-sdk/epid/common/math/printutils.h index 6f21b09e..9c2efd43 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/printutils.h +++ b/external/epid-sdk/epid/common/math/printutils.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ #ifndef EPID_COMMON_MATH_PRINTUTILS_H_ #define EPID_COMMON_MATH_PRINTUTILS_H_ -#include "epid/common/types.h" #include "epid/common/math/bignum.h" -#include "epid/common/math/finitefield.h" #include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/types.h" /// Debug print routines /*! diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/bignum-internal.h b/external/epid-sdk/epid/common/math/src/bignum-internal.h similarity index 74% rename from external/epid-sdk-3.0.0/epid/common/math/src/bignum-internal.h rename to external/epid-sdk/epid/common/math/src/bignum-internal.h index e30b6f83..fcddee99 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/bignum-internal.h +++ b/external/epid-sdk/epid/common/math/src/bignum-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,9 +22,17 @@ #ifndef EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_ #define EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_ -#include "ext/ipp/include/ippcpepid.h" -#include "epid/common/stdtypes.h" #include "epid/common/errors.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" +#include "ext/ipp/include/ippcp.h" + +typedef void* BNU; +typedef void const* ConstBNU; +typedef Ipp32u* IppBNU; +typedef Ipp32u const* ConstIppBNU; +typedef Ipp8u* IppOctStr; +typedef Ipp8u const* ConstIppOctStr; /// Big Number struct BigNum { @@ -50,7 +58,7 @@ Length of octet string, should be multiple of 4 \returns length of big number unsigned in uint32_t chunks \returns -1 in case of any error */ -int OctStr2Bnu(uint32_t* bnu_ptr, void const* octstr_ptr, int octstr_len); +int OctStr2Bnu(BNU bnu_ptr, ConstOctStr octstr_ptr, int octstr_len); /// Get octet string size in bits /*! @@ -61,23 +69,6 @@ Length of octet string in bytes. \returns bit size of big number value from octet string */ -size_t OctStrBitSize(uint8_t const* octstr_ptr, size_t octstr_len); - -/// Initializes a BigNum from a BNU. -/*! - \param[in] bnu - The desired value as a bnu. - \param[in] bnu_len - The size of bnu_str in 32 bit words. - \param[out] bn - The target BigNum. - - \note A BNU is a big integer represented as array of 4 byte words written in - little endian order - - \returns ::EpidStatus -*/ -EpidStatus InitBigNumFromBnu(uint32_t const* bnu, size_t bnu_len, - struct BigNum* bn); +size_t OctStrBitSize(ConstOctStr octstr_ptr, size_t octstr_len); #endif // EPID_COMMON_MATH_SRC_BIGNUM_INTERNAL_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/bignum.c b/external/epid-sdk/epid/common/math/src/bignum.c similarity index 84% rename from external/epid-sdk-3.0.0/epid/common/math/src/bignum.c rename to external/epid-sdk/epid/common/math/src/bignum.c index 5ab4fdb1..4ea62d70 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/bignum.c +++ b/external/epid-sdk/epid/common/math/src/bignum.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -92,7 +92,7 @@ void DeleteBigNum(BigNum** bignum) { } } -EpidStatus ReadBigNum(void const* bn_str, size_t strlen, BigNum* bn) { +EpidStatus ReadBigNum(ConstOctStr bn_str, size_t strlen, BigNum* bn) { IppStatus sts; size_t i; bool is_zero = true; @@ -139,52 +139,14 @@ EpidStatus ReadBigNum(void const* bn_str, size_t strlen, BigNum* bn) { return kEpidNoErr; } -/// Initializes a BigNum from a BNU. -/*! - \param[in] bnu - The desired value as a bnu. - \param[in] bnu_len - The size of bnu_str in 32 bit words. - \param[out] bn - The target BigNum. - - \returns ::EpidStatus - - \note A BNU is a big integer represented as array of 4 byte words written in - little endian order - - \note This is re-documented here because doxygen does not pull in the - internal headers -*/ -EpidStatus InitBigNumFromBnu(uint32_t const* bnu, size_t bnu_len, - struct BigNum* bn) { - IppStatus sts; - if (!bn || !bnu) return kEpidBadArgErr; - - if (!bn->ipp_bn) return kEpidBadArgErr; - - if (INT_MAX < bnu_len || bnu_len <= 0) return kEpidBadArgErr; - - sts = ippsSet_BN(IppsBigNumPOS, (int)bnu_len, bnu, bn->ipp_bn); - if (sts != ippStsNoErr) { - if (ippStsContextMatchErr == sts || ippStsSizeErr == sts || - ippStsLengthErr == sts || ippStsOutOfRangeErr == sts) - return kEpidBadArgErr; - else - return kEpidMathErr; - } - - return kEpidNoErr; -} - -EpidStatus WriteBigNum(BigNum const* bn, size_t strlen, void* bn_str) { +EpidStatus WriteBigNum(BigNum const* bn, size_t strlen, OctStr bn_str) { IppStatus sts; int ipp_strlen = (int)strlen; if (!bn || !bn_str) return kEpidBadArgErr; if (!bn->ipp_bn) return kEpidBadArgErr; - sts = ippsGetOctString_BN((Ipp8u*)bn_str, ipp_strlen, bn->ipp_bn); + sts = ippsGetOctString_BN((OctStr)bn_str, ipp_strlen, bn->ipp_bn); if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts || ippStsRangeErr == sts || ippStsLengthErr == sts) @@ -197,36 +159,37 @@ EpidStatus WriteBigNum(BigNum const* bn, size_t strlen, void* bn_str) { } /// convert octet string into "big number unsigned" representation -int OctStr2Bnu(uint32_t* bnu_ptr, void const* octstr_ptr, int octstr_len) { +int OctStr2Bnu(BNU bnu_ptr, ConstOctStr octstr_ptr, int octstr_len) { int bnusize = 0; - uint8_t const* byte_str = (uint8_t const*)octstr_ptr; + ConstIppOctStr byte_str = (ConstIppOctStr)octstr_ptr; + IppBNU bnu = (IppBNU)bnu_ptr; if (!bnu_ptr || !octstr_ptr) { return -1; } if (octstr_len < 4 || octstr_len % 4 != 0) return -1; - *bnu_ptr = 0; + *bnu = 0; /* start from the end of string */ for (; octstr_len >= 4; bnusize++, octstr_len -= 4) { /* pack 4 bytes into single Ipp32u value*/ - *bnu_ptr++ = (byte_str[octstr_len - 4] << (8 * 3)) + - (byte_str[octstr_len - 3] << (8 * 2)) + - (byte_str[octstr_len - 2] << (8 * 1)) + - byte_str[octstr_len - 1]; + *bnu++ = (byte_str[octstr_len - 4] << (8 * 3)) + + (byte_str[octstr_len - 3] << (8 * 2)) + + (byte_str[octstr_len - 2] << (8 * 1)) + byte_str[octstr_len - 1]; } return bnusize ? bnusize : -1; } /// Get octet string size in bits -size_t OctStrBitSize(uint8_t const* octstr_ptr, size_t octstr_len) { +size_t OctStrBitSize(ConstOctStr octstr_ptr, size_t octstr_len) { uint8_t byte; size_t bitsize = 0; + ConstIppOctStr octstr = (ConstIppOctStr)octstr_ptr; // find highest non zero byte size_t i = 0; - while (i < octstr_len && !octstr_ptr[i]) i++; + while (i < octstr_len && !octstr[i]) i++; if (i == octstr_len) return 0; - byte = octstr_ptr[i]; + byte = octstr[i]; // refine bit size if (0 == byte) return 0; @@ -358,7 +321,7 @@ EpidStatus BigNumIsEven(BigNum const* a, bool* is_even) { IppStatus sts = ippStsNoErr; IppsBigNumSGN sgn; int bit_size; - Ipp32u* data; + IppBNU data; // Check required parameters if (!a || !is_even) { return kEpidBadArgErr; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_sign.c b/external/epid-sdk/epid/common/math/src/ecdsa_sign.c similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_sign.c rename to external/epid-sdk/epid/common/math/src/ecdsa_sign.c index fffaab07..2225ea53 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_sign.c +++ b/external/epid-sdk/epid/common/math/src/ecdsa_sign.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ * \brief EcdsaSignBuffer implementation. */ -#include "epid/common/math/ecdsa.h" #include "epid/common/math/bignum.h" -#include "epid/common/math/src/bignum-internal.h" +#include "epid/common/math/ecdsa.h" #include "epid/common/math/ecgroup.h" +#include "epid/common/math/src/bignum-internal.h" #include "epid/common/src/memory.h" #include "ext/ipp/include/ippcp.h" /// The number of attempts to generate ephemeral key pair #define EPHKEYGEN_WATCHDOG (10) -EpidStatus EcdsaSignBuffer(void const* buf, size_t buf_len, +EpidStatus EcdsaSignBuffer(ConstOctStr buf, size_t buf_len, EcdsaPrivateKey const* privkey, BitSupplier rnd_func, void* rnd_param, EcdsaSignature* sig) { EpidStatus result = kEpidMathErr; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_verify.c b/external/epid-sdk/epid/common/math/src/ecdsa_verify.c similarity index 94% rename from external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_verify.c rename to external/epid-sdk/epid/common/math/src/ecdsa_verify.c index cf3c7c47..3bebfb9a 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/ecdsa_verify.c +++ b/external/epid-sdk/epid/common/math/src/ecdsa_verify.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ static EpidStatus ReadCurvePoint(IppsECCPState* ec, EcdsaPublicKey const* pubkey, IppsECCPPointState* p); -static EpidStatus CalcHashBn(void const* buf, size_t buf_len, +static EpidStatus CalcHashBn(ConstOctStr buf, size_t buf_len, BigNum* bn_digest); static void DeleteCurvePoint(IppsECCPPointState** p); @@ -55,7 +55,7 @@ static void DeleteCurvePoint(IppsECCPPointState** p); static EpidStatus ValidateSignature(BigNum const* bn_sig_x, BigNum const* bn_sig_y); -EpidStatus EcdsaVerifyBuffer(void const* buf, size_t buf_len, +EpidStatus EcdsaVerifyBuffer(ConstOctStr buf, size_t buf_len, EcdsaPublicKey const* pubkey, EcdsaSignature const* sig) { EpidStatus result = kEpidErr; @@ -104,7 +104,12 @@ EpidStatus EcdsaVerifyBuffer(void const* buf, size_t buf_len, epid_status = NewCurvePoint(ec_state, &ecp_pubkey); if (kEpidNoErr != epid_status) break; epid_status = ReadCurvePoint(ec_state, pubkey, ecp_pubkey); - if (kEpidNoErr != epid_status) break; + if (kEpidBadArgErr == epid_status) { + result = kEpidBadArgErr; + break; + } else if (kEpidNoErr != epid_status) { + break; + } // check for invalid pubkey ipp_status = ippsECCPCheckPoint(ecp_pubkey, &ec_result, ec_state); @@ -249,7 +254,13 @@ static EpidStatus ReadCurvePoint(IppsECCPState* ec, ipp_status = ippsECCPSetPoint(bn_pubkey_x->ipp_bn, bn_pubkey_y->ipp_bn, p, ec); - BREAK_ON_IPP_ERROR(ipp_status, result); + if (ipp_status == ippStsOutOfRangeErr) { + result = kEpidBadArgErr; + break; + } else if (ipp_status != ippStsNoErr) { + result = kEpidMathErr; + break; + } } while (0); DeleteBigNum(&bn_pubkey_x); @@ -258,7 +269,7 @@ static EpidStatus ReadCurvePoint(IppsECCPState* ec, return result; } -static EpidStatus CalcHashBn(void const* buf, size_t buf_len, +static EpidStatus CalcHashBn(ConstOctStr buf, size_t buf_len, BigNum* bn_digest) { EpidStatus result = kEpidErr; BigNum* bn_ec_order = NULL; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/ecgroup-internal.h b/external/epid-sdk/epid/common/math/src/ecgroup-internal.h similarity index 79% rename from external/epid-sdk-3.0.0/epid/common/math/src/ecgroup-internal.h rename to external/epid-sdk/epid/common/math/src/ecgroup-internal.h index 3e998671..55dbab4e 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/ecgroup-internal.h +++ b/external/epid-sdk/epid/common/math/src/ecgroup-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,23 +22,24 @@ #ifndef EPID_COMMON_MATH_SRC_ECGROUP_INTERNAL_H_ #define EPID_COMMON_MATH_SRC_ECGROUP_INTERNAL_H_ -#include "ext/ipp/include/ippcpepid.h" +#include "epid/common/math/src/finitefield-internal.h" +#include "ext/ipp/include/ippcp.h" /// Elpitic Curve Group struct EcGroup { /// Internal implementation of elliptic curve group IppsGFpECState* ipp_ec; /// Scratch buffer for operations over elliptic curve group - Ipp8u* scratch_buffer; - /// Information about finite field of elliptic curve group created - IppsGFpInfo info; + OctStr scratch_buffer; + /// Information about finite field of elliptic curve group + struct FiniteField* ff; }; /// Elpitic Curve Point struct EcPoint { /// Internal implementation of elliptic curve point IppsGFpECPoint* ipp_ec_pt; - /// Information about finite field element of elliptic curve group created - IppsGFpInfo info; + /// length of the finite field element of elliptic curve group + int element_len; }; #endif // EPID_COMMON_MATH_SRC_ECGROUP_INTERNAL_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/ecgroup.c b/external/epid-sdk/epid/common/math/src/ecgroup.c similarity index 75% rename from external/epid-sdk-3.0.0/epid/common/math/src/ecgroup.c rename to external/epid-sdk/epid/common/math/src/ecgroup.c index 2629bd62..ba6b5c36 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/ecgroup.c +++ b/external/epid-sdk/epid/common/math/src/ecgroup.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ * \brief Elliptic curve group implementation. */ +#include "epid/common/math/ecgroup.h" #include +#include "epid/common/1.1/types.h" +#include "epid/common/math/hash.h" #include "epid/common/math/src/bignum-internal.h" #include "epid/common/math/src/ecgroup-internal.h" -#include "epid/common/math/ecgroup.h" #include "epid/common/math/src/finitefield-internal.h" -#include "epid/common/math/hash.h" -#include "epid/common/src/memory.h" #include "epid/common/src/endian_convert.h" +#include "epid/common/src/memory.h" #include "ext/ipp/include/ippcp.h" -#include "ext/ipp/include/ippcpepid.h" -#include "epid/common/1.1/types.h" +#include "ext/ipp/include/ippcpdefs.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ @@ -55,14 +55,14 @@ EpidStatus NewEcGroup(FiniteField const* ff, FfElement const* a, BigNum const* cofactor, EcGroup** g) { EpidStatus result = kEpidNoErr; IppsGFpECState* state = NULL; - Ipp8u* scratch_buffer = NULL; + OctStr scratch_buffer = NULL; EcGroup* grp = NULL; do { IppStatus ipp_status; int stateSize = 0; int scratch_size = 0; - Ipp32u* order_bnu; - Ipp32u* cofactor_bnu; + IppBNU order_bnu; + IppBNU cofactor_bnu; int order_bnu_size; int cofactor_bnu_size; IppsBigNumSGN sgn; @@ -71,16 +71,10 @@ EpidStatus NewEcGroup(FiniteField const* ff, FfElement const* a, result = kEpidBadArgErr; break; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != b->info.elementLen || - ff->info.elementLen != x->info.elementLen || - ff->info.elementLen != y->info.elementLen || - a->info.elementLen != b->info.elementLen || - a->info.elementLen != x->info.elementLen || - a->info.elementLen != y->info.elementLen || - b->info.elementLen != x->info.elementLen || - b->info.elementLen != y->info.elementLen || - x->info.elementLen != y->info.elementLen) { + if (ff->element_len != a->element_len || + ff->element_len != b->element_len || + ff->element_len != x->element_len || + ff->element_len != y->element_len) { result = kEpidBadArgErr; break; } @@ -124,9 +118,13 @@ EpidStatus NewEcGroup(FiniteField const* ff, FfElement const* a, } ipp_status = - ippsGFpECInit(a->ipp_ff_elem, b->ipp_ff_elem, x->ipp_ff_elem, - y->ipp_ff_elem, order_bnu, order_bnu_size, cofactor_bnu, - cofactor_bnu_size, ff->ipp_ff, state); + ippsGFpECInit(ff->ipp_ff, a->ipp_ff_elem, b->ipp_ff_elem, state); + if (ippStsNoErr != ipp_status) { + result = kEpidMathErr; + break; + } + ipp_status = ippsGFpECSetSubgroup(x->ipp_ff_elem, y->ipp_ff_elem, + order->ipp_bn, cofactor->ipp_bn, state); if (ippStsNoErr != ipp_status) { result = kEpidMathErr; break; @@ -136,21 +134,23 @@ EpidStatus NewEcGroup(FiniteField const* ff, FfElement const* a, ipp_status = ippsGFpECScratchBufferSize(1, state, &scratch_size); // check return codes if (ippStsNoErr != ipp_status) { - if (ippStsContextMatchErr == ipp_status) - result = kEpidBadArgErr; - else - result = kEpidMathErr; + // ippStsContextMatchErr not possible since we create the state + // in this function + result = kEpidMathErr; break; } // allocate scratch buffer - scratch_buffer = (Ipp8u*)SAFE_ALLOC(scratch_size); + scratch_buffer = (OctStr)SAFE_ALLOC(scratch_size); if (!scratch_buffer) { result = kEpidMemAllocErr; break; } - - grp->info = ff->info; + // Warning: once assigned ground field must never be modified. this was not + // made const + // to allow the FiniteField structure to be used in context when we want to + // modify the parameters. + grp->ff = (FiniteField*)ff; grp->ipp_ec = state; grp->scratch_buffer = scratch_buffer; *g = grp; @@ -225,7 +225,11 @@ EpidStatus NewEcPoint(EcGroup const* g, EcPoint** p) { result = kEpidMemAllocErr; break; } - ecpoint->info = g->info; + if (!g->ff) { + result = kEpidBadArgErr; + break; + } + ecpoint->element_len = g->ff->element_len; ecpoint->ipp_ec_pt = ec_pt_context; *p = ecpoint; result = kEpidNoErr; @@ -271,21 +275,21 @@ void DeleteEcPoint(EcPoint** p) { \see NewEcPoint */ -EpidStatus eccontains(EcGroup* g, void const* p_str, size_t strlen, EcPoint* p, +EpidStatus eccontains(EcGroup* g, ConstOctStr p_str, size_t strlen, EcPoint* p, bool* in_group) { EpidStatus result = kEpidErr; IppStatus sts = ippStsNoErr; - FiniteField fp; + FiniteField* fp = NULL; FfElement* fp_x = NULL; FfElement* fp_y = NULL; - Ipp8u const* byte_str = (Ipp8u const*)p_str; + ConstIppOctStr byte_str = (ConstIppOctStr)p_str; IppECResult ec_result = ippECPointIsNotValid; int ipp_half_strlen = (int)strlen / 2; if (!g || !p_str || !p || !in_group) { return kEpidBadArgErr; } - if (!g->ipp_ec || !p->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !p->ipp_ec_pt) { return kEpidBadArgErr; } @@ -317,51 +321,29 @@ EpidStatus eccontains(EcGroup* g, void const* p_str, size_t strlen, EcPoint* p, break; } // get finite field - sts = ippsGFpECGet(g->ipp_ec, (const IppsGFpState**)&(fp.ipp_ff), 0, 0, 0, - 0, 0, 0, 0, 0); - // check return codes - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts) - result = kEpidBadArgErr; - else - result = kEpidMathErr; - break; - } - + fp = g->ff; // create element X - result = NewFfElement(&fp, &fp_x); + result = NewFfElement(fp, &fp_x); if (kEpidNoErr != result) { break; } // create element Y - result = NewFfElement(&fp, &fp_y); + result = NewFfElement(fp, &fp_y); if (kEpidNoErr != result) { break; } // set element X data - sts = ippsGFpSetElementOctString(byte_str, ipp_half_strlen, - fp_x->ipp_ff_elem, fp.ipp_ff); - // check return codes - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts || ippStsOutOfRangeErr == sts) - result = kEpidBadArgErr; - else - result = kEpidMathErr; + result = SetFfElementOctString(byte_str, ipp_half_strlen, fp_x, fp); + if (kEpidNoErr != result) { break; } // set element Y data - sts = - ippsGFpSetElementOctString(byte_str + ipp_half_strlen, ipp_half_strlen, - fp_y->ipp_ff_elem, fp.ipp_ff); - // check return codes - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts || ippStsOutOfRangeErr == sts) - result = kEpidBadArgErr; - else - result = kEpidMathErr; + result = SetFfElementOctString(byte_str + ipp_half_strlen, ipp_half_strlen, + fp_y, fp); + if (kEpidNoErr != result) { break; } @@ -378,8 +360,7 @@ EpidStatus eccontains(EcGroup* g, void const* p_str, size_t strlen, EcPoint* p, } // verify the point is actually on the curve - sts = ippsGFpECTstPoint(p->ipp_ec_pt, &ec_result, g->ipp_ec, - g->scratch_buffer); + sts = ippsGFpECTstPoint(p->ipp_ec_pt, &ec_result, g->ipp_ec); // check return codes if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts) @@ -388,7 +369,6 @@ EpidStatus eccontains(EcGroup* g, void const* p_str, size_t strlen, EcPoint* p, result = kEpidMathErr; break; } - *in_group = (ippECValid == ec_result); result = kEpidNoErr; } while (0); @@ -398,7 +378,7 @@ EpidStatus eccontains(EcGroup* g, void const* p_str, size_t strlen, EcPoint* p, return result; } -EpidStatus ReadEcPoint(EcGroup* g, void const* p_str, size_t strlen, +EpidStatus ReadEcPoint(EcGroup* g, ConstOctStr p_str, size_t strlen, EcPoint* p) { EpidStatus result; bool in_group = false; @@ -426,20 +406,20 @@ EpidStatus ReadEcPoint(EcGroup* g, void const* p_str, size_t strlen, return kEpidNoErr; } -EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, +EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, OctStr p_str, size_t strlen) { EpidStatus result = kEpidErr; - FiniteField fp; + FiniteField* fp = NULL; FfElement* fp_x = NULL; FfElement* fp_y = NULL; - Ipp8u* byte_str = (Ipp8u*)p_str; + IppOctStr byte_str = (IppOctStr)p_str; IppStatus sts = ippStsNoErr; int ipp_half_strlen = (int)strlen / 2; if (!g || !p || !p_str) { return kEpidBadArgErr; } - if (!g->ipp_ec || !p->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !p->ipp_ec_pt) { return kEpidBadArgErr; } if (INT_MAX < strlen) { @@ -452,25 +432,16 @@ EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, do { // get finite field - sts = ippsGFpECGet(g->ipp_ec, (const IppsGFpState**)&(fp.ipp_ff), 0, 0, 0, - 0, 0, 0, 0, 0); - // check return codes - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts) - result = kEpidBadArgErr; - else - result = kEpidMathErr; - break; - } + fp = g->ff; // create element X - result = NewFfElement(&fp, &fp_x); + result = NewFfElement(fp, &fp_x); if (kEpidNoErr != result) { break; } // create element Y - result = NewFfElement(&fp, &fp_y); + result = NewFfElement(fp, &fp_y); if (kEpidNoErr != result) { break; } @@ -483,7 +454,7 @@ EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, if (ippStsPointAtInfinity == sts) { memset(p_str, 0, strlen); result = kEpidNoErr; - } else if (ippStsContextMatchErr == sts) { + } else if (ippStsContextMatchErr == sts || ippStsOutOfRangeErr == sts) { result = kEpidBadArgErr; } else { result = kEpidMathErr; @@ -493,7 +464,7 @@ EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, // get element X data sts = ippsGFpGetElementOctString(fp_x->ipp_ff_elem, byte_str, - ipp_half_strlen, fp.ipp_ff); + ipp_half_strlen, fp->ipp_ff); // check return codes if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts) @@ -506,7 +477,7 @@ EpidStatus WriteEcPoint(EcGroup* g, EcPoint const* p, void* p_str, // get element Y data sts = ippsGFpGetElementOctString(fp_y->ipp_ff_elem, byte_str + ipp_half_strlen, - ipp_half_strlen, fp.ipp_ff); + ipp_half_strlen, fp->ipp_ff); // check return codes if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts) @@ -528,15 +499,13 @@ EpidStatus EcMul(EcGroup* g, EcPoint const* a, EcPoint const* b, EcPoint* r) { IppStatus sts = ippStsNoErr; if (!g || !a || !b || !r) { return kEpidBadArgErr; - } else if (!g->ipp_ec || !a->ipp_ec_pt || !b->ipp_ec_pt || !r->ipp_ec_pt) { + } else if (!g->ff || !g->ipp_ec || !a->ipp_ec_pt || !b->ipp_ec_pt || + !r->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != a->info.elementLen || - g->info.elementLen != b->info.elementLen || - g->info.elementLen != r->info.elementLen || - a->info.elementLen != b->info.elementLen || - a->info.elementLen != r->info.elementLen || - b->info.elementLen != r->info.elementLen) { + if (g->ff->element_len != a->element_len || + g->ff->element_len != b->element_len || + g->ff->element_len != r->element_len) { return kEpidBadArgErr; } // Multiplies elliptic curve points @@ -561,13 +530,12 @@ EpidStatus EcExp(EcGroup* g, EcPoint const* a, BigNumStr const* b, EcPoint* r) { if (!g || !a || !b || !r) { result = kEpidBadArgErr; break; - } else if (!g->ipp_ec || !a->ipp_ec_pt || !r->ipp_ec_pt) { + } else if (!g->ff || !g->ipp_ec || !a->ipp_ec_pt || !r->ipp_ec_pt) { result = kEpidBadArgErr; break; } - if (g->info.elementLen != a->info.elementLen || - g->info.elementLen != r->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (g->ff->element_len != a->element_len || + g->ff->element_len != r->element_len) { result = kEpidBadArgErr; break; } @@ -577,7 +545,6 @@ EpidStatus EcExp(EcGroup* g, EcPoint const* a, BigNumStr const* b, EcPoint* r) { if (kEpidNoErr != result) break; result = ReadBigNum(b, sizeof(*b), b_bn); if (kEpidNoErr != result) break; - sts = ippsGFpECMulPoint(a->ipp_ec_pt, b_bn->ipp_bn, r->ipp_ec_pt, g->ipp_ec, g->scratch_buffer); if (ippStsNoErr != sts) { @@ -606,41 +573,35 @@ EpidStatus EcMultiExp(EcGroup* g, EcPoint const** a, BigNumStr const** b, EpidStatus result = kEpidErr; BigNum* b_bn = NULL; EcPoint* ecp_t = NULL; - int i = 0; - int ii = 0; - int ipp_m = 0; + size_t i = 0; + size_t ii = 0; if (!g || !a || !b || !r) { return kEpidBadArgErr; } - if (!g->ipp_ec || m <= 0) { + if (!g->ff || !g->ipp_ec || m <= 0) { return kEpidBadArgErr; } - // because we use ipp function with number of items parameter - // defined as "int" we need to verify that input length - // do not exceed INT_MAX to avoid overflow - if (m > INT_MAX) { - return kEpidBadArgErr; - } - ipp_m = (int)m; + // Verify that ec points are not NULL - for (i = 0; i < ipp_m; i++) { + for (i = 0; i < m; i++) { if (!a[i]) { return kEpidBadArgErr; } if (!a[i]->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != a[i]->info.elementLen) { + if (g->ff->element_len != a[i]->element_len) { return kEpidBadArgErr; } - for (ii = i + 1; ii < ipp_m; ii++) { - if (a[i]->info.elementLen != a[ii]->info.elementLen) { + for (ii = 0; ii < i; ii++) { + if (a[i]->element_len != a[ii]->element_len) { return kEpidBadArgErr; } } } - if (g->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -654,11 +615,10 @@ EpidStatus EcMultiExp(EcGroup* g, EcPoint const** a, BigNumStr const** b, result = NewEcPoint(g, &ecp_t); if (kEpidNoErr != result) break; - for (i = 0; i < ipp_m; i++) { + for (i = 0; i < m; i++) { // Initialize big number element for ipp call result = ReadBigNum(b[i], sizeof(BigNumStr), b_bn); if (kEpidNoErr != result) break; - sts = ippsGFpECMulPoint(a[i]->ipp_ec_pt, b_bn->ipp_bn, ecp_t->ipp_ec_pt, g->ipp_ec, g->scratch_buffer); if (ippStsNoErr != sts) { @@ -669,7 +629,7 @@ EpidStatus EcMultiExp(EcGroup* g, EcPoint const** a, BigNumStr const** b, result = kEpidMathErr; break; } - if (1 == m) { + if (i == 0) { sts = ippsGFpECCpyPoint(ecp_t->ipp_ec_pt, r->ipp_ec_pt, g->ipp_ec); if (ippStsNoErr != sts) { result = kEpidMathErr; @@ -698,25 +658,18 @@ EpidStatus EcMultiExpBn(EcGroup* g, EcPoint const** a, BigNum const** b, size_t m, EcPoint* r) { EpidStatus result = kEpidErr; EcPoint* ecp_t = NULL; - int i = 0; - int ii = 0; - int ipp_m = 0; + size_t i = 0; + size_t ii = 0; if (!g || !a || !b || !r) { return kEpidBadArgErr; } - if (!g->ipp_ec || m <= 0) { + if (!g->ff || !g->ipp_ec || m <= 0) { return kEpidBadArgErr; } - // because we use ipp function with number of items parameter - // defined as "int" we need to verify that input length - // do not exceed INT_MAX to avoid overflow - if (m > INT_MAX) { - return kEpidBadArgErr; - } - ipp_m = (int)m; + // Verify that ec points are not NULL - for (i = 0; i < ipp_m; i++) { + for (i = 0; i < m; i++) { if (!a[i]) { return kEpidBadArgErr; } @@ -729,27 +682,28 @@ EpidStatus EcMultiExpBn(EcGroup* g, EcPoint const** a, BigNum const** b, if (!b[i]->ipp_bn) { return kEpidBadArgErr; } - if (g->info.elementLen != a[i]->info.elementLen) { + + if (g->ff->element_len != a[i]->element_len) { return kEpidBadArgErr; } - for (ii = i + 1; ii < ipp_m; ii++) { - if (a[i]->info.elementLen != a[ii]->info.elementLen) { + for (ii = 0; ii < i; ii++) { + if (a[i]->element_len != a[ii]->element_len) { return kEpidBadArgErr; } } } - if (g->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != r->element_len) { return kEpidBadArgErr; } do { IppStatus sts = ippStsNoErr; - // Create temporal EcPoint element result = NewEcPoint(g, &ecp_t); if (kEpidNoErr != result) break; - for (i = 0; i < ipp_m; i++) { + for (i = 0; i < m; i++) { sts = ippsGFpECMulPoint(a[i]->ipp_ec_pt, b[i]->ipp_bn, ecp_t->ipp_ec_pt, g->ipp_ec, g->scratch_buffer); if (ippStsNoErr != sts) { @@ -760,7 +714,7 @@ EpidStatus EcMultiExpBn(EcGroup* g, EcPoint const** a, BigNum const** b, result = kEpidMathErr; break; } - if (1 == m) { + if (i == 0) { sts = ippsGFpECCpyPoint(ecp_t->ipp_ec_pt, r->ipp_ec_pt, g->ipp_ec); if (ippStsNoErr != sts) { result = kEpidMathErr; @@ -797,15 +751,17 @@ EpidStatus EcGetRandom(EcGroup* g, BitSupplier rnd_func, void* rnd_func_param, if (!g || !rnd_func || !r) { return kEpidBadArgErr; } - if (!g->ipp_ec || !g->scratch_buffer) { - return kEpidBadArgErr; - } - if (g->info.elementLen != r->info.elementLen) { + if (!g->ff || !g->ipp_ec || !g->scratch_buffer) { return kEpidBadArgErr; } - sts = ippsGFpECSetPointRandom((IppBitSupplier)rnd_func, rnd_func_param, - r->ipp_ec_pt, g->ipp_ec, g->scratch_buffer); + if (g->ff->element_len != r->element_len) { + return kEpidBadArgErr; + } + + sts = + ippsGFpECSetPointRandom(r->ipp_ec_pt, g->ipp_ec, (IppBitSupplier)rnd_func, + rnd_func_param, g->scratch_buffer); if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts) { return kEpidBadArgErr; @@ -816,7 +772,7 @@ EpidStatus EcGetRandom(EcGroup* g, BitSupplier rnd_func, void* rnd_func_param, return kEpidNoErr; } -EpidStatus EcInGroup(EcGroup* g, void const* p_str, size_t strlen, +EpidStatus EcInGroup(EcGroup* g, ConstOctStr p_str, size_t strlen, bool* in_group) { EpidStatus result = kEpidErr; EcPoint* p = NULL; @@ -824,6 +780,9 @@ EpidStatus EcInGroup(EcGroup* g, void const* p_str, size_t strlen, if (!g || !p_str || !in_group) { return kEpidBadArgErr; } + if (!g->ff) { + return kEpidBadArgErr; + } if (0 == strlen) { return kEpidBadArgErr; } @@ -833,15 +792,15 @@ EpidStatus EcInGroup(EcGroup* g, void const* p_str, size_t strlen, return kEpidBadArgErr; } else { if (strlen == sizeof(G1ElemStr)) { - // check info.elementlen with strlen + // check finitefield.elementlen with strlen // multiply by 2 for x,y and 4 multiply to convert dword to bytes - size_t info_elementLen_in_byte = (g->info.elementLen) * 2 * 4; + size_t info_elementLen_in_byte = (g->ff->element_len) * 2 * 4; if (info_elementLen_in_byte != strlen) { *in_group = false; return kEpidBadArgErr; } // check Fq basic and ground degree - if (g->info.basicGFdegree != 1 || g->info.groundGFdegree != 1) { + if (g->ff->basic_degree != 1 || g->ff->ground_degree != 1) { *in_group = false; return kEpidBadArgErr; } @@ -849,31 +808,25 @@ EpidStatus EcInGroup(EcGroup* g, void const* p_str, size_t strlen, if (strlen == sizeof(G2ElemStr)) { // check info.elementlen with strlen // multiply by 2 for x,y and 4 multiply to convert dword to bytes - size_t info_elementLen_in_byte = (g->info.elementLen) * 2 * 4; - IppStatus sts = ippStsNoErr; - IppsGFpInfo ground_info = {0}; + size_t info_elementLen_in_byte = (g->ff->element_len) * 2 * 4; + FiniteField* ground_ff = NULL; if (info_elementLen_in_byte != strlen) { *in_group = false; return kEpidBadArgErr; } // check Fq2 basic and ground degree - if (g->info.basicGFdegree != 2 || g->info.groundGFdegree != 2) { + if (g->ff->basic_degree != 2 || g->ff->ground_degree != 2) { *in_group = false; return kEpidBadArgErr; } // check Fq basic and ground degree - sts = ippsGFpGetInfo(g->info.pGroundGF, &ground_info); - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts) { - *in_group = false; - return kEpidMathErr; - } else { - *in_group = false; - return kEpidBadArgErr; - } + ground_ff = g->ff->ground_ff; + if (ground_ff == NULL) { + *in_group = false; + return kEpidBadArgErr; } - if (ground_info.basicGFdegree != 1 || ground_info.groundGFdegree != 1) { + if (ground_ff->basic_degree != 1 || ground_ff->ground_degree != 1) { *in_group = false; return kEpidBadArgErr; } @@ -916,30 +869,30 @@ Returns the first bit and the next 336 bits of str in octet string. \returns ::EpidStatus */ -static EpidStatus SplitHashBits(void const* str, size_t str_len, +static EpidStatus SplitHashBits(ConstOctStr str, size_t str_len, uint32_t* first_bit, OctStr336* t) { // this is 336bits /8 bits per byte = 42 bytes OctStr336 next336 = {0}; size_t i = 0; + ConstIppOctStr data = (ConstIppOctStr)str; if (!str || !first_bit || !t) return kEpidBadArgErr; if (str_len < sizeof(next336) + 1) { // we need at least 337 bits! return kEpidBadArgErr; } - for (i = 0; i < sizeof(next336); i++) { // This is not overflowing since str length was assured to // be at least one byte greater than needed for 336 bits. We are // carrying in the first bit of that byte. - uint8_t carry = ((((uint8_t const*)str)[i + 1] & 0x80) >> 7); - next336.data[i] = (((((uint8_t const*)str)[i] << 1) & 0xFF) | carry) & 0xFF; + uint8_t carry = ((data[i + 1] & 0x80) >> 7); + next336.data[i] = (((data[i] << 1) & 0xFF) | carry) & 0xFF; } - *first_bit = ((((uint8_t const*)str)[0] & 0x80) >> 7); + *first_bit = ((data[0] & 0x80) >> 7); *t = next336; return kEpidNoErr; } -EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, +EpidStatus Epid11EcHash(EcGroup* g, ConstOctStr msg, size_t msg_len, EcPoint* r) { EpidStatus result = kEpidErr; @@ -962,16 +915,17 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, BigNum* t_bn = NULL; BigNum* h_bn = NULL; - FiniteField ff = {0}; + FiniteField* ff = NULL; // check parameters if ((!msg && msg_len > 0) || !r || !g) { return kEpidBadArgErr; } - if (!g->ipp_ec || !r->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !r->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -987,8 +941,6 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, uint32_t high_bit = 0; IppsGFpState* ipp_ff = NULL; - uint32_t const* h = NULL; // cofactor - int h_len = 0; int sqrt_loop_count = 2 * EPID_ECHASH_WATCHDOG; Sha256Digest message_digest[2] = {0}; @@ -1001,34 +953,30 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, break; } - sts = ippsGFpECGet(g->ipp_ec, (const IppsGFpState**)&ipp_ff, 0, 0, 0, 0, 0, - 0, &h, &h_len); + result = NewBigNum(sizeof(BigNumStr), &h_bn); + BREAK_ON_EPID_ERROR(result); + sts = ippsGFpECGet(&ipp_ff, 0, 0, g->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); - result = InitFiniteFieldFromIpp(ipp_ff, &ff); - BREAK_ON_EPID_ERROR(result); + sts = ippsGFpECGetSubgroup(&ipp_ff, 0, 0, 0, h_bn->ipp_bn, g->ipp_ec); + BREAK_ON_IPP_ERROR(sts, result); + ff = g->ff; - result = NewFfElement(&ff, &a); + result = NewFfElement(ff, &a); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ff, &b); + result = NewFfElement(ff, &b); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ff, &rx); + result = NewFfElement(ff, &rx); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ff, &t1); + result = NewFfElement(ff, &t1); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ff, &t2); + result = NewFfElement(ff, &t2); BREAK_ON_EPID_ERROR(result); result = NewBigNum(sizeof(t), &t_bn); BREAK_ON_EPID_ERROR(result); - result = NewBigNum(h_len, &h_bn); - BREAK_ON_EPID_ERROR(result); - sts = ippsGFpECGet(g->ipp_ec, 0, a->ipp_ff_elem, b->ipp_ff_elem, 0, 0, 0, 0, - 0, 0); + sts = ippsGFpECGet(0, a->ipp_ff_elem, b->ipp_ff_elem, g->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); - result = InitBigNumFromBnu(h, h_len, h_bn); - BREAK_ON_EPID_ERROR(result); - // compute H = hash (i || m) || Hash (i+1 || m) where (i =ipp32u) // copy variable length message to the buffer to hash if (0 != memcpy_S(hash_buf->msg, @@ -1058,23 +1006,23 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, result = ReadBigNum(&t, sizeof(t), t_bn); BREAK_ON_EPID_ERROR(result); // compute rx = t mod q (aka prime field based on q) - result = InitFfElementFromBn(&ff, t_bn, rx); + result = InitFfElementFromBn(ff, t_bn, rx); BREAK_ON_EPID_ERROR(result); // t1 = (rx^3 + a*rx + b) mod q - result = FfMul(&ff, rx, rx, t1); + result = FfMul(ff, rx, rx, t1); BREAK_ON_EPID_ERROR(result); - result = FfMul(&ff, t1, rx, t1); + result = FfMul(ff, t1, rx, t1); BREAK_ON_EPID_ERROR(result); - result = FfMul(&ff, a, rx, t2); + result = FfMul(ff, a, rx, t2); BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ff, t1, t2, t1); + result = FfAdd(ff, t1, t2, t1); BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ff, t1, b, t1); + result = FfAdd(ff, t1, b, t1); BREAK_ON_EPID_ERROR(result); // t2 = &ff.sqrt(t1) - result = FfSqrt(&ff, t1, t2); + result = FfSqrt(ff, t1, t2); if (kEpidMathQuadraticNonResidueError == result) { // if sqrt fail set i = i+ 2 and repeat from top i += 2; @@ -1092,7 +1040,7 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, // y[0] = min (t2, q-t2), y[1] = max(t2, q-t2) if (0 == high_bit) { // q-t2 = &ff.neg(t2) - result = FfNeg(&ff, t2, t2); + result = FfNeg(ff, t2, t2); BREAK_ON_EPID_ERROR(result); } @@ -1121,15 +1069,15 @@ EpidStatus Epid11EcHash(EcGroup* g, void const* msg, size_t msg_len, return result; } -EpidStatus EcHash(EcGroup* g, void const* msg, size_t msg_len, HashAlg hash_alg, - EcPoint* r) { +EpidStatus EcHash(EcGroup* g, ConstOctStr msg, size_t msg_len, HashAlg hash_alg, + EcPoint* r, uint32_t* iterations) { IppStatus sts = ippStsNoErr; - IppHashID hash_id; + IppHashAlgId hash_id; int ipp_msg_len = 0; - Ipp32u i = 0; + Ipp32u ipp_i = 0; if (!g || (!msg && msg_len > 0) || !r) { return kEpidBadArgErr; - } else if (!g->ipp_ec || !r->ipp_ec_pt) { + } else if (!g->ff || !g->ipp_ec || !r->ipp_ec_pt) { return kEpidBadArgErr; } // because we use ipp function with message length parameter @@ -1140,22 +1088,30 @@ EpidStatus EcHash(EcGroup* g, void const* msg, size_t msg_len, HashAlg hash_alg, } ipp_msg_len = (int)msg_len; if (kSha256 == hash_alg) { - hash_id = ippSHA256; + hash_id = ippHashAlg_SHA256; } else if (kSha384 == hash_alg) { - hash_id = ippSHA384; + hash_id = ippHashAlg_SHA384; } else if (kSha512 == hash_alg) { - hash_id = ippSHA512; + hash_id = ippHashAlg_SHA512; + } else if (kSha512_256 == hash_alg) { + hash_id = ippHashAlg_SHA512_256; } else { return kEpidHashAlgorithmNotSupported; } - if (g->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != r->element_len) { return kEpidBadArgErr; } do { - sts = ippsGFpECSetPointHash(i, msg, ipp_msg_len, hash_id, r->ipp_ec_pt, - g->ipp_ec, g->scratch_buffer); - } while (ippStsQuadraticNonResidueErr == sts && i++ < EPID_ECHASH_WATCHDOG); + sts = ippsGFpECSetPointHash(ipp_i, msg, ipp_msg_len, r->ipp_ec_pt, + g->ipp_ec, hash_id, g->scratch_buffer); + } while (ippStsQuadraticNonResidueErr == sts && + ipp_i++ < EPID_ECHASH_WATCHDOG); + + if (iterations) { + *iterations = (uint32_t)ipp_i; + } if (ippStsContextMatchErr == sts || ippStsBadArgErr == sts || ippStsLengthErr == sts) { @@ -1173,12 +1129,12 @@ EpidStatus EcMakePoint(EcGroup* g, FfElement const* x, EcPoint* r) { if (!g || !x || !r) { return kEpidBadArgErr; } - if (!g->ipp_ec || !x->ipp_ff_elem || !r->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !x->ipp_ff_elem || !r->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != x->info.elementLen || - g->info.elementLen != r->info.elementLen || - x->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != x->element_len || + g->ff->element_len != r->element_len) { return kEpidBadArgErr; } sts = ippsGFpECMakePoint(x->ipp_ff_elem, r->ipp_ec_pt, g->ipp_ec); @@ -1196,12 +1152,12 @@ EpidStatus EcInverse(EcGroup* g, EcPoint const* p, EcPoint* r) { IppStatus sts = ippStsNoErr; if (!g || !p || !r) { return kEpidBadArgErr; - } else if (!g->ipp_ec || !p->ipp_ec_pt || !r->ipp_ec_pt) { + } else if (!g->ff || !g->ipp_ec || !p->ipp_ec_pt || !r->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != p->info.elementLen || - g->info.elementLen != r->info.elementLen || - p->info.elementLen != r->info.elementLen) { + + if (g->ff->element_len != p->element_len || + g->ff->element_len != r->element_len) { return kEpidBadArgErr; } // Inverses elliptic curve point @@ -1224,12 +1180,11 @@ EpidStatus EcIsEqual(EcGroup* g, EcPoint const* a, EcPoint const* b, if (!g || !a || !b || !is_equal) { return kEpidBadArgErr; } - if (!g->ipp_ec || !a->ipp_ec_pt || !b->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !a->ipp_ec_pt || !b->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != a->info.elementLen || - g->info.elementLen != b->info.elementLen || - a->info.elementLen != b->info.elementLen) { + if (g->ff->element_len != a->element_len || + g->ff->element_len != b->element_len) { return kEpidBadArgErr; } @@ -1253,14 +1208,23 @@ EpidStatus EcIsIdentity(EcGroup* g, EcPoint const* p, bool* is_identity) { if (!g || !p || !is_identity) { return kEpidBadArgErr; } - if (!g->ipp_ec || !p->ipp_ec_pt) { + if (!g->ff || !g->ipp_ec || !p->ipp_ec_pt) { return kEpidBadArgErr; } - if (g->info.elementLen != p->info.elementLen) { + if (g->ff->element_len != p->element_len) { return kEpidBadArgErr; } - sts = ippsGFpECTstPoint(p->ipp_ec_pt, &result, g->ipp_ec, g->scratch_buffer); + sts = ippsGFpECTstPoint(p->ipp_ec_pt, &result, g->ipp_ec); + if (ippStsNoErr != sts) { + if (ippStsContextMatchErr == sts) { + return kEpidBadArgErr; + } else { + return kEpidMathErr; + } + } + sts = ippsGFpECTstPointInSubgroup(p->ipp_ec_pt, &result, g->ipp_ec, + g->scratch_buffer); if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts) { return kEpidBadArgErr; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/finitefield-internal.h b/external/epid-sdk/epid/common/math/src/finitefield-internal.h similarity index 56% rename from external/epid-sdk-3.0.0/epid/common/math/src/finitefield-internal.h rename to external/epid-sdk/epid/common/math/src/finitefield-internal.h index 4b68a6e4..1123f3db 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/finitefield-internal.h +++ b/external/epid-sdk/epid/common/math/src/finitefield-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,27 +22,43 @@ #ifndef EPID_COMMON_MATH_SRC_FINITEFIELD_INTERNAL_H_ #define EPID_COMMON_MATH_SRC_FINITEFIELD_INTERNAL_H_ -#include "ext/ipp/include/ippcpepid.h" +#include "epid/common/math/bignum.h" +#include "epid/common/math/src/bignum-internal.h" +#include "ext/ipp/include/ippcp.h" /// Finite Field struct FiniteField { /// Internal implementation of finite field IppsGFpState* ipp_ff; - /// Information about finite field created - IppsGFpInfo info; - /// Prime modulus size in bytes - size_t prime_modulus_size; + /// Previous finitefield + struct FiniteField* ground_ff; + /// Degree of basic field + int basic_degree; + /// Degree of current field + int ground_degree; + /// Size of element in BNU units + int element_len; + /// Minimum number of bytes needed to serialize an element + size_t element_strlen_required; + /*! + Galois field prime or free standing coefficient of + irreducible polynomial of finite field extension. + */ + BigNum* modulus_0; }; /// Finite Field Element struct FfElement { /// Internal implementation of finite field element IppsGFpElement* ipp_ff_elem; - /// Information about finite field element was created for - IppsGFpInfo info; + /// Element size of Finite Field element + int element_len; + /// Degree of Finite Field element + int degree; }; -/// Initialize FiniteField structure -EpidStatus InitFiniteFieldFromIpp(IppsGFpState* ipp_ff, FiniteField* ff); +EpidStatus SetFfElementOctString(ConstOctStr ff_elem_str, int strlen, + struct FfElement* ff_elem, + struct FiniteField* ff); #endif // EPID_COMMON_MATH_SRC_FINITEFIELD_INTERNAL_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/finitefield.c b/external/epid-sdk/epid/common/math/src/finitefield.c similarity index 75% rename from external/epid-sdk-3.0.0/epid/common/math/src/finitefield.c rename to external/epid-sdk/epid/common/math/src/finitefield.c index 27e994c7..5589e753 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/finitefield.c +++ b/external/epid-sdk/epid/common/math/src/finitefield.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,15 +19,17 @@ * \brief Finite field implementation. */ -#include -#include -#include #include "epid/common/math/finitefield.h" -#include "epid/common/math/src/bignum-internal.h" +#include +#include +#include #include "epid/common/math/src/finitefield-internal.h" #include "epid/common/src/memory.h" -#include "ext/ipp/include/ippcp.h" -#include "ext/ipp/include/ippcpepid.h" + +#ifndef MIN +/// Evaluate to minimum of two values +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif // MIN /// Number of leading zero bits in 32 bit integer x. static size_t Nlz32(uint32_t x) { @@ -64,63 +66,13 @@ static size_t Nlz32(uint32_t x) { /// Convert bit size to byte size #define BIT2BYTE_SIZE(bits) (((bits) + 7) >> 3) -/// Initializes a FiniteField structure -EpidStatus InitFiniteFieldFromIpp(IppsGFpState* ipp_ff, FiniteField* ff) { - EpidStatus result = kEpidErr; - IppStatus sts = ippStsNoErr; - IppsGFpInfo basic_info; - Ipp32u* basic_modulus = NULL; - - if (!ipp_ff || !ff) return kEpidBadArgErr; - - do { - memset(ff, 0, sizeof(*ff)); - - // set FiniteField::info - sts = ippsGFpGetInfo(ipp_ff, &(ff->info)); - if (ippStsNoErr != sts) { - result = kEpidMathErr; - break; - } - - // set FiniteField::ipp_ff context - ff->ipp_ff = ipp_ff; - - // set FiniteField::prime_modulus_size - sts = ippsGFpGetInfo(ff->info.pBasicGF, &basic_info); - if (ippStsNoErr != sts) { - result = kEpidMathErr; - break; - } - - basic_modulus = (Ipp32u*)SAFE_ALLOC(basic_info.elementLen * sizeof(Ipp32u)); - if (!basic_modulus) { - result = kEpidMemAllocErr; - break; - } - - sts = ippsGFpGetModulus(ff->info.pBasicGF, basic_modulus); - if (ippStsNoErr != sts) { - result = kEpidMathErr; - break; - } - - ff->prime_modulus_size = - BIT2BYTE_SIZE(BNU_BITSIZE(basic_modulus, basic_info.elementLen)); - - result = kEpidNoErr; - } while (0); - - SAFE_FREE(basic_modulus); - - return result; -} - EpidStatus NewFiniteField(BigNumStr const* prime, FiniteField** ff) { EpidStatus result = kEpidErr; IppsGFpState* ipp_finitefield_ctx = NULL; FiniteField* finitefield_ptr = NULL; + BigNum* prime_bn = NULL; do { + EpidStatus status = kEpidErr; IppStatus sts = ippStsNoErr; Ipp32u bnu[sizeof(BigNumStr) / sizeof(Ipp32u)]; int bnu_size; @@ -161,8 +113,21 @@ EpidStatus NewFiniteField(BigNumStr const* prime, FiniteField** ff) { result = kEpidMemAllocErr; break; } + + status = NewBigNum(sizeof(BigNumStr), &prime_bn); + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } + + status = ReadBigNum(prime, sizeof(BigNumStr), prime_bn); + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } // Initialize ipp finite field context - sts = ippsGFpInit(bnu, bit_size, ipp_finitefield_ctx); + sts = ippsGFpInit(prime_bn->ipp_bn, bit_size, ippsGFpMethod_pArb(), + ipp_finitefield_ctx); if (ippStsNoErr != sts) { if (ippStsSizeErr == sts) { result = kEpidBadArgErr; @@ -176,15 +141,21 @@ EpidStatus NewFiniteField(BigNumStr const* prime, FiniteField** ff) { result = kEpidMemAllocErr; break; } - result = InitFiniteFieldFromIpp(ipp_finitefield_ctx, finitefield_ptr); - if (kEpidNoErr != result) break; - + finitefield_ptr->element_strlen_required = + BIT2BYTE_SIZE(BNU_BITSIZE(bnu, bnu_size)); + finitefield_ptr->modulus_0 = prime_bn; + finitefield_ptr->basic_degree = 1; + finitefield_ptr->ground_degree = 1; + finitefield_ptr->element_len = bnu_size; + finitefield_ptr->ground_ff = NULL; + finitefield_ptr->ipp_ff = ipp_finitefield_ctx; *ff = finitefield_ptr; result = kEpidNoErr; } while (0); if (kEpidNoErr != result) { SAFE_FREE(finitefield_ptr); + SAFE_FREE(prime_bn); SAFE_FREE(ipp_finitefield_ctx); } return result; @@ -195,8 +166,11 @@ EpidStatus NewFiniteFieldViaBinomalExtension(FiniteField const* ground_field, int degree, FiniteField** ff) { EpidStatus result = kEpidErr; IppsGFpState* ipp_finitefield_ctx = NULL; + IppOctStr ff_elem_str = NULL; FiniteField* finitefield_ptr = NULL; + BigNum* modulus_0 = NULL; do { + EpidStatus status = kEpidErr; IppStatus sts = ippStsNoErr; int state_size_in_bytes = 0; if (!ground_field || !ground_element || !ff) { @@ -227,9 +201,13 @@ EpidStatus NewFiniteFieldViaBinomalExtension(FiniteField const* ground_field, } // Initialize ipp binomial extension finite field context - sts = - ippsGFpxInitBinomial(ground_field->ipp_ff, ground_element->ipp_ff_elem, - degree, ipp_finitefield_ctx); + sts = ippsGFpxInitBinomial( + ground_field->ipp_ff, degree, ground_element->ipp_ff_elem, + 2 == degree + ? (3 == ground_field->basic_degree ? ippsGFpxMethod_binom2() + : ippsGFpxMethod_binom2_epid2()) + : ippsGFpxMethod_binom3_epid2(), + ipp_finitefield_ctx); if (ippStsNoErr != sts) { if (ippStsSizeErr == sts) { result = kEpidBadArgErr; @@ -243,15 +221,52 @@ EpidStatus NewFiniteFieldViaBinomalExtension(FiniteField const* ground_field, result = kEpidMemAllocErr; break; } - result = InitFiniteFieldFromIpp(ipp_finitefield_ctx, finitefield_ptr); + finitefield_ptr->element_strlen_required = + ground_field->element_strlen_required * degree; + ff_elem_str = + (IppOctStr)SAFE_ALLOC(ground_field->element_len * sizeof(Ipp32u)); + if (!ff_elem_str) { + result = kEpidMemAllocErr; + break; + } + status = NewBigNum(ground_field->element_len * sizeof(Ipp32u), &modulus_0); + if (kEpidNoErr != status) { + break; + } + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } + result = + WriteFfElement((FiniteField*)ground_field, ground_element, ff_elem_str, + ground_field->element_len * sizeof(Ipp32u)); if (kEpidNoErr != result) break; + status = ReadBigNum(ff_elem_str, ground_field->element_len * sizeof(Ipp32u), + modulus_0); + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } + finitefield_ptr->basic_degree = ground_field->basic_degree * degree; + finitefield_ptr->ground_degree = degree; + finitefield_ptr->element_len = ground_field->element_len * degree; + finitefield_ptr->modulus_0 = modulus_0; + // Warning: once assigned ground field must never be modified. this was not + // made const + // to allow the FiniteField structure to be used in context when we want to + // modify the parameters. + finitefield_ptr->ground_ff = (FiniteField*)ground_field; + finitefield_ptr->ipp_ff = ipp_finitefield_ctx; *ff = finitefield_ptr; result = kEpidNoErr; } while (0); + SAFE_FREE(ff_elem_str); + if (kEpidNoErr != result) { SAFE_FREE(finitefield_ptr); + SAFE_FREE(modulus_0); SAFE_FREE(ipp_finitefield_ctx); } return result; @@ -263,9 +278,12 @@ EpidStatus NewFiniteFieldViaPolynomialExtension(FiniteField const* ground_field, EpidStatus result = kEpidErr; IppsGFpState* ipp_finitefield_ctx = NULL; FiniteField* finitefield_ptr = NULL; - Ipp32u* irr_polynomial_bnu = NULL; + FfElement** ff_elems = NULL; + IppsGFpElement** ff_elems_state = NULL; + BigNum* modulus_0 = NULL; int i; do { + EpidStatus status = kEpidErr; IppStatus sts = ippStsNoErr; int state_size_in_bytes = 0; if (!ground_field || !irr_polynomial || !ff) { @@ -278,17 +296,6 @@ EpidStatus NewFiniteFieldViaPolynomialExtension(FiniteField const* ground_field, break; } - // irr_polynomial to IPP representation - irr_polynomial_bnu = (Ipp32u*)SAFE_ALLOC(sizeof(BigNumStr) * degree); - if (!irr_polynomial_bnu) { - result = kEpidMemAllocErr; - break; - } - for (i = 0; i < degree; ++i) { - OctStr2Bnu(irr_polynomial_bnu + (i * sizeof(BigNumStr) / 4), - &irr_polynomial[i], sizeof(irr_polynomial[i])); - } - // Determine the memory requirement for finite field context sts = ippsGFpxGetSize(ground_field->ipp_ff, degree, &state_size_in_bytes); if (ippStsNoErr != sts) { @@ -306,10 +313,36 @@ EpidStatus NewFiniteFieldViaPolynomialExtension(FiniteField const* ground_field, result = kEpidMemAllocErr; break; } + ff_elems = (FfElement**)SAFE_ALLOC(sizeof(FfElement*) * degree); + if (!ff_elems) { + result = kEpidMemAllocErr; + break; + } + ff_elems_state = + (IppsGFpElement**)SAFE_ALLOC(sizeof(IppsGFpElement*) * degree); + if (!ff_elems_state) { + result = kEpidMemAllocErr; + break; + } + for (i = 0; i < degree; ++i) { + status = NewFfElement(ground_field, &ff_elems[i]); + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } + status = ReadFfElement((FiniteField*)ground_field, &irr_polynomial[i], + sizeof(BigNumStr), ff_elems[i]); + if (kEpidNoErr != status) { + result = kEpidMathErr; + break; + } + ff_elems_state[i] = ff_elems[i]->ipp_ff_elem; + } // Initialize ipp binomial extension finite field context - sts = ippsGFpxInit(ground_field->ipp_ff, irr_polynomial_bnu, degree, - ipp_finitefield_ctx); + sts = ippsGFpxInit(ground_field->ipp_ff, degree, + (const IppsGFpElement* const*)ff_elems_state, degree, + ippsGFpxMethod_com(), ipp_finitefield_ctx); if (ippStsNoErr != sts) { if (ippStsSizeErr == sts) { result = kEpidBadArgErr; @@ -318,21 +351,47 @@ EpidStatus NewFiniteFieldViaPolynomialExtension(FiniteField const* ground_field, } break; } + status = NewBigNum(sizeof(irr_polynomial[0]), &modulus_0); + if (kEpidNoErr != status) { + break; + } + status = + ReadBigNum(&irr_polynomial[0], sizeof(irr_polynomial[0]), modulus_0); + if (kEpidNoErr != status) { + break; + } finitefield_ptr = (FiniteField*)SAFE_ALLOC(sizeof(FiniteField)); if (!finitefield_ptr) { result = kEpidMemAllocErr; break; } - result = InitFiniteFieldFromIpp(ipp_finitefield_ctx, finitefield_ptr); - if (kEpidNoErr != result) break; - + finitefield_ptr->element_strlen_required = + ground_field->element_len * sizeof(Ipp32u) * degree; + finitefield_ptr->modulus_0 = modulus_0; + finitefield_ptr->basic_degree = ground_field->basic_degree * degree; + finitefield_ptr->ground_degree = degree; + finitefield_ptr->element_len = ground_field->element_len * degree; + // Warning: once assigned ground field must never be modified. this was not + // made const + // to allow the FiniteField structure to be used in context when we want to + // modify the parameters. + finitefield_ptr->ground_ff = (FiniteField*)ground_field; + finitefield_ptr->ipp_ff = ipp_finitefield_ctx; *ff = finitefield_ptr; result = kEpidNoErr; } while (0); - SAFE_FREE(irr_polynomial_bnu); + if (ff_elems != NULL) { + for (i = 0; i < degree; i++) { + DeleteFfElement(&ff_elems[i]); + } + } + SAFE_FREE(ff_elems); + SAFE_FREE(ff_elems_state); + if (kEpidNoErr != result) { SAFE_FREE(finitefield_ptr); + SAFE_FREE(modulus_0) SAFE_FREE(ipp_finitefield_ctx); } return result; @@ -342,6 +401,7 @@ void DeleteFiniteField(FiniteField** ff) { if (ff) { if (*ff) { SAFE_FREE((*ff)->ipp_ff); + DeleteBigNum(&(*ff)->modulus_0); } SAFE_FREE((*ff)); } @@ -390,12 +450,8 @@ EpidStatus NewFfElement(FiniteField const* ff, FfElement** new_ff_elem) { } ff_elem->ipp_ff_elem = ipp_ff_elem; - - sts = ippsGFpGetInfo(ff->ipp_ff, &(ff_elem->info)); - if (ippStsNoErr != sts) { - result = kEpidMathErr; - break; - } + ff_elem->element_len = ff->element_len; + ff_elem->degree = ff->ground_degree; *new_ff_elem = ff_elem; result = kEpidNoErr; @@ -417,12 +473,109 @@ void DeleteFfElement(FfElement** ff_elem) { } } -EpidStatus ReadFfElement(FiniteField* ff, void const* ff_elem_str, +EpidStatus IsValidFfElemOctString(ConstOctStr ff_elem_str, int strlen, + FiniteField const* ff) { + int i; + EpidStatus result = kEpidNoErr; + IppStatus sts = ippStsNoErr; + FiniteField const* basic_ff; + BigNum* pData = NULL; + int prime_length; + IppOctStr ff_elem_str_p; + Ipp32u cmp_res; + int tmp_strlen = strlen; + if (!ff || !ff_elem_str) { + return kEpidBadArgErr; + } + basic_ff = ff; + while (basic_ff->ground_ff != NULL) { + basic_ff = basic_ff->ground_ff; + } + prime_length = basic_ff->element_len * sizeof(Ipp32u); + ff_elem_str_p = (IppOctStr)ff_elem_str; + for (i = 0; (i < ff->basic_degree) && (tmp_strlen > 0); i++) { + int length; + length = MIN(prime_length, tmp_strlen); + result = NewBigNum(length, &pData); + if (kEpidNoErr != result) { + break; + } + result = ReadBigNum(ff_elem_str_p, length, pData); + if (kEpidNoErr != result) { + break; + } + sts = ippsCmp_BN(basic_ff->modulus_0->ipp_bn, pData->ipp_bn, &cmp_res); + // check return codes + if (ippStsNoErr != sts) { + if (ippStsContextMatchErr == sts) + result = kEpidBadArgErr; + else + result = kEpidMathErr; + break; + } + if (cmp_res != IPP_IS_GT) { + result = kEpidBadArgErr; + break; + } + DeleteBigNum(&pData); + tmp_strlen -= length; + ff_elem_str_p += length; + } + DeleteBigNum(&pData); + return result; +} + +EpidStatus SetFfElementOctString(ConstOctStr ff_elem_str, int strlen, + FfElement* ff_elem, FiniteField* ff) { + EpidStatus result = kEpidErr; + IppOctStr extended_ff_elem_str = NULL; + if (!ff || !ff_elem || !ff_elem_str) { + return kEpidBadArgErr; + } + do { + IppStatus sts; + // Ipp2017u2 contians a bug in ippsGFpSetElementOctString, does not check + // whether ff_elem_str < modulus + result = IsValidFfElemOctString(ff_elem_str, strlen, ff); + if (kEpidNoErr != result) { + break; + } + // workaround because of bug in ipp2017u2 + if (strlen < (int)(ff->element_len * sizeof(Ipp32u))) { + int length = ff->element_len * sizeof(Ipp32u); + extended_ff_elem_str = (IppOctStr)SAFE_ALLOC(length); + if (!extended_ff_elem_str) { + result = kEpidMemAllocErr; + break; + } + memset(extended_ff_elem_str, 0, length); + memcpy_S(extended_ff_elem_str, length, ff_elem_str, strlen); + strlen = length; + sts = ippsGFpSetElementOctString(extended_ff_elem_str, strlen, + ff_elem->ipp_ff_elem, ff->ipp_ff); + } else { + sts = ippsGFpSetElementOctString(ff_elem_str, strlen, + ff_elem->ipp_ff_elem, ff->ipp_ff); + } + if (ippStsNoErr != sts) { + if (ippStsContextMatchErr == sts || ippStsOutOfRangeErr == sts) { + result = kEpidBadArgErr; + } else { + result = kEpidMathErr; + } + break; + } + } while (0); + SAFE_FREE(extended_ff_elem_str); + return result; +} + +EpidStatus ReadFfElement(FiniteField* ff, ConstOctStr ff_elem_str, size_t strlen, FfElement* ff_elem) { - IppStatus sts; size_t strlen_required = 0; int ipp_str_size = 0; - uint8_t const* str = (uint8_t const*)ff_elem_str; + EpidStatus result = kEpidNoErr; + ConstIppOctStr str = (ConstIppOctStr)ff_elem_str; if (!ff || !ff_elem_str || !ff_elem) { return kEpidBadArgErr; @@ -430,18 +583,17 @@ EpidStatus ReadFfElement(FiniteField* ff, void const* ff_elem_str, if (!ff_elem->ipp_ff_elem || !ff->ipp_ff) { return kEpidBadArgErr; } - if (ff->info.elementLen != ff_elem->info.elementLen) { + + if (ff->element_len != ff_elem->element_len) { return kEpidBadArgErr; } - // ippsGFpSetElementOctString expects serialized value consists - // of "degree" number of chunks, where each chunk is of modulus byte size. - strlen_required = ff->prime_modulus_size * ff->info.basicGFdegree; + strlen_required = ff->element_strlen_required; - // Remove leading zeros when de-serealizing finite field of degree 1. + // Remove leading zeros when de-serializing finite field of degree 1. // This takes care of serialization chunk size adjustments when importing // a big numbers. - if (1 == ff->info.basicGFdegree) { + if (1 == ff->basic_degree) { while (strlen_required < strlen && 0 == *str) { str++; strlen--; @@ -459,24 +611,15 @@ EpidStatus ReadFfElement(FiniteField* ff, void const* ff_elem_str, return kEpidBadArgErr; } - sts = ippsGFpSetElementOctString(str, ipp_str_size, ff_elem->ipp_ff_elem, - ff->ipp_ff); - if (ippStsNoErr != sts) { - if (ippStsContextMatchErr == sts || ippStsOutOfRangeErr == sts) { - return kEpidBadArgErr; - } else { - return kEpidMathErr; - } - } + result = SetFfElementOctString(str, ipp_str_size, ff_elem, ff); - return kEpidNoErr; + return result; } /// Gets the prime value of a finite field /*! - This function returns a new bignum containing the field's prime value. - A new bignum is returned so that callers do not have to figure out the proper - size. + This function returns a reference to the bignum containing the field's prime + value. This function only works with non-composite fields. @@ -488,53 +631,25 @@ EpidStatus ReadFfElement(FiniteField* ff, void const* ff_elem_str, \returns ::EpidStatus */ EpidStatus GetFiniteFieldPrime(FiniteField* ff, BigNum** bn) { - EpidStatus result = kEpidErr; - IppStatus sts; - BigNum* prime_bn = NULL; - Ipp32u* prime_bnu = NULL; if (!ff || !bn) { return kEpidBadArgErr; } if (!ff->ipp_ff) { return kEpidBadArgErr; } - if (ff->info.basicGFdegree != 1 || ff->info.groundGFdegree != 1) { + if (ff->basic_degree != 1 || ff->ground_degree != 1) { return kEpidBadArgErr; } - do { - size_t elem_dword_size = ff->info.elementLen; - size_t elem_bytes_size = elem_dword_size * sizeof(Ipp32u); - result = NewBigNum(elem_bytes_size, &prime_bn); - if (kEpidNoErr != result) { - break; - } - prime_bnu = (Ipp32u*)SAFE_ALLOC(elem_bytes_size); - if (NULL == prime_bnu) { - result = kEpidMemAllocErr; - break; - } - sts = ippsGFpGetModulus(ff->ipp_ff, prime_bnu); - result = InitBigNumFromBnu(prime_bnu, elem_dword_size, prime_bn); - if (kEpidNoErr != result) { - break; - } - result = kEpidNoErr; - } while (0); - SAFE_FREE(prime_bnu); - if (kEpidNoErr != result) { - DeleteBigNum(&prime_bn); - } else { - *bn = prime_bn; - } - return result; + *bn = ff->modulus_0; + return kEpidNoErr; } EpidStatus InitFfElementFromBn(FiniteField* ff, BigNum* bn, FfElement* ff_elem) { EpidStatus result = kEpidErr; - BigNum* prime_bn = NULL; + BigNum* prime_bn = NULL; // non-owning reference BigNum* mod_bn = NULL; - Ipp32u* mod_str = NULL; + BNU mod_str = NULL; if (!ff || !bn || !ff_elem) { return kEpidBadArgErr; @@ -542,14 +657,14 @@ EpidStatus InitFfElementFromBn(FiniteField* ff, BigNum* bn, if (!ff_elem->ipp_ff_elem || !ff->ipp_ff) { return kEpidBadArgErr; } - if (ff->info.basicGFdegree != 1 || ff->info.groundGFdegree != 1) { + if (ff->basic_degree != 1 || ff->ground_degree != 1) { return kEpidBadArgErr; } - if (ff->info.elementLen != ff_elem->info.elementLen) { + if (ff->element_len != ff_elem->element_len) { return kEpidBadArgErr; } do { - size_t elem_size = ff->info.elementLen * sizeof(Ipp32u); + size_t elem_size = ff->element_len * sizeof(Ipp32u); result = NewBigNum(elem_size, &mod_bn); if (kEpidNoErr != result) { break; @@ -563,7 +678,7 @@ EpidStatus InitFfElementFromBn(FiniteField* ff, BigNum* bn, if (kEpidNoErr != result) { break; } - mod_str = (Ipp32u*)SAFE_ALLOC(elem_size); + mod_str = (BNU)SAFE_ALLOC(elem_size); if (NULL == mod_str) { result = kEpidMemAllocErr; break; @@ -579,17 +694,17 @@ EpidStatus InitFfElementFromBn(FiniteField* ff, BigNum* bn, result = kEpidNoErr; } while (0); SAFE_FREE(mod_str); - DeleteBigNum(&prime_bn); + prime_bn = NULL; DeleteBigNum(&mod_bn); return result; } EpidStatus WriteFfElement(FiniteField* ff, FfElement const* ff_elem, - void* ff_elem_str, size_t strlen) { + OctStr ff_elem_str, size_t strlen) { IppStatus sts; size_t strlen_required = 0; size_t pad = 0; - uint8_t* str = (uint8_t*)ff_elem_str; + IppOctStr str = (IppOctStr)ff_elem_str; if (!ff || !ff_elem_str || !ff_elem) { return kEpidBadArgErr; @@ -600,17 +715,15 @@ EpidStatus WriteFfElement(FiniteField* ff, FfElement const* ff_elem, if (INT_MAX < strlen) { return kEpidBadArgErr; } - if (ff->info.elementLen != ff_elem->info.elementLen) { + if (ff->element_len != ff_elem->element_len) { return kEpidBadArgErr; } - // ippsGFpGetElementOctString serialize value into a buffer consists - // of "degree" number of chunks, where each chunk is of modulus byte size. - strlen_required = ff->prime_modulus_size * ff->info.basicGFdegree; + strlen_required = ff->element_strlen_required; // add zero padding for extension of a degree 1 (a prime field) // so it can be deserialized into big number correctly. - if (1 == ff->info.basicGFdegree && strlen_required < strlen) { + if (1 == ff->basic_degree && strlen_required < strlen) { pad = strlen - strlen_required; memset(str, 0, pad); strlen -= pad; @@ -641,9 +754,7 @@ EpidStatus FfNeg(FiniteField* ff, FfElement const* a, FfElement* r) { } else if (!ff->ipp_ff || !a->ipp_ff_elem || !r->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (ff->element_len != a->element_len || ff->element_len != r->element_len) { return kEpidBadArgErr; } sts = ippsGFpNeg(a->ipp_ff_elem, r->ipp_ff_elem, ff->ipp_ff); @@ -665,9 +776,7 @@ EpidStatus FfInv(FiniteField* ff, FfElement const* a, FfElement* r) { } else if (!ff->ipp_ff || !a->ipp_ff_elem || !r->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (ff->element_len != a->element_len || ff->element_len != r->element_len) { return kEpidBadArgErr; } // Invert the element @@ -693,11 +802,8 @@ EpidStatus FfAdd(FiniteField* ff, FfElement const* a, FfElement const* b, !r->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != b->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != b->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (ff->element_len != a->element_len || ff->element_len != b->element_len || + ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -719,11 +825,9 @@ EpidStatus FfSub(FiniteField* ff, FfElement const* a, FfElement const* b, !r->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != b->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != b->info.elementLen || - a->info.elementLen != r->info.elementLen) { + + if (ff->element_len != a->element_len || ff->element_len != b->element_len || + ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -747,16 +851,14 @@ EpidStatus FfMul(FiniteField* ff, FfElement const* a, FfElement const* b, return kEpidBadArgErr; } // Multiplies elements - if (a->info.elementLen != b->info.elementLen && - a->info.elementLen == a->info.groundGFdegree * b->info.elementLen) { - sts = ippsGFpMul_GFpE(a->ipp_ff_elem, b->ipp_ff_elem, r->ipp_ff_elem, - ff->ipp_ff); + if (a->element_len != b->element_len && + a->element_len == a->degree * b->element_len) { + sts = ippsGFpMul_PE(a->ipp_ff_elem, b->ipp_ff_elem, r->ipp_ff_elem, + ff->ipp_ff); } else { - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != b->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != b->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (ff->element_len != a->element_len || + ff->element_len != b->element_len || + ff->element_len != r->element_len) { return kEpidBadArgErr; } sts = @@ -781,7 +883,7 @@ EpidStatus FfIsZero(FiniteField* ff, FfElement const* a, bool* is_zero) { } else if (!ff->ipp_ff || !a->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen) { + if (ff->element_len != a->element_len) { return kEpidBadArgErr; } // Check if the element is zero @@ -804,7 +906,7 @@ EpidStatus FfIsZero(FiniteField* ff, FfElement const* a, bool* is_zero) { EpidStatus FfExp(FiniteField* ff, FfElement const* a, BigNum const* b, FfElement* r) { EpidStatus result = kEpidErr; - Ipp8u* scratch_buffer = NULL; + OctStr scratch_buffer = NULL; int exp_bit_size = 0; int element_size = 0; @@ -818,9 +920,8 @@ EpidStatus FfExp(FiniteField* ff, FfElement const* a, BigNum const* b, result = kEpidBadArgErr; break; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != r->info.elementLen || - a->info.elementLen != r->info.elementLen) { + if (ff->element_len != a->element_len || + ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -836,7 +937,7 @@ EpidStatus FfExp(FiniteField* ff, FfElement const* a, BigNum const* b, break; } - scratch_buffer = (Ipp8u*)SAFE_ALLOC(element_size); + scratch_buffer = (OctStr)SAFE_ALLOC(element_size); if (!scratch_buffer) { result = kEpidMemAllocErr; break; @@ -864,7 +965,7 @@ EpidStatus FfMultiExp(FiniteField* ff, FfElement const** p, BigNumStr const** b, IppsGFpElement** ipp_p = NULL; IppsBigNumState** ipp_b = NULL; BigNum** bignums = NULL; - Ipp8u* scratch_buffer = NULL; + OctStr scratch_buffer = NULL; int i = 0; int ipp_m = 0; @@ -889,11 +990,11 @@ EpidStatus FfMultiExp(FiniteField* ff, FfElement const** p, BigNumStr const** b, if (!p[i]->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != p[i]->info.elementLen) { + if (ff->element_len != p[i]->element_len) { return kEpidBadArgErr; } } - if (ff->info.elementLen != r->info.elementLen) { + if (ff->element_len != r->element_len) { return kEpidBadArgErr; } @@ -942,7 +1043,7 @@ EpidStatus FfMultiExp(FiniteField* ff, FfElement const** p, BigNumStr const** b, break; } // allocate memory for scratch buffer - scratch_buffer = (Ipp8u*)SAFE_ALLOC(scratch_buffer_size); + scratch_buffer = (OctStr)SAFE_ALLOC(scratch_buffer_size); if (!scratch_buffer) { result = kEpidMemAllocErr; break; @@ -978,9 +1079,8 @@ EpidStatus FfMultiExpBn(FiniteField* ff, FfElement const** p, BigNum const** b, EpidStatus result = kEpidErr; IppsGFpElement** ipp_p = NULL; IppsBigNumState** ipp_b = NULL; - Ipp8u* scratch_buffer = NULL; + OctStr scratch_buffer = NULL; - size_t s = 0; int exp_bit_size = 0; size_t i = 0; int ipp_m = 0; @@ -990,15 +1090,9 @@ EpidStatus FfMultiExpBn(FiniteField* ff, FfElement const** p, BigNum const** b, return kEpidBadArgErr; } else if (!ff->ipp_ff || !r->ipp_ff_elem || m <= 0) { return kEpidBadArgErr; - } else if (ff->info.elementLen != r->info.elementLen) { + } else if (ff->element_len != r->element_len) { return kEpidBadArgErr; } - for (s = 0; s < m; s++) { - if (!p[s] || !b[s]) { - return kEpidBadArgErr; - } - } - // because we use ipp function with number of items parameter // defined as "int" we need to verify that input length // do not exceed INT_MAX to avoid overflow @@ -1008,13 +1102,10 @@ EpidStatus FfMultiExpBn(FiniteField* ff, FfElement const** p, BigNum const** b, ipp_m = (int)m; for (i = 0; i < m; i++) { int b_size = 0; - if (!p[i]) { + if (!p[i] || !p[i]->ipp_ff_elem || !b[i] || !b[i]->ipp_bn) { return kEpidBadArgErr; } - if (!p[i]->ipp_ff_elem) { - return kEpidBadArgErr; - } - if (ff->info.elementLen != p[i]->info.elementLen) { + if (ff->element_len != p[i]->element_len) { return kEpidBadArgErr; } sts = ippsGetSize_BN(b[i]->ipp_bn, &b_size); @@ -1058,7 +1149,7 @@ EpidStatus FfMultiExpBn(FiniteField* ff, FfElement const** p, BigNum const** b, break; } // allocate memory for scratch buffer - scratch_buffer = (Ipp8u*)SAFE_ALLOC(scratch_buffer_size); + scratch_buffer = (OctStr)SAFE_ALLOC(scratch_buffer_size); if (!scratch_buffer) { result = kEpidMemAllocErr; break; @@ -1102,9 +1193,7 @@ EpidStatus FfIsEqual(FiniteField* ff, FfElement const* a, FfElement const* b, if (!ff->ipp_ff || !a->ipp_ff_elem || !b->ipp_ff_elem) { return kEpidBadArgErr; } - if (ff->info.elementLen != a->info.elementLen || - ff->info.elementLen != b->info.elementLen || - a->info.elementLen != b->info.elementLen) { + if (ff->element_len != a->element_len || ff->element_len != b->element_len) { return kEpidBadArgErr; } @@ -1121,12 +1210,12 @@ EpidStatus FfIsEqual(FiniteField* ff, FfElement const* a, FfElement const* b, return kEpidNoErr; } -EpidStatus FfHash(FiniteField* ff, void const* msg, size_t msg_len, +EpidStatus FfHash(FiniteField* ff, ConstOctStr msg, size_t msg_len, HashAlg hash_alg, FfElement* r) { EpidStatus result = kEpidErr; do { IppStatus sts = ippStsNoErr; - IppHashID hash_id; + IppHashAlgId hash_id; int ipp_msg_len = 0; if (!ff || !msg || !r) { result = kEpidBadArgErr; @@ -1145,20 +1234,22 @@ EpidStatus FfHash(FiniteField* ff, void const* msg, size_t msg_len, ipp_msg_len = (int)msg_len; if (kSha256 == hash_alg) { - hash_id = ippSHA256; + hash_id = ippHashAlg_SHA256; } else if (kSha384 == hash_alg) { - hash_id = ippSHA384; + hash_id = ippHashAlg_SHA384; } else if (kSha512 == hash_alg) { - hash_id = ippSHA512; + hash_id = ippHashAlg_SHA512; + } else if (kSha512_256 == hash_alg) { + hash_id = ippHashAlg_SHA512_256; } else { result = kEpidHashAlgorithmNotSupported; break; } - if (ff->info.elementLen != r->info.elementLen) { + if (ff->element_len != r->element_len) { return kEpidBadArgErr; } - sts = ippsGFpSetElementHash(msg, ipp_msg_len, hash_id, r->ipp_ff_elem, - ff->ipp_ff); + sts = ippsGFpSetElementHash(msg, ipp_msg_len, r->ipp_ff_elem, ff->ipp_ff, + hash_id); if (ippStsNoErr != sts) { if (ippStsContextMatchErr == sts || ippStsBadArgErr == sts || ippStsLengthErr == sts) { @@ -1177,13 +1268,10 @@ EpidStatus FfHash(FiniteField* ff, void const* msg, size_t msg_len, EpidStatus FfGetRandom(FiniteField* ff, BigNumStr const* low_bound, BitSupplier rnd_func, void* rnd_param, FfElement* r) { EpidStatus result = kEpidErr; - IppsGFpElement* low = NULL; + FfElement* low = NULL; do { IppStatus sts = ippStsNoErr; - unsigned int ctxsize = 0; unsigned int rngloopCount = RNG_WATCHDOG; - Ipp32u bnu_low_bound[sizeof(BigNumStr) / sizeof(Ipp32u)]; - int bnu_size; if (!ff || !low_bound || !rnd_func || !r) { result = kEpidBadArgErr; break; @@ -1192,41 +1280,28 @@ EpidStatus FfGetRandom(FiniteField* ff, BigNumStr const* low_bound, result = kEpidBadArgErr; break; } - if (ff->info.elementLen != r->info.elementLen) { + if (ff->element_len != r->element_len) { return kEpidBadArgErr; } // create a new FfElement to hold low_bound - sts = ippsGFpElementGetSize(ff->ipp_ff, (int*)&ctxsize); - if (ippStsNoErr != sts) { - result = kEpidMathErr; + result = NewFfElement(ff, &low); + if (kEpidNoErr != result) { break; } - // Allocate space for ipp Ff Element context - low = (IppsGFpElement*)SAFE_ALLOC(ctxsize); - if (!low) { - result = kEpidMemAllocErr; - break; - } - bnu_size = OctStr2Bnu(bnu_low_bound, low_bound, sizeof(*low_bound)); - if (bnu_size < 0) { - result = kEpidMathErr; - break; - } - // initialize state - sts = ippsGFpElementInit(bnu_low_bound, bnu_size, low, ff->ipp_ff); - if (ippStsNoErr != sts) { - result = kEpidMathErr; + result = ReadFfElement(ff, low_bound, sizeof(*low_bound), low); + if (kEpidNoErr != result) { break; } do { int cmpResult = IPP_IS_NE; - sts = ippsGFpSetElementRandom((IppBitSupplier)rnd_func, rnd_param, - r->ipp_ff_elem, ff->ipp_ff); + sts = ippsGFpSetElementRandom(r->ipp_ff_elem, ff->ipp_ff, + (IppBitSupplier)rnd_func, rnd_param); if (ippStsNoErr != sts) { result = kEpidMathErr; break; } - sts = ippsGFpCmpElement(r->ipp_ff_elem, low, &cmpResult, ff->ipp_ff); + sts = ippsGFpCmpElement(r->ipp_ff_elem, low->ipp_ff_elem, &cmpResult, + ff->ipp_ff); if (ippStsNoErr != sts) { result = kEpidMathErr; break; @@ -1241,20 +1316,12 @@ EpidStatus FfGetRandom(FiniteField* ff, BigNumStr const* low_bound, } } while (--rngloopCount); } while (0); - SAFE_FREE(low); + DeleteFfElement(&low); return result; } EpidStatus FfSqrt(FiniteField* ff, FfElement const* a, FfElement* r) { EpidStatus result = kEpidErr; - Ipp8u one_str = 1; - BigNumStr qm1_str; - const BigNumStr zero_str = {0}; - bool is_equal = false; - unsigned int s; - bool is_even = false; - unsigned int i; - BigNum* prime = NULL; BigNum* qm1 = NULL; BigNum* one = NULL; FfElement* qm1_ffe = NULL; @@ -1281,6 +1348,15 @@ EpidStatus FfSqrt(FiniteField* ff, FfElement const* a, FfElement* r) { return kEpidBadArgErr; } do { + BigNum* prime = NULL; // non-owning reference + bool is_equal = false; + unsigned int s; + bool is_even = false; + unsigned int i; + Ipp8u one_str = 1; + BigNumStr qm1_str; + const BigNumStr zero_str = {0}; + result = GetFiniteFieldPrime(ff, &prime); if (kEpidNoErr != result) { break; @@ -1556,6 +1632,7 @@ EpidStatus FfSqrt(FiniteField* ff, FfElement const* a, FfElement* r) { break; } result = kEpidNoErr; + prime = NULL; } while (0); DeleteFfElement(&dd); DeleteFfElement(>p1d2); @@ -1578,6 +1655,5 @@ EpidStatus FfSqrt(FiniteField* ff, FfElement const* a, FfElement* r) { DeleteFfElement(&qm1_ffe); DeleteBigNum(&one); DeleteBigNum(&qm1); - DeleteBigNum(&prime); return result; } diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/pairing-internal.h b/external/epid-sdk/epid/common/math/src/pairing-internal.h similarity index 90% rename from external/epid-sdk-3.0.0/epid/common/math/src/pairing-internal.h rename to external/epid-sdk/epid/common/math/src/pairing-internal.h index 59037063..af14ac65 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/pairing-internal.h +++ b/external/epid-sdk/epid/common/math/src/pairing-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -31,9 +31,9 @@ struct PairingState { /// parameters of G1 bool neg; ///< 8-bit integer representing a Boolean value FfElement* g[3][5]; ///< 15 elements in Fq2 - FiniteField Fq; ///< Fq - FiniteField Fq2; ///< Fq2 - FiniteField Fq6; ///< Fq6 + FiniteField* Fq; ///< Fq + FiniteField* Fq2; ///< Fq2 + FiniteField* Fq6; ///< Fq6 }; #endif // EPID_COMMON_MATH_SRC_PAIRING_INTERNAL_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/pairing.c b/external/epid-sdk/epid/common/math/src/pairing.c similarity index 81% rename from external/epid-sdk-3.0.0/epid/common/math/src/pairing.c rename to external/epid-sdk/epid/common/math/src/pairing.c index 079ffff1..b8da1d3d 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/pairing.c +++ b/external/epid-sdk/epid/common/math/src/pairing.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,15 +19,14 @@ * \brief Pairing implementation. */ -#include #include "epid/common/math/pairing.h" +#include #include "epid/common/math/src/bignum-internal.h" -#include "epid/common/math/src/finitefield-internal.h" #include "epid/common/math/src/ecgroup-internal.h" +#include "epid/common/math/src/finitefield-internal.h" #include "epid/common/math/src/pairing-internal.h" #include "epid/common/src/memory.h" #include "ext/ipp/include/ippcp.h" -#include "ext/ipp/include/ippcpepid.h" /// Handle Ipp Errors with Break #define BREAK_ON_IPP_ERROR(sts, ret) \ @@ -128,23 +127,22 @@ EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb, PairingState** ps) { EpidStatus result = kEpidErr; FfElement* xi = NULL; - PairingState* paring_state_ctx = NULL; + PairingState* pairing_state_ctx = NULL; BigNum* e = NULL; BigNum* one = NULL; - BigNum* q = NULL; BigNum* six = NULL; - Ipp8u* scratch_buffer = NULL; + OctStr scratch_buffer = NULL; do { IppStatus sts = ippStsNoErr; IppsGFpState* Fq6 = NULL; IppsGFpState* Fq2 = NULL; IppsGFpState* Fq = NULL; - FiniteField Ffq2; - IppsGFpInfo info = {0}; - Fq2ElemDat Fq6IrrPolynomial[3 + 1] = {0}; + FiniteField* Ffq6 = NULL; + FiniteField* Ffq2 = NULL; + FiniteField* Ffq = NULL; + Fq2ElemDat Fq6IrrPolynomial = {0}; uint8_t one_str[] = {1}; uint8_t six_str[] = {6}; - FqElemDat qDat = {0}; int i = 0; int j = 0; int bufferSize = 0; @@ -159,59 +157,60 @@ EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb, break; } // get Fq6, Fq2, Fq - sts = ippsGFpGetInfo(ff->ipp_ff, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq6 = (IppsGFpState*)info.pGroundGF; - sts = ippsGFpGetInfo(Fq6, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq2 = (IppsGFpState*)info.pGroundGF; - result = InitFiniteFieldFromIpp(Fq2, &Ffq2); - BREAK_ON_EPID_ERROR(result); - sts = ippsGFpGetInfo(Fq2, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq = (IppsGFpState*)info.pGroundGF; - // now get ref to modulus of Fq - sts = ippsGFpGetModulus(Fq, (Ipp32u*)&qDat); - BREAK_ON_IPP_ERROR(sts, result); + Ffq6 = ff->ground_ff; + if (!Ffq6) { + result = kEpidBadArgErr; + break; + } + Fq6 = Ffq6->ipp_ff; + Ffq2 = Ffq6->ground_ff; + if (!Ffq2) { + result = kEpidBadArgErr; + break; + } + Fq2 = Ffq2->ipp_ff; + Ffq = Ffq2->ground_ff; + if (!Ffq) { + result = kEpidBadArgErr; + break; + } + Fq = Ffq->ipp_ff; // extract xi from Fq6 irr poly - result = NewFfElement(&Ffq2, &xi); + result = NewFfElement(Ffq2, &xi); + BREAK_ON_EPID_ERROR(result); + result = WriteBigNum(Ffq6->modulus_0, sizeof(Fq6IrrPolynomial), + &Fq6IrrPolynomial); + BREAK_ON_EPID_ERROR(result); + result = SetFfElementOctString(&Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial), + xi, Ffq2); BREAK_ON_EPID_ERROR(result); - sts = ippsGFpGetModulus(Fq6, (Ipp32u*)&Fq6IrrPolynomial[0]); - BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpSetElement((Ipp32u const*)&Fq6IrrPolynomial[0], - sizeof(Fq6IrrPolynomial[0]) / sizeof(Ipp32u), - xi->ipp_ff_elem, Fq2); - BREAK_ON_IPP_ERROR(sts, result); // first coefficent is -xi sts = ippsGFpNeg(xi->ipp_ff_elem, xi->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); - paring_state_ctx = (PairingState*)SAFE_ALLOC(sizeof(PairingState)); - if (!paring_state_ctx) { + pairing_state_ctx = (PairingState*)SAFE_ALLOC(sizeof(PairingState)); + if (!pairing_state_ctx) { result = kEpidMemAllocErr; break; } // 1. Set param(pairing) = (param(G1), param(G2), param(GT), t, neg) - paring_state_ctx->ga = (EcGroup*)ga; - paring_state_ctx->gb = (EcGroup*)gb; - paring_state_ctx->ff = ff; - result = NewBigNum(sizeof(BigNumStr), &paring_state_ctx->t); + pairing_state_ctx->ga = (EcGroup*)ga; + pairing_state_ctx->gb = (EcGroup*)gb; + pairing_state_ctx->ff = ff; + result = NewBigNum(sizeof(BigNumStr), &pairing_state_ctx->t); BREAK_ON_EPID_ERROR(result); - result = ReadBigNum(t, sizeof(BigNumStr), paring_state_ctx->t); - BREAK_ON_EPID_ERROR(result); - paring_state_ctx->neg = neg; - result = InitFiniteFieldFromIpp(Fq6, &(paring_state_ctx->Fq6)); - BREAK_ON_EPID_ERROR(result); - result = InitFiniteFieldFromIpp(Fq2, &(paring_state_ctx->Fq2)); - BREAK_ON_EPID_ERROR(result); - result = InitFiniteFieldFromIpp(Fq, &(paring_state_ctx->Fq)); + result = ReadBigNum(t, sizeof(BigNumStr), pairing_state_ctx->t); BREAK_ON_EPID_ERROR(result); + pairing_state_ctx->neg = neg; + pairing_state_ctx->Fq6 = Ffq6; + pairing_state_ctx->Fq2 = Ffq2; + pairing_state_ctx->Fq = Ffq; // 2. Let g[0][0], ..., g[0][4], g[1][0], ..., g[1][4], g[2][0], ..., // g[2][4] be 15 elements in Fq2. for (i = 0; i < 3; i++) { for (j = 0; j < 5; j++) { - result = NewFfElement(&Ffq2, &paring_state_ctx->g[i][j]); + result = NewFfElement(Ffq2, &pairing_state_ctx->g[i][j]); BREAK_ON_EPID_ERROR(result); } } @@ -220,15 +219,10 @@ EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb, BREAK_ON_EPID_ERROR(result); result = ReadBigNum(one_str, sizeof(one_str), one); BREAK_ON_EPID_ERROR(result); - result = NewBigNum(sizeof(BigNumStr), &q); - BREAK_ON_EPID_ERROR(result); - sts = ippsSet_BN(IppsBigNumPOS, sizeof(qDat) / sizeof(Ipp32u), - (Ipp32u*)&qDat, q->ipp_bn); - BREAK_ON_IPP_ERROR(sts, result); result = NewBigNum(sizeof(BigNumStr), &e); BREAK_ON_EPID_ERROR(result); // q - 1 - sts = ippsSub_BN(q->ipp_bn, one->ipp_bn, e->ipp_bn); + sts = ippsSub_BN(Ffq->modulus_0->ipp_bn, one->ipp_bn, e->ipp_bn); BREAK_ON_IPP_ERROR(sts, result); result = NewBigNum(sizeof(BigNumStr), &six); BREAK_ON_EPID_ERROR(result); @@ -243,58 +237,57 @@ EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb, BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpScratchBufferSize(1, bitSize, Fq2, &bufferSize); BREAK_ON_IPP_ERROR(sts, result); - scratch_buffer = (Ipp8u*)SAFE_ALLOC(bufferSize); + scratch_buffer = (OctStr)SAFE_ALLOC(bufferSize); if (!scratch_buffer) { result = kEpidMemAllocErr; break; } - sts = - ippsGFpExp(xi->ipp_ff_elem, e->ipp_bn, - paring_state_ctx->g[0][0]->ipp_ff_elem, Fq2, scratch_buffer); + sts = ippsGFpExp(xi->ipp_ff_elem, e->ipp_bn, + pairing_state_ctx->g[0][0]->ipp_ff_elem, Fq2, + scratch_buffer); BREAK_ON_IPP_ERROR(sts, result); // 5. For i = 0, ..., 4, compute for (i = 0; i < 5; i++) { // a. If i > 0, compute g[0][i] = Fq2.mul(g[0][i-1], g[0][0]). if (i > 0) { - sts = ippsGFpMul(paring_state_ctx->g[0][i - 1]->ipp_ff_elem, - paring_state_ctx->g[0][0]->ipp_ff_elem, - paring_state_ctx->g[0][i]->ipp_ff_elem, Fq2); + sts = ippsGFpMul(pairing_state_ctx->g[0][i - 1]->ipp_ff_elem, + pairing_state_ctx->g[0][0]->ipp_ff_elem, + pairing_state_ctx->g[0][i]->ipp_ff_elem, Fq2); } // b. Compute g[1][i] = Fq2.conjugate(g[0][i]), - sts = ippsGFpConj(paring_state_ctx->g[0][i]->ipp_ff_elem, - paring_state_ctx->g[1][i]->ipp_ff_elem, Fq2); + sts = ippsGFpConj(pairing_state_ctx->g[0][i]->ipp_ff_elem, + pairing_state_ctx->g[1][i]->ipp_ff_elem, Fq2); // c. Compute g[1][i] = Fq2.mul(g[0][i], g[1][i]), - sts = ippsGFpMul(paring_state_ctx->g[0][i]->ipp_ff_elem, - paring_state_ctx->g[1][i]->ipp_ff_elem, - paring_state_ctx->g[1][i]->ipp_ff_elem, Fq2); + sts = ippsGFpMul(pairing_state_ctx->g[0][i]->ipp_ff_elem, + pairing_state_ctx->g[1][i]->ipp_ff_elem, + pairing_state_ctx->g[1][i]->ipp_ff_elem, Fq2); // d. Compute g[2][i] = Fq2.mul(g[0][i], g[1][i]). - sts = ippsGFpMul(paring_state_ctx->g[0][i]->ipp_ff_elem, - paring_state_ctx->g[1][i]->ipp_ff_elem, - paring_state_ctx->g[2][i]->ipp_ff_elem, Fq2); + sts = ippsGFpMul(pairing_state_ctx->g[0][i]->ipp_ff_elem, + pairing_state_ctx->g[1][i]->ipp_ff_elem, + pairing_state_ctx->g[2][i]->ipp_ff_elem, Fq2); } // 6. Save g[0][0], ..., g[0][4], g[1][0], ..., g[1][4], g[2][0], ..., // g[2][4] // for the pairing operations. - *ps = paring_state_ctx; + *ps = pairing_state_ctx; result = kEpidNoErr; } while (0); SAFE_FREE(scratch_buffer) DeleteBigNum(&six); DeleteBigNum(&e); - DeleteBigNum(&q); DeleteBigNum(&one); DeleteFfElement(&xi); if (kEpidNoErr != result) { - if (paring_state_ctx) { + if (pairing_state_ctx) { int i = 0; int j = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 5; j++) { - DeleteFfElement(&paring_state_ctx->g[i][j]); + DeleteFfElement(&pairing_state_ctx->g[i][j]); } } - DeleteBigNum(&paring_state_ctx->t); - SAFE_FREE(paring_state_ctx); + DeleteBigNum(&pairing_state_ctx->t); + SAFE_FREE(pairing_state_ctx); } } return result; @@ -325,8 +318,8 @@ void DeletePairingState(PairingState** ps) { } } -EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, - EcPoint const* b) { +EpidStatus Pairing(PairingState* ps, EcPoint const* a, EcPoint const* b, + FfElement* d) { EpidStatus result = kEpidErr; FfElement* ax = NULL; FfElement* ay = NULL; @@ -349,6 +342,9 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, Ipp32u two_dat[] = {2}; Ipp32u six_dat[] = {6}; Ipp32u one_dat[] = {1}; + G1ElemStr first_val_str = {0}; + G2ElemStr second_val_str = {0}; + bool in_group = true; int s_ternary[sizeof(BigNumStr) * CHAR_BIT] = {0}; int i = 0; int n = 0; @@ -357,8 +353,12 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, result = kEpidBadArgErr; break; } + if (!ps->Fq || !ps->Fq2) { + result = kEpidBadArgErr; + break; + } if (!d->ipp_ff_elem || !a->ipp_ec_pt || !b->ipp_ec_pt || !ps->ff || - !ps->ff->ipp_ff || !ps->Fq.ipp_ff || !ps->Fq2.ipp_ff || !ps->t || + !ps->ff->ipp_ff || !ps->Fq->ipp_ff || !ps->Fq2->ipp_ff || !ps->t || !ps->t->ipp_bn || !ps->ga || !ps->ga->ipp_ec || !ps->gb || !ps->gb->ipp_ec) { result = kEpidBadArgErr; @@ -366,29 +366,29 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, } // Let ax, ay be elements in Fq. Let bx, by, x, y, z, z2, bx', by' // be elements in Fq2. Let f be a variable in GT. - result = NewFfElement(&ps->Fq, &ax); + result = NewFfElement(ps->Fq, &ax); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &ay); + result = NewFfElement(ps->Fq, &ay); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &bx); + result = NewFfElement(ps->Fq2, &bx); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &by); + result = NewFfElement(ps->Fq2, &by); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &x); + result = NewFfElement(ps->Fq2, &x); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &y); + result = NewFfElement(ps->Fq2, &y); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &z); + result = NewFfElement(ps->Fq2, &z); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &z2); + result = NewFfElement(ps->Fq2, &z2); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &bx_); + result = NewFfElement(ps->Fq2, &bx_); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &by_); + result = NewFfElement(ps->Fq2, &by_); BREAK_ON_EPID_ERROR(result); result = NewFfElement(ps->ff, &f); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq2, &neg_qy); + result = NewFfElement(ps->Fq2, &neg_qy); BREAK_ON_EPID_ERROR(result); // 1. If neg = 0, compute integer s = 6t + 2, otherwise, compute @@ -420,23 +420,43 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, Ternary(s_ternary, &n, sizeof(s_ternary) / sizeof(s_ternary[0]), s); BREAK_ON_EPID_ERROR(result); // 3. Set (ax, ay) = E(Fq).outputPoint(a) + // check if a is in ga that was used to create ps + result = WriteEcPoint(ps->ga, a, &first_val_str, sizeof(first_val_str)); + BREAK_ON_EPID_ERROR(result); + result = + EcInGroup(ps->ga, &first_val_str, sizeof(first_val_str), &in_group); + BREAK_ON_EPID_ERROR(result); + if (false == in_group) { + result = kEpidBadArgErr; + break; + } sts = ippsGFpECGetPoint(a->ipp_ec_pt, ax->ipp_ff_elem, ay->ipp_ff_elem, ps->ga->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); // 4. Set (bx, by) = E(Fq2).outputPoint(b). + // check if b is in gb that was used to create ps + result = WriteEcPoint(ps->gb, b, &second_val_str, sizeof(second_val_str)); + BREAK_ON_EPID_ERROR(result); + result = + EcInGroup(ps->gb, &second_val_str, sizeof(second_val_str), &in_group); + BREAK_ON_EPID_ERROR(result); + if (false == in_group) { + result = kEpidBadArgErr; + break; + } sts = ippsGFpECGetPoint(b->ipp_ec_pt, bx->ipp_ff_elem, by->ipp_ff_elem, ps->gb->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); // 5. Set X = bx, Y = by, Z = Z2 = 1. - sts = ippsGFpCpyElement(bx->ipp_ff_elem, x->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpCpyElement(bx->ipp_ff_elem, x->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpCpyElement(by->ipp_ff_elem, y->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpCpyElement(by->ipp_ff_elem, y->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement(one_dat, sizeof(one_dat) / sizeof(Ipp32u), - z->ipp_ff_elem, ps->Fq2.ipp_ff); + z->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement(one_dat, sizeof(one_dat) / sizeof(Ipp32u), - z2->ipp_ff_elem, ps->Fq2.ipp_ff); + z2->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 6. Set d = 1. sts = ippsGFpSetElement(one_dat, sizeof(one_dat) / sizeof(Ipp32u), @@ -459,7 +479,7 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, // i. Set (f, x, y, z, z2) = line(ax, ay, x, y, z, z2, bx, // -by), BREAK_ON_EPID_ERROR(result); - sts = ippsGFpNeg(by->ipp_ff_elem, neg_qy->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpNeg(by->ipp_ff_elem, neg_qy->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); result = Line(ps->ff, f, x, y, z, z2, ax, ay, x, y, z, z2, bx, neg_qy); BREAK_ON_EPID_ERROR(result); @@ -482,7 +502,7 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, // 8. if neg = true, if (ps->neg) { // a. Set Y = Fq2.negate(y), - sts = ippsGFpNeg(y->ipp_ff_elem, y->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpNeg(y->ipp_ff_elem, y->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // b. Set d = Fq12.conjugate(d). sts = ippsGFpConj(d->ipp_ff_elem, d->ipp_ff_elem, ps->ff->ipp_ff); @@ -501,7 +521,7 @@ EpidStatus Pairing(PairingState* ps, FfElement* d, EcPoint const* a, result = PiOp(ps, bx_, by_, bx, by, 2); BREAK_ON_EPID_ERROR(result); // 13. Set by' = Fq2.negate(by'). - sts = ippsGFpNeg(by_->ipp_ff_elem, by_->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpNeg(by_->ipp_ff_elem, by_->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 14. Set (f, x, y, z, z2) = line(ax, ay, x, y, z, z2, bx', by'). result = Line(ps->ff, f, x, y, z, z2, ax, ay, x, y, z, z2, bx_, by_); @@ -791,8 +811,9 @@ static EpidStatus PiOp(PairingState* ps, FfElement* x_out, FfElement* y_out, IppStatus sts = ippStsNoErr; IppsGFpState* Fq2 = 0; IppsGFpState* Fq6 = 0; - FiniteField* Fq12 = 0; - IppsGFpInfo info = {0}; + FiniteField* Ffq12 = 0; + FiniteField* Ffq6 = 0; + FiniteField* Ffq2 = 0; // check parameters if (!ps || !x_out || !y_out || !x || !y) { return kEpidBadArgErr; @@ -800,14 +821,21 @@ static EpidStatus PiOp(PairingState* ps, FfElement* x_out, FfElement* y_out, if (e < 1 || e > 3) { return kEpidBadArgErr; } - Fq12 = ps->ff; + Ffq12 = ps->ff; // get Fq6, Fq2 - sts = ippsGFpGetInfo(Fq12->ipp_ff, &info); - RETURN_ON_IPP_ERROR(sts); - Fq6 = (IppsGFpState*)info.pGroundGF; - sts = ippsGFpGetInfo(Fq6, &info); - RETURN_ON_IPP_ERROR(sts); - Fq2 = (IppsGFpState*)info.pGroundGF; + if (!Ffq12) { + return kEpidBadArgErr; + } + Ffq6 = Ffq12->ground_ff; + if (!Ffq6) { + return kEpidBadArgErr; + } + Fq6 = Ffq6->ipp_ff; + Ffq2 = Ffq6->ground_ff; + if (!Ffq2) { + return kEpidBadArgErr; + } + Fq2 = Ffq2->ipp_ff; // 1. Set x' = x and y' = y. sts = ippsGFpCpyElement(x->ipp_ff_elem, x_out->ipp_ff_elem, Fq2); RETURN_ON_IPP_ERROR(sts); @@ -853,18 +881,21 @@ static EpidStatus FrobeniusOp(PairingState* ps, FfElement* d_out, if (!ps || !d_out || !a) { return kEpidBadArgErr; } - if (e < 1 || e > 3 || !d_out->ipp_ff_elem || !a->ipp_ff_elem || !ps->ff || - !ps->ff->ipp_ff || !ps->Fq2.ipp_ff) { + if (!ps->ff || !ps->Fq2) { + return kEpidBadArgErr; + } + if (e < 1 || e > 3 || !d_out->ipp_ff_elem || !a->ipp_ff_elem || + !ps->ff->ipp_ff || !ps->Fq2->ipp_ff) { return kEpidBadArgErr; } for (i = 0; i < sizeof(d) / sizeof(FfElement*); i++) { - result = NewFfElement(&ps->Fq2, &d[i]); + result = NewFfElement(ps->Fq2, &d[i]); BREAK_ON_EPID_ERROR(result); } // 1. Let a = ((a[0], a[2], a[4]), (a[1], a[3], a[5])). - sts = ippsGFpGetElement(a->ipp_ff_elem, (Ipp32u*)&a_dat, + sts = ippsGFpGetElement(a->ipp_ff_elem, (BNU)&a_dat, sizeof(a_dat) / sizeof(Ipp32u), ps->ff->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 2. Let d = ((d[0], d[2], d[4]), (d[1], d[3], d[5])). @@ -872,66 +903,67 @@ static EpidStatus FrobeniusOp(PairingState* ps, FfElement* d_out, // a. set d[i] = a[i]. sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0].x[0], sizeof(a_dat.x[0].x[0]) / sizeof(Ipp32u), - d[0]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[0]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0].x[1], sizeof(a_dat.x[0].x[1]) / sizeof(Ipp32u), - d[2]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[2]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0].x[2], sizeof(a_dat.x[0].x[2]) / sizeof(Ipp32u), - d[4]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[4]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1].x[0], sizeof(a_dat.x[1].x[0]) / sizeof(Ipp32u), - d[1]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[1]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1].x[1], sizeof(a_dat.x[1].x[1]) / sizeof(Ipp32u), - d[3]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[3]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1].x[2], sizeof(a_dat.x[1].x[2]) / sizeof(Ipp32u), - d[5]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[5]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // b. If e = 1 or 3, set d[i] = Fq2.conjugate(d[i]). if (1 == e || 3 == e) { for (i = 0; i < sizeof(d) / sizeof(FfElement*); i++) { - sts = ippsGFpConj(d[i]->ipp_ff_elem, d[i]->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = + ippsGFpConj(d[i]->ipp_ff_elem, d[i]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); } } // 4. For i = 1, ..., 5, compute d[i] = Fq2.mul(d[i], g[e-1][i-1]). for (i = 1; i < sizeof(d) / sizeof(FfElement*); i++) { sts = ippsGFpMul(d[i]->ipp_ff_elem, ps->g[e - 1][i - 1]->ipp_ff_elem, - d[i]->ipp_ff_elem, ps->Fq2.ipp_ff); + d[i]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); } // 5. Return d. - sts = ippsGFpGetElement(d[0]->ipp_ff_elem, (Ipp32u*)&d_dat.x[0].x[0], + sts = ippsGFpGetElement(d[0]->ipp_ff_elem, (BNU)&d_dat.x[0].x[0], sizeof(d_dat.x[0].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(d[2]->ipp_ff_elem, (Ipp32u*)&d_dat.x[0].x[1], + sts = ippsGFpGetElement(d[2]->ipp_ff_elem, (BNU)&d_dat.x[0].x[1], sizeof(d_dat.x[0].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(d[4]->ipp_ff_elem, (Ipp32u*)&d_dat.x[0].x[2], + sts = ippsGFpGetElement(d[4]->ipp_ff_elem, (BNU)&d_dat.x[0].x[2], sizeof(d_dat.x[0].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(d[1]->ipp_ff_elem, (Ipp32u*)&d_dat.x[1].x[0], + sts = ippsGFpGetElement(d[1]->ipp_ff_elem, (BNU)&d_dat.x[1].x[0], sizeof(d_dat.x[1].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(d[3]->ipp_ff_elem, (Ipp32u*)&d_dat.x[1].x[1], + sts = ippsGFpGetElement(d[3]->ipp_ff_elem, (BNU)&d_dat.x[1].x[1], sizeof(d_dat.x[1].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(d[5]->ipp_ff_elem, (Ipp32u*)&d_dat.x[1].x[2], + sts = ippsGFpGetElement(d[5]->ipp_ff_elem, (BNU)&d_dat.x[1].x[2], sizeof(d_dat.x[1].x[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&d_dat, sizeof(d_dat) / sizeof(Ipp32u), d_out->ipp_ff_elem, ps->ff->ipp_ff); @@ -977,8 +1009,8 @@ static EpidStatus Line(FiniteField* gt, FfElement* f, FfElement* x_out, IppStatus sts = ippStsNoErr; IppsGFpState* Fq2 = 0; IppsGFpState* Fq6 = 0; - IppsGFpInfo info = {0}; - FiniteField Ffq2; + FiniteField* Ffq6 = 0; + FiniteField* Ffq2 = 0; // check parameters if (!f || !x_out || !y_out || !z_out || !z2_out || !px || !py || !x || !y || @@ -995,62 +1027,64 @@ static EpidStatus Line(FiniteField* gt, FfElement* f, FfElement* x_out, break; } // get Fq6, Fq2 - sts = ippsGFpGetInfo(gt->ipp_ff, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq6 = (IppsGFpState*)info.pGroundGF; - sts = ippsGFpGetInfo(Fq6, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq2 = (IppsGFpState*)info.pGroundGF; - result = InitFiniteFieldFromIpp(Fq2, &Ffq2); - BREAK_ON_EPID_ERROR(result); + Ffq6 = gt->ground_ff; + if (!Ffq6) { + return kEpidBadArgErr; + } + Fq6 = Ffq6->ipp_ff; + Ffq2 = Ffq6->ground_ff; + if (!Ffq2) { + return kEpidBadArgErr; + } + Fq2 = Ffq2->ipp_ff; // Let t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 be temporary // elements in Fq2. All the following operations are computed in // Fq2 unless explicitly specified. - result = NewFfElement(&Ffq2, &t0); + result = NewFfElement(Ffq2, &t0); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t1); + result = NewFfElement(Ffq2, &t1); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t2); + result = NewFfElement(Ffq2, &t2); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t3); + result = NewFfElement(Ffq2, &t3); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t4); + result = NewFfElement(Ffq2, &t4); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t5); + result = NewFfElement(Ffq2, &t5); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t6); + result = NewFfElement(Ffq2, &t6); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t7); + result = NewFfElement(Ffq2, &t7); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t8); + result = NewFfElement(Ffq2, &t8); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t9); + result = NewFfElement(Ffq2, &t9); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t10); + result = NewFfElement(Ffq2, &t10); if (kEpidNoErr != result) { break; } - result = NewFfElement(&Ffq2, &t); + result = NewFfElement(Ffq2, &t); if (kEpidNoErr != result) { break; } @@ -1158,8 +1192,8 @@ static EpidStatus Line(FiniteField* gt, FfElement* f, FfElement* x_out, sts = ippsGFpSub(t9->ipp_ff_elem, t10->ipp_ff_elem, t9->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 20. Set t10 = Fq2.mul(Z', Py). - sts = ippsGFpMul_GFpE(z_out->ipp_ff_elem, py->ipp_ff_elem, t10->ipp_ff_elem, - Fq2); + sts = ippsGFpMul_PE(z_out->ipp_ff_elem, py->ipp_ff_elem, t10->ipp_ff_elem, + Fq2); BREAK_ON_IPP_ERROR(sts, result); // 21. Set t10 = t10 + t10. sts = ippsGFpAdd(t10->ipp_ff_elem, t10->ipp_ff_elem, t10->ipp_ff_elem, Fq2); @@ -1168,20 +1202,19 @@ static EpidStatus Line(FiniteField* gt, FfElement* f, FfElement* x_out, sts = ippsGFpNeg(t6->ipp_ff_elem, t6->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 23. Set t1 = Fq2.mul(t6, Px). - sts = - ippsGFpMul_GFpE(t6->ipp_ff_elem, px->ipp_ff_elem, t1->ipp_ff_elem, Fq2); + sts = ippsGFpMul_PE(t6->ipp_ff_elem, px->ipp_ff_elem, t1->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 24. Set t1 = t1 + t1. sts = ippsGFpAdd(t1->ipp_ff_elem, t1->ipp_ff_elem, t1->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 25. Set f = ((t10, 0, 0), (t1, t9, 0)). - sts = ippsGFpGetElement(t10->ipp_ff_elem, (Ipp32u*)&fDat.x[0].x[0], + sts = ippsGFpGetElement(t10->ipp_ff_elem, (BNU)&fDat.x[0].x[0], sizeof(fDat.x[0].x[0]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(t1->ipp_ff_elem, (Ipp32u*)&fDat.x[1].x[0], + sts = ippsGFpGetElement(t1->ipp_ff_elem, (BNU)&fDat.x[1].x[0], sizeof(fDat.x[1].x[0]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(t9->ipp_ff_elem, (Ipp32u*)&fDat.x[1].x[1], + sts = ippsGFpGetElement(t9->ipp_ff_elem, (BNU)&fDat.x[1].x[1], sizeof(fDat.x[1].x[1]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&fDat, sizeof(fDat) / sizeof(Ipp32u), @@ -1230,8 +1263,9 @@ static EpidStatus Tangent(FiniteField* gt, FfElement* f, FfElement* x_out, IppStatus sts = ippStsNoErr; IppsGFpState* Fq2 = NULL; IppsGFpState* Fq6 = NULL; - FiniteField Ffq2; - IppsGFpInfo info = {0}; + FiniteField* Ffq2 = NULL; + FiniteField* Ffq6 = NULL; + int i = 0; // validate input if (!gt || !f || !x_out || !y_out || !z_out || !z2_out || !px || !py || @@ -1247,33 +1281,37 @@ static EpidStatus Tangent(FiniteField* gt, FfElement* f, FfElement* x_out, break; } // get Fq2, Fq6 - sts = ippsGFpGetInfo(gt->ipp_ff, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq6 = (IppsGFpState*)info.pGroundGF; - sts = ippsGFpGetInfo(Fq6, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq2 = (IppsGFpState*)info.pGroundGF; - result = InitFiniteFieldFromIpp(Fq2, &Ffq2); - BREAK_ON_EPID_ERROR(result); + Ffq6 = gt->ground_ff; + if (!Ffq6) { + result = kEpidBadArgErr; + break; + } + Fq6 = Ffq6->ipp_ff; + Ffq2 = Ffq6->ground_ff; + if (!Ffq2) { + result = kEpidBadArgErr; + break; + } + Fq2 = Ffq2->ipp_ff; // Let t0, t1, t2, t3, t4, t5, t6 be elements in Fq2. All the following // operations are computed in Fq2 unless explicitly specified. // 1. Set t0 = X * X. - result = NewFfElement(&Ffq2, &t0); + result = NewFfElement(Ffq2, &t0); BREAK_ON_EPID_ERROR(result); sts = ippsGFpMul(x->ipp_ff_elem, x->ipp_ff_elem, t0->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 2. Set t1 = Y * Y. - result = NewFfElement(&Ffq2, &t1); + result = NewFfElement(Ffq2, &t1); BREAK_ON_EPID_ERROR(result); sts = ippsGFpMul(y->ipp_ff_elem, y->ipp_ff_elem, t1->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 3. Set t2 = t1 * t1. - result = NewFfElement(&Ffq2, &t2); + result = NewFfElement(Ffq2, &t2); BREAK_ON_EPID_ERROR(result); sts = ippsGFpMul(t1->ipp_ff_elem, t1->ipp_ff_elem, t2->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 4. Set t3 = (t1 + X)^2 - t0 - t2. - result = NewFfElement(&Ffq2, &t3); + result = NewFfElement(Ffq2, &t3); BREAK_ON_EPID_ERROR(result); sts = ippsGFpAdd(t1->ipp_ff_elem, x->ipp_ff_elem, t3->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); @@ -1287,19 +1325,19 @@ static EpidStatus Tangent(FiniteField* gt, FfElement* f, FfElement* x_out, sts = ippsGFpAdd(t3->ipp_ff_elem, t3->ipp_ff_elem, t3->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 6. Set t4 = 3 * t0. - result = NewFfElement(&Ffq2, &t4); + result = NewFfElement(Ffq2, &t4); BREAK_ON_EPID_ERROR(result); sts = ippsGFpAdd(t0->ipp_ff_elem, t0->ipp_ff_elem, t4->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(t4->ipp_ff_elem, t0->ipp_ff_elem, t4->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 7. Set t6 = X + t4. - result = NewFfElement(&Ffq2, &t6); + result = NewFfElement(Ffq2, &t6); BREAK_ON_EPID_ERROR(result); sts = ippsGFpAdd(x->ipp_ff_elem, t4->ipp_ff_elem, t6->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 8. Set t5 = t4 * t4. - result = NewFfElement(&Ffq2, &t5); + result = NewFfElement(Ffq2, &t5); BREAK_ON_EPID_ERROR(result); sts = ippsGFpMul(t4->ipp_ff_elem, t4->ipp_ff_elem, t5->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); @@ -1341,8 +1379,7 @@ static EpidStatus Tangent(FiniteField* gt, FfElement* f, FfElement* x_out, sts = ippsGFpNeg(t3->ipp_ff_elem, t3->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 13.Set t3 = Fq2.mul(t3, Px). - sts = - ippsGFpMul_GFpE(t3->ipp_ff_elem, px->ipp_ff_elem, t3->ipp_ff_elem, Fq2); + sts = ippsGFpMul_PE(t3->ipp_ff_elem, px->ipp_ff_elem, t3->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 14.Set t6 = t6 * t6 - t0 - t5 - 4 * t1. sts = ippsGFpMul(t6->ipp_ff_elem, t6->ipp_ff_elem, t6->ipp_ff_elem, Fq2); @@ -1361,17 +1398,16 @@ static EpidStatus Tangent(FiniteField* gt, FfElement* f, FfElement* x_out, sts = ippsGFpAdd(t0->ipp_ff_elem, t0->ipp_ff_elem, t0->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 16.Set t0 = Fq2.mul(t0, Py). - sts = - ippsGFpMul_GFpE(t0->ipp_ff_elem, py->ipp_ff_elem, t0->ipp_ff_elem, Fq2); + sts = ippsGFpMul_PE(t0->ipp_ff_elem, py->ipp_ff_elem, t0->ipp_ff_elem, Fq2); BREAK_ON_IPP_ERROR(sts, result); // 17.Set f = ((t0, 0, 0), (t3, t6, 0)). - sts = ippsGFpGetElement(t0->ipp_ff_elem, (Ipp32u*)&fDat.x[0].x[0], + sts = ippsGFpGetElement(t0->ipp_ff_elem, (BNU)&fDat.x[0].x[0], sizeof(fDat.x[0].x[0]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(t3->ipp_ff_elem, (Ipp32u*)&fDat.x[1].x[0], + sts = ippsGFpGetElement(t3->ipp_ff_elem, (BNU)&fDat.x[1].x[0], sizeof(fDat.x[1].x[0]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(t6->ipp_ff_elem, (Ipp32u*)&fDat.x[1].x[1], + sts = ippsGFpGetElement(t6->ipp_ff_elem, (BNU)&fDat.x[1].x[1], sizeof(fDat.x[1].x[1]) / sizeof(Ipp32u), Fq2); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&fDat, sizeof(fDat) / sizeof(Ipp32u), @@ -1425,7 +1461,7 @@ static EpidStatus Ternary(int* s, int* n, int max_elements, BigNum const* x) { int flag = 0; int i = 0; int num_bits = 0; - Ipp32u* data = 0; + IppBNU data = 0; // check parameters if (!s || !n || !x || !x->ipp_bn) { @@ -1525,59 +1561,65 @@ static EpidStatus MulXiFast(FfElement* e, FfElement const* a, retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } - if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq.ipp_ff || - !ps->Fq2.ipp_ff) { + if (!ps->Fq || !ps->Fq2) { + retvalue = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(retvalue); + } + if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq->ipp_ff || + !ps->Fq2->ipp_ff) { retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } // All the following arithmetic operations are in ps->Fq. // 1. Let a = (a[0], a[1]), xi = (xi[0], xi[1]), and e = (e[0], e[1]). - retvalue = NewFfElement(&(ps->Fq), &a0); + retvalue = NewFfElement(ps->Fq, &a0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq), &a1); + retvalue = NewFfElement(ps->Fq, &a1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq), &e0); + retvalue = NewFfElement(ps->Fq, &e0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq), &e1); + retvalue = NewFfElement(ps->Fq, &e1); BREAK_ON_EPID_ERROR(retvalue); - sts = ippsGFpGetElement(a->ipp_ff_elem, (Ipp32u*)&a_dat, - sizeof(a_dat) / sizeof(Ipp32u), ps->Fq2.ipp_ff); + sts = ippsGFpGetElement(a->ipp_ff_elem, (BNU)&a_dat, + sizeof(a_dat) / sizeof(Ipp32u), ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0], sizeof(a_dat.x[0]) / sizeof(Ipp32u), - a0->ipp_ff_elem, ps->Fq.ipp_ff); + a0->ipp_ff_elem, ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1], sizeof(a_dat.x[1]) / sizeof(Ipp32u), - a1->ipp_ff_elem, ps->Fq.ipp_ff); + a1->ipp_ff_elem, ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 4. If xi[0] = 2, xi[1] = 1, beta = -1, then e[0] and e[1] can // be computed as // a. e[0] = a[0] + a[0] - a[1]. sts = ippsGFpAdd(a0->ipp_ff_elem, a0->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq.ipp_ff); + ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSub(e0->ipp_ff_elem, a1->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq.ipp_ff); + ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // b. e[1] = a[0] + a[1] + a[1]. sts = ippsGFpAdd(a0->ipp_ff_elem, a1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq.ipp_ff); + ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpAdd(e1->ipp_ff_elem, a1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq.ipp_ff); + ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 5. Return e = (e[0], e[1]). - sts = ippsGFpGetElement(e0->ipp_ff_elem, (Ipp32u*)&e_dat.x[0], - sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq.ipp_ff); + sts = + ippsGFpGetElement(e0->ipp_ff_elem, (BNU)&e_dat.x[0], + sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); - sts = ippsGFpGetElement(e1->ipp_ff_elem, (Ipp32u*)&e_dat.x[1], - sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq.ipp_ff); + sts = + ippsGFpGetElement(e1->ipp_ff_elem, (BNU)&e_dat.x[1], + sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&e_dat, sizeof(e_dat) / sizeof(Ipp32u), - e->ipp_ff_elem, ps->Fq2.ipp_ff); + e->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); retvalue = kEpidNoErr; } while (0); @@ -1614,27 +1656,31 @@ static EpidStatus MulV(FfElement* e, FfElement* a, PairingState* ps) { retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } - if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq2.ipp_ff || - !ps->Fq6.ipp_ff) { + if (!ps->Fq2 || !ps->Fq6) { + retvalue = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(retvalue); + } + if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq2->ipp_ff || + !ps->Fq6->ipp_ff) { retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } // 1. Let a = (a[0], a[1], a[2]) and e = (e[0], e[1], e[2]). - retvalue = NewFfElement(&(ps->Fq2), &a2); + retvalue = NewFfElement(ps->Fq2, &a2); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e0); + retvalue = NewFfElement(ps->Fq2, &e0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e1); + retvalue = NewFfElement(ps->Fq2, &e1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e2); + retvalue = NewFfElement(ps->Fq2, &e2); BREAK_ON_EPID_ERROR(retvalue); - sts = ippsGFpGetElement(a->ipp_ff_elem, (Ipp32u*)&a_dat, - sizeof(a_dat) / sizeof(Ipp32u), ps->Fq6.ipp_ff); + sts = ippsGFpGetElement(a->ipp_ff_elem, (BNU)&a_dat, + sizeof(a_dat) / sizeof(Ipp32u), ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[2], sizeof(a_dat.x[2]) / sizeof(Ipp32u), - a2->ipp_ff_elem, ps->Fq2.ipp_ff); + a2->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 2. e[0] = Fq2.mulXi(a[2]). retvalue = MulXiFast(e0, a2, ps); @@ -1645,11 +1691,11 @@ static EpidStatus MulV(FfElement* e, FfElement* a, PairingState* ps) { e_dat.x[2] = a_dat.x[1]; sts = - ippsGFpGetElement(e0->ipp_ff_elem, (Ipp32u*)&e_dat.x[0], - sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq2.ipp_ff); + ippsGFpGetElement(e0->ipp_ff_elem, (BNU)&e_dat.x[0], + sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&e_dat, sizeof(e_dat) / sizeof(Ipp32u), - e->ipp_ff_elem, ps->Fq6.ipp_ff); + e->ipp_ff_elem, ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); retvalue = kEpidNoErr; } while (0); @@ -1696,121 +1742,125 @@ static EpidStatus Fq6MulGFpE2(FfElement* e, FfElement* a, FfElement* b0, retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } + if (!ps->Fq2 || !ps->Fq6) { + retvalue = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(retvalue); + } if (!e->ipp_ff_elem || !a->ipp_ff_elem || !b0->ipp_ff_elem || - !b1->ipp_ff_elem || !ps->Fq2.ipp_ff || !ps->Fq6.ipp_ff) { + !b1->ipp_ff_elem || !ps->Fq2->ipp_ff || !ps->Fq6->ipp_ff) { retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } // Let t0, t1, t3, t4 be temporary variables in Fq2. All the // following arithmetic operations are in Fq2. - retvalue = NewFfElement(&(ps->Fq2), &t0); + retvalue = NewFfElement(ps->Fq2, &t0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &t1); + retvalue = NewFfElement(ps->Fq2, &t1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &t2); + retvalue = NewFfElement(ps->Fq2, &t2); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &t3); + retvalue = NewFfElement(ps->Fq2, &t3); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &t4); + retvalue = NewFfElement(ps->Fq2, &t4); BREAK_ON_EPID_ERROR(retvalue); // 1. Let a = (a[0], a[1], a[2]) and e = (e[0], e[1], e[2]). - retvalue = NewFfElement(&(ps->Fq2), &a0); + retvalue = NewFfElement(ps->Fq2, &a0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &a1); + retvalue = NewFfElement(ps->Fq2, &a1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &a2); + retvalue = NewFfElement(ps->Fq2, &a2); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e0); + retvalue = NewFfElement(ps->Fq2, &e0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e1); + retvalue = NewFfElement(ps->Fq2, &e1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &e2); + retvalue = NewFfElement(ps->Fq2, &e2); BREAK_ON_EPID_ERROR(retvalue); - sts = ippsGFpGetElement(a->ipp_ff_elem, (Ipp32u*)&a_dat, - sizeof(a_dat) / sizeof(Ipp32u), ps->Fq6.ipp_ff); + sts = ippsGFpGetElement(a->ipp_ff_elem, (BNU)&a_dat, + sizeof(a_dat) / sizeof(Ipp32u), ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0], sizeof(a_dat.x[0]) / sizeof(Ipp32u), - a0->ipp_ff_elem, ps->Fq2.ipp_ff); + a0->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1], sizeof(a_dat.x[1]) / sizeof(Ipp32u), - a1->ipp_ff_elem, ps->Fq2.ipp_ff); + a1->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[2], sizeof(a_dat.x[2]) / sizeof(Ipp32u), - a2->ipp_ff_elem, ps->Fq2.ipp_ff); + a2->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 2. t0 = a[0] * b[0]. sts = ippsGFpMul(a0->ipp_ff_elem, b0->ipp_ff_elem, t0->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 3. t1 = a[1] * b[1]. sts = ippsGFpMul(a1->ipp_ff_elem, b1->ipp_ff_elem, t1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 4. t3 = a[1] + a[2]. sts = ippsGFpAdd(a1->ipp_ff_elem, a2->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 5. t3 = t3 * b[1]. sts = ippsGFpMul(t3->ipp_ff_elem, b1->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 6. t3 = t3 - t1. sts = ippsGFpSub(t3->ipp_ff_elem, t1->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 7. e[0] = Fq2.mulXi(t3) + t0. retvalue = MulXiFast(e0, t3, ps); BREAK_ON_EPID_ERROR(retvalue); sts = ippsGFpAdd(e0->ipp_ff_elem, t0->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 8. t3 = a[0] + a[1]. sts = ippsGFpAdd(a0->ipp_ff_elem, a1->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 9. t4 = b[0] + b[1]. sts = ippsGFpAdd(b0->ipp_ff_elem, b1->ipp_ff_elem, t4->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 10. t3 = t3 * t4. sts = ippsGFpMul(t3->ipp_ff_elem, t4->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 11. e[1] = t3 - t0 - t1. sts = ippsGFpSub(t3->ipp_ff_elem, t0->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSub(e1->ipp_ff_elem, t1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 12. t3 = a[2] * b[0]. sts = ippsGFpMul(a2->ipp_ff_elem, b0->ipp_ff_elem, t3->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 13. e[2] = t3 + t1. sts = ippsGFpAdd(t3->ipp_ff_elem, t1->ipp_ff_elem, e2->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 14. Return e. sts = - ippsGFpGetElement(e0->ipp_ff_elem, (Ipp32u*)&e_dat.x[0], - sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq2.ipp_ff); + ippsGFpGetElement(e0->ipp_ff_elem, (BNU)&e_dat.x[0], + sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = - ippsGFpGetElement(e1->ipp_ff_elem, (Ipp32u*)&e_dat.x[1], - sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq2.ipp_ff); + ippsGFpGetElement(e1->ipp_ff_elem, (BNU)&e_dat.x[1], + sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = - ippsGFpGetElement(e2->ipp_ff_elem, (Ipp32u*)&e_dat.x[2], - sizeof(e_dat.x[2]) / sizeof(Ipp32u), ps->Fq2.ipp_ff); + ippsGFpGetElement(e2->ipp_ff_elem, (BNU)&e_dat.x[2], + sizeof(e_dat.x[2]) / sizeof(Ipp32u), ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&e_dat, sizeof(e_dat) / sizeof(Ipp32u), - e->ipp_ff_elem, ps->Fq6.ipp_ff); + e->ipp_ff_elem, ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); retvalue = kEpidNoErr; } while (0); @@ -1863,73 +1913,78 @@ static EpidStatus MulSpecial(FfElement* e, FfElement const* a, retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } + if (!ps->Fq2 || !ps->Fq6) { + retvalue = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(retvalue); + } if (!e->ipp_ff_elem || !a->ipp_ff_elem || !b->ipp_ff_elem || - !ps->Fq2.ipp_ff || !ps->Fq6.ipp_ff || !ps->ff || !ps->ff->ipp_ff) { + !ps->Fq2->ipp_ff || !ps->Fq6->ipp_ff || !ps->ff || !ps->ff->ipp_ff) { retvalue = kEpidBadArgErr; BREAK_ON_EPID_ERROR(retvalue); } // Let t0, t1, t2 be temporary variables in ps->Fq6. - retvalue = NewFfElement(&(ps->Fq6), &t0); + retvalue = NewFfElement(ps->Fq6, &t0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq6), &t1); + retvalue = NewFfElement(ps->Fq6, &t1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq6), &t2); + retvalue = NewFfElement(ps->Fq6, &t2); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &b0plusb1); + retvalue = NewFfElement(ps->Fq2, &b0plusb1); BREAK_ON_EPID_ERROR(retvalue); // 1. Let a = (a[0], a[1]) and e = (e[0], e[1]). - retvalue = NewFfElement(&(ps->Fq6), &a0); + retvalue = NewFfElement(ps->Fq6, &a0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq6), &a1); + retvalue = NewFfElement(ps->Fq6, &a1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq6), &e0); + retvalue = NewFfElement(ps->Fq6, &e0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq6), &e1); + retvalue = NewFfElement(ps->Fq6, &e1); BREAK_ON_EPID_ERROR(retvalue); - sts = ippsGFpGetElement(a->ipp_ff_elem, (Ipp32u*)&a_dat, + sts = ippsGFpGetElement(a->ipp_ff_elem, (BNU)&a_dat, sizeof(a_dat) / sizeof(Ipp32u), ps->ff->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[0], sizeof(a_dat.x[0]) / sizeof(Ipp32u), - a0->ipp_ff_elem, ps->Fq6.ipp_ff); + a0->ipp_ff_elem, ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&a_dat.x[1], sizeof(a_dat.x[1]) / sizeof(Ipp32u), - a1->ipp_ff_elem, ps->Fq6.ipp_ff); + a1->ipp_ff_elem, ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 2. Let b = ((b[0], b[2], b[4]), (b[1], b[3], b[5])) where // b[0], ..., b[5] are elements in ps->Fq2 and b[2] = b[4] = b[5] // = 0. - retvalue = NewFfElement(&(ps->Fq2), &b0); + retvalue = NewFfElement(ps->Fq2, &b0); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &b1); + retvalue = NewFfElement(ps->Fq2, &b1); BREAK_ON_EPID_ERROR(retvalue); - retvalue = NewFfElement(&(ps->Fq2), &b3); + retvalue = NewFfElement(ps->Fq2, &b3); BREAK_ON_EPID_ERROR(retvalue); - sts = ippsGFpGetElement(b->ipp_ff_elem, (Ipp32u*)&b_dat, + sts = ippsGFpGetElement(b->ipp_ff_elem, (BNU)&b_dat, sizeof(b_dat) / sizeof(Ipp32u), ps->ff->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&b_dat.x[0].x[0], sizeof(a_dat.x[0].x[0]) / sizeof(Ipp32u), - b0->ipp_ff_elem, ps->Fq2.ipp_ff); + b0->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&b_dat.x[1].x[0], sizeof(a_dat.x[1].x[0]) / sizeof(Ipp32u), - b1->ipp_ff_elem, ps->Fq2.ipp_ff); + b1->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&b_dat.x[1].x[1], sizeof(a_dat.x[1].x[1]) / sizeof(Ipp32u), - b3->ipp_ff_elem, ps->Fq2.ipp_ff); + b3->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 3. t0 = ps->Fq6.mul(a[0], b[0]). - sts = ippsGFpMul_GFpE(a0->ipp_ff_elem, b0->ipp_ff_elem, t0->ipp_ff_elem, - ps->Fq6.ipp_ff); + + sts = ippsGFpMul_PE(a0->ipp_ff_elem, b0->ipp_ff_elem, t0->ipp_ff_elem, + ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 4. t1 = ps->Fq6.mul(a[1], b[1], b[3]). retvalue = Fq6MulGFpE2(t1, a1, b1, b3, ps); @@ -1939,34 +1994,34 @@ static EpidStatus MulSpecial(FfElement* e, FfElement const* a, BREAK_ON_EPID_ERROR(retvalue); // 6. e[0] = ps->Fq6.add(t0, e[0]). sts = ippsGFpAdd(t0->ipp_ff_elem, e0->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq6.ipp_ff); + ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 7. t2 = ps->Fq6.add(a[0], a[1]). sts = ippsGFpAdd(a0->ipp_ff_elem, a1->ipp_ff_elem, t2->ipp_ff_elem, - ps->Fq6.ipp_ff); + ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 8. e[1] = ps->Fq6.mul(t2, b[0] + b[1], b[3]). sts = ippsGFpAdd(b0->ipp_ff_elem, b1->ipp_ff_elem, b0plusb1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); retvalue = Fq6MulGFpE2(e1, t2, b0plusb1, b3, ps); BREAK_ON_EPID_ERROR(retvalue); // 9. e[1] = ps->Fq6.subtract(e[1], t0). sts = ippsGFpSub(e1->ipp_ff_elem, t0->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq6.ipp_ff); + ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 10. e[1] = ps->Fq6.subtract(e[1], t1). sts = ippsGFpSub(e1->ipp_ff_elem, t1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq6.ipp_ff); + ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); // 11. Return e. sts = - ippsGFpGetElement(e0->ipp_ff_elem, (Ipp32u*)&e_dat.x[0], - sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq6.ipp_ff); + ippsGFpGetElement(e0->ipp_ff_elem, (BNU)&e_dat.x[0], + sizeof(e_dat.x[0]) / sizeof(Ipp32u), ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = - ippsGFpGetElement(e1->ipp_ff_elem, (Ipp32u*)&e_dat.x[1], - sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq6.ipp_ff); + ippsGFpGetElement(e1->ipp_ff_elem, (BNU)&e_dat.x[1], + sizeof(e_dat.x[1]) / sizeof(Ipp32u), ps->Fq6->ipp_ff); BREAK_ON_IPP_ERROR(sts, retvalue); sts = ippsGFpSetElement((Ipp32u*)&e_dat, sizeof(e_dat) / sizeof(Ipp32u), e->ipp_ff_elem, ps->ff->ipp_ff); @@ -2002,74 +2057,76 @@ static EpidStatus SquareForFq4(PairingState* ps, FfElement* e0, FfElement* e1, FfElement* t0 = NULL; FfElement* t1 = NULL; FfElement* xi = NULL; - Fq2ElemStr Fq6IrrPolynomial[3 + 1] = {0}; + Fq2ElemStr Fq6IrrPolynomial = {0}; // check parameters if (!e0 || !e1 || !a0 || !a1 || !ps) return kEpidBadArgErr; - + if (!ps->Fq2 || !ps->Fq6) { + return kEpidBadArgErr; + } if (!e0->ipp_ff_elem || !e1->ipp_ff_elem || !a0->ipp_ff_elem || - !a1->ipp_ff_elem || !ps->ff || !ps->ff->ipp_ff || !ps->Fq2.ipp_ff || - !ps->Fq6.ipp_ff) + !a1->ipp_ff_elem || !ps->ff || !ps->ff->ipp_ff || !ps->Fq2->ipp_ff || + !ps->Fq6->ipp_ff) return kEpidBadArgErr; do { IppStatus sts = ippStsNoErr; // extract xi from Fq6 irr poly - result = NewFfElement(&(ps->Fq2), &xi); + result = NewFfElement(ps->Fq2, &xi); + BREAK_ON_EPID_ERROR(result); + result = WriteBigNum(ps->Fq6->modulus_0, sizeof(Fq6IrrPolynomial), + &Fq6IrrPolynomial); + BREAK_ON_EPID_ERROR(result); + result = SetFfElementOctString(&Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial), + xi, ps->Fq2); BREAK_ON_EPID_ERROR(result); - sts = ippsGFpGetModulus(ps->Fq6.ipp_ff, (Ipp32u*)&Fq6IrrPolynomial[0]); - BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpSetElement((Ipp32u const*)&Fq6IrrPolynomial[0], - sizeof(Fq6IrrPolynomial[0]) / sizeof(Ipp32u), - xi->ipp_ff_elem, ps->Fq2.ipp_ff); - BREAK_ON_IPP_ERROR(sts, result); // first coefficent is -xi - sts = ippsGFpNeg(xi->ipp_ff_elem, xi->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpNeg(xi->ipp_ff_elem, xi->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // Let t0, t1 be temporary variables in Fq2. All the following // operations are computed in Fq2. - result = NewFfElement(&(ps->Fq2), &t0); + result = NewFfElement(ps->Fq2, &t0); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t1); + result = NewFfElement(ps->Fq2, &t1); BREAK_ON_EPID_ERROR(result); // 1. Set t0 = a0 * a0. sts = ippsGFpMul(a0->ipp_ff_elem, a0->ipp_ff_elem, t0->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 2. Set t1 = a1 * a1. sts = ippsGFpMul(a1->ipp_ff_elem, a1->ipp_ff_elem, t1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 3. Set e0 = t1 * xi. sts = ippsGFpMul(t1->ipp_ff_elem, xi->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 4. Set e0 = e0 + t0. sts = ippsGFpAdd(e0->ipp_ff_elem, t0->ipp_ff_elem, e0->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 5. Set e1 = a0 + a1. sts = ippsGFpAdd(a0->ipp_ff_elem, a1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 6. Set e1 = e1 * e1 - t0 - t1. sts = ippsGFpMul(e1->ipp_ff_elem, e1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e1->ipp_ff_elem, t0->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e1->ipp_ff_elem, t1->ipp_ff_elem, e1->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 7. Return (e0, e1). result = kEpidNoErr; } while (0); - EpidZeroMemory(Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial)); + EpidZeroMemory(&Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial)); DeleteFfElement(&t0); DeleteFfElement(&t1); DeleteFfElement(&xi); @@ -2099,80 +2156,82 @@ static EpidStatus SquareCyclotomic(PairingState* ps, FfElement* e_out, int i = 0; Fq12ElemStr a_str = {0}; Fq12ElemStr e_str = {0}; - Fq2ElemStr Fq6IrrPolynomial[3 + 1] = {0}; + Fq2ElemStr Fq6IrrPolynomial = {0}; // check parameters if (!e_out || !a_in || !ps) return kEpidBadArgErr; - + if (!ps->Fq || !ps->Fq2 || !ps->Fq6) { + return kEpidBadArgErr; + } if (!e_out->ipp_ff_elem || !a_in->ipp_ff_elem || !ps->ff || !ps->ff->ipp_ff || - !ps->Fq.ipp_ff || !ps->Fq2.ipp_ff || !ps->Fq6.ipp_ff) + !ps->Fq->ipp_ff || !ps->Fq2->ipp_ff || !ps->Fq6->ipp_ff) return kEpidBadArgErr; do { IppStatus sts = ippStsNoErr; // extract xi from Fq6 irr poly - result = NewFfElement(&(ps->Fq2), &xi); + result = NewFfElement(ps->Fq2, &xi); + BREAK_ON_EPID_ERROR(result); + result = WriteBigNum(ps->Fq6->modulus_0, sizeof(Fq6IrrPolynomial), + &Fq6IrrPolynomial); + BREAK_ON_EPID_ERROR(result); + result = SetFfElementOctString(&Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial), + xi, ps->Fq2); BREAK_ON_EPID_ERROR(result); - sts = ippsGFpGetModulus(ps->Fq6.ipp_ff, (Ipp32u*)&Fq6IrrPolynomial); - BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpSetElement((Ipp32u const*)&Fq6IrrPolynomial[0], - sizeof(Fq6IrrPolynomial[0]) / sizeof(Ipp32u), - xi->ipp_ff_elem, ps->Fq2.ipp_ff); - BREAK_ON_IPP_ERROR(sts, result); // first coefficent is -xi - sts = ippsGFpNeg(xi->ipp_ff_elem, xi->ipp_ff_elem, ps->Fq2.ipp_ff); + sts = ippsGFpNeg(xi->ipp_ff_elem, xi->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // Let t00, t01, t02, t10, t11, t12 be temporary variables in // Fq2. All the following operations are computed in Fq2 unless // specified otherwise. - result = NewFfElement(&(ps->Fq2), &t00); + result = NewFfElement(ps->Fq2, &t00); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t01); + result = NewFfElement(ps->Fq2, &t01); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t02); + result = NewFfElement(ps->Fq2, &t02); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t10); + result = NewFfElement(ps->Fq2, &t10); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t11); + result = NewFfElement(ps->Fq2, &t11); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &t12); + result = NewFfElement(ps->Fq2, &t12); BREAK_ON_EPID_ERROR(result); for (i = 0; i < 6; i++) { - result = NewFfElement(&(ps->Fq2), &a[i]); + result = NewFfElement(ps->Fq2, &a[i]); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&(ps->Fq2), &e[i]); + result = NewFfElement(ps->Fq2, &e[i]); BREAK_ON_EPID_ERROR(result); } BREAK_ON_EPID_ERROR(result); // 1. Let a = ((a[0], a[2], a[4]), (a[1], a[3], a[5])). - sts = ippsGFpGetElement(a_in->ipp_ff_elem, (Ipp32u*)&a_str, + sts = ippsGFpGetElement(a_in->ipp_ff_elem, (BNU)&a_str, sizeof(a_str) / sizeof(Ipp32u), ps->ff->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[0].a[0], sizeof(a_str.a[0].a[0]) / sizeof(Ipp32u), - a[0]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[0]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[0].a[1], sizeof(a_str.a[0].a[1]) / sizeof(Ipp32u), - a[2]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[2]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[0].a[2], sizeof(a_str.a[0].a[2]) / sizeof(Ipp32u), - a[4]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[4]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[1].a[0], sizeof(a_str.a[1].a[0]) / sizeof(Ipp32u), - a[1]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[1]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[1].a[1], sizeof(a_str.a[1].a[1]) / sizeof(Ipp32u), - a[3]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[3]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&a_str.a[1].a[2], sizeof(a_str.a[1].a[2]) / sizeof(Ipp32u), - a[5]->ipp_ff_elem, ps->Fq2.ipp_ff); + a[5]->ipp_ff_elem, ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 2. Let e = ((e[0], e[2], e[4]), (e[1], e[3], e[5])). @@ -2187,110 +2246,110 @@ static EpidStatus SquareCyclotomic(PairingState* ps, FfElement* e_out, BREAK_ON_EPID_ERROR(result); // 6. Set t10 = t10 * xi. sts = ippsGFpMul(t10->ipp_ff_elem, xi->ipp_ff_elem, t10->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 7. Set e[0] = 3 * t00 - 2 * a[0]. sts = ippsGFpAdd(t00->ipp_ff_elem, t00->ipp_ff_elem, e[0]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[0]->ipp_ff_elem, t00->ipp_ff_elem, e[0]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[0]->ipp_ff_elem, a[0]->ipp_ff_elem, e[0]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[0]->ipp_ff_elem, a[0]->ipp_ff_elem, e[0]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 8. Set e[2] = 3 * t01 - 2 * a[2]. sts = ippsGFpAdd(t01->ipp_ff_elem, t01->ipp_ff_elem, e[2]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[2]->ipp_ff_elem, t01->ipp_ff_elem, e[2]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[2]->ipp_ff_elem, a[2]->ipp_ff_elem, e[2]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[2]->ipp_ff_elem, a[2]->ipp_ff_elem, e[2]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 9. Set e[4] = 3 * t02 - 2 * a[4]. sts = ippsGFpAdd(t02->ipp_ff_elem, t02->ipp_ff_elem, e[4]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[4]->ipp_ff_elem, t02->ipp_ff_elem, e[4]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[4]->ipp_ff_elem, a[4]->ipp_ff_elem, e[4]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSub(e[4]->ipp_ff_elem, a[4]->ipp_ff_elem, e[4]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 10. Set e[1] = 3 * t10 + 2 * a[1]. sts = ippsGFpAdd(t10->ipp_ff_elem, t10->ipp_ff_elem, e[1]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[1]->ipp_ff_elem, t10->ipp_ff_elem, e[1]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[1]->ipp_ff_elem, a[1]->ipp_ff_elem, e[1]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[1]->ipp_ff_elem, a[1]->ipp_ff_elem, e[1]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 11. Set e[3] = 3 * t11 + 2 * a[3]. sts = ippsGFpAdd(t11->ipp_ff_elem, t11->ipp_ff_elem, e[3]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[3]->ipp_ff_elem, t11->ipp_ff_elem, e[3]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[3]->ipp_ff_elem, a[3]->ipp_ff_elem, e[3]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[3]->ipp_ff_elem, a[3]->ipp_ff_elem, e[3]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 12. Set e[5] = 3 * t12 + 2 * a[5]. sts = ippsGFpAdd(t12->ipp_ff_elem, t12->ipp_ff_elem, e[5]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[5]->ipp_ff_elem, t12->ipp_ff_elem, e[5]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[5]->ipp_ff_elem, a[5]->ipp_ff_elem, e[5]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpAdd(e[5]->ipp_ff_elem, a[5]->ipp_ff_elem, e[5]->ipp_ff_elem, - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); // 13. Return e. - sts = ippsGFpGetElement(e[0]->ipp_ff_elem, (Ipp32u*)&e_str.a[0].a[0], + sts = ippsGFpGetElement(e[0]->ipp_ff_elem, (BNU)&e_str.a[0].a[0], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(e[2]->ipp_ff_elem, (Ipp32u*)&e_str.a[0].a[1], + sts = ippsGFpGetElement(e[2]->ipp_ff_elem, (BNU)&e_str.a[0].a[1], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(e[4]->ipp_ff_elem, (Ipp32u*)&e_str.a[0].a[2], + sts = ippsGFpGetElement(e[4]->ipp_ff_elem, (BNU)&e_str.a[0].a[2], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(e[1]->ipp_ff_elem, (Ipp32u*)&e_str.a[1].a[0], + sts = ippsGFpGetElement(e[1]->ipp_ff_elem, (BNU)&e_str.a[1].a[0], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(e[3]->ipp_ff_elem, (Ipp32u*)&e_str.a[1].a[1], + sts = ippsGFpGetElement(e[3]->ipp_ff_elem, (BNU)&e_str.a[1].a[1], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); - sts = ippsGFpGetElement(e[5]->ipp_ff_elem, (Ipp32u*)&e_str.a[1].a[2], + sts = ippsGFpGetElement(e[5]->ipp_ff_elem, (BNU)&e_str.a[1].a[2], sizeof(e_str.a[0].a[0]) / sizeof(Ipp32u), - ps->Fq2.ipp_ff); + ps->Fq2->ipp_ff); BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpSetElement((Ipp32u*)&e_str, sizeof(e_str) / sizeof(Ipp32u), e_out->ipp_ff_elem, ps->ff->ipp_ff); @@ -2300,7 +2359,7 @@ static EpidStatus SquareCyclotomic(PairingState* ps, FfElement* e_out, EpidZeroMemory(&a_str, sizeof(a_str)); EpidZeroMemory(&e_str, sizeof(e_str)); - EpidZeroMemory(Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial)); + EpidZeroMemory(&Fq6IrrPolynomial, sizeof(Fq6IrrPolynomial)); DeleteFfElement(&t00); DeleteFfElement(&t01); DeleteFfElement(&t02); @@ -2336,15 +2395,17 @@ static EpidStatus ExpCyclotomic(PairingState* ps, FfElement* e, // check parameters if (!e || !a || !b || !ps) return kEpidBadArgErr; - - if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq.ipp_ff || !ps->Fq2.ipp_ff || - !b->ipp_bn) + if (!ps->Fq || !ps->Fq2) { + return kEpidBadArgErr; + } + if (!e->ipp_ff_elem || !a->ipp_ff_elem || !ps->Fq->ipp_ff || + !ps->Fq2->ipp_ff || !b->ipp_bn) return kEpidBadArgErr; do { IppStatus sts = ippStsNoErr; int num_bits = 0; - Ipp32u* b_str = 0; + IppBNU b_str = 0; int i = 0; // 1. Let bn...b1b0 be the binary representation of b. diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/printutils.c b/external/epid-sdk/epid/common/math/src/printutils.c similarity index 85% rename from external/epid-sdk-3.0.0/epid/common/math/src/printutils.c rename to external/epid-sdk/epid/common/math/src/printutils.c index d1b1e81f..cd474636 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/printutils.c +++ b/external/epid-sdk/epid/common/math/src/printutils.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,11 +27,11 @@ #include #include -#include "ext/ipp/include/ippcp.h" #include "epid/common/math/src/bignum-internal.h" #include "epid/common/math/src/ecgroup-internal.h" #include "epid/common/math/src/finitefield-internal.h" #include "epid/common/src/memory.h" +#include "ext/ipp/include/ippcp.h" /// Allowed number of characters printed in one line #define WIDTH 49 @@ -57,7 +57,7 @@ /// Print to specified stream #define PRINT(...) fprintf(stdout, __VA_ARGS__) -static int PrintBuf(void const* buf, size_t size) { +static int PrintBuf(ConstOctStr buf, size_t size) { size_t curr_column = 0; size_t i = 0; if (!buf || size == 0) { @@ -117,14 +117,14 @@ void PrintBigNum(BigNum const* big_num, char const* var_name) { PRINT("\n"); break; } - sts = ippsGetOctString_BN((Ipp8u*)buf, ipp_word_buf_size * sizeof(Ipp32u), + sts = ippsGetOctString_BN((OctStr)buf, ipp_word_buf_size * sizeof(Ipp32u), big_num->ipp_bn); if (ippStsNoErr != sts) { MAKE_INDENT(); PRINT("\n"); break; } - if (0 != PrintBuf((const void*)buf, ipp_word_buf_size * sizeof(Ipp32u))) { + if (0 != PrintBuf((ConstOctStr)buf, ipp_word_buf_size * sizeof(Ipp32u))) { MAKE_INDENT(); PRINT("\n"); break; @@ -157,9 +157,9 @@ void PrintFfElement(FiniteField const* ff, FfElement const* ff_element, } // get the data - ipp_ff_element_size = ff_element->info.elementLen * sizeof(Ipp32u); + ipp_ff_element_size = ff_element->element_len * sizeof(Ipp32u); sts = ippsGFpGetElementOctString(ff_element->ipp_ff_elem, - (Ipp8u*)&ff_element_str, ipp_ff_element_size, + (OctStr)&ff_element_str, ipp_ff_element_size, ff->ipp_ff); if (ippStsNoErr != sts) { PRINT("%s (FfElement):\n", var_name); @@ -189,7 +189,7 @@ void PrintFfElement(FiniteField const* ff, FfElement const* ff_element, void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point, char const* var_name, PrintUtilFormat format) { - FiniteField fp; + FiniteField* fp = NULL; FfElement* fp_x = NULL; FfElement* fp_y = NULL; uint8_t ec_point_str[sizeof(G2ElemStr)]; @@ -202,7 +202,7 @@ void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point, PRINT("\n"); return; } - if (!ec_point->ipp_ec_pt || !g->ipp_ec) { + if (!ec_point->ipp_ec_pt || !g->ff || !g->ipp_ec) { PRINT("%s (EcPoint):\n", var_name); MAKE_INDENT(); PRINT("\n"); @@ -212,31 +212,24 @@ void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point, IppStatus sts = ippStsNoErr; int ipp_half_strlen; // get finite field - sts = ippsGFpECGet(g->ipp_ec, (const IppsGFpState**)&(fp.ipp_ff), 0, 0, 0, - 0, 0, 0, 0, 0); - if (ippStsNoErr != sts) { - PRINT("%s (EcPoint):\n", var_name); - MAKE_INDENT(); - PRINT("\n"); - break; - } + fp = g->ff; // create element X - if (kEpidNoErr != NewFfElement(&fp, &fp_x)) { + if (kEpidNoErr != NewFfElement(fp, &fp_x)) { PRINT("%s (EcPoint):\n", var_name); MAKE_INDENT(); PRINT("\n"); break; } // create element Y - if (kEpidNoErr != NewFfElement(&fp, &fp_y)) { + if (kEpidNoErr != NewFfElement(fp, &fp_y)) { PRINT("%s (EcPoint):\n", var_name); MAKE_INDENT(); PRINT("\n"); break; } - ipp_half_strlen = fp_x->info.elementLen * sizeof(Ipp32u); + ipp_half_strlen = fp_x->element_len * sizeof(Ipp32u); // get elements from point sts = ippsGFpECGetPoint(ec_point->ipp_ec_pt, fp_x->ipp_ff_elem, @@ -250,8 +243,9 @@ void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point, } // get element X data - sts = ippsGFpGetElementOctString(fp_x->ipp_ff_elem, (Ipp8u*)&ec_point_str, - ipp_half_strlen, fp.ipp_ff); + sts = + ippsGFpGetElementOctString(fp_x->ipp_ff_elem, (IppOctStr)&ec_point_str, + ipp_half_strlen, fp->ipp_ff); // check return codes if (ippStsNoErr != sts) { PRINT("%s (EcPoint):\n", var_name); @@ -261,8 +255,8 @@ void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point, } // get element Y data sts = ippsGFpGetElementOctString(fp_y->ipp_ff_elem, - (Ipp8u*)&ec_point_str + ipp_half_strlen, - ipp_half_strlen, fp.ipp_ff); + (IppOctStr)&ec_point_str + ipp_half_strlen, + ipp_half_strlen, fp->ipp_ff); // check return codes if (ippStsNoErr != sts) { PRINT("%s (EcPoint):\n", var_name); @@ -297,7 +291,7 @@ void PrintBigNumStr(BigNumStr const* big_num_str, char const* var_name) { PRINT("\n"); return; } - if (0 != PrintBuf((const void*)big_num_str, sizeof(*big_num_str))) { + if (0 != PrintBuf((ConstOctStr)big_num_str, sizeof(*big_num_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -314,7 +308,7 @@ void PrintFpElemStr(FpElemStr const* fp_elem_str, char const* var_name) { PRINT("\n"); return; } - if (0 != PrintBuf((const void*)fp_elem_str, sizeof(*fp_elem_str))) { + if (0 != PrintBuf((ConstOctStr)fp_elem_str, sizeof(*fp_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -331,7 +325,7 @@ void PrintFqElemStr(FqElemStr const* fq_elem_str, char const* var_name) { PRINT("\n"); return; } - if (0 != PrintBuf((const void*)fq_elem_str, sizeof(*fq_elem_str))) { + if (0 != PrintBuf((ConstOctStr)fq_elem_str, sizeof(*fq_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -352,7 +346,7 @@ void PrintFq2ElemStr(Fq2ElemStr const* fq2_elem_str, char const* var_name, if (format == kPrintUtilAnnotated) { MAKE_INDENT(); PRINT("a0:\n"); - if (0 != PrintBuf((const void*)&fq2_elem_str->a[0], + if (0 != PrintBuf((ConstOctStr)&fq2_elem_str->a[0], sizeof(fq2_elem_str->a[0]))) { MAKE_INDENT(); PRINT("\n"); @@ -360,14 +354,14 @@ void PrintFq2ElemStr(Fq2ElemStr const* fq2_elem_str, char const* var_name, } MAKE_INDENT(); PRINT("a1:\n"); - if (0 != PrintBuf((const void*)&fq2_elem_str->a[1], + if (0 != PrintBuf((ConstOctStr)&fq2_elem_str->a[1], sizeof(fq2_elem_str->a[1]))) { MAKE_INDENT(); PRINT("\n"); return; } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)fq2_elem_str, sizeof(*fq2_elem_str))) { + if (0 != PrintBuf((ConstOctStr)fq2_elem_str, sizeof(*fq2_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -399,7 +393,7 @@ void PrintFq6ElemStr(Fq6ElemStr const* fq6_elem_str, char const* var_name, j++) { MAKE_INDENT(); PRINT("a%u.%u:\n", i, j); - if (0 != PrintBuf((const void*)&fq6_elem_str->a[i].a[j], + if (0 != PrintBuf((ConstOctStr)&fq6_elem_str->a[i].a[j], sizeof(fq6_elem_str->a[i].a[j]))) { MAKE_INDENT(); PRINT("\n"); @@ -408,7 +402,7 @@ void PrintFq6ElemStr(Fq6ElemStr const* fq6_elem_str, char const* var_name, } } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)fq6_elem_str, sizeof(*fq6_elem_str))) { + if (0 != PrintBuf((ConstOctStr)fq6_elem_str, sizeof(*fq6_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -445,7 +439,7 @@ void PrintFq12ElemStr(Fq12ElemStr const* fq12_elem_str, char const* var_name, k++) { MAKE_INDENT(); PRINT("a%u.%u.%u:\n", i, j, k); - if (0 != PrintBuf((const void*)&fq12_elem_str->a[i].a[j].a[k], + if (0 != PrintBuf((ConstOctStr)&fq12_elem_str->a[i].a[j].a[k], sizeof(fq12_elem_str->a[i].a[j].a[k]))) { MAKE_INDENT(); PRINT("\n"); @@ -455,7 +449,7 @@ void PrintFq12ElemStr(Fq12ElemStr const* fq12_elem_str, char const* var_name, } } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)fq12_elem_str, sizeof(*fq12_elem_str))) { + if (0 != PrintBuf((ConstOctStr)fq12_elem_str, sizeof(*fq12_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -481,20 +475,20 @@ void PrintG1ElemStr(G1ElemStr const* g1_elem_str, char const* var_name, if (format == kPrintUtilAnnotated) { MAKE_INDENT(); PRINT("x:\n"); - if (0 != PrintBuf((const void*)&g1_elem_str->x, sizeof(g1_elem_str->x))) { + if (0 != PrintBuf((ConstOctStr)&g1_elem_str->x, sizeof(g1_elem_str->x))) { MAKE_INDENT(); PRINT("\n"); return; } MAKE_INDENT(); PRINT("y:\n"); - if (0 != PrintBuf((const void*)&g1_elem_str->y, sizeof(g1_elem_str->y))) { + if (0 != PrintBuf((ConstOctStr)&g1_elem_str->y, sizeof(g1_elem_str->y))) { MAKE_INDENT(); PRINT("\n"); return; } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)g1_elem_str, sizeof(*g1_elem_str))) { + if (0 != PrintBuf((ConstOctStr)g1_elem_str, sizeof(*g1_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -521,7 +515,7 @@ void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name, MAKE_INDENT(); PRINT("x0:\n"); if (0 != - PrintBuf((const void*)&g2_elem_str->x[0], sizeof(g2_elem_str->x[0]))) { + PrintBuf((ConstOctStr)&g2_elem_str->x[0], sizeof(g2_elem_str->x[0]))) { MAKE_INDENT(); PRINT("\n"); return; @@ -529,7 +523,7 @@ void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name, MAKE_INDENT(); PRINT("x1:\n"); if (0 != - PrintBuf((const void*)&g2_elem_str->x[1], sizeof(g2_elem_str->x[1]))) { + PrintBuf((ConstOctStr)&g2_elem_str->x[1], sizeof(g2_elem_str->x[1]))) { MAKE_INDENT(); PRINT("\n"); return; @@ -537,7 +531,7 @@ void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name, MAKE_INDENT(); PRINT("y0:\n"); if (0 != - PrintBuf((const void*)&g2_elem_str->y[0], sizeof(g2_elem_str->y[0]))) { + PrintBuf((ConstOctStr)&g2_elem_str->y[0], sizeof(g2_elem_str->y[0]))) { MAKE_INDENT(); PRINT("\n"); return; @@ -545,13 +539,13 @@ void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name, MAKE_INDENT(); PRINT("y1:\n"); if (0 != - PrintBuf((const void*)&g2_elem_str->y[1], sizeof(g2_elem_str->y[1]))) { + PrintBuf((ConstOctStr)&g2_elem_str->y[1], sizeof(g2_elem_str->y[1]))) { MAKE_INDENT(); PRINT("\n"); return; } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)g2_elem_str, sizeof(*g2_elem_str))) { + if (0 != PrintBuf((ConstOctStr)g2_elem_str, sizeof(*g2_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; @@ -579,7 +573,7 @@ void PrintGtElemStr(GtElemStr const* gt_elem_str, char const* var_name, for (i = 0; i < sizeof(gt_elem_str->x) / sizeof(gt_elem_str->x[0]); i++) { MAKE_INDENT(); PRINT("x%u:\n", i); - if (0 != PrintBuf((const void*)>_elem_str->x[i], + if (0 != PrintBuf((ConstOctStr)>_elem_str->x[i], sizeof(gt_elem_str->x[i]))) { MAKE_INDENT(); PRINT("\n"); @@ -587,7 +581,7 @@ void PrintGtElemStr(GtElemStr const* gt_elem_str, char const* var_name, } } } else if (format == kPrintUtilUnannotated) { - if (0 != PrintBuf((const void*)gt_elem_str, sizeof(*gt_elem_str))) { + if (0 != PrintBuf((ConstOctStr)gt_elem_str, sizeof(*gt_elem_str))) { MAKE_INDENT(); PRINT("\n"); return; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/sha256.c b/external/epid-sdk/epid/common/math/src/sha256.c similarity index 88% rename from external/epid-sdk-3.0.0/epid/common/math/src/sha256.c rename to external/epid-sdk/epid/common/math/src/sha256.c index 7f1b3f31..cea65de6 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/sha256.c +++ b/external/epid-sdk/epid/common/math/src/sha256.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * \brief SHA256 implementation. */ #include "epid/common/math/hash.h" +#include "epid/common/math/src/bignum-internal.h" #include "ext/ipp/include/ippcp.h" EpidStatus Sha256MessageDigest(void const* msg, size_t len, @@ -30,7 +31,7 @@ EpidStatus Sha256MessageDigest(void const* msg, size_t len, if (INT_MAX < len) return kEpidBadArgErr; - sts = ippsSHA256MessageDigest(msg, ipp_len, (Ipp8u*)digest); + sts = ippsSHA256MessageDigest(msg, ipp_len, (IppOctStr)digest); if (ippStsNoErr != sts) { if (ippStsLengthErr == sts) { return kEpidBadArgErr; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/tatepairing-internal.h b/external/epid-sdk/epid/common/math/src/tatepairing-internal.h similarity index 92% rename from external/epid-sdk-3.0.0/epid/common/math/src/tatepairing-internal.h rename to external/epid-sdk/epid/common/math/src/tatepairing-internal.h index 019f3ff1..163f4f34 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/tatepairing-internal.h +++ b/external/epid-sdk/epid/common/math/src/tatepairing-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ struct Epid11PairingState { BigNum* final_exp_constant; ///< (q^2 - q + 1)/p FfElement* fq3_inv_constant; ///< (inverse(qnr), 0) in Fq3 FfElement* fq3_inv2_constant; ///< (inverse(qnr)^2, 0) in Fq3 - FiniteField Fq; ///< Fq - FiniteField Fq3; ///< Fq3 + FiniteField* Fq; ///< Fq + FiniteField* Fq3; ///< Fq3 FfElement* alpha_q[3]; ///< {t^(0*q), t^(1*q), t^(2*q)} }; diff --git a/external/epid-sdk-3.0.0/epid/common/math/src/tatepairing.c b/external/epid-sdk/epid/common/math/src/tatepairing.c similarity index 65% rename from external/epid-sdk-3.0.0/epid/common/math/src/tatepairing.c rename to external/epid-sdk/epid/common/math/src/tatepairing.c index 0267eb96..adc42eb3 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/src/tatepairing.c +++ b/external/epid-sdk/epid/common/math/src/tatepairing.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,17 @@ /*! * \file -* \brief EPID 1.1 pairing implementation. +* \brief Intel(R) EPID 1.1 pairing implementation. */ #include "epid/common/math/tatepairing.h" #include "epid/common/1.1/types.h" #include "epid/common/math/src/bignum-internal.h" -#include "epid/common/math/src/finitefield-internal.h" #include "epid/common/math/src/ecgroup-internal.h" +#include "epid/common/math/src/finitefield-internal.h" #include "epid/common/math/src/tatepairing-internal.h" #include "epid/common/src/memory.h" #include "ext/ipp/include/ippcp.h" -#include "ext/ipp/include/ippcpepid.h" /// Handle Ipp Errors with Break #define BREAK_ON_IPP_ERROR(sts, ret) \ @@ -83,162 +82,148 @@ EpidStatus NewEpid11PairingState(EcGroup const* ga, EcGroup const* gb, FiniteField const* ff, Epid11PairingState** ps) { EpidStatus result = kEpidErr; - Epid11PairingState* paring_state_ctx = NULL; + Epid11PairingState* pairing_state_ctx = NULL; BigNum* tmp = NULL; BigNum* p = NULL; - BigNum* q = NULL; FfElement* qnr = NULL; FfElement* inv_qnr = NULL; FfElement* neg_qnr = NULL; Fq3ElemStr fq3_str = {0}; - FqElemDat q_data = {0}; int i = 0; do { IppStatus sts = ippStsNoErr; IppsGFpState* Fq3 = NULL; IppsGFpState* Fq = NULL; - IppsGFpInfo info = {0}; - Fq3ElemDat ff_modulus[3] = {0}; + Fq3ElemDat ff_modulus = {0}; uint8_t one_str[] = {1}; - const Ipp32u* p_data = NULL; - int p_len = 0; uint8_t remainder_str = 0xff; Fq3ElemStr trans_100 = {0}; Fq3ElemStr trans_010 = {0}; + FiniteField* Ffq = NULL; // validate inputs if (!ga || !gb || !ff || !ps) { result = kEpidBadArgErr; break; } - if (!ga->ipp_ec || !gb->ipp_ec || !ff->ipp_ff) { + if (!ga->ff || !ga->ipp_ec || !gb->ff || !gb->ipp_ec || !ff->ipp_ff) { result = kEpidBadArgErr; break; } - if (1 != ga->info.basicGFdegree || 3 != gb->info.basicGFdegree || - 6 != ff->info.basicGFdegree || - sizeof(Epid11G1ElemStr) != (ga->info.elementLen << 3) || - sizeof(Epid11G2ElemStr) != (gb->info.elementLen << 3) || - sizeof(Epid11GtElemStr) != (ff->info.elementLen << 2)) { + if (1 != ga->ff->basic_degree || 3 != gb->ff->basic_degree || + 6 != ff->basic_degree || + sizeof(Epid11G1ElemStr) != (ga->ff->element_len << 3) || + sizeof(Epid11G2ElemStr) != (gb->ff->element_len << 3) || + sizeof(Epid11GtElemStr) != (ff->element_len << 2)) { result = kEpidBadArgErr; break; } - paring_state_ctx = + pairing_state_ctx = (Epid11PairingState*)SAFE_ALLOC(sizeof(Epid11PairingState)); - if (!paring_state_ctx) { + if (!pairing_state_ctx) { result = kEpidMemAllocErr; break; } - // store EPID fields and groups - paring_state_ctx->ga = (EcGroup*)ga; - paring_state_ctx->gb = (EcGroup*)gb; - paring_state_ctx->ff = (FiniteField*)ff; + // store Intel(R) EPID fields and groups + pairing_state_ctx->ga = (EcGroup*)ga; + pairing_state_ctx->gb = (EcGroup*)gb; + pairing_state_ctx->ff = (FiniteField*)ff; // get Fq3, Fq - sts = ippsGFpGetInfo(ff->ipp_ff, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq3 = (IppsGFpState*)info.pGroundGF; - result = InitFiniteFieldFromIpp(Fq3, &(paring_state_ctx->Fq3)); - BREAK_ON_EPID_ERROR(result); - - sts = ippsGFpGetInfo(Fq3, &info); - BREAK_ON_IPP_ERROR(sts, result); - Fq = (IppsGFpState*)info.pGroundGF; - result = InitFiniteFieldFromIpp(Fq, &(paring_state_ctx->Fq)); - BREAK_ON_EPID_ERROR(result); + pairing_state_ctx->Fq3 = ff->ground_ff; + if (!pairing_state_ctx->Fq3) { + result = kEpidBadArgErr; + break; + } + Fq3 = pairing_state_ctx->Fq3->ipp_ff; + pairing_state_ctx->Fq = pairing_state_ctx->Fq3->ground_ff; + Ffq = pairing_state_ctx->Fq; + if (!pairing_state_ctx->Fq) { + result = kEpidBadArgErr; + break; + } + Fq = pairing_state_ctx->Fq->ipp_ff; // compute fq3_inv_constant = (inverse(qnr), 0, 0) - result = NewFfElement(&paring_state_ctx->Fq3, - &paring_state_ctx->fq3_inv_constant); + result = NewFfElement(pairing_state_ctx->Fq3, + &pairing_state_ctx->fq3_inv_constant); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&paring_state_ctx->Fq, &neg_qnr); + result = NewFfElement(pairing_state_ctx->Fq, &neg_qnr); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&paring_state_ctx->Fq, &qnr); + result = NewFfElement(pairing_state_ctx->Fq, &qnr); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&paring_state_ctx->Fq, &inv_qnr); + result = NewFfElement(pairing_state_ctx->Fq, &inv_qnr); BREAK_ON_EPID_ERROR(result); - sts = ippsGFpGetModulus(ff->ipp_ff, (Ipp32u*)&ff_modulus); - BREAK_ON_IPP_ERROR(sts, result); - sts = - ippsGFpSetElement(ff_modulus[0].x[0].x, COUNT_OF(ff_modulus[0].x[0].x), - neg_qnr->ipp_ff_elem, Fq); - BREAK_ON_IPP_ERROR(sts, result); - result = FfNeg(&paring_state_ctx->Fq, neg_qnr, qnr); + result = WriteBigNum(ff->modulus_0, sizeof(ff_modulus), &ff_modulus); BREAK_ON_EPID_ERROR(result); - result = FfInv(&paring_state_ctx->Fq, qnr, inv_qnr); + result = SetFfElementOctString((ConstOctStr)ff_modulus.x[0].x, + sizeof(ff_modulus.x[0].x), neg_qnr, + pairing_state_ctx->Fq); BREAK_ON_EPID_ERROR(result); - result = WriteFfElement(&paring_state_ctx->Fq, inv_qnr, &fq3_str.a[0], + result = FfNeg(pairing_state_ctx->Fq, neg_qnr, qnr); + BREAK_ON_EPID_ERROR(result); + result = FfInv(pairing_state_ctx->Fq, qnr, inv_qnr); + BREAK_ON_EPID_ERROR(result); + result = WriteFfElement(pairing_state_ctx->Fq, inv_qnr, &fq3_str.a[0], sizeof(fq3_str.a[0])); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&paring_state_ctx->Fq3, &fq3_str, sizeof(fq3_str), - paring_state_ctx->fq3_inv_constant); + result = ReadFfElement(pairing_state_ctx->Fq3, &fq3_str, sizeof(fq3_str), + pairing_state_ctx->fq3_inv_constant); BREAK_ON_EPID_ERROR(result); // compute fq3_inv2_constant = (inverse(qnr)^2, 0, 0) // inv_qnr = inv_qnr^2 - result = NewFfElement(&paring_state_ctx->Fq3, - &paring_state_ctx->fq3_inv2_constant); + result = NewFfElement(pairing_state_ctx->Fq3, + &pairing_state_ctx->fq3_inv2_constant); BREAK_ON_EPID_ERROR(result); - result = FfMul(&paring_state_ctx->Fq, inv_qnr, inv_qnr, inv_qnr); + result = FfMul(pairing_state_ctx->Fq, inv_qnr, inv_qnr, inv_qnr); BREAK_ON_EPID_ERROR(result); - result = WriteFfElement(&paring_state_ctx->Fq, inv_qnr, &fq3_str.a[0], + result = WriteFfElement(pairing_state_ctx->Fq, inv_qnr, &fq3_str.a[0], sizeof(fq3_str.a[0])); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&paring_state_ctx->Fq3, &fq3_str, sizeof(fq3_str), - paring_state_ctx->fq3_inv2_constant); + result = ReadFfElement(pairing_state_ctx->Fq3, &fq3_str, sizeof(fq3_str), + pairing_state_ctx->fq3_inv2_constant); BREAK_ON_EPID_ERROR(result); - // save parameter q for future use - sts = ippsGFpGetModulus(Fq, (Ipp32u*)&q_data); - BREAK_ON_IPP_ERROR(sts, result); - result = NewBigNum(sizeof(BigNumStr), &q); - BREAK_ON_EPID_ERROR(result); - sts = ippsSet_BN(IppsBigNumPOS, sizeof(q_data) / sizeof(Ipp32u), - (Ipp32u*)&q_data, q->ipp_bn); - BREAK_ON_IPP_ERROR(sts, result); - // save parameters a and p for future use - result = NewFfElement(&paring_state_ctx->Fq, &paring_state_ctx->a); + result = NewFfElement(pairing_state_ctx->Fq, &pairing_state_ctx->a); BREAK_ON_EPID_ERROR(result); result = NewBigNum(sizeof(BigNumStr), &p); BREAK_ON_EPID_ERROR(result); - sts = ippsGFpECGet(ga->ipp_ec, NULL, paring_state_ctx->a->ipp_ff_elem, NULL, - NULL, NULL, &p_data, &p_len, NULL, NULL); + sts = + ippsGFpECGet(NULL, pairing_state_ctx->a->ipp_ff_elem, NULL, ga->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); - if (p_len * sizeof(*p_data) > sizeof(BigNumStr)) { - result = kEpidErr; // order size is unexpected - break; - } - sts = ippsSet_BN(IppsBigNumPOS, p_len, p_data, p->ipp_bn); + sts = ippsGFpECGetSubgroup(NULL, NULL, NULL, p->ipp_bn, NULL, ga->ipp_ec); BREAK_ON_IPP_ERROR(sts, result); // compute p bit size requred for pairing - sts = ippsGetOctString_BN((Ipp8u*)&paring_state_ctx->p, - sizeof(paring_state_ctx->p), p->ipp_bn); + sts = ippsGetOctString_BN((OctStr)&pairing_state_ctx->p, + sizeof(pairing_state_ctx->p), p->ipp_bn); BREAK_ON_IPP_ERROR(sts, result); - paring_state_ctx->p_bitsize = OctStrBitSize( - paring_state_ctx->p.data.data, sizeof(paring_state_ctx->p.data.data)); + pairing_state_ctx->p_bitsize = OctStrBitSize( + pairing_state_ctx->p.data.data, sizeof(pairing_state_ctx->p.data.data)); // compute final_exp_constant = (q^2 - q + 1)/p - result = - NewBigNum(2 * sizeof(BigNumStr), &paring_state_ctx->final_exp_constant); + result = NewBigNum(2 * sizeof(BigNumStr), + &pairing_state_ctx->final_exp_constant); BREAK_ON_EPID_ERROR(result); result = NewBigNum(sizeof(BigNumStr), &tmp); BREAK_ON_EPID_ERROR(result); result = ReadBigNum(one_str, sizeof(one_str), tmp); BREAK_ON_EPID_ERROR(result); - result = BigNumMul(q, q, paring_state_ctx->final_exp_constant); + result = BigNumMul(Ffq->modulus_0, Ffq->modulus_0, + pairing_state_ctx->final_exp_constant); BREAK_ON_EPID_ERROR(result); - result = BigNumSub(paring_state_ctx->final_exp_constant, q, - paring_state_ctx->final_exp_constant); + result = BigNumSub(pairing_state_ctx->final_exp_constant, Ffq->modulus_0, + pairing_state_ctx->final_exp_constant); BREAK_ON_EPID_ERROR(result); - result = BigNumAdd(paring_state_ctx->final_exp_constant, tmp, - paring_state_ctx->final_exp_constant); + result = BigNumAdd(pairing_state_ctx->final_exp_constant, tmp, + pairing_state_ctx->final_exp_constant); BREAK_ON_EPID_ERROR(result); - result = BigNumDiv(paring_state_ctx->final_exp_constant, p, - paring_state_ctx->final_exp_constant, tmp); + result = BigNumDiv(pairing_state_ctx->final_exp_constant, p, + pairing_state_ctx->final_exp_constant, tmp); BREAK_ON_EPID_ERROR(result); result = WriteBigNum(tmp, sizeof(remainder_str), &remainder_str); if (kEpidNoErr != result || 0 != remainder_str) { @@ -247,51 +232,50 @@ EpidStatus NewEpid11PairingState(EcGroup const* ga, EcGroup const* gb, } for (i = 0; i < 3; i++) { - result = - NewFfElement(&paring_state_ctx->Fq3, &(paring_state_ctx->alpha_q[i])); + result = NewFfElement(pairing_state_ctx->Fq3, + &(pairing_state_ctx->alpha_q[i])); BREAK_ON_EPID_ERROR(result); } BREAK_ON_EPID_ERROR(result); /* t^(0*q) */ trans_100.a[0].data.data[31] = 1; - result = ReadFfElement(&paring_state_ctx->Fq3, &trans_100, - sizeof(trans_100), paring_state_ctx->alpha_q[0]); + result = ReadFfElement(pairing_state_ctx->Fq3, &trans_100, + sizeof(trans_100), pairing_state_ctx->alpha_q[0]); BREAK_ON_EPID_ERROR(result); /* t^(1*q) */ trans_010.a[1].data.data[31] = 1; - result = ReadFfElement(&paring_state_ctx->Fq3, &trans_010, - sizeof(trans_010), paring_state_ctx->alpha_q[1]); + result = ReadFfElement(pairing_state_ctx->Fq3, &trans_010, + sizeof(trans_010), pairing_state_ctx->alpha_q[1]); BREAK_ON_EPID_ERROR(result); - result = FfExp(&paring_state_ctx->Fq3, paring_state_ctx->alpha_q[1], q, - paring_state_ctx->alpha_q[1]); + result = FfExp(pairing_state_ctx->Fq3, pairing_state_ctx->alpha_q[1], + Ffq->modulus_0, pairing_state_ctx->alpha_q[1]); BREAK_ON_EPID_ERROR(result); /* t^(2*q) */ - result = FfMul(&paring_state_ctx->Fq3, paring_state_ctx->alpha_q[1], - paring_state_ctx->alpha_q[1], paring_state_ctx->alpha_q[2]); + result = + FfMul(pairing_state_ctx->Fq3, pairing_state_ctx->alpha_q[1], + pairing_state_ctx->alpha_q[1], pairing_state_ctx->alpha_q[2]); BREAK_ON_EPID_ERROR(result); - *ps = paring_state_ctx; + *ps = pairing_state_ctx; result = kEpidNoErr; } while (0); EpidZeroMemory(&fq3_str, sizeof(fq3_str)); - EpidZeroMemory(&q_data, sizeof(q_data)); DeleteBigNum(&p); - DeleteBigNum(&q); DeleteBigNum(&tmp); DeleteFfElement(&qnr); DeleteFfElement(&inv_qnr); DeleteFfElement(&neg_qnr); if (kEpidNoErr != result) { - if (paring_state_ctx) { - DeleteFfElement(&paring_state_ctx->a); - DeleteFfElement(&paring_state_ctx->fq3_inv_constant); - DeleteFfElement(&paring_state_ctx->fq3_inv2_constant); - DeleteBigNum(&paring_state_ctx->final_exp_constant); + if (pairing_state_ctx) { + DeleteFfElement(&pairing_state_ctx->a); + DeleteFfElement(&pairing_state_ctx->fq3_inv_constant); + DeleteFfElement(&pairing_state_ctx->fq3_inv2_constant); + DeleteBigNum(&pairing_state_ctx->final_exp_constant); for (i = 0; i < 3; i++) { - DeleteFfElement(&(paring_state_ctx->alpha_q[i])); + DeleteFfElement(&(pairing_state_ctx->alpha_q[i])); } - SAFE_FREE(paring_state_ctx); + SAFE_FREE(pairing_state_ctx); } } return result; @@ -347,7 +331,12 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, int i; if (!ps || !a || !b || !d) return kEpidBadArgErr; - + if (!ps->Fq || !ps->Fq3) { + return kEpidBadArgErr; + } + if (!ps->Fq->ipp_ff || !ps->Fq3->ipp_ff) { + return kEpidBadArgErr; + } do { Epid11GtElemStr one_fq6 = {0}; FqElemStr one_fq = {0}; @@ -365,15 +354,15 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, } // Let Q = (Q.x, Q.y), where Q.x and Q.y are elements in Fqd. - result = NewFfElement(&ps->Fq3, &b0); + result = NewFfElement(ps->Fq3, &b0); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq3, &b1); + result = NewFfElement(ps->Fq3, &b1); BREAK_ON_EPID_ERROR(result); result = WriteEcPoint(ps->gb, b, &b_str, sizeof(b_str)); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq3, &b_str.x, sizeof(b_str.x), b0); + result = ReadFfElement(ps->Fq3, &b_str.x, sizeof(b_str.x), b0); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq3, &b_str.y, sizeof(b_str.y), b1); + result = ReadFfElement(ps->Fq3, &b_str.y, sizeof(b_str.y), b1); BREAK_ON_EPID_ERROR(result); // Now we compute Qx, Qy, two elements in GT, as follows. @@ -383,59 +372,59 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, BREAK_ON_EPID_ERROR(result); // Compute Qx = (inv * Q.x, 0). - result = FfMul(&ps->Fq3, ps->fq3_inv_constant, b0, b0); + result = FfMul(ps->Fq3, ps->fq3_inv_constant, b0, b0); BREAK_ON_EPID_ERROR(result); - result = WriteFfElement(&ps->Fq3, b0, &bx_str.a[0], sizeof(bx_str.a[0])); + result = WriteFfElement(ps->Fq3, b0, &bx_str.a[0], sizeof(bx_str.a[0])); BREAK_ON_EPID_ERROR(result); result = ReadFfElement(ps->ff, &bx_str, sizeof(bx_str), pQx); BREAK_ON_EPID_ERROR(result); // Compute Qy = (0, inv^2 * Q.y). - result = FfMul(&ps->Fq3, ps->fq3_inv2_constant, b1, b1); + result = FfMul(ps->Fq3, ps->fq3_inv2_constant, b1, b1); BREAK_ON_EPID_ERROR(result); - result = WriteFfElement(&ps->Fq3, b1, &by_str.a[1], sizeof(by_str.a[1])); + result = WriteFfElement(ps->Fq3, b1, &by_str.a[1], sizeof(by_str.a[1])); BREAK_ON_EPID_ERROR(result); result = ReadFfElement(ps->ff, &by_str, sizeof(by_str), pQy); BREAK_ON_EPID_ERROR(result); // Let P = (px, py), where px, py are big integers. - result = NewFfElement(&ps->Fq, &px); + result = NewFfElement(ps->Fq, &px); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &py); + result = NewFfElement(ps->Fq, &py); BREAK_ON_EPID_ERROR(result); result = WriteEcPoint(ps->ga, a, &a_str, sizeof(a_str)); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq, &a_str.x, sizeof(a_str.x), px); + result = ReadFfElement(ps->Fq, &a_str.x, sizeof(a_str.x), px); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq, &a_str.y, sizeof(a_str.y), py); + result = ReadFfElement(ps->Fq, &a_str.y, sizeof(a_str.y), py); BREAK_ON_EPID_ERROR(result); // Let X, Y, Z, X', Y', Z', w, v, ty, ry be elements in Fq. - result = NewFfElement(&ps->Fq, &X); + result = NewFfElement(ps->Fq, &X); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &Y); + result = NewFfElement(ps->Fq, &Y); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &Z); + result = NewFfElement(ps->Fq, &Z); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &X2); + result = NewFfElement(ps->Fq, &X2); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &Y2); + result = NewFfElement(ps->Fq, &Y2); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &Z2); + result = NewFfElement(ps->Fq, &Z2); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &w); + result = NewFfElement(ps->Fq, &w); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &v); + result = NewFfElement(ps->Fq, &v); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &ty); + result = NewFfElement(ps->Fq, &ty); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &ry); + result = NewFfElement(ps->Fq, &ry); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &t1); + result = NewFfElement(ps->Fq, &t1); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &t2); + result = NewFfElement(ps->Fq, &t2); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq, &t3); + result = NewFfElement(ps->Fq, &t3); BREAK_ON_EPID_ERROR(result); // Let tx, rx be elements in GT. @@ -451,19 +440,19 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, BREAK_ON_EPID_ERROR(result); // Set X = px, - result = ReadFfElement(&ps->Fq, &a_str.x, sizeof(a_str.x), X); + result = ReadFfElement(ps->Fq, &a_str.x, sizeof(a_str.x), X); BREAK_ON_EPID_ERROR(result); // Y = py, - result = ReadFfElement(&ps->Fq, &a_str.y, sizeof(a_str.y), Y); + result = ReadFfElement(ps->Fq, &a_str.y, sizeof(a_str.y), Y); BREAK_ON_EPID_ERROR(result); // Z = 1, - result = ReadFfElement(&ps->Fq, &one_fq, sizeof(one_fq), Z); + result = ReadFfElement(ps->Fq, &one_fq, sizeof(one_fq), Z); BREAK_ON_EPID_ERROR(result); // ry = 1. - result = ReadFfElement(&ps->Fq, &one_fq, sizeof(one_fq), ry); + result = ReadFfElement(ps->Fq, &one_fq, sizeof(one_fq), ry); BREAK_ON_EPID_ERROR(result); // Set rx = 1, identity element of GT. @@ -475,88 +464,88 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, for (i = (int)ps->p_bitsize - 2; i >= 0; i--) { bool pi = ps->p.data.data[sizeof(ps->p) - 1 - (i >> 3)] & (1 << (i & 7)); - result = FfMul(&ps->Fq, Z, Z, ty); // ty = Z^2 + result = FfMul(ps->Fq, Z, Z, ty); // ty = Z^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, ty, ty, t1); // t1 = Z^4 + result = FfMul(ps->Fq, ty, ty, t1); // t1 = Z^4 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, t1, ps->a, t1); // t1 = a*Z^4 + result = FfMul(ps->Fq, t1, ps->a, t1); // t1 = a*Z^4 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, X, X, w); // w = X^2 + result = FfMul(ps->Fq, X, X, w); // w = X^2 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, w, w, t2); // t2 = 2 * X^2 + result = FfAdd(ps->Fq, w, w, t2); // t2 = 2 * X^2 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, w, t2, w); // w = 3 * X^2 + result = FfAdd(ps->Fq, w, t2, w); // w = 3 * X^2 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, w, t1, w); // w = 3 * X^2 + a * Z^4 + result = FfAdd(ps->Fq, w, t1, w); // w = 3 * X^2 + a * Z^4 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, Y, Y, t1); // t1 = Y^2 + result = FfMul(ps->Fq, Y, Y, t1); // t1 = Y^2 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, t1, t1, t3); // t3 = 2* Y^2 + result = FfAdd(ps->Fq, t1, t1, t3); // t3 = 2* Y^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, t3, X, v); // v = 2 * X * Y^2 + result = FfMul(ps->Fq, t3, X, v); // v = 2 * X * Y^2 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, v, v, v); // v = 4 * X * Y^2 + result = FfAdd(ps->Fq, v, v, v); // v = 4 * X * Y^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, w, w, X2); // X2 = w^2 + result = FfMul(ps->Fq, w, w, X2); // X2 = w^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, X2, v, X2); // X2 = w^2 - v + result = FfSub(ps->Fq, X2, v, X2); // X2 = w^2 - v BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, X2, v, X2); // X2 = w^2 - 2 * w + result = FfSub(ps->Fq, X2, v, X2); // X2 = w^2 - 2 * w BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, t3, t3, t3); // t3 = 4 * Y^4 + result = FfMul(ps->Fq, t3, t3, t3); // t3 = 4 * Y^4 BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, t3, t3, t3); // t3 = 8 * Y^4 + result = FfAdd(ps->Fq, t3, t3, t3); // t3 = 8 * Y^4 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, v, X2, Y2); // Y2 = v - X2 + result = FfSub(ps->Fq, v, X2, Y2); // Y2 = v - X2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, Y2, w, Y2); // Y2 = w * (v - X2) + result = FfMul(ps->Fq, Y2, w, Y2); // Y2 = w * (v - X2) BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, Y2, t3, Y2); // Y2 = w * (v - X2) - 8 * Y^4 + result = FfSub(ps->Fq, Y2, t3, Y2); // Y2 = w * (v - X2) - 8 * Y^4 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, Y, Z, Z2); // Z2 = Y * Z + result = FfMul(ps->Fq, Y, Z, Z2); // Z2 = Y * Z BREAK_ON_EPID_ERROR(result); - result = FfAdd(&ps->Fq, Z2, Z2, Z2); // Z2 = 2 * Y * Z + result = FfAdd(ps->Fq, Z2, Z2, Z2); // Z2 = 2 * Y * Z BREAK_ON_EPID_ERROR(result); /* compute line */ - result = FfMul(&ps->Fq, ty, w, t2); // t2 = w * Z^2 + result = FfMul(ps->Fq, ty, w, t2); // t2 = w * Z^2 BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, t2, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, t2, tt2); BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, pQx, tt2, tt1); // tt1 = w * Z^2 * Qx BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, w, X, t2); // t2 = w * X + result = FfMul(ps->Fq, w, X, t2); // t2 = w * X BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, t2, t1, t2); // t2 = w * X - Y^2 + result = FfSub(ps->Fq, t2, t1, t2); // t2 = w * X - Y^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, t2, t1, t2); // t2 = w * X - 2 * Y^2 + result = FfSub(ps->Fq, t2, t1, t2); // t2 = w * X - 2 * Y^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, ty, Z2, ty); // ty = Z2 * Z^2 + result = FfMul(ps->Fq, ty, Z2, ty); // ty = Z2 * Z^2 BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, ty, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, ty, tt2); BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, pQy, tt2, tx); // tx = ty * Qy BREAK_ON_EPID_ERROR(result); result = FfSub(ps->ff, tx, tt1, tx); // tx = ty * Qy - w * Z^2 * Qx BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, t2, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, t2, tt2); BREAK_ON_EPID_ERROR(result); result = FfAdd(ps->ff, tx, tt2, tx); // tx = ty * Qy - w * Z^2 * Qx + w * X - 2 * Y^2 BREAK_ON_EPID_ERROR(result); sts = ippsGFpCpyElement(X2->ipp_ff_elem, X->ipp_ff_elem, - ps->Fq.ipp_ff); // X = X2 + ps->Fq->ipp_ff); // X = X2 BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpCpyElement(Y2->ipp_ff_elem, Y->ipp_ff_elem, - ps->Fq.ipp_ff); // Y = Y2 + ps->Fq->ipp_ff); // Y = Y2 BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpCpyElement(Z2->ipp_ff_elem, Z->ipp_ff_elem, - ps->Fq.ipp_ff); // Z = Z2 + ps->Fq->ipp_ff); // Z = Z2 BREAK_ON_IPP_ERROR(sts, result); /* udpate rx, ry */ @@ -564,68 +553,68 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, tx, tt1, rx); // rx = tx * rx * rx BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, ry, ry, t1); // t1 = ry * ry + result = FfMul(ps->Fq, ry, ry, t1); // t1 = ry * ry BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, ty, t1, ry); // ry = ty * ry * ry + result = FfMul(ps->Fq, ty, t1, ry); // ry = ty * ry * ry BREAK_ON_EPID_ERROR(result); if (pi && i) { - result = FfMul(&ps->Fq, Z, Z, t1); // t1 = Z^2 + result = FfMul(ps->Fq, Z, Z, t1); // t1 = Z^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, px, t1, w); // w = px * Z^2 + result = FfMul(ps->Fq, px, t1, w); // w = px * Z^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, w, X, w); // w = px * Z^2 - X + result = FfSub(ps->Fq, w, X, w); // w = px * Z^2 - X BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, t1, Z, t1); // t1 = Z^3 + result = FfMul(ps->Fq, t1, Z, t1); // t1 = Z^3 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, py, t1, v); // v = py * Z^3 + result = FfMul(ps->Fq, py, t1, v); // v = py * Z^3 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, v, Y, v); // v = py * Z^3 - Y + result = FfSub(ps->Fq, v, Y, v); // v = py * Z^3 - Y BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, w, w, t1); // t1 = w^2 + result = FfMul(ps->Fq, w, w, t1); // t1 = w^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, w, t1, t2); // t2 = w^3 + result = FfMul(ps->Fq, w, t1, t2); // t2 = w^3 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, X, t1, t3); // t3 = X * w^2 + result = FfMul(ps->Fq, X, t1, t3); // t3 = X * w^2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, v, v, X2); // X2 = v^2 + result = FfMul(ps->Fq, v, v, X2); // X2 = v^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, X2, t2, X2); // X2 = v^2 - w^3 + result = FfSub(ps->Fq, X2, t2, X2); // X2 = v^2 - w^3 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, X2, t3, X2); // X2 = v^2 - w^3 - X * w^2 + result = FfSub(ps->Fq, X2, t3, X2); // X2 = v^2 - w^3 - X * w^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, X2, t3, X2); // X2 = v^2 - w^3 - 2 * X * w^2 + result = FfSub(ps->Fq, X2, t3, X2); // X2 = v^2 - w^3 - 2 * X * w^2 BREAK_ON_EPID_ERROR(result); - result = FfSub(&ps->Fq, t3, X2, Y2); // Y2 = X * w^2 - X2 + result = FfSub(ps->Fq, t3, X2, Y2); // Y2 = X * w^2 - X2 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, Y2, v, Y2); // Y2 = v * (X * w^2 - X2) + result = FfMul(ps->Fq, Y2, v, Y2); // Y2 = v * (X * w^2 - X2) BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, t2, Y, t2); // t2 = Y * w^3 + result = FfMul(ps->Fq, t2, Y, t2); // t2 = Y * w^3 BREAK_ON_EPID_ERROR(result); result = - FfSub(&ps->Fq, Y2, t2, Y2); // Y2 = v * (X * w^2 - X2) - Y * w^3 + FfSub(ps->Fq, Y2, t2, Y2); // Y2 = v * (X * w^2 - X2) - Y * w^3 BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, w, Z, Z2); // Z2 = w * Z + result = FfMul(ps->Fq, w, Z, Z2); // Z2 = w * Z BREAK_ON_EPID_ERROR(result); /* compute tx, ty */ sts = ippsGFpCpyElement(Z2->ipp_ff_elem, ty->ipp_ff_elem, - ps->Fq.ipp_ff); // ty = Z2 + ps->Fq->ipp_ff); // ty = Z2 BREAK_ON_IPP_ERROR(sts, result); - result = Fq6FromFq(ps->ff, &ps->Fq, py, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, py, tt2); BREAK_ON_EPID_ERROR(result); result = FfSub(ps->ff, pQy, tt2, tx); // tx = Qy - py BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, Z2, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, Z2, tt2); BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, tx, tt2, tx); // tx = Z2 * (Qy - py) BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, px, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, px, tt2); BREAK_ON_EPID_ERROR(result); result = FfSub(ps->ff, pQx, tt2, tt1); // tt1 = Qx - px BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, v, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, v, tt2); BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, tt1, tt2, tt1); // tt1 = v * (Qx - px) BREAK_ON_EPID_ERROR(result); @@ -634,27 +623,27 @@ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, BREAK_ON_EPID_ERROR(result); sts = ippsGFpCpyElement(X2->ipp_ff_elem, X->ipp_ff_elem, - ps->Fq.ipp_ff); // X = X2 + ps->Fq->ipp_ff); // X = X2 BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpCpyElement(Y2->ipp_ff_elem, Y->ipp_ff_elem, - ps->Fq.ipp_ff); // Y = Y2 + ps->Fq->ipp_ff); // Y = Y2 BREAK_ON_IPP_ERROR(sts, result); sts = ippsGFpCpyElement(Z2->ipp_ff_elem, Z->ipp_ff_elem, - ps->Fq.ipp_ff); // Z = Z2 + ps->Fq->ipp_ff); // Z = Z2 BREAK_ON_IPP_ERROR(sts, result); /* udpate rx, ry */ result = FfMul(ps->ff, rx, tx, rx); // rx = rx * tx BREAK_ON_EPID_ERROR(result); - result = FfMul(&ps->Fq, ry, ty, ry); // ry = ry * ty + result = FfMul(ps->Fq, ry, ty, ry); // ry = ry * ty BREAK_ON_EPID_ERROR(result); } } BREAK_ON_EPID_ERROR(result); - result = FfInv(&ps->Fq, ry, ry); // ry = ry^-1 + result = FfInv(ps->Fq, ry, ry); // ry = ry^-1 BREAK_ON_EPID_ERROR(result); - result = Fq6FromFq(ps->ff, &ps->Fq, ry, tt2); + result = Fq6FromFq(ps->ff, ps->Fq, ry, tt2); BREAK_ON_EPID_ERROR(result); result = FfMul(ps->ff, rx, tt2, r); // r = rx * ry BREAK_ON_EPID_ERROR(result); @@ -729,9 +718,9 @@ static EpidStatus JoinFq3(Epid11PairingState* ps, FfElement const* a, result = kEpidBadArgErr; break; } - result = WriteFfElement(&ps->Fq3, a, &r_str.a[0], sizeof(r_str.a[0])); + result = WriteFfElement(ps->Fq3, a, &r_str.a[0], sizeof(r_str.a[0])); BREAK_ON_EPID_ERROR(result); - result = WriteFfElement(&ps->Fq3, b, &r_str.a[1], sizeof(r_str.a[1])); + result = WriteFfElement(ps->Fq3, b, &r_str.a[1], sizeof(r_str.a[1])); BREAK_ON_EPID_ERROR(result); result = ReadFfElement(ps->ff, &r_str, sizeof(r_str), r); BREAK_ON_EPID_ERROR(result); @@ -756,9 +745,9 @@ static EpidStatus SplitFq6(Epid11PairingState* ps, FfElement const* a, } result = WriteFfElement(ps->ff, a, &a_str, sizeof(a_str)); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq3, &a_str.a[0], sizeof(a_str.a[0]), a0); + result = ReadFfElement(ps->Fq3, &a_str.a[0], sizeof(a_str.a[0]), a0); BREAK_ON_EPID_ERROR(result); - result = ReadFfElement(&ps->Fq3, &a_str.a[1], sizeof(a_str.a[1]), a1); + result = ReadFfElement(ps->Fq3, &a_str.a[1], sizeof(a_str.a[1]), a1); BREAK_ON_EPID_ERROR(result); result = kEpidNoErr; } while (0); @@ -791,21 +780,21 @@ static EpidStatus FinalExp(Epid11PairingState* ps, FfElement const* r, } // a.Let r = (r[0], r[1]), where r[0] and r[1] are elements in Fqd, - result = NewFfElement(&ps->Fq3, &r0); + result = NewFfElement(ps->Fq3, &r0); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq3, &r1); + result = NewFfElement(ps->Fq3, &r1); BREAK_ON_EPID_ERROR(result); result = SplitFq6(ps, r, r0, r1); BREAK_ON_EPID_ERROR(result); // b.Compute x = transform(r[0]), where x is an element in Fqd, - result = NewFfElement(&ps->Fq3, &x); + result = NewFfElement(ps->Fq3, &x); BREAK_ON_EPID_ERROR(result); result = Transform(ps, r0, x); BREAK_ON_EPID_ERROR(result); // c.Compute y = transform(r[1]), where x is an element in Fqd, - result = NewFfElement(&ps->Fq3, &y); + result = NewFfElement(ps->Fq3, &y); BREAK_ON_EPID_ERROR(result); result = Transform(ps, r1, y); BREAK_ON_EPID_ERROR(result); @@ -828,17 +817,17 @@ static EpidStatus FinalExp(Epid11PairingState* ps, FfElement const* r, BREAK_ON_EPID_ERROR(result); // t2 = (r[0], -r[1]) - result = NewFfElement(&ps->Fq3, &neg_r1); + result = NewFfElement(ps->Fq3, &neg_r1); BREAK_ON_EPID_ERROR(result); - result = FfNeg(&ps->Fq3, r1, neg_r1); + result = FfNeg(ps->Fq3, r1, neg_r1); BREAK_ON_EPID_ERROR(result); result = JoinFq3(ps, r0, neg_r1, t2); BREAK_ON_EPID_ERROR(result); // t3 = (x, -y) - result = NewFfElement(&ps->Fq3, &neg_y); + result = NewFfElement(ps->Fq3, &neg_y); BREAK_ON_EPID_ERROR(result); - result = FfNeg(&ps->Fq3, y, neg_y); + result = FfNeg(ps->Fq3, y, neg_y); BREAK_ON_EPID_ERROR(result); result = JoinFq3(ps, x, neg_y, t3); BREAK_ON_EPID_ERROR(result); @@ -906,23 +895,23 @@ static EpidStatus Transform(Epid11PairingState* ps, FfElement const* a, if (!ps || !a || !b) return kEpidBadArgErr; do { - result = WriteFfElement(&ps->Fq3, a, &a_str, sizeof(a_str)); + result = WriteFfElement(ps->Fq3, a, &a_str, sizeof(a_str)); BREAK_ON_EPID_ERROR(result); - result = NewFfElement(&ps->Fq3, &tmp); + result = NewFfElement(ps->Fq3, &tmp); BREAK_ON_EPID_ERROR(result); // b = 0 - result = ReadFfElement(&ps->Fq3, &zero, sizeof(zero), b); + result = ReadFfElement(ps->Fq3, &zero, sizeof(zero), b); BREAK_ON_EPID_ERROR(result); for (i = 0; i < 3; i++) { // tmp = (a[0][i], 0, 0) tmp_str.a[0] = a_str.a[i]; - result = ReadFfElement(&ps->Fq3, &tmp_str, sizeof(tmp_str), tmp); + result = ReadFfElement(ps->Fq3, &tmp_str, sizeof(tmp_str), tmp); BREAK_ON_EPID_ERROR(result); // tmp *= alpha_q[i] - result = FfMul(&ps->Fq3, ps->alpha_q[i], tmp, tmp); + result = FfMul(ps->Fq3, ps->alpha_q[i], tmp, tmp); BREAK_ON_EPID_ERROR(result); // b += tmp - result = FfAdd(&ps->Fq3, tmp, b, b); + result = FfAdd(ps->Fq3, tmp, b, b); BREAK_ON_EPID_ERROR(result); } BREAK_ON_EPID_ERROR(result); diff --git a/external/epid-sdk-3.0.0/epid/common/math/tatepairing.h b/external/epid-sdk/epid/common/math/tatepairing.h similarity index 85% rename from external/epid-sdk-3.0.0/epid/common/math/tatepairing.h rename to external/epid-sdk/epid/common/math/tatepairing.h index 3abeb748..4ac09e8a 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/tatepairing.h +++ b/external/epid-sdk/epid/common/math/tatepairing.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,14 +23,14 @@ #define EPID_COMMON_MATH_TATEPAIRING_H_ #include "epid/common/errors.h" -#include "epid/common/types.h" -#include "epid/common/math/finitefield.h" #include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/types.h" -/// EPID 1.1 pairing operations +/// Intel(R) EPID 1.1 pairing operations /*! - \defgroup Epid11PairingPrimitives EPID 1.1 specific pairing + \defgroup Epid11PairingPrimitives Intel(R) EPID 1.1 specific pairing Provides APIs for defining and using a pairing relationship between two Elliptic curve groups. @@ -38,7 +38,8 @@ 1.1 verification. \ingroup PairingPrimitives - \see EPID 1.1 + \see Intel(R) EPID + 1.1 support @{ */ @@ -66,8 +67,11 @@ typedef struct Epid11PairingState Epid11PairingState; \returns ::EpidStatus + \attention It is the responsibility of the caller to ensure that ga, gb, and + ff exist for the entire lifetime of the new Epid11PairingState. + \see DeleteEpid11PairingState - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus NewEpid11PairingState(EcGroup const* ga, EcGroup const* gb, @@ -85,7 +89,7 @@ EpidStatus NewEpid11PairingState(EcGroup const* ga, EcGroup const* gb, The pairing state. Can be NULL. \see NewEpid11PairingState - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ void DeleteEpid11PairingState(Epid11PairingState** ps); @@ -107,7 +111,7 @@ This pairing operation is intended to support Intel(R) EPID \returns ::EpidStatus - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11Pairing(Epid11PairingState* ps, EcPoint const* a, diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/bignum-test.cc b/external/epid-sdk/epid/common/math/unittests/bignum-test.cc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/bignum-test.cc rename to external/epid-sdk/epid/common/math/unittests/bignum-test.cc index bd8c360a..5de5c175 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/bignum-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/bignum-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,10 +19,11 @@ * \brief BigNum unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" extern "C" { #include "epid/common/math/bignum.h" diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_sign-test.cc b/external/epid-sdk/epid/common/math/unittests/ecdsa_sign-test.cc similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_sign-test.cc rename to external/epid-sdk/epid/common/math/unittests/ecdsa_sign-test.cc index a9759cb0..167b65a7 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_sign-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/ecdsa_sign-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_verify-test.cc b/external/epid-sdk/epid/common/math/unittests/ecdsa_verify-test.cc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_verify-test.cc rename to external/epid-sdk/epid/common/math/unittests/ecdsa_verify-test.cc index 7f283303..e7cb2bf0 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecdsa_verify-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/ecdsa_verify-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecgroup-test.cc b/external/epid-sdk/epid/common/math/unittests/ecgroup-test.cc similarity index 77% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/ecgroup-test.cc rename to external/epid-sdk/epid/common/math/unittests/ecgroup-test.cc index b8b3aa67..426b32a9 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/ecgroup-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/ecgroup-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,23 +21,24 @@ #include #include -#include #include +#include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/common/math/ecgroup.h" #include "epid/common/math/finitefield.h" } -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" /// compares G1ElemStr values bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) { @@ -88,9 +89,9 @@ class EFq2Params { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; static const FqElemStr param_b = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}; + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}; // Setup Fq2 with parameters (q, beta) // Fq^2 = Fq[u] / (u^2 - beta) @@ -113,22 +114,22 @@ class EFq2Params { // set h = 2q - p, aka cofactor std::vector cofactor_str( - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, 0xee, 0x71, 0xa4, 0xa0, - 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, 0xea, 0xb0, 0x25, 0x08, 0x4a, - 0x8c, 0x9b, 0x10, 0x19}); + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, + 0xee, 0x71, 0xa4, 0xa0, 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, + 0xea, 0xb0, 0x25, 0x08, 0x4a, 0x8c, 0x9b, 0x10, 0x19}); cofactor = BigNumObj(cofactor_str); // set n = p * h, AKA order std::vector order_str( - {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, 0xc7, - 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, 0xe8, 0x54, - 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, 0x70, 0x21, 0xdc, - 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, 0x4e, 0x84, 0xcd, 0x19, - 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, 0xa0, 0x2e, 0x7f, 0x40, 0x13, - 0xb2, 0xfa, 0xa1, 0x45}); + {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, + 0xc7, 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, + 0xe8, 0x54, 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, + 0x70, 0x21, 0xdc, 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, + 0x4e, 0x84, 0xcd, 0x19, 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, + 0xa0, 0x2e, 0x7f, 0x40, 0x13, 0xb2, 0xfa, 0xa1, 0x45}); order = BigNumObj(order_str); } @@ -163,6 +164,7 @@ class EcGroupTest : public ::testing::Test { static const G1ElemStr efq_r_sha256_str; static const G1ElemStr efq_r_sha384_str; static const G1ElemStr efq_r_sha512_str; + static const G1ElemStr efq_r_sha512256_str; static const uint8_t sha_msg[]; static const G2ElemStr efq2_a_str; @@ -173,13 +175,13 @@ class EcGroupTest : public ::testing::Test { static const G2ElemStr efq2_inv_a_str; static const G2ElemStr efq2_identity_str; - // Epid 1.1 hash of message "aad" + // Intel(R) EPID 1.1 hash of message "aad" static const Epid11G3ElemStr kAadHash; - // Epid 1.1 hash of message "bsn0" + // Intel(R) EPID 1.1 hash of message "bsn0" static const Epid11G3ElemStr kBsn0Hash; - // Epid 1.1 hash of message "test" + // Intel(R) EPID 1.1 hash of message "test" static const Epid11G3ElemStr kTestHash; - // Epid 1.1 hash of message "aac" + // Intel(R) EPID 1.1 hash of message "aac" static const Epid11G3ElemStr kAacHash; virtual void SetUp() { @@ -266,269 +268,277 @@ class EcGroupTest : public ::testing::Test { }; const G1ElemStr EcGroupTest::g1_str = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; const G2ElemStr EcGroupTest::g2_str = { - {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, 0x13, - 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, 0x47, 0x0E, - 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, - {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, 0x25, - 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, 0x53, 0xE2, - 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, - {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, 0x03, - 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, 0x68, 0x38, - 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, - {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, 0xF8, - 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, 0xD6, 0x13, - 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; + {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, + 0x13, 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, + 0x47, 0x0E, 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, + {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, + 0x25, 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, + 0x53, 0xE2, 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, + {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, + 0x03, 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, + 0x68, 0x38, 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, + {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, + 0xF8, 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, + 0xD6, 0x13, 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; const FqElemStr EcGroupTest::a1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}; const FqElemStr EcGroupTest::b1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; const BigNumStr EcGroupTest::h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; const BigNumStr EcGroupTest::p = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, - 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; const BigNumStr EcGroupTest::q = { - {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}}; const G1ElemStr EcGroupTest::efq_a_str = { - {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, - {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, 0x30, - 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, 0xF7, 0xCD, - 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; + {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, + 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, + 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; const G1ElemStr EcGroupTest::efq_b_str = { - {{{0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, 0x67, - 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, 0xD9, 0x98, - 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}}}, - {{{0x63, 0xB0, 0xAD, 0xB8, 0x2C, 0xE8, 0x14, 0xFD, 0xA2, 0x39, 0x0E, 0x66, - 0xB7, 0xD0, 0x6A, 0xAB, 0xEE, 0xFA, 0x2E, 0x24, 0x9B, 0xB5, 0x14, 0x35, - 0xFE, 0xB6, 0xB0, 0xFF, 0xFD, 0x5F, 0x73, 0x19}}}}; + {{{0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, + 0x67, 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, + 0xD9, 0x98, 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}}}, + {{{0x63, 0xB0, 0xAD, 0xB8, 0x2C, 0xE8, 0x14, 0xFD, 0xA2, 0x39, 0x0E, + 0x66, 0xB7, 0xD0, 0x6A, 0xAB, 0xEE, 0xFA, 0x2E, 0x24, 0x9B, 0xB5, + 0x14, 0x35, 0xFE, 0xB6, 0xB0, 0xFF, 0xFD, 0x5F, 0x73, 0x19}}}}; const BigNumStr EcGroupTest::x_str = { - {{0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, 0xFF, 0xFF, - 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x81, - 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF}}}; + {{0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, 0xFF, + 0xFF, 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x81, 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF}}}; const BigNumStr EcGroupTest::y_str = { - {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, 0x08, 0xFF, 0xFF, - 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, - 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}}; + {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, 0x08, 0xFF, + 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, + 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}}; const G1ElemStr EcGroupTest::efq_mul_ab_str = { - {{{0x30, 0xF8, 0x33, 0xB7, 0x1C, 0x85, 0x94, 0x6D, 0x6F, 0x3C, 0x97, 0x77, - 0x81, 0xA5, 0xC2, 0x98, 0x93, 0x5C, 0x8C, 0xC1, 0xFF, 0x35, 0x9E, 0x68, - 0xF6, 0x4D, 0x18, 0xDD, 0x65, 0xA9, 0xC0, 0x60}}}, - {{{0x89, 0xE5, 0x08, 0x2D, 0xD1, 0xD8, 0xC7, 0xBF, 0xDE, 0x16, 0x24, 0xA7, - 0x2F, 0xF1, 0x48, 0x00, 0x26, 0xAF, 0x89, 0xEA, 0xC9, 0x94, 0x78, 0xFF, - 0x2A, 0xB0, 0x20, 0xED, 0x33, 0x0C, 0x4E, 0x88}}}}; + {{{0x30, 0xF8, 0x33, 0xB7, 0x1C, 0x85, 0x94, 0x6D, 0x6F, 0x3C, 0x97, + 0x77, 0x81, 0xA5, 0xC2, 0x98, 0x93, 0x5C, 0x8C, 0xC1, 0xFF, 0x35, + 0x9E, 0x68, 0xF6, 0x4D, 0x18, 0xDD, 0x65, 0xA9, 0xC0, 0x60}}}, + {{{0x89, 0xE5, 0x08, 0x2D, 0xD1, 0xD8, 0xC7, 0xBF, 0xDE, 0x16, 0x24, + 0xA7, 0x2F, 0xF1, 0x48, 0x00, 0x26, 0xAF, 0x89, 0xEA, 0xC9, 0x94, + 0x78, 0xFF, 0x2A, 0xB0, 0x20, 0xED, 0x33, 0x0C, 0x4E, 0x88}}}}; const G1ElemStr EcGroupTest::efq_exp_ax_str = { - {{{0x44, 0x45, 0xFA, 0x16, 0x23, 0x66, 0x26, 0x9D, 0x44, 0xB9, 0x43, 0xAB, - 0x87, 0xE3, 0x56, 0xCA, 0x9C, 0x89, 0x44, 0x8E, 0xE8, 0x19, 0x29, 0x4D, - 0x4D, 0x59, 0x7D, 0xBE, 0x46, 0x3F, 0x55, 0x0D}}}, - {{{0x98, 0x09, 0xCF, 0x43, 0x46, 0x75, 0xB8, 0x71, 0xFF, 0x37, 0xBA, 0xA0, - 0x63, 0xE2, 0xAC, 0x09, 0x38, 0x10, 0x70, 0xAC, 0x15, 0x52, 0x28, 0xF4, - 0x77, 0x68, 0x32, 0x7B, 0x6E, 0xFB, 0xC1, 0x43}}}}; + {{{0x44, 0x45, 0xFA, 0x16, 0x23, 0x66, 0x26, 0x9D, 0x44, 0xB9, 0x43, + 0xAB, 0x87, 0xE3, 0x56, 0xCA, 0x9C, 0x89, 0x44, 0x8E, 0xE8, 0x19, + 0x29, 0x4D, 0x4D, 0x59, 0x7D, 0xBE, 0x46, 0x3F, 0x55, 0x0D}}}, + {{{0x98, 0x09, 0xCF, 0x43, 0x46, 0x75, 0xB8, 0x71, 0xFF, 0x37, 0xBA, + 0xA0, 0x63, 0xE2, 0xAC, 0x09, 0x38, 0x10, 0x70, 0xAC, 0x15, 0x52, + 0x28, 0xF4, 0x77, 0x68, 0x32, 0x7B, 0x6E, 0xFB, 0xC1, 0x43}}}}; const G1ElemStr EcGroupTest::efq_multiexp_abxy_str = { - {{{0x63, 0x4A, 0xD4, 0xC1, 0x6B, 0x90, 0x67, 0xA2, 0x0B, 0xE2, 0xB3, 0xE9, - 0x95, 0x3F, 0x82, 0x7E, 0x21, 0xBF, 0x9F, 0xCD, 0xA0, 0x16, 0x56, 0x6B, - 0x31, 0x66, 0x68, 0xBB, 0x25, 0xF8, 0xBD, 0xF3}}}, - {{{0xBD, 0x5F, 0xF8, 0x48, 0xD4, 0xBF, 0x35, 0x2D, 0xDC, 0xD1, 0x78, 0x74, - 0xFF, 0xB1, 0x47, 0xD5, 0x6B, 0x21, 0xE5, 0x15, 0x01, 0xA8, 0xDC, 0x8B, - 0x3C, 0x9D, 0x96, 0xC7, 0xC6, 0xB0, 0x05, 0x20}}}}; + {{{0x63, 0x4A, 0xD4, 0xC1, 0x6B, 0x90, 0x67, 0xA2, 0x0B, 0xE2, 0xB3, + 0xE9, 0x95, 0x3F, 0x82, 0x7E, 0x21, 0xBF, 0x9F, 0xCD, 0xA0, 0x16, + 0x56, 0x6B, 0x31, 0x66, 0x68, 0xBB, 0x25, 0xF8, 0xBD, 0xF3}}}, + {{{0xBD, 0x5F, 0xF8, 0x48, 0xD4, 0xBF, 0x35, 0x2D, 0xDC, 0xD1, 0x78, + 0x74, 0xFF, 0xB1, 0x47, 0xD5, 0x6B, 0x21, 0xE5, 0x15, 0x01, 0xA8, + 0xDC, 0x8B, 0x3C, 0x9D, 0x96, 0xC7, 0xC6, 0xB0, 0x05, 0x20}}}}; const G1ElemStr EcGroupTest::efq_inv_a_str = { - {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, - {{{0x87, 0x9A, 0xD7, 0x34, 0x50, 0xF5, 0x9E, 0x7C, 0xF1, 0x6B, 0x93, 0x2E, - 0xE3, 0xB0, 0xF0, 0x33, 0x22, 0x6C, 0x83, 0x04, 0xA5, 0x01, 0x12, 0xB5, - 0x0A, 0x56, 0x1B, 0x5C, 0x8F, 0x98, 0xA4, 0xD1}}}}; + {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0x87, 0x9A, 0xD7, 0x34, 0x50, 0xF5, 0x9E, 0x7C, 0xF1, 0x6B, 0x93, + 0x2E, 0xE3, 0xB0, 0xF0, 0x33, 0x22, 0x6C, 0x83, 0x04, 0xA5, 0x01, + 0x12, 0xB5, 0x0A, 0x56, 0x1B, 0x5C, 0x8F, 0x98, 0xA4, 0xD1}}}}; const G1ElemStr EcGroupTest::efq_identity_str = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}; const uint8_t EcGroupTest::sha_msg[] = {'a', 'b', 'c'}; const G1ElemStr EcGroupTest::efq_r_sha256_str = { - {{{0x2E, 0xBB, 0x50, 0x4D, 0x88, 0xFF, 0x25, 0x62, 0xF3, 0x71, 0x65, 0x81, - 0xAD, 0xBE, 0x83, 0x6E, 0x54, 0xF5, 0xA6, 0x2A, 0x70, 0xE6, 0x18, 0x6B, - 0xD5, 0x4A, 0x10, 0x3C, 0x80, 0x08, 0x95, 0x3D}}}, - {{{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38, 0xB1, - 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E, 0x2C, 0x1F, - 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}}}; + {{{0x2E, 0xBB, 0x50, 0x4D, 0x88, 0xFF, 0x25, 0x62, 0xF3, 0x71, 0x65, + 0x81, 0xAD, 0xBE, 0x83, 0x6E, 0x54, 0xF5, 0xA6, 0x2A, 0x70, 0xE6, + 0x18, 0x6B, 0xD5, 0x4A, 0x10, 0x3C, 0x80, 0x08, 0x95, 0x3D}}}, + {{{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38, + 0xB1, 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E, + 0x2C, 0x1F, 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}}}; const G1ElemStr EcGroupTest::efq_r_sha384_str = { - {{{0xE1, 0xC8, 0x28, 0xB1, 0x9A, 0xDF, 0x5D, 0x4B, 0xC4, 0x25, 0x90, 0xFB, - 0x38, 0x20, 0xD4, 0x8B, 0x30, 0x8F, 0x95, 0x76, 0xC3, 0x7F, 0x9D, 0xAD, - 0x94, 0xC4, 0x31, 0x80, 0xD7, 0xDF, 0xD5, 0xFE}}}, - {{{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80, 0x92, - 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3, 0x48, 0xA9, - 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}}}; + {{{0xE1, 0xC8, 0x28, 0xB1, 0x9A, 0xDF, 0x5D, 0x4B, 0xC4, 0x25, 0x90, + 0xFB, 0x38, 0x20, 0xD4, 0x8B, 0x30, 0x8F, 0x95, 0x76, 0xC3, 0x7F, + 0x9D, 0xAD, 0x94, 0xC4, 0x31, 0x80, 0xD7, 0xDF, 0xD5, 0xFE}}}, + {{{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80, + 0x92, 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3, + 0x48, 0xA9, 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}}}; const G1ElemStr EcGroupTest::efq_r_sha512_str = { - {{{0x8C, 0x62, 0xA0, 0x2D, 0x55, 0x55, 0x55, 0x86, 0xBC, 0x82, 0xA6, 0xA2, - 0x21, 0x97, 0x9B, 0x9B, 0xB4, 0x03, 0x3D, 0x83, 0xF3, 0xBA, 0xDA, 0x9C, - 0x42, 0xF7, 0xB3, 0x94, 0x99, 0x2A, 0x96, 0xE4}}}, - {{{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54, 0x24, - 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2, 0xF2, 0x7B, - 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}}}; + {{{0x8C, 0x62, 0xA0, 0x2D, 0x55, 0x55, 0x55, 0x86, 0xBC, 0x82, 0xA6, + 0xA2, 0x21, 0x97, 0x9B, 0x9B, 0xB4, 0x03, 0x3D, 0x83, 0xF3, 0xBA, + 0xDA, 0x9C, 0x42, 0xF7, 0xB3, 0x94, 0x99, 0x2A, 0x96, 0xE4}}}, + {{{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54, + 0x24, 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2, + 0xF2, 0x7B, 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}}}; + +const G1ElemStr EcGroupTest::efq_r_sha512256_str = { + {{{0x63, 0x28, 0x40, 0x14, 0x73, 0xd5, 0x91, 0xc4, 0xa2, 0xa4, 0xb6, + 0xd8, 0xa8, 0x75, 0x21, 0xd1, 0x26, 0x4e, 0x42, 0x13, 0x1f, 0xfa, + 0xed, 0x90, 0x8d, 0x56, 0x34, 0x57, 0x8a, 0x3a, 0x47, 0xa0}}}, + {{{0x30, 0xbe, 0x3f, 0x12, 0x00, 0x74, 0x48, 0xaa, 0x91, 0x90, 0x84, + 0x12, 0x4d, 0x58, 0x54, 0xe7, 0x04, 0x65, 0x37, 0x97, 0x88, 0xcf, + 0x67, 0xa0, 0x8c, 0x56, 0x93, 0xa7, 0x7f, 0xe8, 0x74, 0xfc}}}}; const G2ElemStr EcGroupTest::efq2_a_str = { { - {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, 0x9C, - 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, 0x32, 0x7C, - 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, - {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, 0x37, - 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, 0x1E, 0x60, - 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, + {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, + 0x9C, 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, + 0x32, 0x7C, 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, + {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, + 0x37, 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, + 0x1E, 0x60, 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, }, { - {0xD3, 0x67, 0xA5, 0xCC, 0xEF, 0x7B, 0xD1, 0x8D, 0x4A, 0x7F, 0xF1, 0x8F, - 0x66, 0xCB, 0x5E, 0x86, 0xAC, 0xCB, 0x36, 0x5F, 0x29, 0x90, 0x28, 0x55, - 0xF0, 0xDC, 0x6E, 0x8B, 0x87, 0xB5, 0xD8, 0x32}, - {0x6C, 0x0A, 0xC5, 0x58, 0xB1, 0x4E, 0xCA, 0x85, 0x44, 0x3E, 0xDE, 0x71, - 0x9B, 0xC7, 0x90, 0x19, 0x06, 0xD2, 0xA0, 0x4E, 0xC7, 0x33, 0xF4, 0x5C, - 0xE8, 0x16, 0xE2, 0x67, 0xDB, 0xBF, 0x64, 0x84}, + {0xD3, 0x67, 0xA5, 0xCC, 0xEF, 0x7B, 0xD1, 0x8D, 0x4A, 0x7F, 0xF1, + 0x8F, 0x66, 0xCB, 0x5E, 0x86, 0xAC, 0xCB, 0x36, 0x5F, 0x29, 0x90, + 0x28, 0x55, 0xF0, 0xDC, 0x6E, 0x8B, 0x87, 0xB5, 0xD8, 0x32}, + {0x6C, 0x0A, 0xC5, 0x58, 0xB1, 0x4E, 0xCA, 0x85, 0x44, 0x3E, 0xDE, + 0x71, 0x9B, 0xC7, 0x90, 0x19, 0x06, 0xD2, 0xA0, 0x4E, 0xC7, 0x33, + 0xF4, 0x5C, 0xE8, 0x16, 0xE2, 0x67, 0xDB, 0xBF, 0x64, 0x84}, }, }; const G2ElemStr EcGroupTest::efq2_b_str = { { - {0x16, 0xF1, 0x61, 0x76, 0x06, 0x3E, 0xE9, 0xC0, 0xB9, 0xB1, 0x3A, 0x75, - 0xFC, 0xDB, 0x90, 0xCD, 0x01, 0xF4, 0x9F, 0xCC, 0xAA, 0x24, 0x69, 0x83, - 0xBE, 0x20, 0x44, 0x87, 0x58, 0x90, 0x0F, 0x4F}, - {0xC7, 0x50, 0x37, 0xC1, 0xB9, 0x2D, 0xE1, 0xE3, 0x79, 0x20, 0x7B, 0x62, - 0x90, 0xF8, 0xC7, 0xF0, 0xD7, 0x5A, 0xE7, 0xAD, 0x65, 0xE1, 0xC7, 0x50, - 0x59, 0xA1, 0xFC, 0x49, 0xBC, 0x2A, 0xE5, 0xD7}, + {0x16, 0xF1, 0x61, 0x76, 0x06, 0x3E, 0xE9, 0xC0, 0xB9, 0xB1, 0x3A, + 0x75, 0xFC, 0xDB, 0x90, 0xCD, 0x01, 0xF4, 0x9F, 0xCC, 0xAA, 0x24, + 0x69, 0x83, 0xBE, 0x20, 0x44, 0x87, 0x58, 0x90, 0x0F, 0x4F}, + {0xC7, 0x50, 0x37, 0xC1, 0xB9, 0x2D, 0xE1, 0xE3, 0x79, 0x20, 0x7B, + 0x62, 0x90, 0xF8, 0xC7, 0xF0, 0xD7, 0x5A, 0xE7, 0xAD, 0x65, 0xE1, + 0xC7, 0x50, 0x59, 0xA1, 0xFC, 0x49, 0xBC, 0x2A, 0xE5, 0xD7}, }, { - {0x12, 0x73, 0x3B, 0xA4, 0xDD, 0x0F, 0xBB, 0x35, 0x38, 0x4A, 0xE0, 0x3D, - 0x79, 0x63, 0x66, 0x73, 0x9C, 0x07, 0xE1, 0xEC, 0x71, 0x16, 0x50, 0x75, - 0xA1, 0xBA, 0xE5, 0x37, 0x45, 0x1A, 0x0C, 0x59}, - {0xC9, 0x49, 0xB9, 0xDB, 0x7E, 0x76, 0xC5, 0xC5, 0x0A, 0x87, 0xB7, 0x56, - 0x88, 0x09, 0x21, 0xC6, 0xF6, 0x6C, 0xCC, 0x5E, 0x80, 0xFD, 0x05, 0xD0, - 0x5F, 0xC6, 0x2E, 0x06, 0xA1, 0xBE, 0x5B, 0xA0}, + {0x12, 0x73, 0x3B, 0xA4, 0xDD, 0x0F, 0xBB, 0x35, 0x38, 0x4A, 0xE0, + 0x3D, 0x79, 0x63, 0x66, 0x73, 0x9C, 0x07, 0xE1, 0xEC, 0x71, 0x16, + 0x50, 0x75, 0xA1, 0xBA, 0xE5, 0x37, 0x45, 0x1A, 0x0C, 0x59}, + {0xC9, 0x49, 0xB9, 0xDB, 0x7E, 0x76, 0xC5, 0xC5, 0x0A, 0x87, 0xB7, + 0x56, 0x88, 0x09, 0x21, 0xC6, 0xF6, 0x6C, 0xCC, 0x5E, 0x80, 0xFD, + 0x05, 0xD0, 0x5F, 0xC6, 0x2E, 0x06, 0xA1, 0xBE, 0x5B, 0xA0}, }, }; const G2ElemStr EcGroupTest::efq2_mul_ab_str = { { - {0x25, 0xCC, 0x11, 0x80, 0x8F, 0x08, 0x1D, 0x66, 0xF8, 0xDB, 0xBC, 0x98, - 0x26, 0x24, 0x26, 0xCF, 0x04, 0x02, 0xB6, 0x99, 0x1B, 0x52, 0xA8, 0xE3, - 0x4E, 0x9A, 0x85, 0xB0, 0x5C, 0xCE, 0xDD, 0xC5}, - {0xFC, 0x3C, 0xC2, 0x2C, 0x4B, 0x63, 0x72, 0x5F, 0xA9, 0xF9, 0x8C, 0x62, - 0xF4, 0xE7, 0x30, 0x71, 0x6F, 0x78, 0xF5, 0xFE, 0xF6, 0xDF, 0xF7, 0xB5, - 0x21, 0x69, 0x7C, 0x50, 0xAC, 0x56, 0xD9, 0xB5}, + {0x25, 0xCC, 0x11, 0x80, 0x8F, 0x08, 0x1D, 0x66, 0xF8, 0xDB, 0xBC, + 0x98, 0x26, 0x24, 0x26, 0xCF, 0x04, 0x02, 0xB6, 0x99, 0x1B, 0x52, + 0xA8, 0xE3, 0x4E, 0x9A, 0x85, 0xB0, 0x5C, 0xCE, 0xDD, 0xC5}, + {0xFC, 0x3C, 0xC2, 0x2C, 0x4B, 0x63, 0x72, 0x5F, 0xA9, 0xF9, 0x8C, + 0x62, 0xF4, 0xE7, 0x30, 0x71, 0x6F, 0x78, 0xF5, 0xFE, 0xF6, 0xDF, + 0xF7, 0xB5, 0x21, 0x69, 0x7C, 0x50, 0xAC, 0x56, 0xD9, 0xB5}, }, { - {0xA5, 0xD6, 0xAB, 0x2D, 0xED, 0x8E, 0xFE, 0x43, 0xCB, 0xC9, 0xEF, 0x09, - 0xC8, 0x2D, 0xE8, 0xD0, 0x3B, 0xC0, 0x5C, 0x7F, 0xE5, 0x3A, 0x1D, 0x72, - 0xF2, 0xF5, 0x03, 0xBD, 0xE5, 0xEB, 0x08, 0xA0}, - {0xE6, 0xF3, 0x59, 0xE4, 0xD2, 0x52, 0xFD, 0x4F, 0xEC, 0xCE, 0x49, 0x9F, - 0x86, 0x50, 0x2D, 0x4A, 0x59, 0x2C, 0xA2, 0x4E, 0xE3, 0xFE, 0xF2, 0xFC, - 0xB9, 0xF4, 0x22, 0x88, 0xBC, 0x79, 0x21, 0xD0}, + {0xA5, 0xD6, 0xAB, 0x2D, 0xED, 0x8E, 0xFE, 0x43, 0xCB, 0xC9, 0xEF, + 0x09, 0xC8, 0x2D, 0xE8, 0xD0, 0x3B, 0xC0, 0x5C, 0x7F, 0xE5, 0x3A, + 0x1D, 0x72, 0xF2, 0xF5, 0x03, 0xBD, 0xE5, 0xEB, 0x08, 0xA0}, + {0xE6, 0xF3, 0x59, 0xE4, 0xD2, 0x52, 0xFD, 0x4F, 0xEC, 0xCE, 0x49, + 0x9F, 0x86, 0x50, 0x2D, 0x4A, 0x59, 0x2C, 0xA2, 0x4E, 0xE3, 0xFE, + 0xF2, 0xFC, 0xB9, 0xF4, 0x22, 0x88, 0xBC, 0x79, 0x21, 0xD0}, }, }; const G2ElemStr EcGroupTest::efq2_exp_ax_str = { { - {0xC0, 0x5A, 0x37, 0xAD, 0x08, 0xAB, 0x22, 0xCF, 0xF7, 0xF9, 0xCC, 0xD4, - 0x5A, 0x47, 0x38, 0x82, 0xE1, 0xC2, 0x06, 0x35, 0x4D, 0x5B, 0x95, 0xA1, - 0xA3, 0xC1, 0x83, 0x6C, 0x0F, 0x31, 0x24, 0xD2}, - {0xC7, 0x86, 0xE1, 0x59, 0x63, 0xCE, 0x21, 0x2A, 0x57, 0x77, 0xE5, 0x48, - 0xF7, 0x60, 0x21, 0x00, 0x40, 0x2F, 0x09, 0x18, 0x5C, 0x32, 0x32, 0x75, - 0xD7, 0xB9, 0xE7, 0xB1, 0x95, 0xD5, 0xDF, 0x02}, + {0xC0, 0x5A, 0x37, 0xAD, 0x08, 0xAB, 0x22, 0xCF, 0xF7, 0xF9, 0xCC, + 0xD4, 0x5A, 0x47, 0x38, 0x82, 0xE1, 0xC2, 0x06, 0x35, 0x4D, 0x5B, + 0x95, 0xA1, 0xA3, 0xC1, 0x83, 0x6C, 0x0F, 0x31, 0x24, 0xD2}, + {0xC7, 0x86, 0xE1, 0x59, 0x63, 0xCE, 0x21, 0x2A, 0x57, 0x77, 0xE5, + 0x48, 0xF7, 0x60, 0x21, 0x00, 0x40, 0x2F, 0x09, 0x18, 0x5C, 0x32, + 0x32, 0x75, 0xD7, 0xB9, 0xE7, 0xB1, 0x95, 0xD5, 0xDF, 0x02}, }, { - {0xE5, 0xDE, 0xC6, 0x3E, 0x05, 0xFC, 0x6F, 0x7A, 0xE3, 0x2D, 0x7D, 0x90, - 0x5F, 0x43, 0xE2, 0xB0, 0x9E, 0xCD, 0xEC, 0x7B, 0x37, 0x4C, 0x0A, 0x3E, - 0x87, 0x4E, 0xE6, 0xDA, 0xD1, 0x90, 0xC0, 0xD1}, - {0x70, 0x90, 0x54, 0x7F, 0x78, 0x93, 0xFA, 0xC4, 0xF7, 0x3A, 0x4D, 0xBC, - 0x03, 0x5E, 0x83, 0xDF, 0xEF, 0xF7, 0x52, 0xF9, 0x64, 0x7F, 0x17, 0xC1, - 0x69, 0xD6, 0xD7, 0x96, 0x18, 0x62, 0x46, 0xD1}, + {0xE5, 0xDE, 0xC6, 0x3E, 0x05, 0xFC, 0x6F, 0x7A, 0xE3, 0x2D, 0x7D, + 0x90, 0x5F, 0x43, 0xE2, 0xB0, 0x9E, 0xCD, 0xEC, 0x7B, 0x37, 0x4C, + 0x0A, 0x3E, 0x87, 0x4E, 0xE6, 0xDA, 0xD1, 0x90, 0xC0, 0xD1}, + {0x70, 0x90, 0x54, 0x7F, 0x78, 0x93, 0xFA, 0xC4, 0xF7, 0x3A, 0x4D, + 0xBC, 0x03, 0x5E, 0x83, 0xDF, 0xEF, 0xF7, 0x52, 0xF9, 0x64, 0x7F, + 0x17, 0xC1, 0x69, 0xD6, 0xD7, 0x96, 0x18, 0x62, 0x46, 0xD1}, }, }; const G2ElemStr EcGroupTest::efq2_multiexp_abxy_str = { { - {0xE8, 0x6E, 0x02, 0x7A, 0xEC, 0xEA, 0xBA, 0x7E, 0xE5, 0x7C, 0xAD, 0x98, - 0x37, 0x54, 0xB2, 0x15, 0x64, 0x9C, 0x81, 0xFF, 0x69, 0xCC, 0xD6, 0xA6, - 0xAA, 0xA7, 0x10, 0x4F, 0x9B, 0x0C, 0x50, 0x14}, - {0x7C, 0xAF, 0xC0, 0x6F, 0xC8, 0x87, 0xFF, 0x4A, 0x6F, 0xB5, 0x9E, 0x63, - 0x74, 0x20, 0xB5, 0xC6, 0x4F, 0x14, 0x0B, 0x6C, 0xBF, 0x00, 0x71, 0xE2, - 0x6D, 0x6C, 0x41, 0x6A, 0x0B, 0xA5, 0x5B, 0xCF}, + {0xE8, 0x6E, 0x02, 0x7A, 0xEC, 0xEA, 0xBA, 0x7E, 0xE5, 0x7C, 0xAD, + 0x98, 0x37, 0x54, 0xB2, 0x15, 0x64, 0x9C, 0x81, 0xFF, 0x69, 0xCC, + 0xD6, 0xA6, 0xAA, 0xA7, 0x10, 0x4F, 0x9B, 0x0C, 0x50, 0x14}, + {0x7C, 0xAF, 0xC0, 0x6F, 0xC8, 0x87, 0xFF, 0x4A, 0x6F, 0xB5, 0x9E, + 0x63, 0x74, 0x20, 0xB5, 0xC6, 0x4F, 0x14, 0x0B, 0x6C, 0xBF, 0x00, + 0x71, 0xE2, 0x6D, 0x6C, 0x41, 0x6A, 0x0B, 0xA5, 0x5B, 0xCF}, }, { - {0x16, 0xCC, 0x9B, 0x37, 0xE7, 0xCB, 0x16, 0x5C, 0x39, 0x7C, 0x10, 0x7E, - 0xE0, 0xDD, 0x34, 0x90, 0xBE, 0x56, 0x28, 0x76, 0x27, 0x59, 0xCE, 0xB3, - 0xD7, 0xB4, 0x56, 0xD4, 0x0D, 0xD1, 0xB8, 0xFB}, - {0x5E, 0x9E, 0x27, 0x30, 0x60, 0x87, 0x3B, 0xA4, 0x9B, 0x15, 0xEE, 0x86, - 0x15, 0x1D, 0xF4, 0xF3, 0x07, 0x31, 0x46, 0xFD, 0xB7, 0x51, 0xFF, 0xC0, - 0x42, 0x94, 0x38, 0xB7, 0x84, 0x5F, 0x86, 0x3A}, + {0x16, 0xCC, 0x9B, 0x37, 0xE7, 0xCB, 0x16, 0x5C, 0x39, 0x7C, 0x10, + 0x7E, 0xE0, 0xDD, 0x34, 0x90, 0xBE, 0x56, 0x28, 0x76, 0x27, 0x59, + 0xCE, 0xB3, 0xD7, 0xB4, 0x56, 0xD4, 0x0D, 0xD1, 0xB8, 0xFB}, + {0x5E, 0x9E, 0x27, 0x30, 0x60, 0x87, 0x3B, 0xA4, 0x9B, 0x15, 0xEE, + 0x86, 0x15, 0x1D, 0xF4, 0xF3, 0x07, 0x31, 0x46, 0xFD, 0xB7, 0x51, + 0xFF, 0xC0, 0x42, 0x94, 0x38, 0xB7, 0x84, 0x5F, 0x86, 0x3A}, }, }; const G2ElemStr EcGroupTest::efq2_inv_a_str = { { - {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, 0x9C, - 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, 0x32, 0x7C, - 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, - {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, 0x37, - 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, 0x1E, 0x60, - 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, + {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, + 0x9C, 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, + 0x32, 0x7C, 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, + {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, + 0x37, 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, + 0x1E, 0x60, 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, }, { - {0x2C, 0x98, 0x5A, 0x33, 0x10, 0x81, 0x1F, 0x3F, 0xFC, 0x66, 0x00, 0xCF, - 0x87, 0xA6, 0x46, 0x18, 0x60, 0x11, 0x2F, 0x9B, 0xE9, 0x07, 0xE2, 0x2C, - 0xE2, 0x4C, 0xBF, 0x50, 0x27, 0x1D, 0x57, 0xE1}, - {0x93, 0xF5, 0x3A, 0xA7, 0x4E, 0xAE, 0x26, 0x48, 0x02, 0xA7, 0x13, 0xED, - 0x52, 0xAA, 0x14, 0x86, 0x06, 0x09, 0xC5, 0xAC, 0x4B, 0x64, 0x16, 0x25, - 0xEB, 0x12, 0x4B, 0x73, 0xD3, 0x13, 0xCB, 0x8F}, + {0x2C, 0x98, 0x5A, 0x33, 0x10, 0x81, 0x1F, 0x3F, 0xFC, 0x66, 0x00, + 0xCF, 0x87, 0xA6, 0x46, 0x18, 0x60, 0x11, 0x2F, 0x9B, 0xE9, 0x07, + 0xE2, 0x2C, 0xE2, 0x4C, 0xBF, 0x50, 0x27, 0x1D, 0x57, 0xE1}, + {0x93, 0xF5, 0x3A, 0xA7, 0x4E, 0xAE, 0x26, 0x48, 0x02, 0xA7, 0x13, + 0xED, 0x52, 0xAA, 0x14, 0x86, 0x06, 0x09, 0xC5, 0xAC, 0x4B, 0x64, + 0x16, 0x25, 0xEB, 0x12, 0x4B, 0x73, 0xD3, 0x13, 0xCB, 0x8F}, }, }; const G2ElemStr EcGroupTest::efq2_identity_str = { { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }, { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }, }; @@ -575,10 +585,10 @@ const G1ElemStr EcGroupTest::kAacHash = { // NewEcGroup TEST_F(EcGroupTest, NewFailsGivenArgumentsMismatch) { // construct Fq^2 finite field - FqElemStr beta_str = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, - 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, - 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, 0xD3, 0x29, 0x2D, - 0xDB, 0xAE, 0xD3, 0x30, 0x12}}; + FqElemStr beta_str = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, + 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}; FfElementObj neg_beta(&fq); THROW_ON_EPIDERR(FfNeg(fq, FfElementObj(&fq, beta_str), neg_beta)); FiniteFieldObj fq2(fq, neg_beta, 2); @@ -941,11 +951,6 @@ TEST_F(EcGroupTest, ExpResultIsCorrect) { WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); EXPECT_EQ(this->efq_exp_ax_str, efq_r_str); } -TEST_F(EcGroupTest, ExpFailsGivenOutOfRangeExponent) { - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, - EcExp(this->efq, this->efq_a, &this->p, this->efq_r)); -} TEST_F(EcGroupTest, ExpSucceedsGivenG2ZeroExponent) { G2ElemStr efq2_r_str; BigNumStr zero_bn_str = {0}; @@ -1002,11 +1007,6 @@ TEST_F(EcGroupTest, SscmExpResultIsCorrect) { WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); EXPECT_EQ(this->efq_exp_ax_str, efq_r_str); } -TEST_F(EcGroupTest, SscmExpFailsGivenOutOfRangeExponent) { - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, - EcSscmExp(this->efq, this->efq_a, &this->p, this->efq_r)); -} TEST_F(EcGroupTest, SscmExpSucceedsGivenG2ZeroExponent) { G2ElemStr efq2_r_str; BigNumStr zero_bn_str = {0}; @@ -1030,14 +1030,14 @@ TEST_F(EcGroupTest, MultiExpFailsGivenArgumentsMismatch) { EcPoint const* pts_ec1[] = {this->efq_a, this->efq_b}; EcPoint const* pts_ec2[] = {this->efq2_a, this->efq2_b}; EcPoint const* pts_ec1_ec2[] = {this->efq_a, this->efq2_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumStr const* b[] = {&bnm0, &bnm1}; size_t m = 2; @@ -1050,14 +1050,14 @@ TEST_F(EcGroupTest, MultiExpFailsGivenArgumentsMismatch) { TEST_F(EcGroupTest, MultiExpFailsGivenNullPointer) { EcPoint const* pts[] = {this->efq_a, this->efq_b}; EcPoint const* pts_withnull[] = {nullptr, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumStr const* b[] = {&bnm0, &bnm1}; BigNumStr const* b_withnull[] = {nullptr, &bnm1}; size_t m = 2; @@ -1072,42 +1072,6 @@ TEST_F(EcGroupTest, MultiExpFailsGivenNullPointer) { EXPECT_EQ(kEpidBadArgErr, EcMultiExp(this->efq, pts, b_withnull, m, this->efq_r)); } -TEST_F(EcGroupTest, MultiExpFailsGivenIncorrectMLen) { - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; - BigNumStr const* b[] = {&bnm0, &bnm1}; - EXPECT_EQ(kEpidBadArgErr, EcMultiExp(this->efq, pts, b, 0, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcMultiExp(this->efq, pts, b, std::numeric_limits::max(), - this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcMultiExp(this->efq, pts, b, (size_t)INT_MAX + 1, this->efq_r)); -} -TEST_F(EcGroupTest, MultiExpFailsGivenOutOfRangeExponent) { - EcPoint const* pts[] = {this->efq_a}; - BigNumStr const* b_1[] = {&this->p}; - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, EcMultiExp(this->efq, pts, b_1, 1, this->efq_r)); -} -TEST_F(EcGroupTest, MultiExpFailsGivenOutOfRangeExponents) { - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm_1 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, - 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, - 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, - 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - BigNumStr const* b_1[] = {&bnm_1, &this->p}; - BigNumStr const* b_2[] = {&this->p, &bnm_1}; - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, EcMultiExp(this->efq, pts, b_1, 2, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, EcMultiExp(this->efq, pts, b_2, 2, this->efq_r)); -} TEST_F(EcGroupTest, MultiExpWorksGivenOneZeroExponent) { G1ElemStr efq_r_str; BigNumStr zero_bn_str = {0}; @@ -1218,20 +1182,35 @@ TEST_F(EcGroupTest, MultiExpWorksGivenTwoG2Exponents) { WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); EXPECT_EQ(this->efq2_multiexp_abxy_str, efq2_r_str); } +TEST_F(EcGroupTest, MultiExpWorksTwiceGivenSameOutputBuf) { + G2ElemStr efq2_r_str; + EcPoint const* pts[] = {this->efq2_a, this->efq2_b}; + BigNumStr const* b[] = {&this->x_str, &this->y_str}; + size_t m = 2; + EcPointObj temp(&this->efq2); + G2ElemStr temp_str; + EXPECT_EQ(kEpidNoErr, EcMultiExp(this->efq2, pts, b, m, this->efq2_r)); + temp = this->efq2_r; + EXPECT_EQ(kEpidNoErr, EcMultiExp(this->efq2, pts, b, m, this->efq2_r)); + THROW_ON_EPIDERR( + WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); + THROW_ON_EPIDERR(WriteEcPoint(this->efq2, temp, &temp_str, sizeof(temp_str))); + EXPECT_EQ(temp_str, efq2_r_str); +} /////////////////////////////////////////////////////////////////////// // EcMultiExpBn TEST_F(EcGroupTest, MultiExpBnFailsGivenArgumentsMismatch) { EcPoint const* pts_ec1[] = {this->efq_a, this->efq_b}; EcPoint const* pts_ec2[] = {this->efq2_a, this->efq2_b}; EcPoint const* pts_ec1_ec2[] = {this->efq_a, this->efq2_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumObj bno0(bnm0); BigNumObj bno1(bnm1); BigNum const* b[] = {bno0, bno1}; @@ -1248,14 +1227,14 @@ TEST_F(EcGroupTest, MultiExpBnFailsGivenArgumentsMismatch) { TEST_F(EcGroupTest, MultiExpBnFailsGivenNullPointer) { EcPoint const* pts[] = {this->efq_a, this->efq_b}; EcPoint const* pts_withnull[] = {nullptr, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumObj bno0(bnm0); BigNumObj bno1(bnm1); BigNum const* b[] = {bno0, bno1}; @@ -1272,42 +1251,6 @@ TEST_F(EcGroupTest, MultiExpBnFailsGivenNullPointer) { EXPECT_EQ(kEpidBadArgErr, EcMultiExpBn(this->efq, pts, b_withnull, m, this->efq_r)); } -TEST_F(EcGroupTest, MultiExpBnFailsGivenIncorrectMLen) { - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; - BigNumObj bno0(bnm0); - BigNumObj bno1(bnm1); - BigNum const* b[] = {bno0, bno1}; - EXPECT_EQ(kEpidBadArgErr, EcMultiExpBn(this->efq, pts, b, 0, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcMultiExpBn(this->efq, pts, b, std::numeric_limits::max(), - this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcMultiExpBn(this->efq, pts, b, (size_t)INT_MAX + 1, this->efq_r)); -} -TEST_F(EcGroupTest, MultiExpBnFailsGivenOutOfRangeExponent) { - EcPoint const* pt[] = {this->efq_a}; - BigNumObj bno_p(this->p); - BigNum const* b[] = {bno_p}; - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm_1 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, - 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, - 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, - 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - BigNumObj bno_1(bnm_1); - BigNum const* b_1[] = {bno_1, bno_p}; - BigNum const* b_2[] = {bno_p, bno_1}; - EXPECT_EQ(kEpidBadArgErr, EcMultiExpBn(this->efq, pt, b, 1, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, EcMultiExpBn(this->efq, pts, b_1, 2, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, EcMultiExpBn(this->efq, pts, b_2, 2, this->efq_r)); -} TEST_F(EcGroupTest, MultiExpBnWorksGivenOneZeroExponent) { G1ElemStr efq_r_str; BigNumStr zero_bn_str = {0}; @@ -1442,6 +1385,23 @@ TEST_F(EcGroupTest, MultiExpBnWorksGivenTwoG2Exponents) { WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); EXPECT_EQ(this->efq2_multiexp_abxy_str, efq2_r_str); } +TEST_F(EcGroupTest, MultiExpBnWorksTwiceGivenSameOutputBuf) { + G2ElemStr efq2_r_str; + EcPoint const* pts[] = {this->efq2_a, this->efq2_b}; + BigNumObj bno_x(this->x_str); + BigNumObj bno_y(this->y_str); + BigNum const* b[] = {bno_x, bno_y}; + size_t m = 2; + EcPointObj temp(&this->efq2); + G2ElemStr temp_str; + EXPECT_EQ(kEpidNoErr, EcMultiExpBn(this->efq2, pts, b, m, this->efq2_r)); + temp = this->efq2_r; + EXPECT_EQ(kEpidNoErr, EcMultiExpBn(this->efq2, pts, b, m, this->efq2_r)); + THROW_ON_EPIDERR( + WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); + THROW_ON_EPIDERR(WriteEcPoint(this->efq2, temp, &temp_str, sizeof(temp_str))); + EXPECT_EQ(temp_str, efq2_r_str); +} TEST_F(EcGroupTest, MultiExpBnWorksGivenTwoDifferentSizeG3Exponents) { const G1ElemStr g3_b_str = { {{{ @@ -1477,9 +1437,9 @@ TEST_F(EcGroupTest, MultiExpBnWorksGivenTwoDifferentSizeG3Exponents) { 0x39, 0x57, 0xd4, 0xc5, 0x78, 0xf2, 0x77, 0x5c, 0x9f, 0x6c, 0xfe, 0x12, 0x00, 0xa8, 0xe0, 0xd3, 0x81, 0x38, 0xaa, 0x5a}; const BigNumStr bnm_nc_tick_str = {{{ - 0xcd, 0x2e, 0xe8, 0xf4, 0x85, 0x95, 0x04, 0x09, 0xbd, 0xa4, 0xfa, 0x07, - 0xe3, 0x1c, 0xb9, 0x5a, 0x82, 0x73, 0xa6, 0xea, 0x47, 0x5c, 0x31, 0x74, - 0x3c, 0x0a, 0xeb, 0x62, 0x94, 0x2f, 0x7b, 0x10, + 0xcd, 0x2e, 0xe8, 0xf4, 0x85, 0x95, 0x04, 0x09, 0xbd, 0xa4, 0xfa, + 0x07, 0xe3, 0x1c, 0xb9, 0x5a, 0x82, 0x73, 0xa6, 0xea, 0x47, 0x5c, + 0x31, 0x74, 0x3c, 0x0a, 0xeb, 0x62, 0x94, 0x2f, 0x7b, 0x10, }}}; BigNumObj bno_sf(bnm_sf_str); // In order to callculate exp sf data should be devided by group order @@ -1510,14 +1470,14 @@ TEST_F(EcGroupTest, SscmMultiExpFailsGivenArgumentsMismatch) { EcPoint const* pts_ec1[] = {this->efq_a, this->efq_b}; EcPoint const* pts_ec2[] = {this->efq2_a, this->efq2_b}; EcPoint const* pts_ec1_ec2[] = {this->efq_a, this->efq2_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumStr const* b[] = {&bnm0, &bnm1}; size_t m = 2; @@ -1533,14 +1493,14 @@ TEST_F(EcGroupTest, SscmMultiExpFailsGivenArgumentsMismatch) { TEST_F(EcGroupTest, SscmMultiExpFailsGivenNullPointer) { EcPoint const* pts[] = {this->efq_a, this->efq_b}; EcPoint const* pts_withnull[] = {nullptr, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, + 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, + 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, + 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; + const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, + 0xFF, 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, + 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, + 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; BigNumStr const* b[] = {&bnm0, &bnm1}; BigNumStr const* b_withnull[] = {nullptr, &bnm1}; size_t m = 2; @@ -1556,45 +1516,6 @@ TEST_F(EcGroupTest, SscmMultiExpFailsGivenNullPointer) { EXPECT_EQ(kEpidBadArgErr, EcSscmMultiExp(this->efq, pts, b_withnull, m, this->efq_r)); } -TEST_F(EcGroupTest, SscmMultiExpFailsGivenIncorrectMLen) { - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm0 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, - 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, - 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, - 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - const BigNumStr bnm1 = {{0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, - 0xFF, 0x6B, 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, - 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, 0x84, 0xFF, 0xFF, - 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; - BigNumStr const* b[] = {&bnm0, &bnm1}; - EXPECT_EQ(kEpidBadArgErr, EcSscmMultiExp(this->efq, pts, b, 0, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcSscmMultiExp(this->efq, pts, b, - std::numeric_limits::max(), this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, EcSscmMultiExp(this->efq, pts, b, - (size_t)INT_MAX + 1, this->efq_r)); -} -TEST_F(EcGroupTest, SscmMultiExpFailsGivenOutOfRangeExponent) { - EcPoint const* pts[] = {this->efq_a}; - BigNumStr const* b_1[] = {&this->p}; - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, - EcSscmMultiExp(this->efq, pts, b_1, 1, this->efq_r)); -} -TEST_F(EcGroupTest, SscmMultiExpFailsGivenOutOfRangeExponents) { - EcPoint const* pts[] = {this->efq_a, this->efq_b}; - const BigNumStr bnm_1 = {{0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, - 0x6B, 0x08, 0xFF, 0xFF, 0x0B, 0xF3, 0xAF, 0x27, - 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, - 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}}; - BigNumStr const* b_1[] = {&bnm_1, &this->p}; - BigNumStr const* b_2[] = {&this->p, &bnm_1}; - // The exponent should be less than elliptic curve group order - EXPECT_EQ(kEpidBadArgErr, - EcSscmMultiExp(this->efq, pts, b_1, 2, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcSscmMultiExp(this->efq, pts, b_2, 2, this->efq_r)); -} TEST_F(EcGroupTest, SscmMultiExpWorksGivenOneZeroExponent) { G1ElemStr efq_r_str; BigNumStr zero_bn_str = {0}; @@ -1705,6 +1626,21 @@ TEST_F(EcGroupTest, SscmMultiExpWorksGivenTwoG2Exponents) { WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); EXPECT_EQ(this->efq2_multiexp_abxy_str, efq2_r_str); } +TEST_F(EcGroupTest, SscmMultiExpWorksTwiceGivenSameOutputBuf) { + G2ElemStr efq2_r_str; + EcPoint const* pts[] = {this->efq2_a, this->efq2_b}; + BigNumStr const* b[] = {&this->x_str, &this->y_str}; + size_t m = 2; + EcPointObj temp(&this->efq2); + G2ElemStr temp_str; + EXPECT_EQ(kEpidNoErr, EcSscmMultiExp(this->efq2, pts, b, m, this->efq2_r)); + temp = this->efq2_r; + EXPECT_EQ(kEpidNoErr, EcSscmMultiExp(this->efq2, pts, b, m, this->efq2_r)); + THROW_ON_EPIDERR( + WriteEcPoint(this->efq2, this->efq2_r, &efq2_r_str, sizeof(efq2_r_str))); + THROW_ON_EPIDERR(WriteEcPoint(this->efq2, temp, &temp_str, sizeof(temp_str))); + EXPECT_EQ(temp_str, efq2_r_str); +} /////////////////////////////////////////////////////////////////////// // EcGetRandom TEST_F(EcGroupTest, GetRandomFailsGivenArgumentsMismatch) { @@ -1800,71 +1736,176 @@ TEST_F(EcGroupTest, InGroupFailsGivenContextMismatch) { TEST_F(EcGroupTest, HashFailsGivenArgumentsMismatch) { uint8_t const msg[] = {0}; EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq2, msg, sizeof(msg), kSha256, this->efq_r)); + EcHash(this->efq2, msg, sizeof(msg), kSha256, this->efq_r, NULL)); EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, msg, sizeof(msg), kSha256, this->efq2_r)); + EcHash(this->efq, msg, sizeof(msg), kSha256, this->efq2_r, NULL)); } TEST_F(EcGroupTest, HashFailsGivenNullPointer) { uint8_t const msg[] = {0}; EXPECT_EQ(kEpidBadArgErr, - EcHash(nullptr, msg, sizeof(msg), kSha256, this->efq_r)); + EcHash(nullptr, msg, sizeof(msg), kSha256, this->efq_r, NULL)); + EXPECT_EQ(kEpidBadArgErr, EcHash(this->efq, nullptr, sizeof(msg), kSha256, + this->efq_r, NULL)); EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, nullptr, sizeof(msg), kSha256, this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, msg, sizeof(msg), kSha256, nullptr)); + EcHash(this->efq, msg, sizeof(msg), kSha256, nullptr, NULL)); } TEST_F(EcGroupTest, HashFailsGivenUnsupportedHashAlg) { uint8_t const msg[] = {0}; EXPECT_EQ(kEpidHashAlgorithmNotSupported, - EcHash(this->efq, msg, sizeof(msg), kSha512_256, this->efq_r)); + EcHash(this->efq, msg, sizeof(msg), kSha3_256, this->efq_r, NULL)); EXPECT_EQ(kEpidHashAlgorithmNotSupported, - EcHash(this->efq, msg, sizeof(msg), kSha3_256, this->efq_r)); + EcHash(this->efq, msg, sizeof(msg), kSha3_384, this->efq_r, NULL)); EXPECT_EQ(kEpidHashAlgorithmNotSupported, - EcHash(this->efq, msg, sizeof(msg), kSha3_384, this->efq_r)); - EXPECT_EQ(kEpidHashAlgorithmNotSupported, - EcHash(this->efq, msg, sizeof(msg), kSha3_512, this->efq_r)); + EcHash(this->efq, msg, sizeof(msg), kSha3_512, this->efq_r, NULL)); } TEST_F(EcGroupTest, HashFailsGivenIncorrectMsgLen) { uint8_t const msg[] = {0}; EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, nullptr, 1, kSha256, this->efq_r)); + EcHash(this->efq, nullptr, 1, kSha256, this->efq_r, NULL)); EXPECT_EQ(kEpidBadArgErr, EcHash(this->efq, msg, std::numeric_limits::max(), kSha256, - this->efq_r)); - EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, msg, (size_t)INT_MAX + 1, kSha256, this->efq_r)); + this->efq_r, NULL)); + EXPECT_EQ(kEpidBadArgErr, EcHash(this->efq, msg, (size_t)INT_MAX + 1, kSha256, + this->efq_r, NULL)); #if (SIZE_MAX >= 0x100000001) // When size_t value allowed to be 0x100000001 - EXPECT_EQ(kEpidBadArgErr, - EcHash(this->efq, msg, (size_t)0x100000001, kSha256, this->efq_r)); + EXPECT_EQ(kEpidBadArgErr, EcHash(this->efq, msg, (size_t)0x100000001, kSha256, + this->efq_r, NULL)); #endif } TEST_F(EcGroupTest, HashAcceptsZeroLengthMessage) { - EXPECT_EQ(kEpidNoErr, EcHash(this->efq, "", 0, kSha256, this->efq_r)); + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, "", 0, kSha256, this->efq_r, NULL)); } TEST_F(EcGroupTest, HashWorksGivenSHA256HashAlg) { G1ElemStr efq_r_str; - EXPECT_EQ(kEpidNoErr, - EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha256, this->efq_r)); + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha256, + this->efq_r, NULL)); THROW_ON_EPIDERR( WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); EXPECT_EQ(this->efq_r_sha256_str, efq_r_str); } TEST_F(EcGroupTest, HashWorksGivenSHA384HashAlg) { G1ElemStr efq_r_str; - EXPECT_EQ(kEpidNoErr, - EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha384, this->efq_r)); + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha384, + this->efq_r, NULL)); THROW_ON_EPIDERR( WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); EXPECT_EQ(this->efq_r_sha384_str, efq_r_str); } TEST_F(EcGroupTest, HashWorksGivenSHA512HashAlg) { G1ElemStr efq_r_str; - EXPECT_EQ(kEpidNoErr, - EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha512, this->efq_r)); + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha512, + this->efq_r, NULL)); THROW_ON_EPIDERR( WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); EXPECT_EQ(this->efq_r_sha512_str, efq_r_str); } +TEST_F(EcGroupTest, HashWorksGivenSHA512256HashAlg) { + G1ElemStr efq_r_str; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha512_256, + this->efq_r, NULL)); + THROW_ON_EPIDERR( + WriteEcPoint(this->efq, this->efq_r, &efq_r_str, sizeof(efq_r_str))); + EXPECT_EQ(this->efq_r_sha512256_str, efq_r_str); +} +TEST_F(EcGroupTest, HashReturnsValidISha256) { + uint32_t i = 0; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha256, + this->efq_r, &i)); + EXPECT_EQ((uint32_t)4, i); +} +TEST_F(EcGroupTest, HashReturnsValidISha384) { + uint32_t i = 0; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha384, + this->efq_r, &i)); + EXPECT_EQ((uint32_t)0, i); +} +TEST_F(EcGroupTest, HashReturnsValidISha512) { + uint32_t i = 0; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha512, + this->efq_r, &i)); + EXPECT_EQ((uint32_t)1, i); +} +TEST_F(EcGroupTest, HashReturnsValidISha512256) { + uint32_t i = 0; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, sha_msg, sizeof(sha_msg), kSha512_256, + this->efq_r, &i)); + EXPECT_EQ((uint32_t)0, i); +} +TEST_F(EcGroupTest, HashWorksForArbitraryMsg) { + uint32_t i = 0; + std::vector msg_aad = {'a', 'a', 'd'}; + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, msg_aad.data(), msg_aad.size(), + kSha512, this->efq_r, &i)); + G1ElemStr exp_aad = { + 0x5e, 0x73, 0xbe, 0x39, 0x6b, 0xd8, 0x50, 0x2f, 0xb1, 0x93, 0xbf, + 0x9a, 0x3f, 0x42, 0x9d, 0x2a, 0xeb, 0xb7, 0x89, 0xb6, 0xcf, 0x52, + 0x78, 0x61, 0x19, 0x24, 0xae, 0x56, 0xb3, 0x15, 0xd6, 0x7e, 0x0d, + 0xb4, 0x3c, 0x33, 0xf3, 0x0a, 0xf1, 0x80, 0x21, 0x23, 0xd5, 0x6c, + 0x4a, 0xb6, 0x68, 0xcf, 0xa9, 0xcd, 0x44, 0x91, 0xc9, 0x6b, 0x50, + 0x96, 0x0f, 0x13, 0x47, 0x2d, 0x0b, 0xd5, 0x19, 0x68}; + G1ElemStr res_aad; + THROW_ON_EPIDERR( + WriteEcPoint(this->efq, this->efq_r, &res_aad, sizeof(res_aad))); + EXPECT_EQ(exp_aad, res_aad); + i = 0; + std::vector msg_1_MB(1024 * 1024); // exactly 1 MB; + uint8_t c = 0; + for (size_t j = 0; j < msg_1_MB.size(); ++j) { + msg_1_MB[j] = c++; + } + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, msg_1_MB.data(), msg_1_MB.size(), + kSha512, this->efq_r, &i)); + G1ElemStr exp_1_MB = { + 0xd8, 0xf7, 0xcd, 0x26, 0xa1, 0x86, 0x2e, 0x25, 0xa5, 0x17, 0x84, + 0x98, 0x80, 0x5b, 0xb6, 0x10, 0x1c, 0x0d, 0xe1, 0xf4, 0xaa, 0x50, + 0xfa, 0xdd, 0x67, 0x2f, 0xfd, 0x96, 0x95, 0x57, 0x1d, 0x0f, 0x92, + 0xcd, 0xd1, 0x99, 0x27, 0x29, 0xbe, 0x7c, 0x66, 0x27, 0x8e, 0x5b, + 0xc7, 0x0f, 0x9f, 0xad, 0xd7, 0x29, 0x54, 0x0f, 0xea, 0xa8, 0x01, + 0x42, 0xf9, 0x47, 0x1d, 0xec, 0x5c, 0x0c, 0x2e, 0xdb}; + G1ElemStr res_1_MB; + THROW_ON_EPIDERR( + WriteEcPoint(this->efq, this->efq_r, &res_1_MB, sizeof(res_1_MB))); + EXPECT_EQ(exp_1_MB, res_1_MB); + i = 0; + std::vector msg_1_MB_Minus_2(1024 * 1024 - 2); // exactly 1 MB; + c = 0; + for (size_t j = 0; j < msg_1_MB_Minus_2.size(); ++j) { + msg_1_MB_Minus_2[j] = c++; + } + EXPECT_EQ(kEpidNoErr, + EcHash(this->efq, msg_1_MB_Minus_2.data(), msg_1_MB_Minus_2.size(), + kSha512, this->efq_r, &i)); + G1ElemStr exp_1_MB_Minus_2 = { + 0x96, 0x31, 0xc8, 0xf7, 0x63, 0x82, 0x4b, 0x69, 0xae, 0xcd, 0x7a, + 0x54, 0xed, 0x66, 0x45, 0x22, 0xa1, 0xd3, 0x5a, 0x07, 0x56, 0xf4, + 0xfb, 0x47, 0xc7, 0xdf, 0x07, 0xf7, 0x21, 0xfb, 0x77, 0x2b, 0x65, + 0xe1, 0xa2, 0x2e, 0x3b, 0x1a, 0xc8, 0x62, 0x0b, 0xb8, 0xac, 0x32, + 0x21, 0xce, 0xa1, 0x74, 0x50, 0x55, 0xc2, 0x03, 0x91, 0x35, 0x63, + 0x25, 0x45, 0xb3, 0xc6, 0x3c, 0xe0, 0xe8, 0x74, 0xb4}; + G1ElemStr res_1_MB_Minus_2; + THROW_ON_EPIDERR(WriteEcPoint(this->efq, this->efq_r, &res_1_MB_Minus_2, + sizeof(res_1_MB_Minus_2))); + EXPECT_EQ(exp_1_MB_Minus_2, res_1_MB_Minus_2); + i = 0; + std::vector msg_102(102); // exactly 1 MB; + c = 0; + for (size_t j = 0; j < msg_102.size(); ++j) { + msg_102[j] = c++; + } + EXPECT_EQ(kEpidNoErr, EcHash(this->efq, msg_102.data(), msg_102.size(), + kSha512, this->efq_r, &i)); + G1ElemStr exp_102 = { + 0x21, 0xf6, 0xb5, 0x2c, 0xbc, 0xb7, 0x90, 0x2b, 0x36, 0xe1, 0x43, + 0xb6, 0xca, 0x66, 0x7e, 0x0a, 0x87, 0x66, 0x32, 0xe0, 0x70, 0x74, + 0x2b, 0x20, 0x92, 0x8f, 0x8b, 0x3d, 0xd7, 0xe1, 0x95, 0xc7, 0xa9, + 0x1b, 0x46, 0x94, 0xab, 0xfc, 0x59, 0x0e, 0x63, 0x9d, 0x42, 0x15, + 0x85, 0xcb, 0x91, 0x12, 0xca, 0x19, 0x54, 0xa3, 0xe9, 0x77, 0xd0, + 0x1b, 0x2a, 0x97, 0x1e, 0xd0, 0x59, 0x33, 0xe1, 0x1d}; + G1ElemStr res_102; + THROW_ON_EPIDERR( + WriteEcPoint(this->efq, this->efq_r, &res_102, sizeof(res_102))); + EXPECT_EQ(exp_102, res_102); +} /////////////////////////////////////////////////////////////////////// // 1.1 EcHash TEST_F(EcGroupTest, Epid11HashFailsGivenMismatchedArguments) { @@ -1954,12 +1995,12 @@ TEST_F(EcGroupTest, MakePointSucceedsGivenElement) { // a pre-computed point in eqf G1ElemStr efq_ref_str = { - {{0X1C, 0X53, 0X40, 0X69, 0X8B, 0X77, 0X75, 0XAA, 0X2B, 0X7D, 0X91, 0XD6, - 0X29, 0X49, 0X05, 0X7F, 0XF6, 0X4C, 0X63, 0X90, 0X58, 0X22, 0X06, 0XF5, - 0X1F, 0X3B, 0X9F, 0XA2, 0X04, 0X39, 0XA9, 0X67}}, - {{0X3B, 0X65, 0X58, 0XAC, 0X97, 0X46, 0X47, 0XC9, 0X84, 0X57, 0X3F, 0XFA, - 0X4F, 0XB0, 0X64, 0X8D, 0X48, 0XC8, 0X14, 0XEB, 0XF1, 0X94, 0X87, 0XDC, - 0XB3, 0X73, 0X90, 0X1D, 0X75, 0XAD, 0XD5, 0X56}}}; + {{0X1C, 0X53, 0X40, 0X69, 0X8B, 0X77, 0X75, 0XAA, 0X2B, 0X7D, 0X91, + 0XD6, 0X29, 0X49, 0X05, 0X7F, 0XF6, 0X4C, 0X63, 0X90, 0X58, 0X22, + 0X06, 0XF5, 0X1F, 0X3B, 0X9F, 0XA2, 0X04, 0X39, 0XA9, 0X67}}, + {{0X3B, 0X65, 0X58, 0XAC, 0X97, 0X46, 0X47, 0XC9, 0X84, 0X57, 0X3F, + 0XFA, 0X4F, 0XB0, 0X64, 0X8D, 0X48, 0XC8, 0X14, 0XEB, 0XF1, 0X94, + 0X87, 0XDC, 0XB3, 0X73, 0X90, 0X1D, 0X75, 0XAD, 0XD5, 0X56}}}; // create a point with x == ref.x FfElementObj elem(&this->fq, efq_ref_str.x); diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/ffelement-test.cc b/external/epid-sdk/epid/common/math/unittests/ffelement-test.cc similarity index 91% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/ffelement-test.cc rename to external/epid-sdk/epid/common/math/unittests/ffelement-test.cc index 9a9c5d14..212e09e7 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/ffelement-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/ffelement-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,18 +19,19 @@ * \brief FfElement unit tests. */ +#include #include #include -#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/prng-testhelper.h" -#include "epid/common-testhelper/octstr-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/octstr-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" extern "C" { #include "epid/common/math/finitefield.h" @@ -113,10 +114,10 @@ class FfElementTest : public ::testing::Test { fq_4 = FfElementObj(&fq, &fq_4_str, sizeof(fq_4_str)); fq_5 = FfElementObj(&fq, &fq_5_str, sizeof(fq_5_str)); fq_a = FfElementObj(&fq, &bn_a_str, sizeof(bn_a_str)); - // construct EPID 1.1 Fq finite field + // construct Intel(R) EPID 1.1 Fq finite field epid11_fq = FiniteFieldObj(bn_epid11_bn_q_str); - // construct EPID 1.1 Fqd finite field + // construct Intel(R) EPID 1.1 Fqd finite field epid11_fqd = FiniteFieldObj(epid11_fq, bn_epid11_fq_coeffs, COUNT_OF(bn_epid11_fq_coeffs)); @@ -128,7 +129,7 @@ class FfElementTest : public ::testing::Test { THROW_ON_EPIDERR(WriteFfElement(epid11_fq, epid11_neg_qnr, &epid11_ground_element_str.a[0], sizeof(epid11_ground_element_str.a[0]))); - // construct EPID 1.1 Fqk finite field + // construct Intel(R) EPID 1.1 Fqk finite field epid11_GT = FiniteFieldObj( epid11_fqd, FfElementObj(&epid11_fqd, epid11_ground_element_str), 2); @@ -286,6 +287,7 @@ class FfElementTest : public ::testing::Test { static const FqElemStr fq_abc_sha256_str; static const FqElemStr fq_abc_sha384_str; static const FqElemStr fq_abc_sha512_str; + static const FqElemStr fq_abc_sha512256_str; // arbitrary Fq12 constant a (unrelated to a above) static const Fq12ElemStr fq12_g_str; @@ -325,7 +327,7 @@ class FfElementTest : public ::testing::Test { static const BigNumStr fq_multi_exp_exp_6[6]; static const FqElemStr fq_multi_exp_res_6; - // EPID 1.1 GT Multi Exp Data + // Intel(R) EPID 1.1 GT Multi Exp Data static const Fq6ElemStr epid11_GT_multi_exp_base_3[3]; static const std::vector epid11_GT_multi_exp_exp_3[3]; static const Fq6ElemStr epid11_GT_multi_exp_res_3; @@ -337,31 +339,31 @@ class FfElementTest : public ::testing::Test { }; const Fq2ElemStr FfElementTest::fq2_2_1_str = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; const Fq6ElemStr FfElementTest::fq6_0_0_1_0_0_0_str = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; // Intel(R) EPID 2.0 parameter p const BigNumStr FfElementTest::bn_p_str = { @@ -425,23 +427,23 @@ const BigNumStr FfElementTest::bn_epid11_bn_q_str = { // Intel(R) EPID 1.1 parameter qnr const FqElemStr FfElementTest::fq_epid11_fq_qnr = { - {0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, 0x52, 0x94, - 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, 0x2B, 0x6E, - 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}}; + {0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, 0x52, + 0x94, 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, + 0x2B, 0x6E, 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}}; // Intel(R) EPID 1.1 parameter coeff const BigNumStr FfElementTest::bn_epid11_fq_coeffs[3] = { - {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, 0x94, - 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, 0x43, 0x89, - 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, + {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, + 0x94, 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, + 0x43, 0x89, 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, - {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, 0x0E, - 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, 0x85, 0x7A, - 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, + {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, + 0x0E, 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, + 0x85, 0x7A, 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, - {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, 0x4B, - 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, 0x24, 0xA4, - 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; + {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, + 0x4B, 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, + 0x24, 0xA4, 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; // zero const BigNumStr FfElementTest::bn_0_str = { @@ -511,12 +513,12 @@ const FqElemStr FfElementTest::fq_a_str = { 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}; const Fq2ElemStr FfElementTest::fq2_a_str = { - {{{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, - {{{0xDD, 0x2B, 0xE9, 0x59, 0x24, 0xA5, 0xB3, 0xFD, 0xEB, 0xE1, 0x3C, 0xC0, - 0x73, 0x4E, 0x99, 0xEE, 0x36, 0xF6, 0xC0, 0x1A, 0x76, 0x01, 0x0A, 0xF0, - 0xCB, 0xB4, 0x71, 0x88, 0x95, 0xCB, 0x35, 0xBA}}}}}; + {{{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0xDD, 0x2B, 0xE9, 0x59, 0x24, 0xA5, 0xB3, 0xFD, 0xEB, 0xE1, 0x3C, + 0xC0, 0x73, 0x4E, 0x99, 0xEE, 0x36, 0xF6, 0xC0, 0x1A, 0x76, 0x01, + 0x0A, 0xF0, 0xCB, 0xB4, 0x71, 0x88, 0x95, 0xCB, 0x35, 0xBA}}}}}; // arbitrary constant b (256 bit value) const BigNumStr FfElementTest::bn_b_str = { @@ -536,32 +538,32 @@ const FqElemStr FfElementTest::fq_sum_ab_str = { 0x11, 0x78, 0xF6, 0x59, 0x23, 0x75, 0xEF, 0x7D, 0x46, 0x7C}; const Fq2ElemStr FfElementTest::fq2_sum_ab_str = { - {{{{0xF9, 0x0B, 0x7F, 0x72, 0x65, 0x94, 0x67, 0x2A, 0x9F, 0x0F, 0x2F, 0xBA, - 0x3B, 0x2B, 0x26, 0x83, 0xBA, 0xD3, 0xFB, 0x7B, 0x9D, 0x79, 0x11, 0x78, - 0xF6, 0x59, 0x23, 0x75, 0xEF, 0x7D, 0x46, 0x7C}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0xF9, 0x0B, 0x7F, 0x72, 0x65, 0x94, 0x67, 0x2A, 0x9F, 0x0F, 0x2F, + 0xBA, 0x3B, 0x2B, 0x26, 0x83, 0xBA, 0xD3, 0xFB, 0x7B, 0x9D, 0x79, + 0x11, 0x78, 0xF6, 0x59, 0x23, 0x75, 0xEF, 0x7D, 0x46, 0x7C}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; const Fq6ElemStr FfElementTest::fq6_sum_ab_str = { - {{{{0xF9, 0x0B, 0x7F, 0x72, 0x65, 0x94, 0x67, 0x2A, 0x9F, 0x0F, 0x2F, 0xBA, - 0x3B, 0x2B, 0x26, 0x83, 0xBA, 0xD3, 0xFB, 0x7B, 0x9D, 0x79, 0x11, 0x78, - 0xF6, 0x59, 0x23, 0x75, 0xEF, 0x7D, 0x46, 0x7C}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0xF9, 0x0B, 0x7F, 0x72, 0x65, 0x94, 0x67, 0x2A, 0x9F, 0x0F, 0x2F, + 0xBA, 0x3B, 0x2B, 0x26, 0x83, 0xBA, 0xD3, 0xFB, 0x7B, 0x9D, 0x79, + 0x11, 0x78, 0xF6, 0x59, 0x23, 0x75, 0xEF, 0x7D, 0x46, 0x7C}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; const Fq12ElemStr FfElementTest::fq12_sum_ab_str = { {{{{{{0xF9, 0x0B, 0x7F, 0x72, 0x65, 0x94, 0x67, 0x2A, 0x9F, 0x0F, 0x2F, @@ -609,12 +611,12 @@ const FqElemStr FfElementTest::fq_mul_ab_str = { 0x00, 0xCF, 0x82, 0x88, 0xBD, 0x39, 0x0B, 0xA2, 0x0B, 0x58}; const Fq2ElemStr FfElementTest::fq2_mul_ab_str = { - {{{{0xE4, 0xAB, 0xE3, 0xE4, 0x08, 0xC3, 0x8A, 0x00, 0x78, 0x50, 0x01, 0xA9, - 0x4A, 0xFC, 0x43, 0x15, 0xA2, 0x99, 0x51, 0x20, 0x6B, 0x9C, 0x00, 0xCF, - 0x82, 0x88, 0xBD, 0x39, 0x0B, 0xA2, 0x0B, 0x58}}}, - {{{0xB4, 0xE4, 0x39, 0xEA, 0x70, 0xDE, 0x15, 0xC3, 0xC6, 0x91, 0xFD, 0x7F, - 0xBE, 0x2B, 0xF5, 0xD2, 0xC0, 0xB7, 0x20, 0xFC, 0x1F, 0x02, 0x33, 0xC9, - 0x39, 0x93, 0xB9, 0x5E, 0x55, 0x51, 0xB6, 0x46}}}}}; + {{{{0xE4, 0xAB, 0xE3, 0xE4, 0x08, 0xC3, 0x8A, 0x00, 0x78, 0x50, 0x01, + 0xA9, 0x4A, 0xFC, 0x43, 0x15, 0xA2, 0x99, 0x51, 0x20, 0x6B, 0x9C, + 0x00, 0xCF, 0x82, 0x88, 0xBD, 0x39, 0x0B, 0xA2, 0x0B, 0x58}}}, + {{{0xB4, 0xE4, 0x39, 0xEA, 0x70, 0xDE, 0x15, 0xC3, 0xC6, 0x91, 0xFD, + 0x7F, 0xBE, 0x2B, 0xF5, 0xD2, 0xC0, 0xB7, 0x20, 0xFC, 0x1F, 0x02, + 0x33, 0xC9, 0x39, 0x93, 0xB9, 0x5E, 0x55, 0x51, 0xB6, 0x46}}}}}; // 1/a const FqElemStr FfElementTest::fq_inv_a_str = { @@ -651,6 +653,13 @@ const FqElemStr FfElementTest::fq_abc_sha512_str = { 0x50, 0xD1, 0x3B, 0xF2, 0x35, 0xF7, 0x97, 0x91, 0x05, 0x3D, 0x64, 0xC0, 0x06, 0x45, 0x9F, 0xEC, 0xD8, 0xDB, 0x53, 0x3E, 0xC3, }; + +const FqElemStr FfElementTest::fq_abc_sha512256_str = { + 0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9, 0x9B, 0x2E, 0x29, + 0xB7, 0x6B, 0x4C, 0x7D, 0xAB, 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC, + 0x6D, 0x46, 0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23, +}; + const Fq12ElemStr FfElementTest::fq12_g_str = { {{{{{{0xBA, 0x10, 0x1F, 0xF6, 0x46, 0x8B, 0xE9, 0x32, 0x4F, 0xC0, 0xA5, 0x01, 0xAD, 0x5E, 0xE2, 0x31, 0x16, 0x29, 0x96, 0xED, 0xA7, 0xDE, @@ -919,14 +928,14 @@ const Fq12ElemStr FfElementTest::fq12_mul_gb_str = { }; const FqElemStr FfElementTest::fq_multi_exp_base_1[1] = {{ - 0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A, + 0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A, }}; const BigNumStr FfElementTest::fq_multi_exp_exp_1[1] = {{ - 0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, 0xFF, 0xFF, - 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x81, - 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF, + 0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, 0xFF, + 0xFF, 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x81, 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF, }}; const FqElemStr FfElementTest::fq_multi_exp_res_1 = { 0x6A, 0x21, 0xEC, 0x89, 0xCC, 0x13, 0x2F, 0x6F, 0x29, 0x1B, 0x3A, @@ -935,9 +944,9 @@ const FqElemStr FfElementTest::fq_multi_exp_res_1 = { }; const std::vector FfElementTest::fq_multi_exp_exp_1_264({ - 0x08, 0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, 0xFF, - 0xFF, 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x81, 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF, + 0x08, 0xFF, 0xFB, 0x3E, 0x5D, 0xFF, 0x9A, 0xFF, 0x02, 0x00, 0xFF, + 0xFF, 0xFF, 0xF2, 0xE1, 0x85, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x81, 0xFF, 0xFD, 0xFF, 0xEB, 0xFF, 0x29, 0xA7, 0xFF, }); const FqElemStr FfElementTest::fq_multi_exp_res_1_264 = { 0x71, 0x41, 0xa1, 0xdb, 0xd1, 0xd1, 0x50, 0xc2, 0x73, 0x07, 0xc1, @@ -949,19 +958,19 @@ const FqElemStr FfElementTest::fq_multi_exp_res_1_256_264 = { 0x99, 0xe9, 0x23, 0xf9, 0x6b, 0x10, 0x35, 0x7c, 0xf1, 0xa3}; const FqElemStr FfElementTest::fq_multi_exp_base_2[2] = { - {0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, 0x67, - 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, 0xD9, 0x98, - 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}, - {0xDD, 0x2B, 0xE9, 0x59, 0x24, 0xA5, 0xB3, 0xFD, 0xEB, 0xE1, 0x3C, 0xC0, - 0x73, 0x4E, 0x99, 0xEE, 0x36, 0xF6, 0xC0, 0x1A, 0x76, 0x01, 0x0A, 0xF0, - 0xCB, 0xB4, 0x71, 0x88, 0x95, 0xCB, 0x35, 0xBA}}; + {0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2, + 0x67, 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E, + 0xD9, 0x98, 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}, + {0xDD, 0x2B, 0xE9, 0x59, 0x24, 0xA5, 0xB3, 0xFD, 0xEB, 0xE1, 0x3C, + 0xC0, 0x73, 0x4E, 0x99, 0xEE, 0x36, 0xF6, 0xC0, 0x1A, 0x76, 0x01, + 0x0A, 0xF0, 0xCB, 0xB4, 0x71, 0x88, 0x95, 0xCB, 0x35, 0xBA}}; const BigNumStr FfElementTest::fq_multi_exp_exp_2[2] = { - {0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, 0x08, 0xFF, 0xFF, - 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, 0xEB, 0xFF, - 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}, - {0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, 0xFF, 0x6B, 0xD5, - 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, 0x7C, 0xFF, - 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; + {0x11, 0xFF, 0xFF, 0xFF, 0x4F, 0x59, 0xB1, 0xD3, 0x6B, 0x08, 0xFF, + 0xFF, 0x0B, 0xF3, 0xAF, 0x27, 0xFF, 0xB8, 0xFF, 0xFF, 0x98, 0xFF, + 0xEB, 0xFF, 0xF2, 0x6A, 0xFF, 0xFF, 0xEA, 0x31, 0xFF, 0xFF}, + {0xE2, 0xFF, 0x03, 0x1D, 0xFF, 0x19, 0x81, 0xCB, 0xFF, 0xFF, 0x6B, + 0xD5, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, 0xFF, 0x5A, 0xFF, 0x5C, + 0x7C, 0xFF, 0x84, 0xFF, 0xFF, 0x8C, 0x03, 0xB2, 0x26, 0xFF}}; const FqElemStr FfElementTest::fq_multi_exp_res_2 = { 0x8A, 0xF7, 0x96, 0x53, 0x9C, 0xC3, 0x57, 0x89, 0x50, 0xE3, 0xAB, 0x12, 0x62, 0xEA, 0x0C, 0xE4, 0x65, 0xA6, 0x91, 0x09, 0x93, 0x81, @@ -969,56 +978,56 @@ const FqElemStr FfElementTest::fq_multi_exp_res_2 = { }; const FqElemStr FfElementTest::fq_multi_exp_base_3[3] = { - {0x24, 0x9D, 0xDD, 0x1A, 0xC0, 0x07, 0x1F, 0x65, 0xDF, 0xBB, 0xC7, 0x39, - 0x99, 0x44, 0x63, 0x8E, 0x7E, 0xB2, 0x85, 0x82, 0xC6, 0x4E, 0x2D, 0x39, - 0xA8, 0x3F, 0x12, 0xB4, 0xE9, 0x9D, 0x67, 0x28}, - {0x6B, 0x51, 0x6B, 0x33, 0x0B, 0x2E, 0x2A, 0x94, 0x34, 0xCC, 0x7E, 0x97, - 0xFA, 0x85, 0x51, 0x44, 0x30, 0xE5, 0xF2, 0x68, 0x23, 0x31, 0x84, 0xFF, - 0xBB, 0x95, 0x9A, 0xB2, 0x80, 0x95, 0xC4, 0x91}, - {0x77, 0xED, 0xA2, 0x53, 0xA3, 0xBF, 0x6C, 0x58, 0x16, 0x7D, 0xEF, 0x8A, - 0x7D, 0x38, 0x65, 0x3F, 0x92, 0xA6, 0x85, 0xD7, 0x9F, 0x80, 0xA4, 0xA1, - 0x70, 0x02, 0xE5, 0x66, 0xF2, 0xD8, 0xD7, 0xD2}}; + {0x24, 0x9D, 0xDD, 0x1A, 0xC0, 0x07, 0x1F, 0x65, 0xDF, 0xBB, 0xC7, + 0x39, 0x99, 0x44, 0x63, 0x8E, 0x7E, 0xB2, 0x85, 0x82, 0xC6, 0x4E, + 0x2D, 0x39, 0xA8, 0x3F, 0x12, 0xB4, 0xE9, 0x9D, 0x67, 0x28}, + {0x6B, 0x51, 0x6B, 0x33, 0x0B, 0x2E, 0x2A, 0x94, 0x34, 0xCC, 0x7E, + 0x97, 0xFA, 0x85, 0x51, 0x44, 0x30, 0xE5, 0xF2, 0x68, 0x23, 0x31, + 0x84, 0xFF, 0xBB, 0x95, 0x9A, 0xB2, 0x80, 0x95, 0xC4, 0x91}, + {0x77, 0xED, 0xA2, 0x53, 0xA3, 0xBF, 0x6C, 0x58, 0x16, 0x7D, 0xEF, + 0x8A, 0x7D, 0x38, 0x65, 0x3F, 0x92, 0xA6, 0x85, 0xD7, 0x9F, 0x80, + 0xA4, 0xA1, 0x70, 0x02, 0xE5, 0x66, 0xF2, 0xD8, 0xD7, 0xD2}}; const BigNumStr FfElementTest::fq_multi_exp_exp_3[3] = { - {0xFF, 0xFF, 0xFF, 0xB4, 0x48, 0xFF, 0xFF, 0xFF, 0xA3, 0xFF, 0xE3, 0xFF, - 0x61, 0xFF, 0xA2, 0x97, 0x9A, 0xFF, 0x6F, 0x04, 0xC6, 0xB9, 0xFF, 0x22, - 0xFF, 0x20, 0x9E, 0xFF, 0x43, 0xFF, 0xFF, 0xFF}, - {0xB1, 0x19, 0xBF, 0xFF, 0x74, 0x7F, 0xCC, 0x34, 0x1E, 0x30, 0x7D, 0xC5, - 0xC4, 0xFF, 0xE7, 0xF8, 0xFF, 0x5F, 0xFF, 0x73, 0xFF, 0x58, 0xFF, 0xD6, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEC, 0xFF, 0xFF}, - {0xFF, 0xFF, 0x0D, 0xFF, 0xFF, 0xFF, 0xFF, 0x26, 0xA8, 0xFF, 0xFF, 0xFF, - 0x3E, 0xFF, 0xFF, 0xFF, 0xE0, 0x4F, 0xFF, 0xE3, 0xFF, 0xFF, 0xEB, 0x04, - 0x4B, 0xFF, 0x5D, 0x55, 0xFF, 0x2D, 0xFF, 0xFF}}; + {0xFF, 0xFF, 0xFF, 0xB4, 0x48, 0xFF, 0xFF, 0xFF, 0xA3, 0xFF, 0xE3, + 0xFF, 0x61, 0xFF, 0xA2, 0x97, 0x9A, 0xFF, 0x6F, 0x04, 0xC6, 0xB9, + 0xFF, 0x22, 0xFF, 0x20, 0x9E, 0xFF, 0x43, 0xFF, 0xFF, 0xFF}, + {0xB1, 0x19, 0xBF, 0xFF, 0x74, 0x7F, 0xCC, 0x34, 0x1E, 0x30, 0x7D, + 0xC5, 0xC4, 0xFF, 0xE7, 0xF8, 0xFF, 0x5F, 0xFF, 0x73, 0xFF, 0x58, + 0xFF, 0xD6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEC, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x0D, 0xFF, 0xFF, 0xFF, 0xFF, 0x26, 0xA8, 0xFF, 0xFF, + 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0xE0, 0x4F, 0xFF, 0xE3, 0xFF, 0xFF, + 0xEB, 0x04, 0x4B, 0xFF, 0x5D, 0x55, 0xFF, 0x2D, 0xFF, 0xFF}}; const FqElemStr FfElementTest::fq_multi_exp_res_3 = { 0x04, 0x22, 0x21, 0xE7, 0x9F, 0xE3, 0x07, 0x2F, 0xA4, 0xBB, 0x56, 0x84, 0xD5, 0x93, 0x4A, 0xDA, 0x5B, 0x89, 0x07, 0xBE, 0xC5, 0x5F, 0xE6, 0x5C, 0x18, 0xF0, 0xF8, 0x8E, 0x8E, 0x00, 0xB9, 0x87, }; const FqElemStr FfElementTest::fq_multi_exp_base_4[4] = { - {0x81, 0xEE, 0x78, 0x31, 0x4C, 0xC0, 0x3C, 0xDD, 0x16, 0x52, 0xC6, 0x7E, - 0x07, 0x4C, 0xFE, 0xC4, 0x50, 0x63, 0x5A, 0x40, 0xC8, 0xDF, 0x94, 0x23, - 0x1A, 0x90, 0xDD, 0x24, 0x61, 0x23, 0xDD, 0x87}, - {0x76, 0xBB, 0x2C, 0x1C, 0xB3, 0x78, 0x93, 0x7E, 0x10, 0x29, 0xC3, 0xEC, - 0xBD, 0xA3, 0x75, 0x3A, 0xF1, 0x0B, 0xE1, 0xCA, 0xEE, 0x02, 0x58, 0x74, - 0xC7, 0xDC, 0xB8, 0x4F, 0x3F, 0x7B, 0xA2, 0xFC}, - {0x3A, 0xD3, 0x04, 0xAA, 0x9D, 0x2A, 0xDE, 0x86, 0x56, 0x84, 0x80, 0x42, - 0xA5, 0x68, 0xD8, 0x6E, 0x65, 0xC4, 0x08, 0x07, 0x87, 0x4B, 0xC1, 0x92, - 0xCB, 0x68, 0x52, 0x6C, 0x5A, 0x4F, 0x7C, 0xFB}, - {0x56, 0xE7, 0xBD, 0x59, 0x54, 0xCC, 0x20, 0x16, 0xAE, 0x36, 0xD1, 0xB0, - 0xE4, 0x82, 0x47, 0x27, 0x32, 0xD1, 0x38, 0x7C, 0x53, 0x7F, 0xDD, 0xF4, - 0xDE, 0xFA, 0xF7, 0x0F, 0xDD, 0xDF, 0x48, 0xA9}}; + {0x81, 0xEE, 0x78, 0x31, 0x4C, 0xC0, 0x3C, 0xDD, 0x16, 0x52, 0xC6, + 0x7E, 0x07, 0x4C, 0xFE, 0xC4, 0x50, 0x63, 0x5A, 0x40, 0xC8, 0xDF, + 0x94, 0x23, 0x1A, 0x90, 0xDD, 0x24, 0x61, 0x23, 0xDD, 0x87}, + {0x76, 0xBB, 0x2C, 0x1C, 0xB3, 0x78, 0x93, 0x7E, 0x10, 0x29, 0xC3, + 0xEC, 0xBD, 0xA3, 0x75, 0x3A, 0xF1, 0x0B, 0xE1, 0xCA, 0xEE, 0x02, + 0x58, 0x74, 0xC7, 0xDC, 0xB8, 0x4F, 0x3F, 0x7B, 0xA2, 0xFC}, + {0x3A, 0xD3, 0x04, 0xAA, 0x9D, 0x2A, 0xDE, 0x86, 0x56, 0x84, 0x80, + 0x42, 0xA5, 0x68, 0xD8, 0x6E, 0x65, 0xC4, 0x08, 0x07, 0x87, 0x4B, + 0xC1, 0x92, 0xCB, 0x68, 0x52, 0x6C, 0x5A, 0x4F, 0x7C, 0xFB}, + {0x56, 0xE7, 0xBD, 0x59, 0x54, 0xCC, 0x20, 0x16, 0xAE, 0x36, 0xD1, + 0xB0, 0xE4, 0x82, 0x47, 0x27, 0x32, 0xD1, 0x38, 0x7C, 0x53, 0x7F, + 0xDD, 0xF4, 0xDE, 0xFA, 0xF7, 0x0F, 0xDD, 0xDF, 0x48, 0xA9}}; const BigNumStr FfElementTest::fq_multi_exp_exp_4[4] = { - {0xFF, 0xA5, 0xC3, 0xFF, 0xFF, 0x09, 0x18, 0x18, 0x95, 0x40, 0xFF, 0xFF, - 0xDB, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0xFF, 0x25, 0xFF, 0xFF, 0x42, 0x07, - 0xB5, 0xFF, 0x26, 0xE0, 0x4F, 0xB5, 0xB4, 0xFF}, - {0x1F, 0xFF, 0xAA, 0xF1, 0xFF, 0xFF, 0x7E, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, - 0xE7, 0xDF, 0xFF, 0xEE, 0xFF, 0x57, 0xFF, 0xFF, 0xFF, 0xB8, 0xB3, 0x9C, - 0xFF, 0x8A, 0x89, 0xFF, 0xFE, 0x32, 0xFF, 0xC1}, - {0x9A, 0xFF, 0xFF, 0x9B, 0xFF, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0x36, 0xF0, 0xC5, 0xAE, 0x87, 0x41, 0xFF, 0x5C, 0xDD, 0xFF, 0xFF, - 0xFF, 0xFF, 0x59, 0xC9, 0xFF, 0x44, 0x5C, 0x58}, - {0x00, 0xFF, 0x95, 0xFF, 0x21, 0xFF, 0xFF, 0x1D, 0x1A, 0x06, 0xD3, 0xFF, - 0xFF, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, 0xB0, 0x31, 0xFF, 0xFF, 0x1F, - 0x61, 0x48, 0xFF, 0xFF, 0xFF, 0x17, 0xC9, 0x79}}; + {0xFF, 0xA5, 0xC3, 0xFF, 0xFF, 0x09, 0x18, 0x18, 0x95, 0x40, 0xFF, + 0xFF, 0xDB, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0xFF, 0x25, 0xFF, 0xFF, + 0x42, 0x07, 0xB5, 0xFF, 0x26, 0xE0, 0x4F, 0xB5, 0xB4, 0xFF}, + {0x1F, 0xFF, 0xAA, 0xF1, 0xFF, 0xFF, 0x7E, 0xFF, 0xFF, 0xFF, 0x07, + 0xFF, 0xE7, 0xDF, 0xFF, 0xEE, 0xFF, 0x57, 0xFF, 0xFF, 0xFF, 0xB8, + 0xB3, 0x9C, 0xFF, 0x8A, 0x89, 0xFF, 0xFE, 0x32, 0xFF, 0xC1}, + {0x9A, 0xFF, 0xFF, 0x9B, 0xFF, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x36, 0xF0, 0xC5, 0xAE, 0x87, 0x41, 0xFF, 0x5C, 0xDD, + 0xFF, 0xFF, 0xFF, 0xFF, 0x59, 0xC9, 0xFF, 0x44, 0x5C, 0x58}, + {0x00, 0xFF, 0x95, 0xFF, 0x21, 0xFF, 0xFF, 0x1D, 0x1A, 0x06, 0xD3, + 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, 0xB0, 0x31, 0xFF, + 0xFF, 0x1F, 0x61, 0x48, 0xFF, 0xFF, 0xFF, 0x17, 0xC9, 0x79}}; const FqElemStr FfElementTest::fq_multi_exp_res_4 = { 0x26, 0x2C, 0x23, 0x55, 0xD5, 0xBD, 0x7B, 0x67, 0x60, 0xFE, 0x06, 0x7B, 0xCC, 0xB8, 0x6B, 0xC9, 0x00, 0x81, 0xAE, 0xCB, 0xEC, 0x91, @@ -1174,24 +1183,24 @@ const Fq12ElemStr FfElementTest::fq12_multi_exp_base_4[4] = { }; const BigNumStr FfElementTest::fq12_multi_exp_exp_4[4] = { { - 0x14, 0x92, 0xD1, 0x1F, 0xAC, 0x90, 0x4D, 0xC3, 0x3E, 0xB8, 0xA7, 0xFE, - 0x35, 0x98, 0xDA, 0x94, 0xD6, 0xF3, 0x27, 0x29, 0x4B, 0x70, 0xCF, 0x0F, - 0xDA, 0x14, 0x97, 0xA1, 0x9B, 0x6B, 0x24, 0x08, + 0x14, 0x92, 0xD1, 0x1F, 0xAC, 0x90, 0x4D, 0xC3, 0x3E, 0xB8, 0xA7, + 0xFE, 0x35, 0x98, 0xDA, 0x94, 0xD6, 0xF3, 0x27, 0x29, 0x4B, 0x70, + 0xCF, 0x0F, 0xDA, 0x14, 0x97, 0xA1, 0x9B, 0x6B, 0x24, 0x08, }, { - 0x76, 0x8D, 0xE5, 0xC2, 0xAB, 0x78, 0xD9, 0x76, 0x98, 0xFF, 0x92, 0xEA, - 0x95, 0x58, 0xC5, 0x0C, 0x6F, 0x1B, 0x35, 0xC4, 0xBF, 0x4A, 0x9E, 0xC2, - 0x6A, 0xEC, 0xE2, 0xF6, 0xAF, 0xEB, 0xAC, 0x06, + 0x76, 0x8D, 0xE5, 0xC2, 0xAB, 0x78, 0xD9, 0x76, 0x98, 0xFF, 0x92, + 0xEA, 0x95, 0x58, 0xC5, 0x0C, 0x6F, 0x1B, 0x35, 0xC4, 0xBF, 0x4A, + 0x9E, 0xC2, 0x6A, 0xEC, 0xE2, 0xF6, 0xAF, 0xEB, 0xAC, 0x06, }, { - 0x50, 0x38, 0x60, 0x31, 0xAB, 0x05, 0xCC, 0xB1, 0xC2, 0x06, 0xA0, 0xD7, - 0x92, 0x12, 0xBD, 0x17, 0x81, 0xB9, 0x7E, 0x07, 0x9B, 0xD4, 0x3B, 0x2D, - 0x3C, 0x15, 0x3A, 0x5A, 0xF1, 0xC0, 0xC4, 0x75, + 0x50, 0x38, 0x60, 0x31, 0xAB, 0x05, 0xCC, 0xB1, 0xC2, 0x06, 0xA0, + 0xD7, 0x92, 0x12, 0xBD, 0x17, 0x81, 0xB9, 0x7E, 0x07, 0x9B, 0xD4, + 0x3B, 0x2D, 0x3C, 0x15, 0x3A, 0x5A, 0xF1, 0xC0, 0xC4, 0x75, }, { - 0xA1, 0x3F, 0xEA, 0x99, 0x7E, 0xC7, 0x65, 0xF5, 0x41, 0xA6, 0xD6, 0xD3, - 0x77, 0xEC, 0x27, 0xF8, 0x6C, 0x18, 0x28, 0x69, 0x97, 0x08, 0x0E, 0x63, - 0x5A, 0xDA, 0xFE, 0x9F, 0xD1, 0x4A, 0x61, 0x4F, + 0xA1, 0x3F, 0xEA, 0x99, 0x7E, 0xC7, 0x65, 0xF5, 0x41, 0xA6, 0xD6, + 0xD3, 0x77, 0xEC, 0x27, 0xF8, 0x6C, 0x18, 0x28, 0x69, 0x97, 0x08, + 0x0E, 0x63, 0x5A, 0xDA, 0xFE, 0x9F, 0xD1, 0x4A, 0x61, 0x4F, }, }; const Fq12ElemStr FfElementTest::fq12_multi_exp_res_4 = { @@ -1232,38 +1241,38 @@ const Fq12ElemStr FfElementTest::fq12_multi_exp_res_4 = { 0x07, 0xD4, 0x39, 0xD2, 0x7D, 0x1A, 0x0C, 0xEF, 0xF2, 0x84, 0x84, 0x22, 0x8A, 0xB1, 0x80, 0x0D, 0xDC, 0x64, 0x86, 0xFD, 0x70}}}}}}}; const FqElemStr FfElementTest::fq_multi_exp_base_5[5] = { - {0x7B, 0x26, 0x96, 0x84, 0x04, 0x0D, 0x6F, 0x10, 0xAA, 0x7F, 0xD0, 0x0C, - 0x41, 0x3A, 0x68, 0x48, 0xBF, 0x3D, 0xB5, 0xCE, 0x3A, 0x9C, 0xA9, 0x10, - 0xA4, 0x67, 0x7C, 0xC0, 0x41, 0x52, 0xCA, 0xE7}, - {0x2E, 0xD9, 0xEF, 0x86, 0xB6, 0x32, 0x72, 0x89, 0x37, 0xCF, 0x16, 0xCE, - 0x27, 0x15, 0x7A, 0x95, 0xCF, 0x94, 0x1B, 0xF3, 0xCE, 0x49, 0x20, 0x29, - 0x9A, 0x61, 0x2E, 0x0A, 0xF5, 0xE1, 0xDC, 0x9F}, - {0xE0, 0x19, 0x37, 0x44, 0xA7, 0x45, 0x49, 0x7E, 0x19, 0x02, 0x09, 0x78, - 0xBE, 0xA4, 0x65, 0x60, 0x7A, 0xF5, 0xC8, 0xAF, 0x97, 0x5E, 0xDA, 0x3A, - 0xB4, 0x16, 0x70, 0x31, 0xE3, 0xB4, 0x18, 0xA8}, - {0xBC, 0x92, 0x29, 0x92, 0x14, 0xD3, 0x3F, 0xB8, 0xB8, 0x8C, 0x41, 0xDF, - 0xC5, 0xA1, 0xCA, 0x77, 0xE5, 0x73, 0xFE, 0xA7, 0xAC, 0x81, 0x66, 0x11, - 0x5A, 0x6D, 0x7D, 0x97, 0x13, 0x92, 0x8D, 0x1D}, - {0xE1, 0xA0, 0x0D, 0xDC, 0x8F, 0x20, 0xF5, 0x2D, 0x1D, 0x1F, 0xBD, 0x24, - 0x8C, 0xC2, 0x26, 0x06, 0x89, 0xE9, 0x46, 0xA9, 0xD2, 0x44, 0x8F, 0x1A, - 0x8D, 0xAF, 0x20, 0x73, 0x60, 0x0B, 0x66, 0x9C}}; + {0x7B, 0x26, 0x96, 0x84, 0x04, 0x0D, 0x6F, 0x10, 0xAA, 0x7F, 0xD0, + 0x0C, 0x41, 0x3A, 0x68, 0x48, 0xBF, 0x3D, 0xB5, 0xCE, 0x3A, 0x9C, + 0xA9, 0x10, 0xA4, 0x67, 0x7C, 0xC0, 0x41, 0x52, 0xCA, 0xE7}, + {0x2E, 0xD9, 0xEF, 0x86, 0xB6, 0x32, 0x72, 0x89, 0x37, 0xCF, 0x16, + 0xCE, 0x27, 0x15, 0x7A, 0x95, 0xCF, 0x94, 0x1B, 0xF3, 0xCE, 0x49, + 0x20, 0x29, 0x9A, 0x61, 0x2E, 0x0A, 0xF5, 0xE1, 0xDC, 0x9F}, + {0xE0, 0x19, 0x37, 0x44, 0xA7, 0x45, 0x49, 0x7E, 0x19, 0x02, 0x09, + 0x78, 0xBE, 0xA4, 0x65, 0x60, 0x7A, 0xF5, 0xC8, 0xAF, 0x97, 0x5E, + 0xDA, 0x3A, 0xB4, 0x16, 0x70, 0x31, 0xE3, 0xB4, 0x18, 0xA8}, + {0xBC, 0x92, 0x29, 0x92, 0x14, 0xD3, 0x3F, 0xB8, 0xB8, 0x8C, 0x41, + 0xDF, 0xC5, 0xA1, 0xCA, 0x77, 0xE5, 0x73, 0xFE, 0xA7, 0xAC, 0x81, + 0x66, 0x11, 0x5A, 0x6D, 0x7D, 0x97, 0x13, 0x92, 0x8D, 0x1D}, + {0xE1, 0xA0, 0x0D, 0xDC, 0x8F, 0x20, 0xF5, 0x2D, 0x1D, 0x1F, 0xBD, + 0x24, 0x8C, 0xC2, 0x26, 0x06, 0x89, 0xE9, 0x46, 0xA9, 0xD2, 0x44, + 0x8F, 0x1A, 0x8D, 0xAF, 0x20, 0x73, 0x60, 0x0B, 0x66, 0x9C}}; const BigNumStr FfElementTest::fq_multi_exp_exp_5[5] = { - {0x78, 0xE6, 0x3F, 0x42, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD7, 0x6E, - 0xE9, 0xFF, 0x4F, 0xFF, 0x23, 0xFF, 0x67, 0xB4, 0xED, 0xEE, 0xD7, 0xC6, - 0xFF, 0x4B, 0x0B, 0x6F, 0x1F, 0xD6, 0xFD, 0x7F}, - {0xA1, 0x87, 0xFF, 0x1B, 0xFF, 0x85, 0x68, 0xFF, 0x1C, 0xFF, 0xD5, 0xFF, - 0x95, 0x73, 0xFF, 0xFF, 0xFF, 0x9E, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x5E, - 0x9E, 0x62, 0xFF, 0xFF, 0x97, 0xFF, 0xFF, 0xF3}, - {0x2E, 0xE8, 0x1E, 0x35, 0xFF, 0x82, 0x0B, 0x99, 0xEC, 0x30, 0x2B, 0xCE, - 0xEC, 0x83, 0x05, 0xFF, 0x9E, 0x3C, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, - 0x57, 0x26, 0x5B, 0x6C, 0xFF, 0xE6, 0x94, 0xFF}, - {0xFF, 0xFF, 0xFF, 0xFF, 0x94, 0xFF, 0xFF, 0x79, 0xFC, 0xFF, 0x83, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xA9, 0xFF, 0x2F, 0x6B, 0xD1, 0xE7, 0xFF, 0xFF, - 0xFF, 0x7C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, - {0x63, 0x53, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0xFF, 0xFF, 0xFF, 0x09, 0xFF, - 0xC0, 0xD8, 0x17, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x45, - 0xFF, 0x3A, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0x06}}; + {0x78, 0xE6, 0x3F, 0x42, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD7, + 0x6E, 0xE9, 0xFF, 0x4F, 0xFF, 0x23, 0xFF, 0x67, 0xB4, 0xED, 0xEE, + 0xD7, 0xC6, 0xFF, 0x4B, 0x0B, 0x6F, 0x1F, 0xD6, 0xFD, 0x7F}, + {0xA1, 0x87, 0xFF, 0x1B, 0xFF, 0x85, 0x68, 0xFF, 0x1C, 0xFF, 0xD5, + 0xFF, 0x95, 0x73, 0xFF, 0xFF, 0xFF, 0x9E, 0x7E, 0xFF, 0xFF, 0xFF, + 0xFF, 0x5E, 0x9E, 0x62, 0xFF, 0xFF, 0x97, 0xFF, 0xFF, 0xF3}, + {0x2E, 0xE8, 0x1E, 0x35, 0xFF, 0x82, 0x0B, 0x99, 0xEC, 0x30, 0x2B, + 0xCE, 0xEC, 0x83, 0x05, 0xFF, 0x9E, 0x3C, 0xFF, 0xFF, 0xA1, 0xFF, + 0xFF, 0xFF, 0x57, 0x26, 0x5B, 0x6C, 0xFF, 0xE6, 0x94, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xFF, 0x94, 0xFF, 0xFF, 0x79, 0xFC, 0xFF, 0x83, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xA9, 0xFF, 0x2F, 0x6B, 0xD1, 0xE7, + 0xFF, 0xFF, 0xFF, 0x7C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + {0x63, 0x53, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0xFF, 0xFF, 0xFF, 0x09, + 0xFF, 0xC0, 0xD8, 0x17, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x45, 0xFF, 0x3A, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0x06}}; const FqElemStr FfElementTest::fq_multi_exp_res_5 = { 0x8F, 0x6D, 0x54, 0xCA, 0x00, 0x85, 0xD8, 0x78, 0xA4, 0x45, 0x36, @@ -1271,43 +1280,43 @@ const FqElemStr FfElementTest::fq_multi_exp_res_5 = { 0x99, 0xD9, 0xD3, 0x0A, 0x0E, 0x86, 0x98, 0xC2, 0xA7, 0x97, }; const FqElemStr FfElementTest::fq_multi_exp_base_6[6] = { - {0x75, 0x18, 0x6A, 0x3D, 0xCC, 0x76, 0x33, 0x92, 0xD0, 0x57, 0xDA, 0xE0, - 0x37, 0x6F, 0x71, 0xD5, 0x9E, 0x7E, 0x65, 0xED, 0xD7, 0xFD, 0x82, 0xC0, - 0x6C, 0x83, 0x60, 0x30, 0xC1, 0xD3, 0x3D, 0x4D}, - {0xF5, 0x3A, 0x20, 0xAB, 0x22, 0x47, 0x07, 0xAE, 0x71, 0xC1, 0x91, 0x73, - 0xEF, 0x1F, 0x1D, 0x76, 0x2E, 0xEE, 0x0D, 0xDE, 0xD9, 0xF8, 0x5C, 0x85, - 0xC7, 0x5B, 0x93, 0x88, 0xF6, 0xFF, 0x4C, 0xA5}, - {0x21, 0xB3, 0x5E, 0xE8, 0xD2, 0xDA, 0x14, 0x1C, 0xB5, 0x2C, 0xFC, 0x61, - 0x9D, 0xEB, 0x65, 0x87, 0xBB, 0x5B, 0xBC, 0xFD, 0x37, 0x54, 0x6B, 0xDC, - 0xD9, 0xFA, 0x7A, 0xCD, 0x18, 0x7E, 0x8B, 0x89}, - {0x70, 0xB7, 0x19, 0x42, 0xB4, 0x41, 0x2C, 0x1B, 0xBD, 0x7B, 0x25, 0x06, - 0xA2, 0x95, 0xB5, 0xB6, 0x70, 0xDF, 0x58, 0x71, 0xCA, 0x09, 0x12, 0x66, - 0x5A, 0x7B, 0xF0, 0x5F, 0x43, 0x69, 0x32, 0xF6}, - {0x3D, 0x57, 0xE8, 0x3F, 0x1E, 0x39, 0x2B, 0xE5, 0xD0, 0xCF, 0xA9, 0xC8, - 0x72, 0x10, 0x7F, 0xC5, 0x4F, 0xAE, 0xE9, 0x73, 0x28, 0x4C, 0xFC, 0x3F, - 0xD5, 0xFF, 0xE8, 0xCF, 0x2C, 0xEB, 0x33, 0xD3}, - {0x51, 0x80, 0x15, 0x1C, 0xE6, 0x9C, 0x4B, 0x80, 0x40, 0xBA, 0x40, 0x29, - 0x3A, 0x86, 0xA8, 0xB2, 0x66, 0x08, 0x97, 0x8D, 0xEB, 0x8B, 0xA7, 0x93, - 0xE3, 0x49, 0xC6, 0xC0, 0x46, 0x93, 0xC1, 0x75}}; + {0x75, 0x18, 0x6A, 0x3D, 0xCC, 0x76, 0x33, 0x92, 0xD0, 0x57, 0xDA, + 0xE0, 0x37, 0x6F, 0x71, 0xD5, 0x9E, 0x7E, 0x65, 0xED, 0xD7, 0xFD, + 0x82, 0xC0, 0x6C, 0x83, 0x60, 0x30, 0xC1, 0xD3, 0x3D, 0x4D}, + {0xF5, 0x3A, 0x20, 0xAB, 0x22, 0x47, 0x07, 0xAE, 0x71, 0xC1, 0x91, + 0x73, 0xEF, 0x1F, 0x1D, 0x76, 0x2E, 0xEE, 0x0D, 0xDE, 0xD9, 0xF8, + 0x5C, 0x85, 0xC7, 0x5B, 0x93, 0x88, 0xF6, 0xFF, 0x4C, 0xA5}, + {0x21, 0xB3, 0x5E, 0xE8, 0xD2, 0xDA, 0x14, 0x1C, 0xB5, 0x2C, 0xFC, + 0x61, 0x9D, 0xEB, 0x65, 0x87, 0xBB, 0x5B, 0xBC, 0xFD, 0x37, 0x54, + 0x6B, 0xDC, 0xD9, 0xFA, 0x7A, 0xCD, 0x18, 0x7E, 0x8B, 0x89}, + {0x70, 0xB7, 0x19, 0x42, 0xB4, 0x41, 0x2C, 0x1B, 0xBD, 0x7B, 0x25, + 0x06, 0xA2, 0x95, 0xB5, 0xB6, 0x70, 0xDF, 0x58, 0x71, 0xCA, 0x09, + 0x12, 0x66, 0x5A, 0x7B, 0xF0, 0x5F, 0x43, 0x69, 0x32, 0xF6}, + {0x3D, 0x57, 0xE8, 0x3F, 0x1E, 0x39, 0x2B, 0xE5, 0xD0, 0xCF, 0xA9, + 0xC8, 0x72, 0x10, 0x7F, 0xC5, 0x4F, 0xAE, 0xE9, 0x73, 0x28, 0x4C, + 0xFC, 0x3F, 0xD5, 0xFF, 0xE8, 0xCF, 0x2C, 0xEB, 0x33, 0xD3}, + {0x51, 0x80, 0x15, 0x1C, 0xE6, 0x9C, 0x4B, 0x80, 0x40, 0xBA, 0x40, + 0x29, 0x3A, 0x86, 0xA8, 0xB2, 0x66, 0x08, 0x97, 0x8D, 0xEB, 0x8B, + 0xA7, 0x93, 0xE3, 0x49, 0xC6, 0xC0, 0x46, 0x93, 0xC1, 0x75}}; const BigNumStr FfElementTest::fq_multi_exp_exp_6[6] = { - {0xFF, 0xFF, 0xFF, 0x49, 0x50, 0xFF, 0x19, 0xFF, 0xEB, 0xFF, 0xFF, 0xFF, - 0xFF, 0x28, 0x4A, 0x0E, 0xFF, 0x74, 0xFF, 0xC7, 0xFF, 0xD9, 0x81, 0xFF, - 0xFF, 0xFF, 0xD5, 0x2C, 0xFF, 0xFF, 0xFF, 0xAE}, - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0x0C, 0x03, 0xFF, 0x95, 0xFF, 0x11, 0x9D, 0xFF, 0x9B, 0xFF, 0xFF, - 0x68, 0x44, 0xFF, 0xC9, 0xFF, 0x10, 0xC7, 0xBF}, - {0x64, 0xFF, 0x89, 0x4A, 0xFF, 0x20, 0xFF, 0xE7, 0xFF, 0x36, 0x23, 0xDD, - 0xFF, 0xFF, 0xFC, 0xFF, 0x6B, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x94, 0xD3, 0x59, 0xBE}, - {0x0F, 0xFF, 0x76, 0xA5, 0x9E, 0x02, 0x9B, 0xFF, 0xA1, 0xFF, 0xC2, 0xFF, - 0x9D, 0xFF, 0x23, 0xFF, 0xFF, 0xFF, 0xFF, 0x6B, 0x81, 0x2A, 0xFF, 0x98, - 0xFF, 0xFF, 0xB9, 0xFF, 0xB7, 0x78, 0xE6, 0xFF}, - {0xAF, 0xF3, 0xFF, 0x3C, 0xA8, 0xFF, 0xB9, 0x3A, 0xFF, 0xFF, 0xFF, 0x70, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x85, 0xFF, 0xFF, 0x52, - 0xFF, 0x41, 0x10, 0x62, 0xFF, 0x51, 0x35, 0xFF}, - {0xFF, 0xFF, 0xFF, 0xFF, 0xD3, 0xC3, 0xD9, 0xFF, 0xFF, 0x3A, 0x44, 0x88, - 0x04, 0xFF, 0x0B, 0xFF, 0xFF, 0xFF, 0x64, 0xFF, 0xFF, 0x52, 0xFF, 0x7D, - 0x6B, 0x24, 0x6E, 0xFF, 0xFF, 0xFF, 0xA7, 0x71}}; + {0xFF, 0xFF, 0xFF, 0x49, 0x50, 0xFF, 0x19, 0xFF, 0xEB, 0xFF, 0xFF, + 0xFF, 0xFF, 0x28, 0x4A, 0x0E, 0xFF, 0x74, 0xFF, 0xC7, 0xFF, 0xD9, + 0x81, 0xFF, 0xFF, 0xFF, 0xD5, 0x2C, 0xFF, 0xFF, 0xFF, 0xAE}, + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x0C, 0x03, 0xFF, 0x95, 0xFF, 0x11, 0x9D, 0xFF, 0x9B, + 0xFF, 0xFF, 0x68, 0x44, 0xFF, 0xC9, 0xFF, 0x10, 0xC7, 0xBF}, + {0x64, 0xFF, 0x89, 0x4A, 0xFF, 0x20, 0xFF, 0xE7, 0xFF, 0x36, 0x23, + 0xDD, 0xFF, 0xFF, 0xFC, 0xFF, 0x6B, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x94, 0xD3, 0x59, 0xBE}, + {0x0F, 0xFF, 0x76, 0xA5, 0x9E, 0x02, 0x9B, 0xFF, 0xA1, 0xFF, 0xC2, + 0xFF, 0x9D, 0xFF, 0x23, 0xFF, 0xFF, 0xFF, 0xFF, 0x6B, 0x81, 0x2A, + 0xFF, 0x98, 0xFF, 0xFF, 0xB9, 0xFF, 0xB7, 0x78, 0xE6, 0xFF}, + {0xAF, 0xF3, 0xFF, 0x3C, 0xA8, 0xFF, 0xB9, 0x3A, 0xFF, 0xFF, 0xFF, + 0x70, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x85, 0xFF, + 0xFF, 0x52, 0xFF, 0x41, 0x10, 0x62, 0xFF, 0x51, 0x35, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xFF, 0xD3, 0xC3, 0xD9, 0xFF, 0xFF, 0x3A, 0x44, + 0x88, 0x04, 0xFF, 0x0B, 0xFF, 0xFF, 0xFF, 0x64, 0xFF, 0xFF, 0x52, + 0xFF, 0x7D, 0x6B, 0x24, 0x6E, 0xFF, 0xFF, 0xFF, 0xA7, 0x71}}; const FqElemStr FfElementTest::fq_multi_exp_res_6 = { 0xFB, 0x89, 0x4F, 0xBB, 0x91, 0xEE, 0xD6, 0x57, 0x2D, 0x34, 0xF9, 0x0B, 0xE3, 0xEB, 0x71, 0x1D, 0x63, 0x74, 0x96, 0x3B, 0xD4, 0x02, @@ -1365,21 +1374,21 @@ const Fq6ElemStr FfElementTest::epid11_GT_multi_exp_base_3[3] = { 0x67, 0x8D, 0x1E, 0x07, 0xC7, 0x46, 0x87, 0xF6, 0x50, 0xC3, 0xA6, 0x6B}}; const std::vector FfElementTest::epid11_GT_multi_exp_exp_3[3] = { - {0x00, 0x00, 0xAF, 0x5B, 0x22, 0x71, 0x98, 0xB6, 0xEB, 0x67, 0x3D, 0x94, - 0x4A, 0xB6, 0x5E, 0x99, 0x81, 0xC5, 0x96, 0x91, 0x55, 0xBA, 0x2F, 0x16, - 0x01, 0x4E, 0xE1, 0x25, 0xAD, 0xCA, 0x94, 0x88, 0x60, 0x3B, 0xA2, 0x56, - 0x0A, 0x94, 0x0B, 0x2C, 0x3E, 0xD0, 0x8F, 0x15, 0x07, 0x3D, 0xD5, 0xBE, - 0x72, 0x3E, 0x2D, 0x06, 0x74, 0xFF, 0x06, 0xED, 0x47, 0x28, 0x08, 0x0C, - 0xA0, 0x6F, 0xDB, 0x75, 0x55, 0x32, 0xDC, 0x97, 0x47, 0x60, 0x4E, 0x6F, - 0xB4, 0x29, 0x89, 0x0C}, + {0x00, 0x00, 0xAF, 0x5B, 0x22, 0x71, 0x98, 0xB6, 0xEB, 0x67, 0x3D, + 0x94, 0x4A, 0xB6, 0x5E, 0x99, 0x81, 0xC5, 0x96, 0x91, 0x55, 0xBA, + 0x2F, 0x16, 0x01, 0x4E, 0xE1, 0x25, 0xAD, 0xCA, 0x94, 0x88, 0x60, + 0x3B, 0xA2, 0x56, 0x0A, 0x94, 0x0B, 0x2C, 0x3E, 0xD0, 0x8F, 0x15, + 0x07, 0x3D, 0xD5, 0xBE, 0x72, 0x3E, 0x2D, 0x06, 0x74, 0xFF, 0x06, + 0xED, 0x47, 0x28, 0x08, 0x0C, 0xA0, 0x6F, 0xDB, 0x75, 0x55, 0x32, + 0xDC, 0x97, 0x47, 0x60, 0x4E, 0x6F, 0xB4, 0x29, 0x89, 0x0C}, - {0x00, 0x00, 0x01, 0xB8, 0x40, 0xBB, 0xE1, 0x1C, 0x84, 0x8E, 0x02, 0xC0, - 0xEF, 0x69, 0x84, 0x90, 0xED, 0xEB, 0x99, 0x94, 0xBC, 0x79, 0x48, 0xC8, - 0x08, 0x3C, 0x25, 0xDA, 0xAC, 0xFF, 0x3A, 0xDD}, + {0x00, 0x00, 0x01, 0xB8, 0x40, 0xBB, 0xE1, 0x1C, 0x84, 0x8E, 0x02, + 0xC0, 0xEF, 0x69, 0x84, 0x90, 0xED, 0xEB, 0x99, 0x94, 0xBC, 0x79, + 0x48, 0xC8, 0x08, 0x3C, 0x25, 0xDA, 0xAC, 0xFF, 0x3A, 0xDD}, - {0x00, 0x00, 0x37, 0x1E, 0xCD, 0x0F, 0x66, 0x09, 0x7D, 0x33, 0x9A, 0xDC, - 0x47, 0x28, 0xF7, 0x91, 0xF3, 0xC2, 0xBC, 0x3A, 0xA9, 0x05, 0x62, 0xFC, - 0xDD, 0x8C, 0x65, 0xC2, 0xA8, 0x14, 0x55, 0x52}, + {0x00, 0x00, 0x37, 0x1E, 0xCD, 0x0F, 0x66, 0x09, 0x7D, 0x33, 0x9A, + 0xDC, 0x47, 0x28, 0xF7, 0x91, 0xF3, 0xC2, 0xBC, 0x3A, 0xA9, 0x05, + 0x62, 0xFC, 0xDD, 0x8C, 0x65, 0xC2, 0xA8, 0x14, 0x55, 0x52}, }; const Fq6ElemStr FfElementTest::epid11_GT_multi_exp_res_3 = { @@ -1468,11 +1477,10 @@ TEST_F(FfElementTest, ReadFailsGivenNullPointer) { } TEST_F(FfElementTest, ReadFailsGivenInvalidBufferSize) { - FqElemStr ff_elem_str; EXPECT_EQ(kEpidBadArgErr, - ReadFfElement(this->fq, &ff_elem_str, 0, this->fq_a)); + ReadFfElement(this->fq, &this->fq_qm1_str, 0, this->fq_a)); EXPECT_EQ(kEpidBadArgErr, - ReadFfElement(this->fq, &ff_elem_str, + ReadFfElement(this->fq, &this->fq_qm1_str, std::numeric_limits::max(), this->fq_a)); } @@ -2134,8 +2142,6 @@ TEST_F(FfElementTest, FfHashFailsGivenNullPointer) { TEST_F(FfElementTest, FfHashFailsGivenUnsupportedHashAlg) { uint8_t const msg[] = {0}; - EXPECT_EQ(kEpidHashAlgorithmNotSupported, - FfHash(this->fq, msg, sizeof(msg), kSha512_256, this->fq_result)); EXPECT_EQ(kEpidHashAlgorithmNotSupported, FfHash(this->fq, msg, sizeof(msg), kSha3_256, this->fq_result)); EXPECT_EQ(kEpidHashAlgorithmNotSupported, @@ -2184,7 +2190,15 @@ TEST_F(FfElementTest, FfHashWorksGivenSHA512HashAlg) { EXPECT_EQ(this->fq_abc_sha512_str, fq_r_str) << "FfHash: Hash element does not match to reference value"; } - +TEST_F(FfElementTest, FfHashWorksGivenSHA512256HashAlg) { + FqElemStr fq_r_str; + EXPECT_EQ(kEpidNoErr, FfHash(this->fq, sha_msg, sizeof(sha_msg), kSha512_256, + this->fq_result)); + THROW_ON_EPIDERR( + WriteFfElement(this->fq, this->fq_result, &fq_r_str, sizeof(fq_r_str))); + EXPECT_EQ(this->fq_abc_sha512256_str, fq_r_str) + << "FfHash: Hash element does not match to reference value"; +} //////////////////////////////////////////////// // FfMultiExp diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/finitefield-test.cc b/external/epid-sdk/epid/common/math/unittests/finitefield-test.cc similarity index 82% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/finitefield-test.cc rename to external/epid-sdk/epid/common/math/unittests/finitefield-test.cc index badce2c9..b39cd5cb 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/finitefield-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/finitefield-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,12 @@ * \brief FiniteField unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" #include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" extern "C" { #include "epid/common/math/finitefield.h" @@ -35,58 +36,58 @@ extern "C" { namespace { /// Intel(R) EPID 2.0 parameters q, beta, xi and v -BigNumStr q = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, - 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, - 0x12, 0x98, 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, - 0x30, 0x13}}; -FqElemStr beta = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, - 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, - 0x12, 0x98, 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, - 0x30, 0x12}}; +BigNumStr q = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, + 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}; +FqElemStr beta = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, + 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}; Fq2ElemStr xi = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; Fq6ElemStr v = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; -FqElemStr qnr = {{0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, - 0x52, 0x94, 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, - 0x26, 0x9A, 0x2B, 0x6E, 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, - 0xAA, 0x24}}; +FqElemStr qnr = {{0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, + 0xB7, 0xA6, 0x52, 0x94, 0x8F, 0xFB, 0x25, 0x9E, + 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, 0x2B, 0x6E, + 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}}; const BigNumStr coeffs[3] = { - {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, 0x94, - 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, 0x43, 0x89, - 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, + {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, + 0x94, 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, + 0x43, 0x89, 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}}, - {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, 0x0E, - 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, 0x85, 0x7A, - 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, + {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, + 0x0E, 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, + 0x85, 0x7A, 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}}, - {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, 0x4B, - 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, 0x24, 0xA4, - 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; + {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, + 0x4B, 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, + 0x24, 0xA4, 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}}; TEST(FiniteField, DeleteWorksGivenNewlyCreatedFiniteField) { FiniteField* finitefield = nullptr; diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/hash-test.cc b/external/epid-sdk/epid/common/math/unittests/hash-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/hash-test.cc rename to external/epid-sdk/epid/common/math/unittests/hash-test.cc index eea7d089..69127f90 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/hash-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/hash-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" #include "epid/common-testhelper/errors-testhelper.h" diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/main-test.cc b/external/epid-sdk/epid/common/math/unittests/main-test.cc similarity index 90% rename from external/epid-sdk-3.0.0/epid/member/unittests/main-test.cc rename to external/epid-sdk/epid/common/math/unittests/main-test.cc index 70f2d3a1..a8bb2fa9 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/main-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/main-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * \brief Main entry point for unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" int main(int argc, char** argv) { diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/octstrconvert-test.cc b/external/epid-sdk/epid/common/math/unittests/octstrconvert-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/octstrconvert-test.cc rename to external/epid-sdk/epid/common/math/unittests/octstrconvert-test.cc index 2ad606bc..129c907e 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/octstrconvert-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/octstrconvert-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ * math libraries. These tests can be omitted if you do not use this function. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "epid/common/stdtypes.h" #include "gtest/gtest.h" diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/pairing-test.cc b/external/epid-sdk/epid/common/math/unittests/pairing-test.cc similarity index 68% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/pairing-test.cc rename to external/epid-sdk/epid/common/math/unittests/pairing-test.cc index a6883077..5eac8c21 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/pairing-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/pairing-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,14 +21,15 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" -#include "epid/common-testhelper/epid_params-testhelper.h" -#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" extern "C" { #include "epid/common/math/pairing.h" @@ -47,6 +48,8 @@ namespace { class PairingTest : public Epid20Params, public ::testing::Test { public: static const BigNumStr t_str; + static const G1ElemStr ga_elem_str; + static const G2ElemStr gb_elem_str; virtual void SetUp() { params = new Epid20Params(); } virtual void TearDown() { delete params; } @@ -59,6 +62,27 @@ const BigNumStr PairingTest::t_str = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x82, 0xF5, 0xC0, 0x30, 0xB0, 0xA8, 0x01}; +const G1ElemStr PairingTest::ga_elem_str = { + 0xd7, 0xe2, 0xf9, 0x37, 0x21, 0x0f, 0x09, 0x97, 0x0f, 0xca, 0xa6, + 0x03, 0x7d, 0x91, 0xc3, 0x75, 0x8a, 0xc9, 0x44, 0x11, 0xfc, 0xaa, + 0x55, 0x67, 0xba, 0xce, 0xaf, 0x8d, 0xf6, 0x7c, 0x84, 0x83, 0x04, + 0xb7, 0xa6, 0xff, 0x9f, 0x0d, 0x26, 0x73, 0xaf, 0x6c, 0xd0, 0x0a, + 0xf6, 0x13, 0xc9, 0x44, 0x3f, 0xf0, 0x82, 0x58, 0x48, 0x59, 0x03, + 0x3f, 0x88, 0xe2, 0x46, 0xd6, 0x0f, 0x93, 0x42, 0x4b, +}; +const G2ElemStr PairingTest::gb_elem_str = { + 0x3f, 0x4c, 0xb5, 0x2d, 0xbc, 0x72, 0xb0, 0x9c, 0x6f, 0xb2, 0xb5, 0xc1, + 0xdc, 0xfb, 0xda, 0x35, 0x91, 0xa6, 0x8d, 0x51, 0x37, 0x70, 0xe2, 0x17, + 0xad, 0x53, 0x23, 0xdc, 0xa3, 0xc3, 0xfd, 0x4c, 0x90, 0xfa, 0x4f, 0xa2, + 0xcb, 0x35, 0xf3, 0x50, 0x5e, 0x8e, 0xf4, 0xce, 0x7f, 0xb0, 0x8a, 0x69, + 0x49, 0xdf, 0xf5, 0x4f, 0xb0, 0xc1, 0xd7, 0xf9, 0xb8, 0xfb, 0x89, 0xd1, + 0xb6, 0xf8, 0x74, 0x04, 0xef, 0xc6, 0x60, 0x05, 0x62, 0xf3, 0x17, 0x5a, + 0x80, 0xf4, 0x4b, 0x97, 0x08, 0x3e, 0x43, 0xa1, 0x44, 0x4c, 0x54, 0x86, + 0x16, 0x20, 0xb9, 0xcc, 0xfb, 0xbd, 0x00, 0x5f, 0xc8, 0x01, 0xfb, 0x5b, + 0xc1, 0x6e, 0x2b, 0x46, 0xe2, 0x04, 0x70, 0xeb, 0xa2, 0xaa, 0x86, 0x5a, + 0x35, 0x14, 0x0e, 0xc9, 0xdf, 0xba, 0x9b, 0x6f, 0x3a, 0xca, 0x94, 0x9c, + 0x44, 0x89, 0x94, 0xa3, 0xeb, 0x61, 0x8b, 0x01, +}; /////////////////////////////////////////////////////////////////////// // NewPairingState / DeletePairingState @@ -184,42 +208,67 @@ TEST_F(PairingTest, PairingWorksFromG1AndG2ToGt) { 0x16, 0xfd, 0x0b, 0xfe, 0x42, 0x1e, 0x17, 0x37, 0x2a, 0x04, 0xea, 0x26, 0xba, 0x6e, 0x2c, 0x36, 0xaf, 0x35, 0x1b, 0x75, 0x6d, 0x17, 0xdc, 0x8e, }; - G1ElemStr ga_elem_str = { - 0xd7, 0xe2, 0xf9, 0x37, 0x21, 0x0f, 0x09, 0x97, 0x0f, 0xca, 0xa6, - 0x03, 0x7d, 0x91, 0xc3, 0x75, 0x8a, 0xc9, 0x44, 0x11, 0xfc, 0xaa, - 0x55, 0x67, 0xba, 0xce, 0xaf, 0x8d, 0xf6, 0x7c, 0x84, 0x83, 0x04, - 0xb7, 0xa6, 0xff, 0x9f, 0x0d, 0x26, 0x73, 0xaf, 0x6c, 0xd0, 0x0a, - 0xf6, 0x13, 0xc9, 0x44, 0x3f, 0xf0, 0x82, 0x58, 0x48, 0x59, 0x03, - 0x3f, 0x88, 0xe2, 0x46, 0xd6, 0x0f, 0x93, 0x42, 0x4b, - }; - G2ElemStr gb_elem_str = { - 0x3f, 0x4c, 0xb5, 0x2d, 0xbc, 0x72, 0xb0, 0x9c, 0x6f, 0xb2, 0xb5, 0xc1, - 0xdc, 0xfb, 0xda, 0x35, 0x91, 0xa6, 0x8d, 0x51, 0x37, 0x70, 0xe2, 0x17, - 0xad, 0x53, 0x23, 0xdc, 0xa3, 0xc3, 0xfd, 0x4c, 0x90, 0xfa, 0x4f, 0xa2, - 0xcb, 0x35, 0xf3, 0x50, 0x5e, 0x8e, 0xf4, 0xce, 0x7f, 0xb0, 0x8a, 0x69, - 0x49, 0xdf, 0xf5, 0x4f, 0xb0, 0xc1, 0xd7, 0xf9, 0xb8, 0xfb, 0x89, 0xd1, - 0xb6, 0xf8, 0x74, 0x04, 0xef, 0xc6, 0x60, 0x05, 0x62, 0xf3, 0x17, 0x5a, - 0x80, 0xf4, 0x4b, 0x97, 0x08, 0x3e, 0x43, 0xa1, 0x44, 0x4c, 0x54, 0x86, - 0x16, 0x20, 0xb9, 0xcc, 0xfb, 0xbd, 0x00, 0x5f, 0xc8, 0x01, 0xfb, 0x5b, - 0xc1, 0x6e, 0x2b, 0x46, 0xe2, 0x04, 0x70, 0xeb, 0xa2, 0xaa, 0x86, 0x5a, - 0x35, 0x14, 0x0e, 0xc9, 0xdf, 0xba, 0x9b, 0x6f, 0x3a, 0xca, 0x94, 0x9c, - 0x44, 0x89, 0x94, 0xa3, 0xeb, 0x61, 0x8b, 0x01, - }; GtElemStr r_str = {0}; FfElementObj r(&this->params->GT); - EcPointObj ga_elem(&this->params->G1, ga_elem_str); - EcPointObj gb_elem(&this->params->G2, gb_elem_str); + EcPointObj ga_elem(&this->params->G1, this->ga_elem_str); + EcPointObj gb_elem(&this->params->G2, this->gb_elem_str); PairingState* ps = nullptr; THROW_ON_EPIDERR(NewPairingState(this->params->G1, this->params->G2, this->params->GT, &this->t_str, neg, &ps)); - EXPECT_EQ(kEpidNoErr, Pairing(ps, r, ga_elem, gb_elem)); + EXPECT_EQ(kEpidNoErr, Pairing(ps, ga_elem, gb_elem, r)); DeletePairingState(&ps); THROW_ON_EPIDERR(WriteFfElement(this->params->GT, r, &r_str, sizeof(r_str))); EXPECT_EQ(r_expected_str, r_str); } +// test that pairing fails if any options are NULL +TEST_F(PairingTest, PairingFailsGivenNullParameters) { + const bool neg = true; + FfElementObj r(&this->params->GT); + EcPointObj ga_elem(&this->params->G1, this->ga_elem_str); + EcPointObj gb_elem(&this->params->G2, this->gb_elem_str); + + PairingState* ps = nullptr; + THROW_ON_EPIDERR(NewPairingState(this->params->G1, this->params->G2, + this->params->GT, &this->t_str, neg, &ps)); + EXPECT_EQ(kEpidBadArgErr, Pairing(NULL, ga_elem, gb_elem, r)); + EXPECT_EQ(kEpidBadArgErr, Pairing(ps, NULL, gb_elem, r)); + EXPECT_EQ(kEpidBadArgErr, Pairing(ps, ga_elem, NULL, r)); + EXPECT_EQ(kEpidBadArgErr, Pairing(ps, ga_elem, gb_elem, NULL)); + DeletePairingState(&ps); +} +// test that pairing checks that the first parameter of the pairing is in a +// EcGroup, that was used to create pairing state. +TEST_F(PairingTest, PairingFailsGivenInvalidGaElem) { + const bool neg = true; + + FfElementObj r(&this->params->GT); + // put G2 element instead of G1 + EcPointObj mismatched_ga_elem(&this->params->G2, this->gb_elem_str); + EcPointObj gb_elem(&this->params->G2, this->gb_elem_str); + PairingState* ps = nullptr; + THROW_ON_EPIDERR(NewPairingState(this->params->G1, this->params->G2, + this->params->GT, &this->t_str, neg, &ps)); + EXPECT_EQ(kEpidBadArgErr, Pairing(ps, mismatched_ga_elem, gb_elem, r)); + DeletePairingState(&ps); +} +// test that pairing checks that the second parameter of the pairing is in a +// EcGroup, that was used to create pairing state. +TEST_F(PairingTest, PairingFailsGivenInvalidGbElem) { + const bool neg = true; + + FfElementObj r(&this->params->GT); + EcPointObj ga_elem(&this->params->G1, this->ga_elem_str); + // put G1 element instead of G2 + EcPointObj mismatched_gb_elem(&this->params->G1, this->ga_elem_str); + PairingState* ps = nullptr; + THROW_ON_EPIDERR(NewPairingState(this->params->G1, this->params->G2, + this->params->GT, &this->t_str, neg, &ps)); + EXPECT_EQ(kEpidBadArgErr, Pairing(ps, ga_elem, mismatched_gb_elem, r)); + DeletePairingState(&ps); +} } // namespace diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/printutils-test.cc b/external/epid-sdk/epid/common/math/unittests/printutils-test.cc similarity index 80% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/printutils-test.cc rename to external/epid-sdk/epid/common/math/unittests/printutils-test.cc index 14e4c822..f012f9d0 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/printutils-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/printutils-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,18 +25,19 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/common/math/bignum.h" #include "epid/common/math/printutils.h" } +#include "epid/common-testhelper/bignum_wrapper-testhelper.h" +#include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" +#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" #include "epid/common-testhelper/finite_field_wrapper-testhelper.h" -#include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" -#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" -#include "epid/common-testhelper/bignum_wrapper-testhelper.h" namespace { @@ -125,20 +126,20 @@ class PrintutilsTest : public ::testing::Test { // set h = 2q - p, aka cofactor std::vector cofactor_str( - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, 0xee, 0x71, 0xa4, 0xa0, - 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, 0xea, 0xb0, 0x25, 0x08, 0x4a, - 0x8c, 0x9b, 0x10, 0x19}); + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xcd, 0x46, 0xe5, 0xf2, 0x5e, + 0xee, 0x71, 0xa4, 0xa0, 0x0c, 0xdc, 0x65, 0xfb, 0x12, 0x96, 0x82, + 0xea, 0xb0, 0x25, 0x08, 0x4a, 0x8c, 0x9b, 0x10, 0x19}); // set n = p * h, AKA order std::vector order_str( - {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, 0xc7, - 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, 0xe8, 0x54, - 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, 0x70, 0x21, 0xdc, - 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, 0x4e, 0x84, 0xcd, 0x19, - 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, 0xa0, 0x2e, 0x7f, 0x40, 0x13, - 0xb2, 0xfa, 0xa1, 0x45}); + {0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xe1, 0x9a, 0x8d, 0xcb, 0xe4, + 0xc7, 0x38, 0xfa, 0x9b, 0x98, 0x4d, 0x1c, 0x12, 0x9f, 0x64, 0x97, + 0xe8, 0x54, 0xa3, 0x0a, 0x81, 0xac, 0x42, 0xf9, 0x39, 0x16, 0xa7, + 0x70, 0x21, 0xdc, 0xfb, 0xb6, 0xe7, 0x7e, 0x1f, 0x5b, 0x55, 0xcc, + 0x4e, 0x84, 0xcd, 0x19, 0x4f, 0x49, 0x20, 0x94, 0xb5, 0xd8, 0x12, + 0xa0, 0x2e, 0x7f, 0x40, 0x13, 0xb2, 0xfa, 0xa1, 0x45}); // Compute xi' = Fq2.inverse(xi). FfElementObj inv_xi(&fq2); @@ -171,35 +172,35 @@ const FpElemStr PrintutilsTest::p_str = { 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x00}; const FqElemStr PrintutilsTest::beta_str = { - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E, - 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, - 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}; + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, + 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x12}}; const Fq2ElemStr PrintutilsTest::xi_str = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}}}; const Fq6ElemStr PrintutilsTest::v_str = { - {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; + {{{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}}; const Fq12ElemStr PrintutilsTest::a_str = { 0xba, 0x10, 0x1f, 0xf6, 0x46, 0x8b, 0xe9, 0x32, 0x4f, 0xc0, 0xa5, 0x01, 0xad, 0x5e, 0xe2, 0x31, 0x16, 0x29, 0x96, 0xed, 0xa7, 0xde, 0x4c, 0xe1, @@ -235,60 +236,60 @@ const Fq12ElemStr PrintutilsTest::a_str = { 0xba, 0x6e, 0x2c, 0x36, 0xaf, 0x35, 0x1b, 0x75, 0x6d, 0x17, 0xdc, 0x8e, }; const FqElemStr PrintutilsTest::a1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}; const FqElemStr PrintutilsTest::b1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}}; const BigNumStr PrintutilsTest::h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; const G1ElemStr PrintutilsTest::g1_str = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; const G2ElemStr PrintutilsTest::g2_str = { - {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, 0x13, - 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, 0x47, 0x0E, - 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, - {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, 0x25, - 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, 0x53, 0xE2, - 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, - {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, 0x03, - 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, 0x68, 0x38, - 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, - {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, 0xF8, - 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, 0xD6, 0x13, - 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; + {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, + 0x13, 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, + 0x47, 0x0E, 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, + {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, + 0x25, 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, + 0x53, 0xE2, 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, + {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, + 0x03, 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, + 0x68, 0x38, 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, + {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, + 0xF8, 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, + 0xD6, 0x13, 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; const G1ElemStr PrintutilsTest::efq_a_str = { - {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, 0x52, - 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, 0x37, 0xE0, - 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, - {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, 0x30, - 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, 0xF7, 0xCD, - 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; + {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, + 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, + 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; const G2ElemStr PrintutilsTest::efq2_a_str = { { - {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, 0x9C, - 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, 0x32, 0x7C, - 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, - {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, 0x37, - 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, 0x1E, 0x60, - 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, + {0x2F, 0x8C, 0xC7, 0xD7, 0xD4, 0x1E, 0x4A, 0xCB, 0x82, 0x92, 0xC7, + 0x9C, 0x0F, 0xA2, 0xF2, 0x1B, 0xDF, 0xEA, 0x96, 0x64, 0x8B, 0xA2, + 0x32, 0x7C, 0xDF, 0xD8, 0x89, 0x10, 0xFD, 0xBB, 0x38, 0xCD}, + {0xB1, 0x23, 0x46, 0x13, 0x4D, 0x9B, 0x8E, 0x8A, 0x95, 0x64, 0xDD, + 0x37, 0x29, 0x44, 0x1F, 0x76, 0xB5, 0x3A, 0x47, 0xD3, 0xE0, 0x18, + 0x1E, 0x60, 0xE9, 0x94, 0x13, 0xA4, 0x47, 0xCD, 0xBE, 0x03}, }, { - {0xD3, 0x67, 0xA5, 0xCC, 0xEF, 0x7B, 0xD1, 0x8D, 0x4A, 0x7F, 0xF1, 0x8F, - 0x66, 0xCB, 0x5E, 0x86, 0xAC, 0xCB, 0x36, 0x5F, 0x29, 0x90, 0x28, 0x55, - 0xF0, 0xDC, 0x6E, 0x8B, 0x87, 0xB5, 0xD8, 0x32}, - {0x6C, 0x0A, 0xC5, 0x58, 0xB1, 0x4E, 0xCA, 0x85, 0x44, 0x3E, 0xDE, 0x71, - 0x9B, 0xC7, 0x90, 0x19, 0x06, 0xD2, 0xA0, 0x4E, 0xC7, 0x33, 0xF4, 0x5C, - 0xE8, 0x16, 0xE2, 0x67, 0xDB, 0xBF, 0x64, 0x84}, + {0xD3, 0x67, 0xA5, 0xCC, 0xEF, 0x7B, 0xD1, 0x8D, 0x4A, 0x7F, 0xF1, + 0x8F, 0x66, 0xCB, 0x5E, 0x86, 0xAC, 0xCB, 0x36, 0x5F, 0x29, 0x90, + 0x28, 0x55, 0xF0, 0xDC, 0x6E, 0x8B, 0x87, 0xB5, 0xD8, 0x32}, + {0x6C, 0x0A, 0xC5, 0x58, 0xB1, 0x4E, 0xCA, 0x85, 0x44, 0x3E, 0xDE, + 0x71, 0x9B, 0xC7, 0x90, 0x19, 0x06, 0xD2, 0xA0, 0x4E, 0xC7, 0x33, + 0xF4, 0x5C, 0xE8, 0x16, 0xE2, 0x67, 0xDB, 0xBF, 0x64, 0x84}, }, }; diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/tatepairing-test.cc b/external/epid-sdk/epid/common/math/unittests/tatepairing-test.cc similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/tatepairing-test.cc rename to external/epid-sdk/epid/common/math/unittests/tatepairing-test.cc index 1a15f6a6..8eb6f06f 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/tatepairing-test.cc +++ b/external/epid-sdk/epid/common/math/unittests/tatepairing-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/1.1/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/ffelement_wrapper-testhelper.h" extern "C" { diff --git a/external/epid-sdk-3.0.0/epid/common/src/commitment.c b/external/epid-sdk/epid/common/src/commitment.c similarity index 97% rename from external/epid-sdk-3.0.0/epid/common/src/commitment.c rename to external/epid-sdk/epid/common/src/commitment.c index 790a2be5..24b89362 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/commitment.c +++ b/external/epid-sdk/epid/common/src/commitment.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,10 @@ * \file * \brief Commitment hash implementation. */ -#include #include "epid/common/src/commitment.h" + +#include +#include "epid/common/math/ecgroup.h" #include "epid/common/src/memory.h" EpidStatus SetKeySpecificCommitValues(GroupPubKey const* pub_key, diff --git a/external/epid-sdk-3.0.0/epid/common/src/commitment.h b/external/epid-sdk/epid/common/src/commitment.h similarity index 80% rename from external/epid-sdk-3.0.0/epid/common/src/commitment.h rename to external/epid-sdk/epid/common/src/commitment.h index 4676cd9c..d23274eb 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/commitment.h +++ b/external/epid-sdk/epid/common/src/commitment.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,25 +21,30 @@ * \addtogroup EpidCommon * @{ */ +#include + #include "epid/common/errors.h" #include "epid/common/types.h" -#include "epid/common/math/ecgroup.h" -#include "epid/common/math/finitefield.h" + +typedef struct FiniteField FiniteField; +typedef struct EcPoint EcPoint; +typedef struct EcGroup EcGroup; +typedef struct FfElement FfElement; #pragma pack(1) /// Storage for values to create commitment in Sign and Verify algorithms typedef struct CommitValues { - BigNumStr p; ///< Intel(R) EPID2.0 parameter p - G1ElemStr g1; ///< Intel(R) EPID2.0 parameter g1 - G2ElemStr g2; ///< Intel(R) EPID2.0 parameter g2 - G1ElemStr h1; ///< Group public key value h1 - G1ElemStr h2; ///< Group public key value h2 - G2ElemStr w; ///< Group public key value w - G1ElemStr B; ///< Variable B computed in algorithm - G1ElemStr K; ///< Variable K computed in algorithm - G1ElemStr T; ///< Variable T computed in algorithm - G1ElemStr R1; ///< Variable R1 computed in algorithm - Fq12ElemStr R2; ///< Variable R2 computed in algorithm + BigNumStr p; ///< Intel(R) EPID2.0 parameter p + G1ElemStr g1; ///< Intel(R) EPID2.0 parameter g1 + G2ElemStr g2; ///< Intel(R) EPID2.0 parameter g2 + G1ElemStr h1; ///< Group public key value h1 + G1ElemStr h2; ///< Group public key value h2 + G2ElemStr w; ///< Group public key value w + G1ElemStr B; ///< Variable B computed in algorithm + G1ElemStr K; ///< Variable K computed in algorithm + G1ElemStr T; ///< Variable T computed in algorithm + G1ElemStr R1; ///< Variable R1 computed in algorithm + GtElemStr R2; ///< Variable R2 computed in algorithm } CommitValues; #pragma pack() diff --git a/external/epid-sdk-3.0.0/epid/common/src/endian_convert.h b/external/epid-sdk/epid/common/src/endian_convert.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/endian_convert.h rename to external/epid-sdk/epid/common/src/endian_convert.h diff --git a/external/epid-sdk-3.0.0/epid/common/src/epid2params.c b/external/epid-sdk/epid/common/src/epid2params.c similarity index 97% rename from external/epid-sdk-3.0.0/epid/common/src/epid2params.c rename to external/epid-sdk/epid/common/src/epid2params.c index 0d60f534..2679935f 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/epid2params.c +++ b/external/epid-sdk/epid/common/src/epid2params.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -111,6 +111,15 @@ EpidStatus CreateEpid2Params(Epid2Params_** params) { if (kEpidNoErr != result) { break; } + result = NewFfElement(internal_param->Fq, &internal_param->b); + if (kEpidNoErr != result) { + break; + } + result = ReadFfElement(internal_param->Fq, ¶ms_str.b, + sizeof(params_str.b), internal_param->b); + if (kEpidNoErr != result) { + break; + } result = NewFfElement(internal_param->Fq2, &internal_param->xi); if (kEpidNoErr != result) { break; @@ -178,6 +187,7 @@ EpidStatus CreateEpid2Params(Epid2Params_** params) { DeleteBigNum(&internal_param->p); DeleteBigNum(&internal_param->q); + DeleteFfElement(&internal_param->b); DeleteBigNum(&internal_param->t); DeleteFp(&internal_param->Fp); @@ -200,6 +210,7 @@ void DeleteEpid2Params(Epid2Params_** epid_params) { DeleteBigNum(&(*epid_params)->p); DeleteBigNum(&(*epid_params)->q); + DeleteFfElement(&(*epid_params)->b); DeleteBigNum(&(*epid_params)->t); DeleteFfElement(&(*epid_params)->xi); DeleteEcPoint(&(*epid_params)->g1); @@ -320,9 +331,9 @@ EpidStatus NewG1(Epid2Params const* param, FiniteField* Fq, EcGroup** G1) { BigNum* cofactor = NULL; // h = 1; const BigNumStr h1 = { - {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; + {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}; if (!param || !Fq || !G1) { return kEpidBadArgErr; diff --git a/external/epid-sdk-3.0.0/epid/common/src/epid2params.h b/external/epid-sdk/epid/common/src/epid2params.h similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/src/epid2params.h rename to external/epid-sdk/epid/common/src/epid2params.h index 22978f38..ad2393a7 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/epid2params.h +++ b/external/epid-sdk/epid/common/src/epid2params.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ typedef struct Epid2Params_ { BigNum* p; ///< a prime BigNum* q; ///< a prime + FfElement* b; ///< an integer between [0, q-1] BigNum* t; ///< an integer bool neg; ///< a boolean FfElement* xi; ///< array of integers between [0, q-1] diff --git a/external/epid-sdk-3.0.0/epid/common/src/epid2params_ate.inc b/external/epid-sdk/epid/common/src/epid2params_ate.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/epid2params_ate.inc rename to external/epid-sdk/epid/common/src/epid2params_ate.inc diff --git a/external/epid-sdk-3.0.0/epid/common/src/errors.c b/external/epid-sdk/epid/common/src/errors.c similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/src/errors.c rename to external/epid-sdk/epid/common/src/errors.c index 8f364baf..fbec3dbe 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/errors.c +++ b/external/epid-sdk/epid/common/src/errors.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ #include -#include "epid/common/stdtypes.h" #include "epid/common/errors.h" +#include "epid/common/stdtypes.h" /// Record mapping status code to string struct ErrorTextEntry { diff --git a/external/epid-sdk-3.0.0/epid/common/src/file_parser-internal.h b/external/epid-sdk/epid/common/src/file_parser-internal.h similarity index 92% rename from external/epid-sdk-3.0.0/epid/common/src/file_parser-internal.h rename to external/epid-sdk/epid/common/src/file_parser-internal.h index 2a1d88c7..67086a9e 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/file_parser-internal.h +++ b/external/epid-sdk/epid/common/src/file_parser-internal.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ -/// Internal functions of Epid issuer material parsing utilities. +/// Internal functions of Intel(R) EPID issuer material parsing utilities. /*! * \file */ @@ -22,9 +22,9 @@ #include +#include "epid/common/errors.h" #include "epid/common/file_parser.h" #include "epid/common/types.h" -#include "epid/common/errors.h" /// Verifies CA certificate to contain EC secp256r1 parameters /*! diff --git a/external/epid-sdk-3.0.0/epid/common/src/file_parser.c b/external/epid-sdk/epid/common/src/file_parser.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/src/file_parser.c rename to external/epid-sdk/epid/common/src/file_parser.c index b452f8d8..a25beba8 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/file_parser.c +++ b/external/epid-sdk/epid/common/src/file_parser.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ #include #include "epid/common/math/ecdsa.h" -#include "epid/common/src/memory.h" #include "epid/common/src/file_parser-internal.h" +#include "epid/common/src/memory.h" const OctStr16 kEpidVersionCode[kNumEpidVersions] = { {0x01, 0x00}, {0x02, 0x00}, @@ -282,7 +282,7 @@ EpidStatus EpidParseGroupPubKeyFile(void const* buf, size_t len, return kEpidBadArgErr; } - if (sizeof(EpidGroupPubKeyCertificate) > len) { + if (len == 0 || len % sizeof(EpidGroupPubKeyCertificate) != 0) { return kEpidBadArgErr; } diff --git a/external/epid-sdk-3.0.0/epid/common/src/grouppubkey.c b/external/epid-sdk/epid/common/src/grouppubkey.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/grouppubkey.c rename to external/epid-sdk/epid/common/src/grouppubkey.c diff --git a/external/epid-sdk-3.0.0/epid/common/src/grouppubkey.h b/external/epid-sdk/epid/common/src/grouppubkey.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/grouppubkey.h rename to external/epid-sdk/epid/common/src/grouppubkey.h diff --git a/external/epid-sdk/epid/common/src/hashsize.c b/external/epid-sdk/epid/common/src/hashsize.c new file mode 100644 index 00000000..322de7af --- /dev/null +++ b/external/epid-sdk/epid/common/src/hashsize.c @@ -0,0 +1,44 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief EpidGetHashSize implementation. + */ + +#include "epid/common/src/hashsize.h" +#include + +size_t EpidGetHashSize(HashAlg hash_alg) { + switch (hash_alg) { + case kSha256: + return EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT; + case kSha384: + return EPID_SHA384_DIGEST_BITSIZE / CHAR_BIT; + case kSha512: + return EPID_SHA512_DIGEST_BITSIZE / CHAR_BIT; + case kSha512_256: + return EPID_SHA512_256_DIGEST_BITSIZE / CHAR_BIT; + case kSha3_256: + return EPID_SHA3_256_DIGEST_BITSIZE / CHAR_BIT; + case kSha3_384: + return EPID_SHA3_384_DIGEST_BITSIZE / CHAR_BIT; + case kSha3_512: + return EPID_SHA3_512_DIGEST_BITSIZE / CHAR_BIT; + default: + return 0; + } +} diff --git a/external/epid-sdk/epid/common/src/hashsize.h b/external/epid-sdk/epid/common/src/hashsize.h new file mode 100644 index 00000000..0fc7c205 --- /dev/null +++ b/external/epid-sdk/epid/common/src/hashsize.h @@ -0,0 +1,46 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief EpidGetHashSize definition. + */ + +#ifndef EPID_COMMON_SRC_HASHSIZE_H_ +#define EPID_COMMON_SRC_HASHSIZE_H_ + +#include +#include "epid/common/types.h" + +/// Size of SHA-256 digest in bits +#define EPID_SHA256_DIGEST_BITSIZE 256 +/// Size of SHA-384 digest in bits +#define EPID_SHA384_DIGEST_BITSIZE 385 +/// Size of SHA-512 digest in bits +#define EPID_SHA512_DIGEST_BITSIZE 512 +/// Size of SHA-512/256 digest in bits +#define EPID_SHA512_256_DIGEST_BITSIZE 256 +/// Size of SHA3-256 digest in bits +#define EPID_SHA3_256_DIGEST_BITSIZE 256 +/// Size of SHA3-384 digest in bits +#define EPID_SHA3_384_DIGEST_BITSIZE 385 +/// Size of SHA3-512 digest in bits +#define EPID_SHA3_512_DIGEST_BITSIZE 512 + +/// Gets hash digest size in bytes. +size_t EpidGetHashSize(HashAlg hash_alg); + +#endif // EPID_COMMON_SRC_HASHSIZE_H_ diff --git a/external/epid-sdk-3.0.0/epid/common/src/memory.c b/external/epid-sdk/epid/common/src/memory.c similarity index 98% rename from external/epid-sdk-3.0.0/epid/common/src/memory.c rename to external/epid-sdk/epid/common/src/memory.c index b37180fb..99a48a8b 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/memory.c +++ b/external/epid-sdk/epid/common/src/memory.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ #include "epid/common/src/memory.h" -#include #include +#include /// Maximum size of the destination buffer #ifndef RSIZE_MAX diff --git a/external/epid-sdk-3.0.0/epid/common/src/memory.h b/external/epid-sdk/epid/common/src/memory.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/memory.h rename to external/epid-sdk/epid/common/src/memory.h diff --git a/external/epid-sdk-3.0.0/epid/common/src/sigrlvalid.c b/external/epid-sdk/epid/common/src/sigrlvalid.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/sigrlvalid.c rename to external/epid-sdk/epid/common/src/sigrlvalid.c diff --git a/external/epid-sdk-3.0.0/epid/common/src/sigrlvalid.h b/external/epid-sdk/epid/common/src/sigrlvalid.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/src/sigrlvalid.h rename to external/epid-sdk/epid/common/src/sigrlvalid.h diff --git a/external/epid-sdk-3.0.0/epid/common/src/stack.c b/external/epid-sdk/epid/common/src/stack.c similarity index 96% rename from external/epid-sdk-3.0.0/epid/common/src/stack.c rename to external/epid-sdk/epid/common/src/stack.c index 39911ae5..314face9 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/stack.c +++ b/external/epid-sdk/epid/common/src/stack.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,8 +17,8 @@ * \file * \brief Stack container implementation. */ -#include #include "epid/common/src/stack.h" +#include #include "epid/common/src/memory.h" /// Internal representation of a Stack @@ -85,6 +85,8 @@ size_t StackGetSize(Stack const* stack) { return stack ? stack->top : (size_t)0; } +void* StackGetBuf(Stack const* stack) { return stack ? stack->buf : NULL; } + void DeleteStack(Stack** stack) { if (stack && *stack) { SAFE_FREE((*stack)->buf); diff --git a/external/epid-sdk-3.0.0/epid/common/src/stack.h b/external/epid-sdk/epid/common/src/stack.h similarity index 90% rename from external/epid-sdk-3.0.0/epid/common/src/stack.h rename to external/epid-sdk/epid/common/src/stack.h index 7b138324..4ac1592b 100644 --- a/external/epid-sdk-3.0.0/epid/common/src/stack.h +++ b/external/epid-sdk/epid/common/src/stack.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -82,6 +82,17 @@ bool StackPopN(Stack* stack, size_t n, void* elements); */ size_t StackGetSize(Stack const* stack); +/// Get number of elements in the stack +/*! + \param[in] stack + Stack context + + \returns Pointer to the buffer, returns NULL if stack is NULL + + \see CreateStack +*/ +void* StackGetBuf(Stack const* stack); + /// Deallocates memory used for the stack. /*! \param[in,out] stack diff --git a/external/epid-sdk-3.0.0/epid/common/stdtypes.h b/external/epid-sdk/epid/common/stdtypes.h similarity index 100% rename from external/epid-sdk-3.0.0/epid/common/stdtypes.h rename to external/epid-sdk/epid/common/stdtypes.h diff --git a/external/epid-sdk/epid/common/tinycommon.parts b/external/epid-sdk/epid/common/tinycommon.parts new file mode 100644 index 00000000..3e9f00ba --- /dev/null +++ b/external/epid-sdk/epid/common/tinycommon.parts @@ -0,0 +1,46 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +"""Build confioguration for include-only common + +Needed to avoid linking to avoid listing ipp in dependencies when only +depending on headers. Eventually should unify this into single header. + +""" +Import('*') +env.PartName('tinycommon') + +include_files = Pattern(src_dir='.', + includes=['*.h'], + recursive=False).files() + +install_files = Pattern(src_dir='.', + includes=[ + '*.h', + '*.c', + '*-test.cc', + '*-testhelper.cc', + '*.parts' + 'Makefile'], + recursive=True) + +if 'install_package' in env['MODE']: + env.InstallTopLevel(install_files, + sub_dir='epid/common') +else: + env.SdkInclude(include_files, sub_dir='epid/common') + if 'install_lib' in env['MODE']: + env.InstallInclude(include_files, sub_dir='epid/common') diff --git a/external/epid-sdk-3.0.0/epid/common/types.h b/external/epid-sdk/epid/common/types.h similarity index 94% rename from external/epid-sdk-3.0.0/epid/common/types.h rename to external/epid-sdk/epid/common/types.h index 19e710ec..49b684dc 100644 --- a/external/epid-sdk-3.0.0/epid/common/types.h +++ b/external/epid-sdk/epid/common/types.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,6 +40,12 @@ @{ */ +/// Generic Octet String Style Number +typedef void* OctStr; + +/// Generic Const Octet String Style Number +typedef void const* ConstOctStr; + /// Recognized hash algorithms typedef enum { /// Invalid @@ -304,6 +310,20 @@ typedef struct VerifierRl { G1ElemStr K[1]; ///< elements in G1 (flexible array) } VerifierRl; +/// Pre-computed member settings. +/*! + * Serialized form of the information about a member that remains + * stable for a given set of keys. + * + * \note e12 = 0 implies that this data is not valid + */ +typedef struct MemberPrecomp { + GtElemStr e12; ///< an element in GT + GtElemStr e22; ///< an element in GT + GtElemStr e2w; ///< an element in GT + GtElemStr ea2; ///< an element in GT +} MemberPrecomp; + /// element to store seed values for later rekey typedef G1ElemStr ReKeySeed; diff --git a/external/epid-sdk-3.0.0/epid/common/unittests/file_parser-test.cc b/external/epid-sdk/epid/common/unittests/file_parser-test.cc similarity index 99% rename from external/epid-sdk-3.0.0/epid/common/unittests/file_parser-test.cc rename to external/epid-sdk/epid/common/unittests/file_parser-test.cc index 77cccfac..5024b8e2 100644 --- a/external/epid-sdk-3.0.0/epid/common/unittests/file_parser-test.cc +++ b/external/epid-sdk/epid/common/unittests/file_parser-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/common/file_parser.h" @@ -463,6 +464,14 @@ TEST_F(EpidFileParser, RejectsGroupPubKeyFileWithInvalidSize) { EpidParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(), this->kGroupPublicKeyFile.size() - 1, &this->kCert, &pubkey)); + EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile( + (void*)this->kGroupMultiPublicKeyFile.data(), + this->kGroupMultiPublicKeyFile.size() - 1, + &this->kCert, &pubkey)); + EXPECT_EQ(kEpidBadArgErr, EpidParseGroupPubKeyFile( + (void*)this->kGroupMultiPublicKeyFile.data(), + this->kGroupMultiPublicKeyFile.size() + 1, + &this->kCert, &pubkey)); } TEST_F(EpidFileParser, RejectsInvalidGroupPubKeyFileType) { diff --git a/external/epid-sdk/epid/member/Makefile b/external/epid-sdk/epid/member/Makefile new file mode 100644 index 00000000..29e0cf35 --- /dev/null +++ b/external/epid-sdk/epid/member/Makefile @@ -0,0 +1,186 @@ +#!/usr/bin/make -f + +#define path variables +IPP_SRC_INCLUDE_DIR = ../../ext/ipp/sources/ippcp/src/ +IPP_INCLUDE_DIR = ../../ext/ipp/sources/include/ +GTEST_INCLUDE_DIR = ../../ext/ + +LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/ +TEST_INSTALL_DIR = $(epidinstalldir)/test/ +HEADERS_INSTALL_DIR := $(epidinstalldir)/include/epid/member/ + +API_HEADERS_INSTALL = $(wildcard ./*.h) + +MEMBER_INCLUDE_DIR = ../../ +TINY_MEMBER_INCLUDE_DIR = ./tiny/ + +MEMBER_SRC = $(wildcard ./src/*.c) +TINY_MEMBER_SRC = $(wildcard ./tiny/src/*.c) +TINY_MEMBER_MATH_SRC = $(wildcard ./tiny/math/src/*.c) +TINY_STDLIB_MEMBER_SRC = $(wildcard ./tiny/stdlib/src/*.c) +MEMBER_TPM2_TSS_UTEST_SRC = $(wildcard ./tpm2/unittests/*.cc) +ifneq ($(TSS_PATH),) + MEMBER_TPM2_SRC = $(wildcard ./tpm2/ibm_tss/*.c) + MEMBER_TPM2_UTEST_SRC = $(filter-out $(wildcard ./tpm2/unittests/*-simulator-test.cc), \ + $(MEMBER_TPM2_TSS_UTEST_SRC)) + MEMBER_INCLUDE_DIR += -I$(TSS_PATH) + CFLAGS += -DTPM_TSS + CXXFLAGS += -DTPM_TSS +else + MEMBER_TPM2_SRC = $(wildcard ./tpm2/src/*.c) + MEMBER_TPM2_UTEST_SRC = $(filter-out $(wildcard ./tpm2/unittests/*-tss-test.cc), \ + $(MEMBER_TPM2_TSS_UTEST_SRC)) +endif +MEMBER_SRC += $(MEMBER_TPM2_SRC) +MEMBER_LIB = ./libmember.a +MATH_LIB = ./libmath.a +STDLIB_LIB = ./libtiny_stdlib.a + +MEMBER_UTEST_EXE = ./member-utest$(EXE_EXTENSION) +MEMBER_UTEST_SRC = $(wildcard ./unittests/*.cc) \ + ./tpm2/unittests/tpm2_wrapper-testhelper.cc +TINY_MEMBER_UTEST_SRC = $(wildcard ./tiny/unittests/*.cc) +TINY_MEMBER_MATH_UTEST_SRC = $(wildcard ./tiny/math/unittests/*.cc) +ifneq ($(TINY),) + MEMBER_OBJ = $(TINY_MEMBER_SRC:.c=.o) + MATH_OBJ = $(TINY_MEMBER_MATH_SRC:.c=.o) + STDLIB_OBJ = $(TINY_STDLIB_MEMBER_SRC:.c=.o) + MEMBER_UTEST_OBJ = $(TINY_MEMBER_UTEST_SRC:.cc=.o) + TINY_MEMBER_MATH_UTEST_OBJ = $(TINY_MEMBER_MATH_UTEST_SRC:.cc=.o) + MEMBER_INCLUDE_DIR += -I$(TINY_MEMBER_INCLUDE_DIR) +else + MEMBER_OBJ = $(MEMBER_SRC:.c=.o) + MEMBER_UTEST_OBJ = $(MEMBER_UTEST_SRC:.cc=.o) + MEMBER_TPM2_UTEST_OBJ = $(MEMBER_TPM2_UTEST_SRC:.cc=.o) +endif + +LIB_MEMBER_DIR = . +LIB_VERIFIER_DIR = ../verifier +LIB_COMMON_TESTHELPER_DIR = ../common-testhelper +LIB_COMMON_DIR = ../common +LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src + +#set flags for linker +LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \ + -L$(LIB_MEMBER_DIR) -L$(LIB_VERIFIER_DIR) -L$(LIB_COMMON_DIR) \ + -L$(LIB_IPPCP_DIR) -lgtest -lcommon-testhelper \ + -lmember -lverifier -lcommon -lippcp + +ifneq ($(TSS_PATH),) + LDFLAGS += -L$(TSS_PATH) -ltss -lcrypto +endif + +ifneq ($(TINY),) + CPPDEFINES := -DNDEBUG + LDFLAGS += -lmath -ltiny_stdlib + CFLAGS := -Os -fno-builtin -fno-stack-protector -fomit-frame-pointer -fno-asynchronous-unwind-tables \ + -fdata-sections -ffunction-sections -fvisibility=hidden -Werror -Wall -Wextra + ifneq ($(OS),Windows_NT) + CFLAGS += -fPIC + endif + ifeq ($(findstring gcc,$(CC)),gcc) + CFLAGS += -Wno-missing-braces + endif + ifeq ($(ARCH), x86) + CFLAGS += -m32 + endif +endif + +$(MEMBER_OBJ): %.o: %.c + $(CC) $(CFLAGS) -I$(IPP_INCLUDE_DIR) -I$(IPP_SRC_INCLUDE_DIR) \ + -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@ + +$(MEMBER_LIB): $(MEMBER_OBJ) + $(AR) rc $(MEMBER_LIB) $(MEMBER_OBJ) + $(RANLIB) $(MEMBER_LIB) + +$(MEMBER_UTEST_EXE): $(MEMBER_UTEST_OBJ) + $(CXX) -o $@ $^ $(LDFLAGS) + +$(MEMBER_UTEST_OBJ): %.o: %.cc + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \ + -I$(GTEST_INCLUDE_DIR) -c $^ + +ifneq ($(TINY),) + $(MATH_OBJ): %.o: %.c + $(CC) $(CFLAGS) -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@ + + $(STDLIB_OBJ): %.o: %.c + $(CC) $(CFLAGS) -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@ + + $(MATH_LIB): $(MATH_OBJ) + $(AR) rc $(MATH_LIB) $(MATH_OBJ) + $(RANLIB) $(MATH_LIB) + + $(STDLIB_LIB): $(STDLIB_OBJ) + $(AR) rc $(STDLIB_LIB) $(STDLIB_OBJ) + $(RANLIB) $(STDLIB_LIB) + + TINY_MEMBER_MATH_UTEST_EXE = ./member.math-utest$(EXE_EXTENSION) + $(TINY_MEMBER_MATH_UTEST_EXE): $(TINY_MEMBER_MATH_UTEST_OBJ) + $(CXX) -o $@ $^ $(LDFLAGS) + + $(TINY_MEMBER_MATH_UTEST_OBJ): %.o: %.cc + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \ + -I$(GTEST_INCLUDE_DIR) -c $^ +else + MEMBER_TPM2_UTEST_EXE = ./member.tpm2-utest$(EXE_EXTENSION) + $(MEMBER_TPM2_UTEST_EXE): $(MEMBER_TPM2_UTEST_OBJ) + $(CXX) -o $@ $^ $(LDFLAGS) + + $(MEMBER_TPM2_UTEST_OBJ): %.o: %.cc + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \ + -I$(GTEST_INCLUDE_DIR) -c $^ +endif + +build: all +LIBS = $(MEMBER_LIB) +ifneq ($(TINY),) + LIBS += $(STDLIB_LIB) $(MATH_LIB) +endif +all: $(LIBS) +install: + mkdir -p '$(LIB_INSTALL_DIR)' + mkdir -p '$(HEADERS_INSTALL_DIR)' + cp $(MEMBER_LIB) '$(LIB_INSTALL_DIR)' +ifneq ($(TINY),) + cp $(MATH_LIB) '$(LIB_INSTALL_DIR)' + cp $(STDLIB_LIB) '$(LIB_INSTALL_DIR)' +endif + cp $(API_HEADERS_INSTALL) '$(HEADERS_INSTALL_DIR)' +#install tests if they exist +ifneq (,$(wildcard $(MEMBER_UTEST_EXE))) + mkdir -p '$(TEST_INSTALL_DIR)' + cp $(MEMBER_UTEST_EXE) '$(TEST_INSTALL_DIR)' +endif +ifneq ($(TINY),) + mkdir -p '$(TEST_INSTALL_DIR)' + cp $(TINY_MEMBER_MATH_UTEST_EXE) '$(TEST_INSTALL_DIR)' +else + mkdir -p '$(TEST_INSTALL_DIR)' + cp $(MEMBER_TPM2_UTEST_EXE) '$(TEST_INSTALL_DIR)' +endif + +utest: $(MEMBER_UTEST_EXE) $(MEMBER_TPM2_UTEST_EXE) $(TINY_MEMBER_MATH_UTEST_EXE) + +run_utest: + $(MEMBER_UTEST_EXE) $(GTEST_FLAGS) + $(MEMBER_TPM2_UTEST_EXE) $(GTEST_FLAGS) + $(TINY_MEMBER_MATH_UTEST_EXE) $(GTEST_FLAGS) + +check: utest run_utest + +clean: + rm -f $(MEMBER_OBJ) \ + $(MEMBER_LIB) \ + $(MATH_OBJ) \ + $(MATH_LIB) \ + $(STDLIB_OBJ) \ + $(STDLIB_LIB) \ + $(MEMBER_UTEST_OBJ) \ + $(MEMBER_UTEST_EXE) \ + $(MEMBER_TPM2_UTEST_OBJ) \ + $(MEMBER_TPM2_UTEST_EXE) \ + $(TINY_MEMBER_MATH_UTEST_OBJ) \ + $(TINY_MEMBER_MATH_UTEST_EXE) \ + *.xml diff --git a/external/epid-sdk/epid/member/api.h b/external/epid-sdk/epid/member/api.h new file mode 100644 index 00000000..b6c8dd05 --- /dev/null +++ b/external/epid-sdk/epid/member/api.h @@ -0,0 +1,443 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Intel(R) EPID SDK member API. +/*! \file */ +#ifndef EPID_MEMBER_API_H_ +#define EPID_MEMBER_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "epid/common/bitsupplier.h" +#include "epid/common/epiddefs.h" +#include "epid/common/errors.h" +#include "epid/common/types.h" + +/// Internal context of member. +typedef struct MemberCtx MemberCtx; + +/// Implementation specific configuration parameters. +typedef struct MemberParams MemberParams; + +/// Member functionality +/*! + \defgroup EpidMemberModule member + + Defines the APIs needed by Intel(R) EPID members. Each member + context (::MemberCtx) represents membership in a single group. + + To use this module, include the header epid/member/api.h. + + \ingroup EpidModule + @{ +*/ + +/// Allocates and initializes a new member context. +/*! + \param[in] params + Implementation specific configuration parameters. + \param[out] ctx + Newly constructed member context. + + \warning buffers allocated using this function should not be + initialized with ::EpidMemberInit. + + \deprecated This API has been superseded by ::EpidMemberGetSize + and ::EpidMemberInit. + + \returns ::EpidStatus + */ +EpidStatus EPID_API EpidMemberCreate(MemberParams const* params, + MemberCtx** ctx); + +/// Computes the size in bytes required for a member context +/*! + \param[in] params + Implementation specific configuration parameters. + \param[out] context_size + Number of bytes required for a ::MemberCtx buffer + + \returns ::EpidStatus + \see EpidMemberInit + */ +EpidStatus EPID_API EpidMemberGetSize(MemberParams const* params, + size_t* context_size); + +/// Initializes a new member context. +/*! + \param[in] params + Implementation specific configuration parameters. + \param[in,out] ctx + An existing buffer that will be used as a ::MemberCtx. + + \warning ctx must be a buffer of at least the size reported by + ::EpidMemberGetSize for the same parameters. + + \returns ::EpidStatus + \see EpidMemberGetSize + */ +EpidStatus EPID_API EpidMemberInit(MemberParams const* params, MemberCtx* ctx); + +/// Creates a request to join a group. +/*! +The created request is part of the interaction with an issuer needed to join +a group. This interaction with the issuer is outside the scope of this API. + +\param[in,out] ctx +The member context. +\param[in] pub_key +The group certificate of group to join. +\param[in] ni +The nonce chosen by issuer as part of join protocol. +\param[out] join_request +The join request. + +\returns ::EpidStatus +*/ +EpidStatus EPID_API EpidCreateJoinRequest(MemberCtx* ctx, + GroupPubKey const* pub_key, + IssuerNonce const* ni, + JoinRequest* join_request); + +/// Provisions a member context from a membership credential +/*! +\param[in,out] ctx +The member context. +\param[in] pub_key +The group certificate of group to provision. +\param[in] credential +membership credential. +\param[in] precomp_str +Precomputed state (implementation specific optional) + +\returns ::EpidStatus +*/ +EpidStatus EPID_API EpidProvisionCredential( + MemberCtx* ctx, GroupPubKey const* pub_key, + MembershipCredential const* credential, MemberPrecomp const* precomp_str); + +/// Provisions a member context from a compressed private key +/*! +\param[in,out] ctx +The member context. +\param[in] pub_key +The group certificate of group to provision. +\param[in] compressed_privkey +private key. +\param[in] precomp_str +Precomputed state (implementation specific optional) + +\returns ::EpidStatus +*/ +EpidStatus EPID_API +EpidProvisionCompressed(MemberCtx* ctx, GroupPubKey const* pub_key, + CompressedPrivKey const* compressed_privkey, + MemberPrecomp const* precomp_str); + +/// Provisions a member context from a private key +/*! +\param[in,out] ctx +The member context. +\param[in] pub_key +The group certificate of group to provision. +\param[in] priv_key +private key. +\param[in] precomp_str +Precomputed state (implementation specific optional) + +\returns ::EpidStatus +*/ +EpidStatus EPID_API EpidProvisionKey(MemberCtx* ctx, GroupPubKey const* pub_key, + PrivKey const* priv_key, + MemberPrecomp const* precomp_str); + +/// Change member from setup state to normal operation +/*! +\param[in,out] ctx +The member context. + +\returns ::EpidStatus +*/ +EpidStatus EPID_API EpidMemberStartup(MemberCtx* ctx); + +/// De-initializes an existing member context buffer. +/*! + Must be called to safely release a member context initialized using + ::EpidMemberInit. + + De-initializes the context. + + \param[in,out] ctx + The member context. Can be NULL. + + \warning This function should not be used on buffers allocated with + ::EpidMemberCreate. Those buffers should be released using ::EpidMemberDelete + + \see EpidMemberInit + */ +void EPID_API EpidMemberDeinit(MemberCtx* ctx); + +/// Deletes an existing member context. +/*! + Must be called to safely release a member context created using + ::EpidMemberCreate. + + De-initializes the context, frees memory used by the context, and sets the + context pointer to NULL. + + \param[in,out] ctx + The member context. Can be NULL. + + \deprecated This API has been superseded by ::EpidMemberDeinit. + + \see EpidMemberCreate + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +void EPID_API EpidMemberDelete(MemberCtx** ctx); + +/// Sets the hash algorithm to be used by a member. +/*! + \param[in] ctx + The member context. + \param[in] hash_alg + The hash algorithm to use. + + \returns ::EpidStatus + + \note + If the result is not ::kEpidNoErr, the hash algorithm used by the member is + undefined. + + \see EpidMemberInit + \see ::HashAlg + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +EpidStatus EPID_API EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg); + +/// Sets the signature based revocation list to be used by a member. +/*! + The caller is responsible for ensuring the revocation list is authorized, + e.g. signed by the issuer. The caller is also responsible checking the version + of the revocation list. The call fails if trying to set an older version + of the revocation list than was last set. + + \attention + The memory pointed to by sig_rl is accessed directly by the member + until a new list is set or the member is destroyed. Do not modify the + contents of this memory. The behavior of subsequent operations that rely on + the revocation list is undefined if the memory is modified. + + \attention + It is the responsibility of the caller to free the memory pointed to by sig_rl + after the member is no longer using it. + + \param[in] ctx + The member context. + \param[in] sig_rl + The signature based revocation list. + \param[in] sig_rl_size + The size of the signature based revocation list in bytes. + + \returns ::EpidStatus + + \note + If the result is not ::kEpidNoErr the signature based revocation list pointed + to by the member is not changed. + + \see EpidMemberInit + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +EpidStatus EPID_API EpidMemberSetSigRl(MemberCtx* ctx, SigRl const* sig_rl, + size_t sig_rl_size); + +/// Computes the size in bytes required for an Intel(R) EPID signature. +/*! + \param[in] sig_rl + The signature based revocation list that is used. NULL is treated as + a zero length list. + + \returns + Size in bytes of an Intel(R) EPID signature including proofs for each entry + in the signature based revocation list. + + \see ::SigRl + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature +*/ +size_t EPID_API EpidGetSigSize(SigRl const* sig_rl); + +/// Writes an Intel(R) EPID signature. +/*! + \param[in] ctx + The member context. + \param[in] msg + The message to sign. + \param[in] msg_len + The length in bytes of message. + \param[in] basename + Optional basename. If basename is NULL a random basename is used. + Signatures generated using random basenames are anonymous. Signatures + generated using the same basename are linkable by the verifier. If a + basename is provided, it must already be registered, or + ::kEpidBadArgErr is returned. + \param[in] basename_len + The size of basename in bytes. Must be 0 if basename is NULL. + \param[out] sig + The generated signature + \param[in] sig_len + The size of signature in bytes. Must be equal to value returned by + EpidGetSigSize(). + + \returns ::EpidStatus + + \note + If the result is not ::kEpidNoErr the content of sig is undefined. + + \see EpidMemberInit + \see EpidMemberSetHashAlg + \see EpidMemberSetSigRl + \see EpidGetSigSize + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +EpidStatus EPID_API EpidSign(MemberCtx const* ctx, void const* msg, + size_t msg_len, void const* basename, + size_t basename_len, EpidSignature* sig, + size_t sig_len); + +/// Registers a basename with a member. +/*! + + To prevent loss of privacy, the member keeps a list of basenames + (corresponding to authorized verifiers). The member signs a message + with a basename only if the basename is in the member's basename + list. + + \warning + The use of a name-based signature creates a platform unique + pseudonymous identifier. Because it reduces the member's privacy, the + user should be notified when it is used and should have control over + its use. + + \param[in] ctx + The member context. + \param[in] basename + The basename. + \param[in] basename_len + Length of the basename. + + \returns ::EpidStatus + + \retval ::kEpidDuplicateErr + The basename was already registered. + + \note + If the result is not ::kEpidNoErr or ::kEpidDuplicateErr it is undefined if the + basename is registered. + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +EpidStatus EPID_API EpidRegisterBasename(MemberCtx* ctx, void const* basename, + size_t basename_len); + +/// Clears registered basenames. +/*! + + Allows clearing registered basenames without recreating member. + + \param[in,out] ctx + The member context. + + \returns ::EpidStatus + + \see ::EpidRegisterBasename + */ +EpidStatus EPID_API EpidClearRegisteredBasenames(MemberCtx* ctx); + +/// Extends the member's pool of pre-computed signatures. +/*! + Generate new pre-computed signatures and add them to the internal pool. + + \param[in] ctx + The member context. + \param[in] number_presigs + The number of pre-computed signatures to add to the internal pool. + + \returns ::EpidStatus + + \see ::EpidMemberInit + */ +EpidStatus EPID_API EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs); + +/// Gets the number of pre-computed signatures in the member's pool. +/*! + \param[in] ctx + The member context. + + \returns + Number of remaining pre-computed signatures. Returns 0 if ctx is NULL. + + \see ::EpidMemberInit +*/ +size_t EPID_API EpidGetNumPreSigs(MemberCtx const* ctx); + +/// Decompresses compressed member private key. +/*! + + Converts a compressed member private key into a member + private key for use by other member APIs. + + \param[in] pub_key + The public key of the group. + \param[in] compressed_privkey + The compressed member private key to be decompressed. + \param[out] priv_key + The member private key. + + \returns ::EpidStatus + + \b Example + + \ref UserManual_GeneratingAnIntelEpidSignature + */ +EpidStatus EPID_API EpidDecompressPrivKey( + GroupPubKey const* pub_key, CompressedPrivKey const* compressed_privkey, + PrivKey* priv_key); + +/*! @} */ + +#ifdef __cplusplus +} +#endif + +#endif // EPID_MEMBER_API_H_ diff --git a/external/epid-sdk/epid/member/member.parts b/external/epid-sdk/epid/member/member.parts new file mode 100644 index 00000000..f90df70c --- /dev/null +++ b/external/epid-sdk/epid/member/member.parts @@ -0,0 +1,93 @@ +############################################################################ +# Copyright 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +Import('*') +env.PartName('member') + +api_headers = Pattern(src_dir='.', includes=['*.h'], recursive=False).files() +src_files = Pattern(src_dir='src', includes=['*.c'], recursive=False).files() +internal_headers = Pattern( + src_dir='src', includes=['*.h'], recursive=False).files() + +tpm_utest_wrapper_files = Pattern( + src_dir='tpm2/unittests', + includes=['tpm2_wrapper-testhelper.cc'], + recursive=False).files() + +utest_files = Pattern( + src_dir='unittests', + includes=[ + '*-test.cc', + '*-testhelper.cc', + ], + recursive=False).files() +utest_headers = Pattern( + src_dir='unittests', includes=[ + '*-testhelper.h', + ], recursive=False).files() + +build_files = Pattern( + src_dir='.', includes=['*.parts', 'Makefile'], recursive=False).files() + +env.Part(parts_file='tpm2/tpm2.parts') + +if 'use_tss' in env['MODE']: + env.Append(CPPDEFINES=['TPM_TSS']) + +if 'install_package' in env['MODE']: + env.InstallTopLevel(api_headers, sub_dir='epid/${PART_SHORT_NAME}') + env.InstallTopLevel( + src_files + internal_headers, sub_dir='epid/${PART_SHORT_NAME}/src') + env.InstallTopLevel( + utest_files + utest_headers, + sub_dir='epid/${PART_SHORT_NAME}/unittests') + env.InstallTopLevel(build_files, sub_dir='epid/${PART_SHORT_NAME}') + +else: + env.DependsOn([ + Component('common'), + Component('member.tpm2'), + ]) + + env.Append(CPPPATH='#') + + testenv = env.Clone() + + outputs = env.Library('${PART_NAME}', src_files) + env.Sdk(outputs) + env.SdkInclude(api_headers, sub_dir='epid/${PART_SHORT_NAME}') + + if 'install_lib' in env['MODE']: + env.InstallLib(outputs) + env.InstallInclude(api_headers, sub_dir='${PART_SHORT_NAME}') + + #unit tests + testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}" + testenv.UnitTest( + "utest", + utest_files + tpm_utest_wrapper_files, + command_args=[ + '--gtest_color=yes', + '--gtest_print_time=1', + '--gtest_output=xml', + '--gtest_filter=**', + ], + make_pdb=(env.isConfigBasedOn('debug') or + env.isConfigBasedOn('static_crt_debug')), + depends=[ + Component('gtest'), Component('common-testhelper'), + Component('member'), Component('verifier') + ], + INSTALL_BIN='${INSTALL_TEST_BIN}') diff --git a/external/epid-sdk/epid/member/software_member.h b/external/epid-sdk/epid/member/software_member.h new file mode 100644 index 00000000..4e861752 --- /dev/null +++ b/external/epid-sdk/epid/member/software_member.h @@ -0,0 +1,48 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Member creation parameters for software only implementation. +/*! + * \file + */ +#ifndef EPID_MEMBER_SOFTWARE_MEMBER_H_ +#define EPID_MEMBER_SOFTWARE_MEMBER_H_ + +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" + +/*! + \addtogroup EpidMemberModule member + @{ + */ + +/// Software only specific member parameters +/*! + You need to use a cryptographically secure random + number generator to create a member context using + ::EpidMemberGetSize and ::EpidMemberInit. The ::BitSupplier is provided + as a function prototype for your own implementation + of the random number generator. +*/ +typedef struct MemberParams { + BitSupplier rnd_func; ///< Random number generator. + void* rnd_param; ///< User data that will be passed to the user_data + /// parameter of the random number generator. + FpElemStr const* f; ///< Secret part of the private key. If NULL a random + /// value will be generated using rnd_func. +} MemberParams; +/*! @} */ + +#endif // EPID_MEMBER_SOFTWARE_MEMBER_H_ diff --git a/external/epid-sdk/epid/member/src/allowed_basenames.c b/external/epid-sdk/epid/member/src/allowed_basenames.c new file mode 100644 index 00000000..e3da4e6b --- /dev/null +++ b/external/epid-sdk/epid/member/src/allowed_basenames.c @@ -0,0 +1,117 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename management implementation +/*! \file */ + +#include "epid/member/src/allowed_basenames.h" + +#include + +#include "epid/common/src/memory.h" + +typedef struct AllowedBasename { + struct AllowedBasename* next; ///< pointer to the next base name + size_t length; ///< size of base name + uint8_t name[1]; ///< base name (flexible array) +} AllowedBasename; + +typedef struct AllowedBasenames { AllowedBasename* data; } AllowedBasenames; + +/// Creates empty list of allowed basenames +EpidStatus CreateBasenames(AllowedBasenames** basename_container) { + AllowedBasenames* new_container = NULL; + if (!basename_container) { + return kEpidBadArgErr; + } + new_container = SAFE_ALLOC(sizeof(AllowedBasenames)); + if (!new_container) { + return kEpidMemAllocErr; + } + new_container->data = NULL; + *basename_container = new_container; + + return kEpidNoErr; +} + +/// Checks if given basename is in the allowed list +bool IsBasenameAllowed(AllowedBasenames const* basenames, void const* basename, + size_t length) { + if (!basenames || !length) { + return false; + } else { + AllowedBasename* rootnode = basenames->data; + while (rootnode != NULL) { + if (rootnode->length == length) { + if (!memcmp(rootnode->name, basename, length)) { + return true; + } + } + rootnode = rootnode->next; + } + } + return false; +} + +/// Adds a new allowed basename +EpidStatus AllowBasename(AllowedBasenames* basenames, void const* basename, + size_t length) { + AllowedBasename* newnode = NULL; + + if (length > (SIZE_MAX - sizeof(AllowedBasename)) + 1) { + return kEpidBadArgErr; + } + if (!basenames || !basename) { + return kEpidBadArgErr; + } + + newnode = SAFE_ALLOC(sizeof(AllowedBasename) + (length - 1)); + if (!newnode) { + return kEpidMemAllocErr; + } + + newnode->next = NULL; + newnode->length = length; + // Memory copy is used to copy a flexible array + if (0 != memcpy_S(newnode->name, length, basename, length)) { + SAFE_FREE(newnode); + return kEpidBadArgErr; + } + + if (!basenames->data) { + basenames->data = newnode; + } else { + AllowedBasename* currentnode = basenames->data; + while (NULL != currentnode->next) { + currentnode = currentnode->next; + } + currentnode->next = newnode; + } + return kEpidNoErr; +} + +/// Deletes list of allowed basenames +void DeleteBasenames(AllowedBasenames** basename_container) { + if (basename_container && *basename_container) { + AllowedBasename* rootnode = (*basename_container)->data; + while (rootnode) { + AllowedBasename* deletenode = rootnode; + rootnode = rootnode->next; + SAFE_FREE(deletenode); + } + (*basename_container)->data = NULL; + SAFE_FREE(*basename_container); + } +} diff --git a/external/epid-sdk/epid/member/src/allowed_basenames.h b/external/epid-sdk/epid/member/src/allowed_basenames.h new file mode 100644 index 00000000..8600effd --- /dev/null +++ b/external/epid-sdk/epid/member/src/allowed_basenames.h @@ -0,0 +1,45 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename management APIs +/*! \file */ + +#ifndef EPID_MEMBER_SRC_ALLOWED_BASENAMES_H_ +#define EPID_MEMBER_SRC_ALLOWED_BASENAMES_H_ + +#include +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" + +/// \cond +typedef struct AllowedBasenames AllowedBasenames; +typedef struct AllowedBasename AllowedBasename; +/// \endcond + +/// Creates empty list of allowed basenames +EpidStatus CreateBasenames(AllowedBasenames** basename_container); + +/// Checks if given basename is in the allowed list +bool IsBasenameAllowed(AllowedBasenames const* basenames, void const* basename, + size_t length); + +/// Adds a new allowed basename +EpidStatus AllowBasename(AllowedBasenames* basenames, void const* basename, + size_t length); + +/// Deletes list of allowed basenames +void DeleteBasenames(AllowedBasenames** basename_container); + +#endif // EPID_MEMBER_SRC_ALLOWED_BASENAMES_H_ diff --git a/external/epid-sdk/epid/member/src/context.c b/external/epid-sdk/epid/member/src/context.c new file mode 100644 index 00000000..73d181c3 --- /dev/null +++ b/external/epid-sdk/epid/member/src/context.c @@ -0,0 +1,289 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member context implementation. + */ + +#include + +#include +#include "epid/common/src/endian_convert.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/common/src/sigrlvalid.h" +#include "epid/common/src/stack.h" +#include "epid/common/types.h" +#include "epid/member/software_member.h" +#include "epid/member/src/allowed_basenames.h" +#include "epid/member/src/context.h" +#include "epid/member/src/precomp.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/createprimary.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/sign.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus EpidMemberGetSize(MemberParams const* params, size_t* context_size) { + if (!params || !context_size) { + return kEpidBadArgErr; + } + *context_size = sizeof(MemberCtx); + return kEpidNoErr; +} + +EpidStatus EpidMemberInit(MemberParams const* params, MemberCtx* ctx) { + EpidStatus sts = kEpidErr; + + if (!params || !ctx) { + return kEpidBadArgErr; + } + memset(ctx, 0, sizeof(*ctx)); + do { + const FpElemStr* f = NULL; + + // set the default hash algorithm to sha512 + ctx->hash_alg = kSha512; +#ifdef TPM_TSS // if build for TSS, make Sha256 default + ctx->hash_alg = kSha256; +#endif + ctx->sig_rl = NULL; + ctx->precomp_ready = false; + ctx->is_initially_provisioned = false; + ctx->is_provisioned = false; + ctx->primary_key_set = false; + + sts = CreateBasenames(&ctx->allowed_basenames); + BREAK_ON_EPID_ERROR(sts); + // Internal representation of Epid2Params + sts = CreateEpid2Params(&ctx->epid2_params); + BREAK_ON_EPID_ERROR(sts); + + // create TPM2 context + sts = Tpm2CreateContext(params, ctx->epid2_params, &ctx->rnd_func, + &ctx->rnd_param, &f, &ctx->tpm2_ctx); + BREAK_ON_EPID_ERROR(sts); + + if (!CreateStack(sizeof(PreComputedSignature), &ctx->presigs)) { + sts = kEpidMemAllocErr; + BREAK_ON_EPID_ERROR(sts); + } + + ctx->f = f; + ctx->join_ctr = 0; + ctx->rf_ctr = 0; + ctx->rnu_ctr = 0; + + sts = NewEcPoint(ctx->epid2_params->G1, (EcPoint**)&ctx->A); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(ctx->epid2_params->Fp, (FfElement**)&ctx->x); + BREAK_ON_EPID_ERROR(sts); + + sts = NewEcPoint(ctx->epid2_params->G1, (EcPoint**)&ctx->h1); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(ctx->epid2_params->G1, (EcPoint**)&ctx->h2); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(ctx->epid2_params->G2, (EcPoint**)&ctx->w); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(ctx->epid2_params->GT, (FfElement**)&ctx->e12); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(ctx->epid2_params->GT, (FfElement**)&ctx->e22); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(ctx->epid2_params->GT, (FfElement**)&ctx->e2w); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(ctx->epid2_params->GT, (FfElement**)&ctx->ea2); + BREAK_ON_EPID_ERROR(sts); + + sts = Tpm2SetHashAlg(ctx->tpm2_ctx, ctx->hash_alg); + BREAK_ON_EPID_ERROR(sts); + ctx->primary_key_set = true; + sts = kEpidNoErr; + } while (0); + if (kEpidNoErr != sts) { + EpidMemberDeinit(ctx); + } + + return (sts); +} + +void EpidMemberDeinit(MemberCtx* ctx) { + size_t i = 0; + size_t presig_size = 0; + PreComputedSignature* buf = NULL; + if (!ctx) { + return; + } + presig_size = StackGetSize(ctx->presigs); + buf = StackGetBuf(ctx->presigs); + for (i = 0; i < presig_size; ++i) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, (buf++)->rf_ctr); + } + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, ctx->join_ctr); + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, ctx->rf_ctr); + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, ctx->rnu_ctr); + DeleteStack(&ctx->presigs); + ctx->rnd_param = NULL; + DeleteEcPoint((EcPoint**)&(ctx->h1)); + DeleteEcPoint((EcPoint**)&(ctx->h2)); + DeleteEcPoint((EcPoint**)&(ctx->A)); + DeleteFfElement((FfElement**)&ctx->x); + DeleteEcPoint((EcPoint**)&(ctx->w)); + DeleteFfElement((FfElement**)&ctx->e12); + DeleteFfElement((FfElement**)&ctx->e22); + DeleteFfElement((FfElement**)&ctx->e2w); + DeleteFfElement((FfElement**)&ctx->ea2); + Tpm2DeleteContext(&ctx->tpm2_ctx); + DeleteEpid2Params(&ctx->epid2_params); + DeleteBasenames(&ctx->allowed_basenames); +} + +EpidStatus EpidMemberCreate(MemberParams const* params, MemberCtx** ctx) { + size_t context_size = 0; + EpidStatus sts = kEpidErr; + MemberCtx* member_ctx = NULL; + if (!params || !ctx) { + return kEpidBadArgErr; + } + do { + sts = EpidMemberGetSize(params, &context_size); + BREAK_ON_EPID_ERROR(sts); + member_ctx = SAFE_ALLOC(context_size); + if (!member_ctx) { + BREAK_ON_EPID_ERROR(kEpidMemAllocErr); + } + sts = EpidMemberInit(params, member_ctx); + BREAK_ON_EPID_ERROR(sts); + } while (0); + if (kEpidNoErr != sts) { + SAFE_FREE(member_ctx); + member_ctx = NULL; + } + *ctx = member_ctx; + return sts; +} + +EpidStatus EpidMemberInitialProvision(MemberCtx* ctx) { + EpidStatus sts = kEpidErr; + + if (!ctx) { + return kEpidBadArgErr; + } + if (ctx->is_initially_provisioned) { + return kEpidOutOfSequenceError; + } + do { + if (ctx->f) { + sts = Tpm2LoadExternal(ctx->tpm2_ctx, ctx->f); + BREAK_ON_EPID_ERROR(sts); + } else { + G1ElemStr f; + sts = Tpm2CreatePrimary(ctx->tpm2_ctx, &f); + BREAK_ON_EPID_ERROR(sts); + } + + ctx->is_initially_provisioned = true; + // f value was set into TPM + ctx->primary_key_set = true; + sts = kEpidNoErr; + } while (0); + + return (sts); +} + +void EpidMemberDelete(MemberCtx** ctx) { + if (!ctx) { + return; + } + EpidMemberDeinit(*ctx); + SAFE_FREE(*ctx); + *ctx = NULL; +} + +EpidStatus EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg) { + EpidStatus sts = kEpidErr; + if (!ctx) return kEpidBadArgErr; + if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg && + kSha512_256 != hash_alg) + return kEpidBadArgErr; + do { + sts = Tpm2SetHashAlg(ctx->tpm2_ctx, hash_alg); + BREAK_ON_EPID_ERROR(sts); + ctx->hash_alg = hash_alg; + } while (0); + return sts; +} + +EpidStatus EpidMemberSetSigRl(MemberCtx* ctx, SigRl const* sig_rl, + size_t sig_rl_size) { + if (!ctx || !sig_rl) { + return kEpidBadArgErr; + } + if (!ctx->is_provisioned) { + return kEpidOutOfSequenceError; + } + if (!IsSigRlValid(&ctx->pub_key.gid, sig_rl, sig_rl_size)) { + return kEpidBadArgErr; + } + // Do not set an older version of sig rl + if (ctx->sig_rl) { + unsigned int current_ver = 0; + unsigned int incoming_ver = 0; + current_ver = ntohl(ctx->sig_rl->version); + incoming_ver = ntohl(sig_rl->version); + if (current_ver >= incoming_ver) { + return kEpidBadArgErr; + } + } + ctx->sig_rl = sig_rl; + + return kEpidNoErr; +} + +EpidStatus EpidRegisterBasename(MemberCtx* ctx, void const* basename, + size_t basename_len) { + EpidStatus sts = kEpidErr; + if (basename_len == 0) { + return kEpidBadArgErr; + } + if (!ctx || !basename) { + return kEpidBadArgErr; + } + + if (IsBasenameAllowed(ctx->allowed_basenames, basename, basename_len)) { + return kEpidDuplicateErr; + } + + sts = AllowBasename(ctx->allowed_basenames, basename, basename_len); + + return sts; +} + +EpidStatus EpidClearRegisteredBasenames(MemberCtx* ctx) { + EpidStatus sts = kEpidErr; + if (!ctx) { + return kEpidBadArgErr; + } + DeleteBasenames(&ctx->allowed_basenames); + sts = CreateBasenames(&ctx->allowed_basenames); + return sts; +} diff --git a/external/epid-sdk/epid/member/src/context.h b/external/epid-sdk/epid/member/src/context.h new file mode 100644 index 00000000..6e667ae2 --- /dev/null +++ b/external/epid-sdk/epid/member/src/context.h @@ -0,0 +1,99 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +#ifndef EPID_MEMBER_SRC_CONTEXT_H_ +#define EPID_MEMBER_SRC_CONTEXT_H_ +/*! + * \file + * \brief Member context interface. + */ + +#include + +#include +#include "epid/common/bitsupplier.h" +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct Epid2Params_ Epid2Params_; +typedef struct AllowedBasenames AllowedBasenames; +typedef struct Stack Stack; +typedef struct EcPoint EcPoint; +typedef struct FfElement FfElement; +/// \endcond + +/// Member context definition +struct MemberCtx { + Epid2Params_* epid2_params; ///< Intel(R) EPID 2.0 params + Tpm2Ctx* tpm2_ctx; ///< TPM2 context + GroupPubKey pub_key; ///< group public key + MemberPrecomp precomp; ///< Member pre-computed data + BitSupplier rnd_func; ///< Pseudo random number generation function + void* rnd_param; ///< Pointer to user context for rnd_func + SigRl const* sig_rl; ///< Signature based revocation list - not owned + AllowedBasenames* allowed_basenames; ///< Base name list + HashAlg hash_alg; ///< Hash algorithm to use + MembershipCredential credential; ///< Membership credential + bool primary_key_set; ///< primary key is set + bool precomp_ready; ///< provisioned precomputed value is ready for use + bool is_initially_provisioned; ///< f initialized + bool is_provisioned; ///< member fully provisioned with key material + EcPoint const* h1; ///< Group public key h1 value + EcPoint const* h2; ///< Group group public key h2 value + EcPoint const* A; ///< Membership Credential A value + FfElement const* x; ///< Membership Credential x value + EcPoint const* w; ///< Group group public key w value + FfElement const* e12; ///< an element in GT, = pairing (h1, g2) + FfElement const* e22; ///< an element in GT, = pairing (h2, g2) + FfElement const* e2w; ///< an element in GT, = pairing (h2, w) + FfElement const* ea2; ///< an element in GT, = pairing (g1, g2) + uint16_t join_ctr; ///< counter for join commands + uint16_t rf_ctr; ///< a TPM commit counter for rf + uint16_t rnu_ctr; ///< TPM counter pointing to Nr Proof related random value + FpElemStr const* f; ///< If NULL an EPS based f is used otherwise f is + /// stored in TPM using load external + Stack* presigs; ///< Pre-computed signature pool +}; + +/// Pre-computed signature. +/*! + Serialized form of an intermediate signature that does not depend on + basename or message. This can be used to time-shift compute time needed to + sign a message. + */ +#pragma pack(1) +typedef struct PreComputedSignature { + G1ElemStr B; ///< an element in G1 + G1ElemStr K; ///< an element in G1 + G1ElemStr T; ///< an element in G1 + G1ElemStr R1; ///< an element in G1 + GtElemStr R2; ///< an element in G1 + FpElemStr a; ///< an integer between [0, p-1] + FpElemStr b; ///< an integer between [0, p-1] + FpElemStr rx; ///< an integer between [0, p-1] + uint16_t rf_ctr; ///< a TPM commit counter for rf + FpElemStr ra; ///< an integer between [0, p-1] + FpElemStr rb; ///< an integer between [0, p-1] + BigNumStr rnd_bsn; ///< random basename +} PreComputedSignature; +#pragma pack() + +/// Minimally provision member with f +EpidStatus EpidMemberInitialProvision(MemberCtx* ctx); + +#endif // EPID_MEMBER_SRC_CONTEXT_H_ diff --git a/external/epid-sdk-3.0.0/epid/member/src/decompress_privkey.c b/external/epid-sdk/epid/member/src/decompress_privkey.c similarity index 88% rename from external/epid-sdk-3.0.0/epid/member/src/decompress_privkey.c rename to external/epid-sdk/epid/member/src/decompress_privkey.c index acba7739..db40214d 100644 --- a/external/epid-sdk-3.0.0/epid/member/src/decompress_privkey.c +++ b/external/epid-sdk/epid/member/src/decompress_privkey.c @@ -1,31 +1,33 @@ /*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ +# Copyright 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ /*! - * \file - * \brief EpidDecompressPrivKey implementation. - */ +* \file +* \brief EpidDecompressPrivKey implementation. +*/ #include "epid/member/api.h" -#include "epid/common/src/memory.h" -#include "epid/common/src/epid2params.h" -#include "epid/common/math/src/bignum-internal.h" +#include "epid/common/errors.h" +#include "epid/common/math/ecgroup.h" #include "epid/common/math/hash.h" -#include "epid/member/src/privkey.h" +#include "epid/common/math/src/bignum-internal.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" /// Handle Intel(R) EPID Error with Break #define BREAK_ON_EPID_ERROR(ret) \ @@ -33,6 +35,17 @@ break; \ } +/*! +* \brief +* Internal implementation of PrivKey +*/ +typedef struct PrivKey_ { + GroupId gid; ///< group ID + EcPoint* A; ///< an element in G1 + FfElement* x; ///< an integer between [0, p-1] + FfElement* f; ///< an integer between [0, p-1] +} PrivKey_; + /// Implements the derivation method used by private key decompression /// Derives two integers x, f between [1, p-1] from the seed value static EpidStatus DeriveXF(FpElemStr* x, FpElemStr* f, Seed const* seed, @@ -145,7 +158,7 @@ EpidStatus EpidDecompressPrivKey(GroupPubKey const* pub_key, result = EcMul(G2, t1, w, t1); BREAK_ON_EPID_ERROR(result); // c. It computes t3 = pairing(A, t1). - result = Pairing(ps_ctx, t3, priv_key_.A, t1); + result = Pairing(ps_ctx, priv_key_.A, t1, t3); BREAK_ON_EPID_ERROR(result); // d. It computes t2 = G1.sscmExp(h1, f). result = EcSscmExp(G1, h1, (BigNumStr const*)&priv_key->f, t2); @@ -154,7 +167,7 @@ EpidStatus EpidDecompressPrivKey(GroupPubKey const* pub_key, result = EcMul(G1, t2, g1, t2); BREAK_ON_EPID_ERROR(result); // f. It computes t4 = pairing(t2, g2). - result = Pairing(ps_ctx, t4, t2, g2); + result = Pairing(ps_ctx, t2, g2, t4); BREAK_ON_EPID_ERROR(result); // g. If GT.isEqual(t3, t4) = false result = FfIsEqual(GT, t3, t4, &is_valid); diff --git a/external/epid-sdk-3.0.0/epid/member/src/get_sigsize.c b/external/epid-sdk/epid/member/src/get_sigsize.c similarity index 96% rename from external/epid-sdk-3.0.0/epid/member/src/get_sigsize.c rename to external/epid-sdk/epid/member/src/get_sigsize.c index 08c8964e..10fafcd8 100644 --- a/external/epid-sdk-3.0.0/epid/member/src/get_sigsize.c +++ b/external/epid-sdk/epid/member/src/get_sigsize.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ * \file * \brief EpidGetSigSize implementation. */ -#include "epid/member/api.h" #include "epid/common/src/endian_convert.h" +#include "epid/member/api.h" size_t EpidGetSigSize(SigRl const* sig_rl) { const size_t kMinSigSize = sizeof(EpidSignature) - sizeof(NrProof); diff --git a/external/epid-sdk/epid/member/src/hash_basename.c b/external/epid-sdk/epid/member/src/hash_basename.c new file mode 100644 index 00000000..1329960d --- /dev/null +++ b/external/epid-sdk/epid/member/src/hash_basename.c @@ -0,0 +1,54 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename hashing helper implementation +/*! \file */ + +#include "epid/member/src/hash_basename.h" + +#include "epid/common/math/ecgroup.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus HashBaseName(EcGroup* G1, HashAlg hash_alg, void const* basename, + size_t basename_len, G1ElemStr* B_str, + uint32_t* iterations) { + EpidStatus sts = kEpidErr; + EcPoint* B = NULL; + + if (!G1 || (0 != basename_len && !basename) || !B_str) { + return kEpidBadArgErr; + } + + do { + sts = NewEcPoint(G1, &B); + BREAK_ON_EPID_ERROR(sts); + + sts = EcHash(G1, basename, basename_len, hash_alg, B, iterations); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, B, B_str, sizeof(*B_str)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + DeleteEcPoint(&B); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/hash_basename.h b/external/epid-sdk/epid/member/src/hash_basename.h new file mode 100644 index 00000000..4d196c2d --- /dev/null +++ b/external/epid-sdk/epid/member/src/hash_basename.h @@ -0,0 +1,59 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename hashing helper API +/*! \file */ +#ifndef EPID_MEMBER_SRC_HASH_BASENAME_H_ +#define EPID_MEMBER_SRC_HASH_BASENAME_H_ + +#include +#include +#include "epid/common/errors.h" +#include "epid/common/types.h" // HashAlg + +/// \cond +typedef struct EcGroup EcGroup; +typedef struct G1ElemStr G1ElemStr; +/// \endcond + +/// Calculates hash of basename +/*! + + \param[in] G1 + The elliptic curve group. + + \param[in] hash_alg + The hash algorithm. + + \param[in] basename + The basename. + + \param[in] basename_len + The size of the basename in bytes. + + \param[out] B_str + The resulting hashed basename. + + \param[out] iterations + The number of hash iterations needed to find a valid hash. Can be NULL. + + \returns ::EpidStatus + +*/ +EpidStatus HashBaseName(EcGroup* G1, HashAlg hash_alg, void const* basename, + size_t basename_len, G1ElemStr* B_str, + uint32_t* iterations); + +#endif // EPID_MEMBER_SRC_HASH_BASENAME_H_ diff --git a/external/epid-sdk/epid/member/src/join.c b/external/epid-sdk/epid/member/src/join.c new file mode 100644 index 00000000..bda9e8d7 --- /dev/null +++ b/external/epid-sdk/epid/member/src/join.c @@ -0,0 +1,152 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Join Request related implementation. +/*! \file */ + +#include + +#include "epid/common/src/epid2params.h" +#include "epid/common/src/grouppubkey.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/src/context.h" +#include "epid/member/src/join_commitment.h" +#include "epid/member/src/privateexp.h" +#include "epid/member/src/resize.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/sign.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus EpidCreateJoinRequest(MemberCtx* ctx, GroupPubKey const* pub_key, + IssuerNonce const* ni, + JoinRequest* join_request) { + EpidStatus sts = kEpidErr; + GroupPubKey_* pub_key_ = NULL; + EcPoint* t = NULL; // temporary used for F and R + EcPoint* h1 = NULL; + EcPoint* K = NULL; + EcPoint* l = NULL; + EcPoint* e = NULL; + + FfElement* k = NULL; + FfElement* s = NULL; + uint8_t* digest = NULL; + + if (!ctx || !pub_key || !ni || !join_request || !ctx->epid2_params) { + return kEpidBadArgErr; + } + + if (kSha256 != ctx->hash_alg && kSha384 != ctx->hash_alg && + kSha512 != ctx->hash_alg && kSha512_256 != ctx->hash_alg) { + return kEpidBadArgErr; + } + + do { + JoinRequest request = {0}; + G1ElemStr R = {0}; + EcGroup* G1 = ctx->epid2_params->G1; + FiniteField* Fp = ctx->epid2_params->Fp; + size_t digest_size = 0; + + if (!ctx->is_provisioned && !ctx->is_initially_provisioned) { + sts = EpidMemberInitialProvision(ctx); + BREAK_ON_EPID_ERROR(sts); + } + + // validate public key by creating + sts = CreateGroupPubKey(pub_key, ctx->epid2_params->G1, + ctx->epid2_params->G2, &pub_key_); + BREAK_ON_EPID_ERROR(sts); + + sts = NewEcPoint(G1, &t); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &h1); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &pub_key->h1, sizeof(pub_key->h1), h1); + BREAK_ON_EPID_ERROR(sts); + + // 2. The member computes F = G1.sscmExp(h1, f). + sts = EpidPrivateExp(ctx, h1, t); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, t, &request.F, sizeof(request.F)); + BREAK_ON_EPID_ERROR(sts); + + // 1. The member chooses a random integer r from [1, p-1]. + // 3. The member computes R = G1.sscmExp(h1, r). + sts = NewEcPoint(G1, &K); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &l); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &e); + BREAK_ON_EPID_ERROR(sts); + sts = + Tpm2Commit(ctx->tpm2_ctx, h1, NULL, 0, NULL, K, l, e, &(ctx->join_ctr)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, e, &R, sizeof(R)); + BREAK_ON_EPID_ERROR(sts); + + sts = HashJoinCommitment(ctx->epid2_params->Fp, ctx->hash_alg, pub_key, + &request.F, &R, ni, &request.c); + BREAK_ON_EPID_ERROR(sts); + + // Extend value c to be of a digest size. + digest_size = EpidGetHashSize(ctx->hash_alg); + digest = (uint8_t*)SAFE_ALLOC(digest_size); + if (!digest) { + sts = kEpidMemAllocErr; + break; + } + sts = ResizeOctStr(&request.c, sizeof(request.c), digest, digest_size); + BREAK_ON_EPID_ERROR(sts); + + // Step 5. The member computes s = (r + c * f) mod p. + sts = NewFfElement(Fp, &k); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &s); + BREAK_ON_EPID_ERROR(sts); + sts = Tpm2Sign(ctx->tpm2_ctx, digest, digest_size, ctx->join_ctr, k, s); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, s, &request.s, sizeof(request.s)); + BREAK_ON_EPID_ERROR(sts); + + // Step 6. The output join request is (F, c, s). + *join_request = request; + + sts = kEpidNoErr; + } while (0); + + if (sts != kEpidNoErr) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, ctx->join_ctr); + } + + DeleteEcPoint(&t); + DeleteEcPoint(&h1); + DeleteEcPoint(&K); + DeleteEcPoint(&l); + DeleteEcPoint(&e); + DeleteFfElement(&k); + DeleteFfElement(&s); + SAFE_FREE(digest); + DeleteGroupPubKey(&pub_key_); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/join_commitment.c b/external/epid-sdk/epid/member/src/join_commitment.c new file mode 100644 index 00000000..62e6dab6 --- /dev/null +++ b/external/epid-sdk/epid/member/src/join_commitment.c @@ -0,0 +1,89 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host join helper implementation +/*! \file */ + +#include "epid/member/src/join_commitment.h" + +#include "epid/common/math/finitefield.h" +#include "epid/common/types.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +#pragma pack(1) +/// Storage for values to create commitment in Sign and Verify algorithms +typedef struct JoinPCommitValues { + BigNumStr p; ///< Intel(R) EPID 2.0 parameter p + G1ElemStr g1; ///< Intel(R) EPID 2.0 parameter g1 + G2ElemStr g2; ///< Intel(R) EPID 2.0 parameter g2 + G1ElemStr h1; ///< Group public key value h1 + G1ElemStr h2; ///< Group public key value h2 + G2ElemStr w; ///< Group public key value w + G1ElemStr F; ///< Variable F computed in algorithm + G1ElemStr R; ///< Variable R computed in algorithm + IssuerNonce NI; ///< Nonce +} JoinPCommitValues; +#pragma pack() + +EpidStatus HashJoinCommitment(FiniteField* Fp, HashAlg hash_alg, + GroupPubKey const* pub_key, + G1ElemStr const* F_str, G1ElemStr const* R_str, + IssuerNonce const* NI, FpElemStr* c_str) { + EpidStatus sts = kEpidErr; + FfElement* c = NULL; + + if (!Fp || !pub_key || !F_str || !R_str || !NI || !c_str) { + return kEpidBadArgErr; + } + + do { + JoinPCommitValues commit_values = {0}; + Epid2Params params = { +#include "epid/common/src/epid2params_ate.inc" + }; + + commit_values.p = params.p; + commit_values.g1 = params.g1; + commit_values.g2 = params.g2; + commit_values.h1 = pub_key->h1; + commit_values.h2 = pub_key->h2; + commit_values.w = pub_key->w; + commit_values.F = *F_str; + commit_values.R = *R_str; + commit_values.NI = *NI; + + sts = NewFfElement(Fp, &c); + BREAK_ON_EPID_ERROR(sts); + + // Step 4. The member computes c = Fp.hash(p || g1 || g2 || h1 || + // h2 || w || F || R || NI). + sts = FfHash(Fp, &commit_values, sizeof(commit_values), hash_alg, c); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + DeleteFfElement(&c); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/join_commitment.h b/external/epid-sdk/epid/member/src/join_commitment.h new file mode 100644 index 00000000..e42873dd --- /dev/null +++ b/external/epid-sdk/epid/member/src/join_commitment.h @@ -0,0 +1,64 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host join helper APIs +/*! \file */ +#ifndef EPID_MEMBER_SRC_JOIN_COMMITMENT_H_ +#define EPID_MEMBER_SRC_JOIN_COMMITMENT_H_ + +#include "epid/common/errors.h" +#include "epid/common/types.h" // HashAlg + +/// \cond +typedef struct FiniteField FiniteField; +typedef struct G1ElemStr G1ElemStr; +typedef struct FpElemStr FpElemStr; +typedef struct OctStr256 OctStr256; +typedef struct OctStr256 IssuerNonce; +/// \endcond + +/// Calculates commitment hash of join commit +/*! + + \param[in] Fp + The finite field. + + \param[in] hash_alg + The hash algorithm. + + \param[in] pub_key + The public key of the group being joined. + + \param[in] F_str + The F value of the join commit. + + \param[in] R_str + The R value of the join commit. + + \param[in] NI + The nonce chosen by issuer as part of join protocol. + + \param[out] c_str + The resulting commitment hash. + + \returns ::EpidStatus + + */ +EpidStatus HashJoinCommitment(FiniteField* Fp, HashAlg hash_alg, + GroupPubKey const* pub_key, + G1ElemStr const* F_str, G1ElemStr const* R_str, + IssuerNonce const* NI, FpElemStr* c_str); + +#endif // EPID_MEMBER_SRC_JOIN_COMMITMENT_H_ diff --git a/external/epid-sdk/epid/member/src/nrprove.c b/external/epid-sdk/epid/member/src/nrprove.c new file mode 100644 index 00000000..c7780bc2 --- /dev/null +++ b/external/epid-sdk/epid/member/src/nrprove.c @@ -0,0 +1,293 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidNrProve implementation. +/*! \file */ +#include "epid/member/src/nrprove.h" + +#include +#include + +#include "epid/common/src/endian_convert.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" +#include "epid/member/src/context.h" +#include "epid/member/src/nrprove_commitment.h" +#include "epid/member/src/privateexp.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/sign.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +static bool IsIdentity(G1ElemStr const* elem_str) { + unsigned char* bytes = (unsigned char*)elem_str; + if (!bytes) { + return false; + } else { + size_t i = 0; + for (i = 0; i < sizeof(*elem_str); i++) { + if (0 != bytes[i]) return false; + } + } + return true; +} + +EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + BasicSignature const* sig, SigRlEntry const* sigrl_entry, + NrProof* proof) { + EpidStatus sts = kEpidErr; + + EcPoint* B = NULL; + EcPoint* K = NULL; + EcPoint* rlB = NULL; + EcPoint* rlK = NULL; + EcPoint* t = NULL; // temp value in G1 either T, R1, R2 + EcPoint* k_tpm = NULL; + EcPoint* l_tpm = NULL; + EcPoint* e_tpm = NULL; + EcPoint* D = NULL; + FfElement* y2 = NULL; + uint8_t* s2 = NULL; + FfElement* mu = NULL; + FfElement* nu = NULL; + FfElement* rmu = NULL; + + FfElement* t2 = NULL; // temporary for multiplication + FfElement* c = NULL; + uint8_t* digest = NULL; + + BigNumStr mu_str = {0}; + BigNumStr nu_str = {0}; + BigNumStr rmu_str = {0}; + + if (!ctx || (0 != msg_len && !msg) || !sig || !sigrl_entry || !proof) + return kEpidBadArgErr; + if (!basename || 0 == basename_len) { + // basename should not be empty + return kEpidBadArgErr; + } + if (!ctx->epid2_params) return kEpidBadArgErr; + + do { + NrProveCommitOutput commit_out = {0}; + FiniteField* Fp = ctx->epid2_params->Fp; + FiniteField* Fq = ctx->epid2_params->Fq; + EcGroup* G1 = ctx->epid2_params->G1; + BitSupplier rnd_func = ctx->rnd_func; + void* rnd_param = ctx->rnd_param; + uint32_t i = 0; + G1ElemStr B_str = {0}; + const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + FpElemStr c_str = {0}; + uint16_t rnu_ctr = + 0; ///< TPM counter pointing to Nr Proof related random value + size_t digest_len = EpidGetHashSize(ctx->hash_alg); + + sts = NewEcPoint(G1, &B); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &K); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &rlB); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &rlK); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &D); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &t); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(Fp, &y2); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &k_tpm); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &l_tpm); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &e_tpm); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(Fp, &mu); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &nu); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &rmu); + BREAK_ON_EPID_ERROR(sts); + + s2 = SAFE_ALLOC(basename_len + sizeof(i)); + if (!s2) { + sts = kEpidMemAllocErr; + break; + } + sts = ReadEcPoint(G1, &sig->K, sizeof(sig->K), K); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadEcPoint(G1, &(sigrl_entry->b), sizeof(sigrl_entry->b), rlB); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &(sigrl_entry->k), sizeof(sigrl_entry->k), rlK); + BREAK_ON_EPID_ERROR(sts); + + // 1. The member chooses random mu from [1, p-1]. + sts = FfGetRandom(Fp, &kOne, rnd_func, rnd_param, mu); + BREAK_ON_EPID_ERROR(sts); + // 2. The member computes nu = -mu mod p. + sts = FfNeg(Fp, mu, nu); + BREAK_ON_EPID_ERROR(sts); + + // 3.1. The member computes D = G1.privateExp(B', f) + sts = EpidPrivateExp((MemberCtx*)ctx, rlB, D); + BREAK_ON_EPID_ERROR(sts); + // 3.2.The member computes T = G1.sscmMultiExp(K', mu, D, nu). + sts = WriteFfElement(Fp, mu, &mu_str, sizeof(mu_str)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, nu, &nu_str, sizeof(nu_str)); + BREAK_ON_EPID_ERROR(sts); + { + EcPoint const* points[2]; + BigNumStr const* exponents[2]; + points[0] = rlK; + points[1] = D; + exponents[0] = &mu_str; + exponents[1] = &nu_str; + sts = EcSscmMultiExp(G1, points, exponents, COUNT_OF(points), t); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, t, &commit_out.T, sizeof(commit_out.T)); + BREAK_ON_EPID_ERROR(sts); + } + // 4.1. The member chooses rmu randomly from[1, p - 1]. + sts = FfGetRandom(Fp, &kOne, rnd_func, rnd_param, rmu); + BREAK_ON_EPID_ERROR(sts); + // 4.2. (KTPM, LTPM, ETPM, counterTPM) = TPM2_Commit(P1 = B', P2 = B) + sts = EcHash(G1, basename, basename_len, ctx->hash_alg, B, &i); + BREAK_ON_EPID_ERROR(sts); + *(uint32_t*)s2 = ntohl(i); + sts = WriteEcPoint(G1, B, &B_str, sizeof(B_str)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fq, &B_str.y, sizeof(B_str.y), y2); + BREAK_ON_EPID_ERROR(sts); + if (0 != memcpy_S(s2 + sizeof(i), basename_len, basename, basename_len)) { + sts = kEpidErr; + break; + } + sts = Tpm2Commit(ctx->tpm2_ctx, rlB, s2, basename_len + sizeof(i), y2, + k_tpm, l_tpm, e_tpm, &rnu_ctr); + BREAK_ON_EPID_ERROR(sts); + + // 5.1. The member computes R1 = G1.sscmExp(K, rmu). + sts = WriteFfElement(Fp, rmu, &rmu_str, sizeof(rmu_str)); + BREAK_ON_EPID_ERROR(sts); + sts = EcSscmExp(G1, K, &rmu_str, t); + BREAK_ON_EPID_ERROR(sts); + // 5.2. The member computes R1 = G1.mul(R1, LTPM). + sts = EcMul(G1, t, l_tpm, t); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, t, &commit_out.R1, sizeof(commit_out.R1)); + BREAK_ON_EPID_ERROR(sts); + + // 6.1. The member computes R2 = G1.sscmExp(K', rmu). + sts = EcSscmExp(G1, rlK, &rmu_str, t); + BREAK_ON_EPID_ERROR(sts); + // 6.2. The member computes R2 = G1.mul(R2, ETPM). + sts = EcMul(G1, t, e_tpm, t); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, t, &commit_out.R2, sizeof(commit_out.R2)); + BREAK_ON_EPID_ERROR(sts); + + sts = HashNrProveCommitment(Fp, ctx->hash_alg, &sig->B, &sig->K, + sigrl_entry, &commit_out, msg, msg_len, &c_str); + BREAK_ON_EPID_ERROR(sts); + + digest = SAFE_ALLOC(digest_len); + if (!digest) { + sts = kEpidMemAllocErr; + break; + } + + sts = NewFfElement(Fp, &t2); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(Fp, &c); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(Fp, &c_str, sizeof(c_str), c); + BREAK_ON_EPID_ERROR(sts); + + // 8. The member computes smu = (rmu + c * mu) mod p. + sts = FfMul(Fp, c, mu, t2); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, rmu, t2, t2); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t2, &proof->smu, sizeof(proof->smu)); + BREAK_ON_EPID_ERROR(sts); + + // 9.1. The member computes c' = (c * nu) mod p + sts = FfMul(Fp, c, nu, t2); + BREAK_ON_EPID_ERROR(sts); + // 9.2. snu = TPM2_Sign(c = c', counterTPM) + sts = WriteFfElement(Fp, t2, digest, digest_len); + BREAK_ON_EPID_ERROR(sts); + sts = Tpm2Sign(ctx->tpm2_ctx, digest, digest_len, rnu_ctr, NULL, t2); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t2, &proof->snu, sizeof(proof->snu)); + BREAK_ON_EPID_ERROR(sts); + + // 10. The member outputs sigma = (T, c, smu, snu), a non-revoked + // proof. If G1.is_identity(T) = true, the member also outputs + // "failed". + + proof->T = commit_out.T; + proof->c = c_str; + + if (IsIdentity(&proof->T)) { + sts = kEpidSigRevokedInSigRl; + BREAK_ON_EPID_ERROR(sts); + } + + sts = kEpidNoErr; + } while (0); + + SAFE_FREE(s2); + EpidZeroMemory(&mu_str, sizeof(mu_str)); + EpidZeroMemory(&nu_str, sizeof(nu_str)); + EpidZeroMemory(&rmu_str, sizeof(rmu_str)); + DeleteFfElement(&y2); + DeleteEcPoint(&B); + DeleteEcPoint(&K); + DeleteEcPoint(&rlB); + DeleteEcPoint(&rlK); + DeleteEcPoint(&D); + DeleteEcPoint(&t); + DeleteEcPoint(&e_tpm); + DeleteEcPoint(&l_tpm); + DeleteEcPoint(&k_tpm); + DeleteFfElement(&mu); + DeleteFfElement(&nu); + DeleteFfElement(&rmu); + DeleteFfElement(&t2); + DeleteFfElement(&c); + SAFE_FREE(digest); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/nrprove.h b/external/epid-sdk/epid/member/src/nrprove.h new file mode 100644 index 00000000..3a1a70ef --- /dev/null +++ b/external/epid-sdk/epid/member/src/nrprove.h @@ -0,0 +1,71 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidNrProve interface. +/*! \file */ +#ifndef EPID_MEMBER_SRC_NRPROVE_H_ +#define EPID_MEMBER_SRC_NRPROVE_H_ + +#include +#include "epid/common/errors.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct BasicSignature BasicSignature; +typedef struct SigRlEntry SigRlEntry; +typedef struct NrProof NrProof; +/// \endcond + +/// Calculates a non-revoked proof for a single signature based revocation +/// list entry. +/*! + Used in constrained environments where, due to limited memory, it may not + be possible to process through a large and potentially unbounded revocation + list. + + \param[in] ctx + The member context. + \param[in] msg + The message. + \param[in] msg_len + The length of message in bytes. + \param[in] basename + The basename used in EpidSignBasic. + \param[in] basename_len + The length of the basename. + \param[in] sig + The basic signature. + \param[in] sigrl_entry + The signature based revocation list entry. + \param[out] proof + The generated non-revoked proof. + + \returns ::EpidStatus + + \note + This function should be used in conjunction with EpidSignBasic(). + + \note + If the result is not ::kEpidNoErr, the content of proof is undefined. + + \see EpidMemberInit + \see EpidSignBasic + */ +EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + BasicSignature const* sig, SigRlEntry const* sigrl_entry, + NrProof* proof); + +#endif // EPID_MEMBER_SRC_NRPROVE_H_ diff --git a/external/epid-sdk/epid/member/src/nrprove_commitment.c b/external/epid-sdk/epid/member/src/nrprove_commitment.c new file mode 100644 index 00000000..41618b89 --- /dev/null +++ b/external/epid-sdk/epid/member/src/nrprove_commitment.c @@ -0,0 +1,113 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host non-revoked proof helper implementation +/*! \file */ + +#include "epid/member/src/nrprove_commitment.h" + +#include +#include "epid/common/math/finitefield.h" +#include "epid/common/src/memory.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +#pragma pack(1) +/// Storage for values to create commitment in NrProve algorithm +typedef struct NrProveCommitValues { + BigNumStr p; //!< A large prime (256-bit) + G1ElemStr g1; //!< Generator of G1 (512-bit) + G1ElemStr B; //!< (element of G1): part of basic signature Sigma0 + G1ElemStr K; //!< (element of G1): part of basic signature Sigma0 + G1ElemStr rlB; //!< (element of G1): one entry in SigRL + G1ElemStr rlK; //!< (element of G1): one entry in SigRL + NrProveCommitOutput commit_out; //!< output of NrProveCommit + uint8_t msg[1]; //!< message +} NrProveCommitValues; +#pragma pack() + +EpidStatus HashNrProveCommitment(FiniteField* Fp, HashAlg hash_alg, + G1ElemStr const* B_str, G1ElemStr const* K_str, + SigRlEntry const* sigrl_entry, + NrProveCommitOutput const* commit_out, + void const* msg, size_t msg_len, + FpElemStr* c_str) { + EpidStatus sts = kEpidErr; + FfElement* c = NULL; + NrProveCommitValues* commit_values = NULL; + + if (!Fp || !B_str || !K_str || !sigrl_entry || !commit_out || + (0 != msg_len && !msg) || !c_str) { + return kEpidBadArgErr; + } + + if (msg_len > + ((SIZE_MAX - sizeof(*commit_values)) + sizeof(*commit_values->msg))) + return kEpidBadArgErr; + + do { + size_t const commit_len = + sizeof(*commit_values) - sizeof(*commit_values->msg) + msg_len; + Epid2Params params = { +#include "epid/common/src/epid2params_ate.inc" + }; + + commit_values = SAFE_ALLOC(commit_len); + if (!commit_values) { + sts = kEpidMemAllocErr; + BREAK_ON_EPID_ERROR(sts); + } + + commit_values->p = params.p; + commit_values->g1 = params.g1; + commit_values->B = *B_str; + commit_values->K = *K_str; + commit_values->rlB = sigrl_entry->b; + commit_values->rlK = sigrl_entry->k; + commit_values->commit_out = *commit_out; + + // commit_values is allocated such that there are msg_len bytes available + // starting at commit_values->msg + if (msg) { + // Memory copy is used to copy a message of variable length + if (0 != memcpy_S(&commit_values->msg[0], msg_len, msg, msg_len)) { + sts = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(sts); + } + } + + sts = NewFfElement(Fp, &c); + BREAK_ON_EPID_ERROR(sts); + + // 7. The member computes c = Fp.hash(p || g1 || B || K || B' || + // K' || T || R1 || R2 || m). + sts = FfHash(Fp, commit_values, commit_len, hash_alg, c); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + SAFE_FREE(commit_values); + DeleteFfElement(&c); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/nrprove_commitment.h b/external/epid-sdk/epid/member/src/nrprove_commitment.h new file mode 100644 index 00000000..91f0cb4a --- /dev/null +++ b/external/epid-sdk/epid/member/src/nrprove_commitment.h @@ -0,0 +1,82 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host non-revoked proof helper APIs +/*! \file */ +#ifndef EPID_MEMBER_SRC_NRPROVE_COMMITMENT_H_ +#define EPID_MEMBER_SRC_NRPROVE_COMMITMENT_H_ + +#include +#include "epid/common/errors.h" +#include "epid/common/types.h" // HashAlg, G1ElemStr + +/// \cond +typedef struct FiniteField FiniteField; +typedef struct FpElemStr FpElemStr; +typedef struct SigRlEntry SigRlEntry; +typedef struct NrProveCommitOutput NrProveCommitOutput; +/// \endcond + +#pragma pack(1) +/// Result of NrProve Commit +typedef struct NrProveCommitOutput { + G1ElemStr T; ///< T value for NrProof + G1ElemStr R1; ///< Serialized G1 element + G1ElemStr R2; ///< Serialized G1 element +} NrProveCommitOutput; +#pragma pack() + +/// Calculates commitment hash of NrProve commit +/*! + + \param[in] Fp + The finite field. + + \param[in] hash_alg + The hash algorithm. + + \param[in] B_str + The B value from the ::BasicSignature. + + \param[in] K_str + The K value from the ::BasicSignature. + + \param[in] sigrl_entry + The signature based revocation list entry corresponding to this + proof. + + \param[in] commit_out + The output from the NrProve commit. + + \param[in] msg + The message. + + \param[in] msg_len + The size of message in bytes. + + \param[out] c_str + The resulting commitment hash. + + \returns ::EpidStatus + + */ +EpidStatus HashNrProveCommitment(FiniteField* Fp, HashAlg hash_alg, + G1ElemStr const* B_str, G1ElemStr const* K_str, + SigRlEntry const* sigrl_entry, + NrProveCommitOutput const* commit_out, + void const* msg, size_t msg_len, + FpElemStr* c_str); + +#endif // EPID_MEMBER_SRC_NRPROVE_COMMITMENT_H_ diff --git a/external/epid-sdk/epid/member/src/precomp.c b/external/epid-sdk/epid/member/src/precomp.c new file mode 100644 index 00000000..c87f479a --- /dev/null +++ b/external/epid-sdk/epid/member/src/precomp.c @@ -0,0 +1,91 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Member pre-computation implementation +/*! \file */ +#include "epid/member/src/precomp.h" + +#include "epid/common/src/epid2params.h" +#include "epid/common/src/grouppubkey.h" +#include "epid/common/types.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus PrecomputeMemberPairing(Epid2Params_ const* epid2_params, + GroupPubKey const* pub_key, + G1ElemStr const* A_str, + MemberPrecomp* precomp) { + EpidStatus sts = kEpidErr; + + GroupPubKey_* pub_key_ = NULL; + EcPoint* A = NULL; + FfElement* e = NULL; + + if (!epid2_params || !pub_key || !A_str || !precomp) return kEpidBadArgErr; + + do { + EcGroup* G1 = epid2_params->G1; + EcGroup* G2 = epid2_params->G2; + FiniteField* GT = epid2_params->GT; + PairingState* ps_ctx = epid2_params->pairing_state; + EcPoint* g2 = epid2_params->g2; + + sts = CreateGroupPubKey(pub_key, G1, G2, &pub_key_); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(GT, &e); + BREAK_ON_EPID_ERROR(sts); + + // 1. The member computes e12 = pairing(h1, g2). + sts = Pairing(ps_ctx, pub_key_->h1, g2, e); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(GT, e, &precomp->e12, sizeof(precomp->e12)); + BREAK_ON_EPID_ERROR(sts); + + // 2. The member computes e22 = pairing(h2, g2). + sts = Pairing(ps_ctx, pub_key_->h2, g2, e); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(GT, e, &precomp->e22, sizeof(precomp->e22)); + BREAK_ON_EPID_ERROR(sts); + + // 3. The member computes e2w = pairing(h2, w). + sts = Pairing(ps_ctx, pub_key_->h2, pub_key_->w, e); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(GT, e, &precomp->e2w, sizeof(precomp->e2w)); + BREAK_ON_EPID_ERROR(sts); + + // 4. The member computes ea2 = pairing(A, g2). + sts = NewEcPoint(G1, &A); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, A_str, sizeof(*A_str), A); + BREAK_ON_EPID_ERROR(sts); + sts = Pairing(ps_ctx, A, g2, e); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(GT, e, &precomp->ea2, sizeof(precomp->ea2)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + DeleteGroupPubKey(&pub_key_); + DeleteEcPoint(&A); + DeleteFfElement(&e); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/precomp.h b/external/epid-sdk/epid/member/src/precomp.h new file mode 100644 index 00000000..58a8c404 --- /dev/null +++ b/external/epid-sdk/epid/member/src/precomp.h @@ -0,0 +1,59 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Member pre-computation API +/*! \file */ +#ifndef EPID_MEMBER_SRC_PRECOMP_H_ +#define EPID_MEMBER_SRC_PRECOMP_H_ + +#include "epid/common/errors.h" + +/// \cond +typedef struct Epid2Params_ Epid2Params_; +typedef struct GroupPubKey GroupPubKey; +typedef struct G1ElemStr G1ElemStr; +typedef struct MemberPrecomp MemberPrecomp; +/// \endcond + +/// Precomputes pairing values for member +/*! + + The the result of the expensive pairing operations can be + pre-computed. The pre-computation result can be saved for future + sign operations using the same group and private key. + + \param[in] epid2_params + The field and group parameters. + + \param[in] pub_key + The public key of the group. + + \param[in] A_str + The A value of the member private key. + + \param[out] precomp + The member pre-computed data. + + \returns ::EpidStatus + + \see CreateEpid2Params + + */ +EpidStatus PrecomputeMemberPairing(Epid2Params_ const* epid2_params, + GroupPubKey const* pub_key, + G1ElemStr const* A_str, + MemberPrecomp* precomp); + +#endif // EPID_MEMBER_SRC_PRECOMP_H_ diff --git a/external/epid-sdk/epid/member/src/presig-internal.h b/external/epid-sdk/epid/member/src/presig-internal.h new file mode 100644 index 00000000..86205056 --- /dev/null +++ b/external/epid-sdk/epid/member/src/presig-internal.h @@ -0,0 +1,53 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Internal pre-computed signature APIs +/*! \file */ + +#ifndef EPID_MEMBER_SRC_PRESIG_INTERNAL_H_ +#define EPID_MEMBER_SRC_PRESIG_INTERNAL_H_ + +#include "epid/common/errors.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct PreComputedSignature PreComputedSignature; +/// \endcond + +/// Provides a precomputed signature +/*! + + Provides and removes a pre-computed signatures from members's pool if + available, otherwise provides a newly calculated a precomputed + signature. + + \warning + Pre-computed signatures must not be accessed outside of the secure + boundary. + + \param[in,out] ctx + The member context. + + \param[out] presig + The pre-computed signature removed from members's pool + + \returns ::EpidStatus + + */ +EpidStatus MemberGetPreSig(MemberCtx* ctx, PreComputedSignature* presig); + +///@} +/*! @} */ +#endif // EPID_MEMBER_SRC_PRESIG_INTERNAL_H_ diff --git a/external/epid-sdk/epid/member/src/presig.c b/external/epid-sdk/epid/member/src/presig.c new file mode 100644 index 00000000..4cd4c814 --- /dev/null +++ b/external/epid-sdk/epid/member/src/presig.c @@ -0,0 +1,295 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Sensitive pre-computed signature implementation +/*! \file */ + +#include + +#include + +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/endian_convert.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/common/src/stack.h" +#include "epid/member/src/context.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/getrandom.h" +#include "epid/member/tpm2/sign.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +static EpidStatus MemberComputePreSig(MemberCtx const* ctx, + PreComputedSignature* precompsig); + +EpidStatus EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs) { + PreComputedSignature* new_presigs = NULL; + size_t i = 0; + if (!ctx || !ctx->presigs) return kEpidBadArgErr; + + if (0 == number_presigs) return kEpidNoErr; + + new_presigs = + (PreComputedSignature*)StackPushN(ctx->presigs, number_presigs, NULL); + if (!new_presigs) return kEpidMemAllocErr; + + for (i = 0; i < number_presigs; i++) { + EpidStatus sts = MemberComputePreSig(ctx, &new_presigs[i]); + if (kEpidNoErr != sts) { + // roll back pre-computed-signature pool + StackPopN(ctx->presigs, number_presigs, 0); + return sts; + } + } + + return kEpidNoErr; +} + +size_t EpidGetNumPreSigs(MemberCtx const* ctx) { + return (ctx && ctx->presigs) ? StackGetSize(ctx->presigs) : (size_t)0; +} + +EpidStatus MemberGetPreSig(MemberCtx* ctx, PreComputedSignature* presig) { + if (!ctx || !presig) { + return kEpidBadArgErr; + } + + if (StackGetSize(ctx->presigs)) { + // Use existing pre-computed signature + if (!StackPopN(ctx->presigs, 1, presig)) { + return kEpidErr; + } + return kEpidNoErr; + } + // generate a new pre-computed signature + return MemberComputePreSig(ctx, presig); +} + +/// Performs Pre-computation that can be used to speed up signing +EpidStatus MemberComputePreSig(MemberCtx const* ctx, + PreComputedSignature* precompsig) { + EpidStatus sts = kEpidErr; + + EcPoint* B = NULL; + EcPoint* k = NULL; + EcPoint* t = NULL; // temporary, used for K, T, R1 + EcPoint* e = NULL; + + FfElement* R2 = NULL; + + FfElement* a = NULL; + FfElement* rx = NULL; // reused for rf + FfElement* rb = NULL; // reused for ra + + FfElement* t1 = NULL; + FfElement* t2 = NULL; + BigNumStr t1_str = {0}; + BigNumStr t2_str = {0}; + struct { + uint32_t i; + BigNumStr bsn; + } p2x = {0}; + FfElement* p2y = NULL; + + if (!ctx || !precompsig || !ctx->epid2_params) { + return kEpidBadArgErr; + } + + do { + // handy shorthands: + Tpm2Ctx* tpm = ctx->tpm2_ctx; + EcGroup* G1 = ctx->epid2_params->G1; + FiniteField* GT = ctx->epid2_params->GT; + FiniteField* Fp = ctx->epid2_params->Fp; + FiniteField* Fq = ctx->epid2_params->Fq; + EcPoint const* h2 = ctx->h2; + EcPoint const* A = ctx->A; + FfElement const* x = ctx->x; + PairingState* ps_ctx = ctx->epid2_params->pairing_state; + + const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + // 1. The member expects the pre-computation is done (e12, e22, e2w, + // ea2). Refer to Section 3.5 for the computation of these + // values. + + sts = NewFfElement(Fq, &p2y); + // The following variables B, K, T, R1 (elements of G1), R2 + // (elements of GT), a, b, rx, rf, ra, rb, t1, t2 (256-bit + // integers) are used. + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &B); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &k); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &t); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &e); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(GT, &R2); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &a); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &rx); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &rb); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &t1); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &t2); + BREAK_ON_EPID_ERROR(sts); + + // 3. The member computes B = G1.getRandom(). + // 4.a. If bsn is not provided, the member chooses randomly an integer bsn + // from [1, p-1]. + sts = Tpm2GetRandom(tpm, sizeof(p2x.bsn) * 8, &p2x.bsn); + BREAK_ON_EPID_ERROR(sts); + precompsig->rnd_bsn = p2x.bsn; + + // 4.b. The member computes (B, i2, y2) = G1.tpmHash(bsn). + sts = EcHash(G1, (const void*)&p2x.bsn, sizeof(p2x.bsn), ctx->hash_alg, B, + &p2x.i); + BREAK_ON_EPID_ERROR(sts); + p2x.i = htonl(p2x.i); + sts = WriteEcPoint(G1, B, &precompsig->B, sizeof(precompsig->B)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fq, &precompsig->B.y, sizeof(precompsig->B.y), p2y); + BREAK_ON_EPID_ERROR(sts); + + // 4.c. (KTPM, LTPM, ETPM, counterTPM) = TPM2_Commit(P1=h1, (s2, y2) = (i1 + // || bsn, y2)), K = KTPM + sts = Tpm2Commit(tpm, ctx->h1, &p2x, sizeof(p2x), p2y, k, t, e, + &precompsig->rf_ctr); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, k, &precompsig->K, sizeof(precompsig->K)); + BREAK_ON_EPID_ERROR(sts); + // 4.k. The member computes R1 = LTPM. + sts = WriteEcPoint(G1, t, &precompsig->R1, sizeof(precompsig->R1)); + BREAK_ON_EPID_ERROR(sts); + + // 4.d. The member chooses randomly an integer a from [1, p-1]. + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, a); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, a, &precompsig->a, sizeof(precompsig->a)); + BREAK_ON_EPID_ERROR(sts); + // 4.e. The member computes T = G1.sscmExp(h2, a). + sts = EcExp(G1, h2, (BigNumStr*)&precompsig->a, t); + BREAK_ON_EPID_ERROR(sts); + // 4.k. The member computes T = G1.mul(T, A). + sts = EcMul(G1, t, A, t); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, t, &precompsig->T, sizeof(precompsig->T)); + BREAK_ON_EPID_ERROR(sts); + + // 4.h. The member chooses rx, ra, rb randomly from [1, p-1]. + + // note : rb are reused as ra + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, rx); + BREAK_ON_EPID_ERROR(sts); + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, rb); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteFfElement(Fp, rx, &precompsig->rx, sizeof(precompsig->rx)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, rb, &precompsig->rb, sizeof(precompsig->rb)); + BREAK_ON_EPID_ERROR(sts); + + // 4.i. The member computes t1 = (- rx) mod p. + sts = FfNeg(Fp, rx, t1); + BREAK_ON_EPID_ERROR(sts); + + // 4.j. The member computes t2 = (rb - a * rx) mod p. + sts = FfMul(Fp, a, rx, t2); + BREAK_ON_EPID_ERROR(sts); + sts = FfNeg(Fp, t2, t2); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, rb, t2, t2); + BREAK_ON_EPID_ERROR(sts); + + // 4.g. The member computes b = (a * x) mod p. + sts = FfMul(Fp, a, x, a); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, a, &precompsig->b, sizeof(precompsig->b)); + BREAK_ON_EPID_ERROR(sts); + + // reusing rb as ra + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, rb); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, rb, &precompsig->ra, sizeof(precompsig->ra)); + BREAK_ON_EPID_ERROR(sts); + + // 4.l.i e12rf = pairing(ETPM, g2) + sts = Pairing(ps_ctx, e, ctx->epid2_params->g2, R2); + BREAK_ON_EPID_ERROR(sts); + + // 4.l.ii. The member computes R2 = GT.sscmMultiExp(ea2, t1, e12rf, 1, + // e22, t2, e2w, ra). + sts = WriteFfElement(Fp, t1, &t1_str, sizeof(t1_str)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t2, &t2_str, sizeof(t2_str)); + BREAK_ON_EPID_ERROR(sts); + { + FfElement const* points[4]; + BigNumStr const* exponents[4]; + points[0] = ctx->ea2; + points[1] = R2; + points[2] = ctx->e22; + points[3] = ctx->e2w; + exponents[0] = &t1_str; + exponents[1] = &kOne; + exponents[2] = &t2_str; + exponents[3] = (BigNumStr*)&precompsig->ra; + sts = FfMultiExp(GT, points, exponents, COUNT_OF(points), R2); + BREAK_ON_EPID_ERROR(sts); + } + + sts = WriteFfElement(GT, R2, &precompsig->R2, sizeof(precompsig->R2)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + if (sts != kEpidNoErr) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, precompsig->rf_ctr); + } + + EpidZeroMemory(&t1_str, sizeof(t1_str)); + EpidZeroMemory(&t2_str, sizeof(t2_str)); + EpidZeroMemory(&p2x, sizeof(p2x)); + + DeleteFfElement(&p2y); + DeleteEcPoint(&B); + DeleteEcPoint(&k); + DeleteEcPoint(&t); + DeleteEcPoint(&e); + DeleteFfElement(&R2); + DeleteFfElement(&a); + DeleteFfElement(&rx); + DeleteFfElement(&rb); + DeleteFfElement(&t1); + DeleteFfElement(&t2); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/privateexp.c b/external/epid-sdk/epid/member/src/privateexp.c new file mode 100644 index 00000000..9c1f0d91 --- /dev/null +++ b/external/epid-sdk/epid/member/src/privateexp.c @@ -0,0 +1,141 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Member private exponentiation implementation +/*! \file */ + +#include "epid/member/src/privateexp.h" + +#include "epid/common/math/ecgroup.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/src/context.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/sign.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus EpidPrivateExp(MemberCtx* ctx, EcPoint const* a, EcPoint* r) { + EpidStatus sts = kEpidErr; + + BigNumStr tmp_ff_str = {0}; + uint16_t counter = 0; + + EcPoint* k_pt = NULL; + EcPoint* l_pt = NULL; + EcPoint* e_pt = NULL; + EcPoint* t1 = NULL; + EcPoint* h = NULL; + + FfElement* k = NULL; + FfElement* s = NULL; + + size_t digest_len = 0; + uint8_t* digest = NULL; + + if (!ctx || !ctx->epid2_params || !a || !r) { + return kEpidBadArgErr; + } + + digest_len = EpidGetHashSize(ctx->hash_alg); + digest = SAFE_ALLOC(digest_len); + if (!digest) { + return kEpidMemAllocErr; + } + + memset(digest, 0, digest_len); + digest[digest_len - 1] = 1; + + do { + FiniteField* Fp = ctx->epid2_params->Fp; + EcGroup* G1 = ctx->epid2_params->G1; + + if (!ctx->is_provisioned && !ctx->is_initially_provisioned) { + sts = EpidMemberInitialProvision(ctx); + BREAK_ON_EPID_ERROR(sts); + } + + // (K_PT, L_PT, E_PT, counter) = TPM2_Commit(P1=B') + sts = NewEcPoint(G1, &k_pt); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &l_pt); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &e_pt); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &t1); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &h); + BREAK_ON_EPID_ERROR(sts); + + sts = + Tpm2Commit(ctx->tpm2_ctx, a, NULL, 0, NULL, k_pt, l_pt, e_pt, &counter); + BREAK_ON_EPID_ERROR(sts); + + // (k, s) = TPM2_Sign(c=1, counter) + sts = NewFfElement(Fp, &k); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &s); + BREAK_ON_EPID_ERROR(sts); + + sts = Tpm2Sign(ctx->tpm2_ctx, digest, digest_len, counter, k, s); + BREAK_ON_EPID_ERROR(sts); + + // k = Fq.inv(k) + sts = FfInv(Fp, k, k); + BREAK_ON_EPID_ERROR(sts); + + // t1 = G1.sscmExp(B', s) + sts = WriteFfElement(Fp, s, &tmp_ff_str, sizeof(tmp_ff_str)); + BREAK_ON_EPID_ERROR(sts); + sts = EcSscmExp(G1, a, &tmp_ff_str, t1); + BREAK_ON_EPID_ERROR(sts); + + // E_PT = G1.inv(E_PT) + sts = EcInverse(G1, e_pt, e_pt); + BREAK_ON_EPID_ERROR(sts); + + // h = G1.mul(t1, E_PT) + sts = EcMul(G1, t1, e_pt, h); + BREAK_ON_EPID_ERROR(sts); + + // h = G1.sscmExp(h, k) + sts = WriteFfElement(Fp, k, &tmp_ff_str, sizeof(tmp_ff_str)); + BREAK_ON_EPID_ERROR(sts); + sts = EcSscmExp(G1, h, &tmp_ff_str, r); + BREAK_ON_EPID_ERROR(sts); + } while (0); + + if (sts != kEpidNoErr) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, counter); + } + DeleteFfElement(&s); + DeleteFfElement(&k); + + DeleteEcPoint(&e_pt); + DeleteEcPoint(&l_pt); + DeleteEcPoint(&k_pt); + DeleteEcPoint(&t1); + DeleteEcPoint(&h); + + EpidZeroMemory(&tmp_ff_str, sizeof(tmp_ff_str)); + SAFE_FREE(digest); + return sts; +} diff --git a/external/epid-sdk-3.0.0/example/signmsg/src/prng.h b/external/epid-sdk/epid/member/src/privateexp.h similarity index 57% rename from external/epid-sdk-3.0.0/example/signmsg/src/prng.h rename to external/epid-sdk/epid/member/src/privateexp.h index a5605123..415bb1a3 100644 --- a/external/epid-sdk-3.0.0/example/signmsg/src/prng.h +++ b/external/epid-sdk/epid/member/src/privateexp.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,24 +13,30 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ - -/*! - * \file - * \brief Pseudo random number generator interface. - */ - -#ifndef EXAMPLE_SIGNMSG_SRC_PRNG_H_ -#define EXAMPLE_SIGNMSG_SRC_PRNG_H_ +/// Member private exponentiation API +/*! \file */ +#ifndef EPID_MEMBER_SRC_PRIVATEEXP_H_ +#define EPID_MEMBER_SRC_PRIVATEEXP_H_ #include "epid/common/errors.h" -/// Creates Pseudo Random Number Generator for ::PrngGen() -EpidStatus PrngCreate(void** prng); +/// \cond +typedef struct EcPoint EcPoint; +typedef struct MemberCtx MemberCtx; +/// \endcond -/// Delete object allocated with ::PrngCreate() -void PrngDelete(void** prng); +/// Raises a point in an elliptic curve group G1 to a private key f. +/*! + \param[in] ctx + The member context. + \param[in] a + The base. + \param[out] r + The result of exponentiation. -/// BitSupplier type of function -int __STDCALL PrngGen(unsigned int* rand_data, int num_bits, void* user_data); + \returns ::EpidStatus +*/ -#endif // EXAMPLE_SIGNMSG_SRC_PRNG_H_ +EpidStatus EpidPrivateExp(MemberCtx* ctx, EcPoint const* a, EcPoint* r); + +#endif // EPID_MEMBER_SRC_PRIVATEEXP_H_ diff --git a/external/epid-sdk/epid/member/src/provision_bulk.c b/external/epid-sdk/epid/member/src/provision_bulk.c new file mode 100644 index 00000000..2c9a3823 --- /dev/null +++ b/external/epid-sdk/epid/member/src/provision_bulk.c @@ -0,0 +1,88 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidProvisionKey implementation. +/*! + * \file + */ + +#include + +#include +#include "epid/common/src/memory.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" +#include "epid/member/src/context.h" +#include "epid/member/src/storage.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/load_external.h" + +EpidStatus EpidProvisionKey(MemberCtx* ctx, GroupPubKey const* pub_key, + PrivKey const* priv_key, + MemberPrecomp const* precomp_str) { + EpidStatus sts = kEpidErr; + uint32_t const nv_index = 0x01c10100; + MembershipCredential credential = {0}; + + if (!pub_key || !priv_key || !ctx) { + return kEpidBadArgErr; + } + + // The member verifies that gid in public key and in private key + // match. If mismatch, abort and return operation failed. + if (memcmp(&pub_key->gid, &priv_key->gid, sizeof(GroupId))) { + return kEpidBadArgErr; + } + + sts = Tpm2LoadExternal(ctx->tpm2_ctx, &priv_key->f); + if (kEpidNoErr != sts) { + return sts; + } + + credential.A = priv_key->A; + credential.x = priv_key->x; + credential.gid = priv_key->gid; + + if (ctx->primary_key_set) { + Tpm2ResetContext(&ctx->tpm2_ctx); + ctx->primary_key_set = false; + } + sts = Tpm2LoadExternal(ctx->tpm2_ctx, &priv_key->f); + if (kEpidNoErr != sts) { + return sts; + } + ctx->primary_key_set = true; + + sts = EpidNvWriteMembershipCredential(ctx->tpm2_ctx, pub_key, &credential, + nv_index); + + if (kEpidNoErr == sts) { + if (precomp_str) { + ctx->precomp = *precomp_str; + ctx->precomp_ready = true; + } else { + EpidZeroMemory(&ctx->precomp, sizeof(ctx->precomp)); + ctx->precomp_ready = false; + } + + ctx->pub_key = *pub_key; + ctx->is_provisioned = true; + + ctx->credential.A = credential.A; + ctx->credential.x = credential.x; + ctx->credential.gid = credential.gid; + } + return sts; +} diff --git a/external/epid-sdk/epid/member/src/provision_compressed.c b/external/epid-sdk/epid/member/src/provision_compressed.c new file mode 100644 index 00000000..b582e53f --- /dev/null +++ b/external/epid-sdk/epid/member/src/provision_compressed.c @@ -0,0 +1,41 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidProvisionCompressed implementation. +/*! + * \file + */ + +#include + +#include +#include "epid/common/types.h" +#include "epid/member/src/context.h" + +EpidStatus EpidProvisionCompressed(MemberCtx* ctx, GroupPubKey const* pub_key, + CompressedPrivKey const* compressed_privkey, + MemberPrecomp const* precomp_str) { + EpidStatus sts = kEpidErr; + PrivKey priv_key; + if (!pub_key || !compressed_privkey || !ctx) { + return kEpidBadArgErr; + } + sts = EpidDecompressPrivKey(pub_key, compressed_privkey, &priv_key); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidProvisionKey(ctx, pub_key, &priv_key, precomp_str); + return sts; +} diff --git a/external/epid-sdk/epid/member/src/provision_join.c b/external/epid-sdk/epid/member/src/provision_join.c new file mode 100644 index 00000000..49bc96e6 --- /dev/null +++ b/external/epid-sdk/epid/member/src/provision_join.c @@ -0,0 +1,85 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidProvisionCredential implementation. +/*! + * \file + */ + +#include + +#include +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/src/context.h" +#include "epid/member/src/storage.h" +#include "epid/member/src/validatekey.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/createprimary.h" + +EpidStatus EpidProvisionCredential(MemberCtx* ctx, GroupPubKey const* pub_key, + MembershipCredential const* credential, + MemberPrecomp const* precomp_str) { + EpidStatus sts = kEpidErr; + uint32_t const nv_index = 0x01c10100; + G1ElemStr f_str; + + if (!pub_key || !credential || !ctx) { + return kEpidBadArgErr; + } + + if (memcmp(&pub_key->gid, &credential->gid, sizeof(GroupId))) { + return kEpidBadArgErr; + } + + if (!ctx->is_provisioned && !ctx->is_initially_provisioned) { + sts = EpidMemberInitialProvision(ctx); + if (kEpidNoErr != sts) return sts; + } + + if (!EpidMemberIsKeyValid(ctx, &credential->A, &credential->x, &pub_key->h1, + &pub_key->w)) { + return kEpidBadArgErr; + } + + sts = EpidNvWriteMembershipCredential(ctx->tpm2_ctx, pub_key, credential, + nv_index); + + if (ctx->primary_key_set) { + Tpm2ResetContext(&ctx->tpm2_ctx); + ctx->primary_key_set = false; + } + sts = Tpm2CreatePrimary(ctx->tpm2_ctx, &f_str); + if (kEpidNoErr != sts) { + return sts; + } + ctx->primary_key_set = true; + if (kEpidNoErr == sts) { + if (precomp_str) { + ctx->precomp = *precomp_str; + ctx->precomp_ready = true; + } else { + EpidZeroMemory(&ctx->precomp, sizeof(ctx->precomp)); + ctx->precomp_ready = false; + } + + ctx->credential.A = credential->A; + ctx->credential.x = credential->x; + ctx->credential.gid = credential->gid; + ctx->pub_key = *pub_key; + ctx->is_provisioned = true; + } + return sts; +} diff --git a/external/epid-sdk/epid/member/src/resize.c b/external/epid-sdk/epid/member/src/resize.c new file mode 100644 index 00000000..fb4a168e --- /dev/null +++ b/external/epid-sdk/epid/member/src/resize.c @@ -0,0 +1,40 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implements ResizeOctStr +/*! \file */ + +#include "epid/member/src/resize.h" + +#include +#include "epid/common/src/memory.h" + +EpidStatus ResizeOctStr(ConstOctStr a, size_t a_size, OctStr r, size_t r_size) { + if (!a || !a_size || !r || !r_size) return kEpidBadArgErr; + if (a_size <= r_size) { + memset(r, 0, r_size - a_size); + if (memcpy_S((uint8_t*)r + (r_size - a_size), a_size, a, a_size)) + return kEpidErr; + } else { + size_t i; + for (i = 0; i < a_size - r_size; i++) { + if (((uint8_t*)a)[i]) + return kEpidBadArgErr; // a does not fit into r_size + } + if (memcpy_S(r, r_size, (uint8_t*)a + (a_size - r_size), r_size)) + return kEpidErr; + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/src/resize.h b/external/epid-sdk/epid/member/src/resize.h new file mode 100644 index 00000000..ee4b9f1e --- /dev/null +++ b/external/epid-sdk/epid/member/src/resize.h @@ -0,0 +1,45 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Declares ResizeOctStr +/*! \file */ + +#ifndef EPID_MEMBER_SRC_RESIZE_H_ +#define EPID_MEMBER_SRC_RESIZE_H_ + +#include +#include "epid/common/errors.h" +#include "epid/common/types.h" + +/// Resizes octet string number +/*! +Prepends input number with zeros when increasing the size. +Removes leading zeros when decreasing the size. +Return error if input number does not fit the new size. + +\param[in] a +Octet string to resize +\param[in] a_size +Size of the a +\param[out] r +Result octet string +\param[in] r_size +New size + +\returns ::EpidStatus +*/ +EpidStatus ResizeOctStr(ConstOctStr a, size_t a_size, OctStr r, size_t r_size); + +#endif // EPID_MEMBER_SRC_RESIZE_H_ diff --git a/external/epid-sdk-3.0.0/epid/member/src/sign.c b/external/epid-sdk/epid/member/src/sign.c similarity index 68% rename from external/epid-sdk-3.0.0/epid/member/src/sign.c rename to external/epid-sdk/epid/member/src/sign.c index 976271f3..2c49aa5d 100644 --- a/external/epid-sdk-3.0.0/epid/member/src/sign.c +++ b/external/epid-sdk/epid/member/src/sign.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,32 +13,34 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ - -/*! - * \file - * \brief EpidSign implementation. - */ +/// EpidSign implementation. +/*! \file */ +#include #include #include "epid/common/src/endian_convert.h" #include "epid/common/src/memory.h" #include "epid/common/src/sigrlvalid.h" -#include "epid/member/api.h" #include "epid/member/src/context.h" +#include "epid/member/src/nrprove.h" +#include "epid/member/src/signbasic.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } EpidStatus EpidSign(MemberCtx const* ctx, void const* msg, size_t msg_len, void const* basename, size_t basename_len, - SigRl const* sig_rl, size_t sig_rl_size, EpidSignature* sig, - size_t sig_len) { - EpidStatus result = kEpidErr; + EpidSignature* sig, size_t sig_len) { + EpidStatus sts = kEpidErr; uint32_t num_sig_rl = 0; OctStr32 octstr32_0 = {{0x00, 0x00, 0x00, 0x00}}; + BigNumStr rnd_bsn = {0}; if (!ctx || !sig) { return kEpidBadArgErr; } - if (!ctx->pub_key) { - return kEpidBadArgErr; - } if (!msg && (0 != msg_len)) { // if message is non-empty it must have both length and content return kEpidBadArgErr; @@ -47,21 +49,21 @@ EpidStatus EpidSign(MemberCtx const* ctx, void const* msg, size_t msg_len, // if basename is non-empty it must have both length and content return kEpidBadArgErr; } - if (sig_rl && (sig_rl_size < sizeof(SigRl) - sizeof(SigRlEntry))) { - return kEpidBadArgErr; + if (!ctx->is_provisioned) { + return kEpidOutOfSequenceError; } - if (sig_rl && EpidGetSigSize(sig_rl) > sig_len) { + if (EpidGetSigSize(ctx->sig_rl) > sig_len) { return kEpidBadArgErr; } // 11. The member sets sigma0 = (B, K, T, c, sx, sf, sa, sb). - result = - EpidSignBasic(ctx, msg, msg_len, basename, basename_len, &sig->sigma0); - if (kEpidNoErr != result) { - return result; + sts = EpidSignBasic(ctx, msg, msg_len, basename, basename_len, &sig->sigma0, + &rnd_bsn); + if (kEpidNoErr != sts) { + return sts; } - if (!sig_rl) { + if (!ctx->sig_rl) { // 12. If SigRL is not provided as input, // a. The member sets RLver = 0 and n2 = 0. // b. The member outputs (sigma0, RLver, n2) and returns "succeeded". @@ -75,22 +77,25 @@ EpidStatus EpidSign(MemberCtx const* ctx, void const* msg, size_t msg_len, // the following steps: // a. The member verifies that gid in public key and in SigRL // match. - if (!IsSigRlValid(&ctx->pub_key->gid, sig_rl, sig_rl_size)) { - return kEpidBadArgErr; - } + // This was done under EpidMemberSetSigRl function. // b. The member copies RLver and n2 values in SigRL to the // signature. - sig->rl_ver = sig_rl->version; - sig->n2 = sig_rl->n2; + sig->rl_ver = ctx->sig_rl->version; + sig->n2 = ctx->sig_rl->n2; // c. For i = 0, ..., n2-1, the member computes sigma[i] = // nrProve(f, B, K, B[i], K[i]). The details of nrProve() // will be given in the next subsection. - num_sig_rl = ntohl(sig_rl->n2); + num_sig_rl = ntohl(ctx->sig_rl->n2); for (i = 0; i < num_sig_rl; i++) { - result = EpidNrProve(ctx, msg, msg_len, &sig->sigma0, &sig_rl->bk[i], - &sig->sigma[i]); - if (kEpidNoErr != result) { - nr_prove_status = result; + if (basename) { + sts = EpidNrProve(ctx, msg, msg_len, basename, basename_len, + &sig->sigma0, &ctx->sig_rl->bk[i], &sig->sigma[i]); + } else { + sts = EpidNrProve(ctx, msg, msg_len, &rnd_bsn, sizeof(rnd_bsn), + &sig->sigma0, &ctx->sig_rl->bk[i], &sig->sigma[i]); + } + if (kEpidNoErr != sts) { + nr_prove_status = sts; } } if (kEpidNoErr != nr_prove_status) { diff --git a/external/epid-sdk/epid/member/src/sign_commitment.c b/external/epid-sdk/epid/member/src/sign_commitment.c new file mode 100644 index 00000000..f317cb6a --- /dev/null +++ b/external/epid-sdk/epid/member/src/sign_commitment.c @@ -0,0 +1,71 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host signing helper implementation +/*! \file */ + +#include "epid/member/src/sign_commitment.h" + +#include "epid/common/math/ecgroup.h" +#include "epid/common/src/commitment.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus HashSignCommitment(FiniteField* Fp, HashAlg hash_alg, + GroupPubKey const* pub_key, + SignCommitOutput const* commit_out, + void const* msg, size_t msg_len, + FpElemStr* c_str) { + EpidStatus sts = kEpidErr; + FfElement* c = NULL; + + if (!Fp || !commit_out || (0 != msg_len && !msg) || !c_str) { + return kEpidBadArgErr; + } + + do { + CommitValues values = {0}; + sts = SetKeySpecificCommitValues(pub_key, &values); + BREAK_ON_EPID_ERROR(sts); + + values.B = commit_out->B; + values.K = commit_out->K; + values.T = commit_out->T; + values.R1 = commit_out->R1; + values.R2 = commit_out->R2; + + sts = NewFfElement(Fp, &c); + BREAK_ON_EPID_ERROR(sts); + + // 5. The member computes t3 = Fp.hash(p || g1 || g2 || h1 || h2 + // || w || B || K || T || R1 || R2). + // 6. The member computes c = Fp.hash(t3 || m). + sts = CalculateCommitmentHash(&values, Fp, hash_alg, msg, msg_len, c); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteFfElement(Fp, c, c_str, sizeof(*c_str)); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + DeleteFfElement(&c); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/sign_commitment.h b/external/epid-sdk/epid/member/src/sign_commitment.h new file mode 100644 index 00000000..45b0b204 --- /dev/null +++ b/external/epid-sdk/epid/member/src/sign_commitment.h @@ -0,0 +1,73 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Host signing helper APIs +/*! \file */ +#ifndef EPID_MEMBER_SRC_SIGN_COMMITMENT_H_ +#define EPID_MEMBER_SRC_SIGN_COMMITMENT_H_ + +#include +#include "epid/common/errors.h" +#include "epid/common/types.h" // HashAlg + +#pragma pack(1) +/// Result of Sign Commit +typedef struct SignCommitOutput { + G1ElemStr B; ///< B value for signature + G1ElemStr K; ///< K value for signature + G1ElemStr T; ///< T value for signature + G1ElemStr R1; ///< Serialized G1 element + GtElemStr R2; ///< Serialized GT element +} SignCommitOutput; +#pragma pack() + +typedef struct SignCommitOutput SignCommitOutput; + +/// \cond +typedef struct FiniteField FiniteField; +typedef struct FpElemStr FpElemStr; +/// \endcond + +/// Calculates commitment hash of sign commit +/*! + + \param[in] Fp + The finite field. + + \param[in] hash_alg + The hash algorithm. + + \param[in] commit_out + The output from the sign commit. + + \param[in] msg + The message. + + \param[in] msg_len + The size of message in bytes. + + \param[out] c_str + The resulting commitment hash. + + \returns ::EpidStatus + + */ +EpidStatus HashSignCommitment(FiniteField* Fp, HashAlg hash_alg, + GroupPubKey const* pub_key, + SignCommitOutput const* commit_out, + void const* msg, size_t msg_len, + FpElemStr* c_str); + +#endif // EPID_MEMBER_SRC_SIGN_COMMITMENT_H_ diff --git a/external/epid-sdk/epid/member/src/signbasic.c b/external/epid-sdk/epid/member/src/signbasic.c new file mode 100644 index 00000000..1e4d76ba --- /dev/null +++ b/external/epid-sdk/epid/member/src/signbasic.c @@ -0,0 +1,340 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidSignBasic implementation. +/*! \file */ +#include "epid/member/src/signbasic.h" + +#include // memset + +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/endian_convert.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/member/api.h" +#include "epid/member/src/allowed_basenames.h" +#include "epid/member/src/context.h" +#include "epid/member/src/hash_basename.h" +#include "epid/member/src/presig-internal.h" +#include "epid/member/src/sign_commitment.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/sign.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + BasicSignature* sig, BigNumStr* rnd_bsn) { + EpidStatus sts = kEpidErr; + + EcPoint* B = NULL; + EcPoint* t = NULL; // temp value in G1 + EcPoint* k = NULL; + EcPoint* e = NULL; + FfElement* R2 = NULL; + FfElement* p2y = NULL; + FfElement* t1 = NULL; + FfElement* t2 = NULL; + + FfElement* a = NULL; + FfElement* b = NULL; + FfElement* rx = NULL; + FfElement* ra = NULL; + FfElement* rb = NULL; + + struct p2x_t { + uint32_t i; + uint8_t bsn[1]; + }* p2x = NULL; + + FfElement* t3 = NULL; // temporary for multiplication + FfElement* c = NULL; + uint8_t* digest = NULL; + + PreComputedSignature curr_presig = {0}; + + if (!ctx || !sig) { + return kEpidBadArgErr; + } + if (!msg && (0 != msg_len)) { + // if message is non-empty it must have both length and content + return kEpidBadArgErr; + } + if (!basename && (0 != basename_len)) { + // if basename is non-empty it must have both length and content + return kEpidBadArgErr; + } + if (!ctx->epid2_params) { + return kEpidBadArgErr; + } + + do { + FiniteField* Fp = ctx->epid2_params->Fp; + SignCommitOutput commit_out = {0}; + FpElemStr c_str = {0}; + EcGroup* G1 = ctx->epid2_params->G1; + FiniteField* GT = ctx->epid2_params->GT; + + FiniteField* Fq = ctx->epid2_params->Fq; + PairingState* ps_ctx = ctx->epid2_params->pairing_state; + const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + BigNumStr t1_str = {0}; + BigNumStr t2_str = {0}; + size_t digest_size = 0; + uint16_t* rf_ctr = (uint16_t*)&ctx->rf_ctr; + FfElement const* x = ctx->x; + + if (basename) { + if (!IsBasenameAllowed(ctx->allowed_basenames, basename, basename_len)) { + sts = kEpidBadArgErr; + BREAK_ON_EPID_ERROR(sts); + } + } + + sts = NewEcPoint(G1, &B); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &k); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &t); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &e); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(GT, &R2); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fq, &p2y); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &t1); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &t2); + BREAK_ON_EPID_ERROR(sts); + p2x = (struct p2x_t*)SAFE_ALLOC(sizeof(struct p2x_t) + basename_len - 1); + if (!p2x) { + sts = kEpidMemAllocErr; + break; + } + + sts = NewFfElement(Fp, &a); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &b); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &rx); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &ra); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &rb); + BREAK_ON_EPID_ERROR(sts); + + sts = MemberGetPreSig((MemberCtx*)ctx, &curr_presig); + BREAK_ON_EPID_ERROR(sts); + + // 3. If the pre-computed signature pre-sigma exists, the member + // loads (B, K, T, a, b, rx, rf, ra, rb, R1, R2) from + // pre-sigma. Refer to Section 4.4 for the computation of + // these values. + sts = ReadFfElement(Fp, &curr_presig.a, sizeof(curr_presig.a), a); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &curr_presig.b, sizeof(curr_presig.b), b); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &curr_presig.rx, sizeof(curr_presig.rx), rx); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &curr_presig.ra, sizeof(curr_presig.ra), ra); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &curr_presig.rb, sizeof(curr_presig.rb), rb); + BREAK_ON_EPID_ERROR(sts); + + // If the basename is provided, use it, otherwise use presig B + if (basename) { + // 3.a. The member computes (B, i2, y2) = G1.tpmHash(bsn). + sts = EcHash(G1, basename, basename_len, ctx->hash_alg, B, &p2x->i); + BREAK_ON_EPID_ERROR(sts); + p2x->i = htonl(p2x->i); + sts = WriteEcPoint(G1, B, &commit_out.B, sizeof(commit_out.B)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fq, &commit_out.B.y, sizeof(commit_out.B.y), p2y); + BREAK_ON_EPID_ERROR(sts); + + // b.i. (KTPM, LTPM, ETPM, counterTPM) = TPM2_Commit(P1=h1,(s2, y2) = (i2 + // || bsn, y2)). + // b.ii.K = KTPM. + if (0 != + memcpy_S((void*)p2x->bsn, basename_len, basename, basename_len)) { + sts = kEpidBadArgErr; + break; + } + sts = + Tpm2Commit(ctx->tpm2_ctx, ctx->h1, p2x, sizeof(p2x->i) + basename_len, + p2y, k, t, e, (uint16_t*)&ctx->rf_ctr); + BREAK_ON_EPID_ERROR(sts); + sts = WriteEcPoint(G1, k, &commit_out.K, sizeof(commit_out.K)); + BREAK_ON_EPID_ERROR(sts); + // c.i. The member computes R1 = LTPM. + sts = WriteEcPoint(G1, t, &commit_out.R1, sizeof(commit_out.R1)); + BREAK_ON_EPID_ERROR(sts); + // c.ii. e12rf = pairing(ETPM, g2) + sts = Pairing(ps_ctx, e, ctx->epid2_params->g2, R2); + BREAK_ON_EPID_ERROR(sts); + // c.iii. R2 = GT.sscmMultiExp(ea2, t1, e12rf, 1, e22, t2, e2w,ra). + // 4.i. The member computes t1 = (- rx) mod p. + sts = FfNeg(Fp, rx, t1); + BREAK_ON_EPID_ERROR(sts); + // 4.j. The member computes t2 = (rb - a * rx) mod p. + sts = FfMul(Fp, a, rx, t2); + BREAK_ON_EPID_ERROR(sts); + sts = FfNeg(Fp, t2, t2); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, rb, t2, t2); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteFfElement(Fp, t1, &t1_str, sizeof(t1_str)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t2, &t2_str, sizeof(t2_str)); + BREAK_ON_EPID_ERROR(sts); + { + FfElement const* points[4]; + BigNumStr const* exponents[4]; + points[0] = ctx->ea2; + points[1] = R2; + points[2] = ctx->e22; + points[3] = ctx->e2w; + exponents[0] = &t1_str; + exponents[1] = &kOne; + exponents[2] = &t2_str; + exponents[3] = (BigNumStr*)&curr_presig.ra; + sts = FfMultiExp(GT, points, exponents, COUNT_OF(points), R2); + BREAK_ON_EPID_ERROR(sts); + } + + sts = WriteFfElement(GT, R2, &commit_out.R2, sizeof(commit_out.R2)); + BREAK_ON_EPID_ERROR(sts); + // d. The member over-writes the counterTPM, B, K, R1 and R2 values. + } else { + if (!rnd_bsn) { + sts = kEpidBadArgErr; + break; + } + sts = ReadEcPoint(G1, &curr_presig.B, sizeof(curr_presig.B), B); + BREAK_ON_EPID_ERROR(sts); + commit_out.B = curr_presig.B; + commit_out.K = curr_presig.K; + commit_out.R1 = curr_presig.R1; + ((MemberCtx*)ctx)->rf_ctr = curr_presig.rf_ctr; + commit_out.R2 = curr_presig.R2; + *rnd_bsn = curr_presig.rnd_bsn; + } + + commit_out.T = curr_presig.T; + + sts = HashSignCommitment(Fp, ctx->hash_alg, &ctx->pub_key, &commit_out, msg, + msg_len, &c_str); + BREAK_ON_EPID_ERROR(sts); + + digest_size = EpidGetHashSize(ctx->hash_alg); + digest = (uint8_t*)SAFE_ALLOC(digest_size); + if (!digest) { + sts = kEpidNoMemErr; + break; + } + memcpy_S(digest + digest_size - sizeof(c_str), sizeof(c_str), &c_str, + sizeof(c_str)); + + sts = NewFfElement(Fp, &t3); + BREAK_ON_EPID_ERROR(sts); + + sts = NewFfElement(Fp, &c); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(Fp, &c_str, sizeof(c_str), c); + BREAK_ON_EPID_ERROR(sts); + + // 7. The member computes sx = (rx + c * x) mod p. + sts = FfMul(Fp, c, x, t3); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, rx, t3, t3); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t3, &sig->sx, sizeof(sig->sx)); + BREAK_ON_EPID_ERROR(sts); + + // 8. The member computes sf = (rf + c * f) mod p. + sts = Tpm2Sign(ctx->tpm2_ctx, digest, digest_size, *rf_ctr, NULL, t3); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t3, &sig->sf, sizeof(sig->sf)); + BREAK_ON_EPID_ERROR(sts); + + // 9. The member computes sa = (ra + c * a) mod p. + sts = FfMul(Fp, c, a, t3); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, ra, t3, t3); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t3, &sig->sa, sizeof(sig->sa)); + BREAK_ON_EPID_ERROR(sts); + + // 10. The member computes sb = (rb + c * b) mod p. + sts = FfMul(Fp, c, b, t3); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, rb, t3, t3); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, t3, &sig->sb, sizeof(sig->sb)); + BREAK_ON_EPID_ERROR(sts); + + sig->B = commit_out.B; + sig->K = commit_out.K; + sig->T = commit_out.T; + sig->c = c_str; + + sts = kEpidNoErr; + } while (0); + + if (sts != kEpidNoErr) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, (uint16_t)ctx->rf_ctr); + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, curr_presig.rf_ctr); + } else if (basename) { + (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, curr_presig.rf_ctr); + } + + EpidZeroMemory(&curr_presig, sizeof(curr_presig)); + + DeleteEcPoint(&B); + DeleteEcPoint(&k); + DeleteEcPoint(&t); + DeleteEcPoint(&e); + DeleteFfElement(&R2); + DeleteFfElement(&p2y); + DeleteFfElement(&t1); + DeleteFfElement(&t2); + + DeleteFfElement(&a); + DeleteFfElement(&b); + DeleteFfElement(&rx); + DeleteFfElement(&ra); + DeleteFfElement(&rb); + + SAFE_FREE(p2x); + + DeleteFfElement(&t3); + DeleteFfElement(&c); + SAFE_FREE(digest); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/signbasic.h b/external/epid-sdk/epid/member/src/signbasic.h new file mode 100644 index 00000000..2d26a29a --- /dev/null +++ b/external/epid-sdk/epid/member/src/signbasic.h @@ -0,0 +1,70 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidSignBasic interface. +/*! \file */ +#ifndef EPID_MEMBER_SRC_SIGNBASIC_H_ +#define EPID_MEMBER_SRC_SIGNBASIC_H_ + +#include +#include "epid/common/errors.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct BasicSignature BasicSignature; +typedef struct BigNumStr BigNumStr; +/// \endcond + +/// Creates a basic signature for use in constrained environment. +/*! + Used in constrained environments where, due to limited memory, it may not + be possible to process through a large and potentially unbounded revocation + list. + + \param[in] ctx + The member context. + \param[in] msg + The message. + \param[in] msg_len + The length of message in bytes. + \param[in] basename + Optional basename. If basename is NULL a random basename is used. + Signatures generated using random basenames are anonymous. Signatures + generated using the same basename are linkable by the verifier. If a + basename is provided it must already be registered or + ::kEpidBadArgErr is returned. + \param[in] basename_len + The size of basename in bytes. Must be 0 if basename is NULL. + \param[out] sig + The generated basic signature + \param[out] rnd_bsn + Random basename, can be NULL if basename is provided. + + \returns ::EpidStatus + + \note + This function should be used in conjunction with EpidNrProve() + + \note + If the result is not ::kEpidNoErr the content of sig, is undefined. + + \see EpidMemberInit + \see EpidNrProve + */ +EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + BasicSignature* sig, BigNumStr* rnd_bsn); + +#endif // EPID_MEMBER_SRC_SIGNBASIC_H_ diff --git a/external/epid-sdk/epid/member/src/startup.c b/external/epid-sdk/epid/member/src/startup.c new file mode 100644 index 00000000..ba310c5a --- /dev/null +++ b/external/epid-sdk/epid/member/src/startup.c @@ -0,0 +1,127 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidMemberStartup implementation. +/*! + * \file + */ + +#include + +#include +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/types.h" // MemberPrecomp +#include "epid/member/src/context.h" +#include "epid/member/src/precomp.h" +#include "epid/member/src/storage.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +static EpidStatus MemberReadPrecomputation(MemberCtx* ctx, + MemberPrecomp const* precomp); + +EpidStatus EpidMemberStartup(MemberCtx* ctx) { + EpidStatus sts = kEpidErr; + uint32_t const nv_index = 0x01c10100; + if (!ctx) { + return kEpidBadArgErr; + } + + do { + EcGroup* G1 = ctx->epid2_params->G1; + EcGroup* G2 = ctx->epid2_params->G2; + FiniteField* Fp = ctx->epid2_params->Fp; + EcPoint* A = (EcPoint*)ctx->A; + FfElement* x = (FfElement*)ctx->x; + EcPoint* h1 = (EcPoint*)ctx->h1; + EcPoint* h2 = (EcPoint*)ctx->h2; + EcPoint* w = (EcPoint*)ctx->w; + sts = EpidNvReadMembershipCredential(ctx->tpm2_ctx, nv_index, &ctx->pub_key, + &ctx->credential); + BREAK_ON_EPID_ERROR(sts); + if (!ctx->precomp_ready) { + sts = PrecomputeMemberPairing(ctx->epid2_params, &ctx->pub_key, + &ctx->credential.A, &ctx->precomp); + BREAK_ON_EPID_ERROR(sts); + ctx->precomp_ready = true; + } + + if (!ctx->is_provisioned && !ctx->is_initially_provisioned) { + sts = EpidMemberInitialProvision(ctx); + BREAK_ON_EPID_ERROR(sts); + } + + sts = ReadEcPoint(G1, &ctx->credential.A, sizeof(ctx->credential.A), A); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(Fp, &ctx->credential.x, sizeof(ctx->credential.x), x); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadEcPoint(G1, &ctx->pub_key.h1, sizeof(ctx->pub_key.h1), h1); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadEcPoint(G1, &ctx->pub_key.h2, sizeof(ctx->pub_key.h2), h2); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadEcPoint(G2, &ctx->pub_key.w, sizeof(ctx->pub_key.w), w); + BREAK_ON_EPID_ERROR(sts); + + sts = MemberReadPrecomputation(ctx, &ctx->precomp); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + return sts; +} + +static EpidStatus MemberReadPrecomputation(MemberCtx* ctx, + MemberPrecomp const* precomp) { + EpidStatus sts = kEpidErr; + + if (!ctx || !precomp || !ctx->epid2_params || !ctx) { + return kEpidBadArgErr; + } + + do { + FiniteField* GT = ctx->epid2_params->GT; + FfElement* e12 = (FfElement*)ctx->e12; + FfElement* e22 = (FfElement*)ctx->e22; + FfElement* e2w = (FfElement*)ctx->e2w; + FfElement* ea2 = (FfElement*)ctx->ea2; + + sts = ReadFfElement(GT, &precomp->e12, sizeof(precomp->e12), e12); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(GT, &precomp->e22, sizeof(precomp->e22), e22); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(GT, &precomp->e2w, sizeof(precomp->e2w), e2w); + BREAK_ON_EPID_ERROR(sts); + + sts = ReadFfElement(GT, &precomp->ea2, sizeof(precomp->ea2), ea2); + BREAK_ON_EPID_ERROR(sts); + + sts = kEpidNoErr; + } while (0); + + return sts; +} diff --git a/external/epid-sdk/epid/member/src/storage.c b/external/epid-sdk/epid/member/src/storage.c new file mode 100644 index 00000000..618faef2 --- /dev/null +++ b/external/epid-sdk/epid/member/src/storage.c @@ -0,0 +1,71 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief Member credentials storage helper API implementation. + */ + +#include "epid/member/src/storage.h" + +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/tpm2/nv.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus EpidNvWriteMembershipCredential( + Tpm2Ctx* ctx, GroupPubKey const* pub_key, + MembershipCredential const* credential, uint32_t nv_index) { + EpidStatus sts = kEpidErr; + uint8_t tmp; + if (!ctx || !pub_key || !credential) return kEpidBadArgErr; + + do { + if (kEpidNoErr != Tpm2NvRead(ctx, nv_index, 1, 0, &tmp)) { + sts = Tpm2NvDefineSpace(ctx, nv_index, + sizeof(*pub_key) + sizeof(*credential)); + BREAK_ON_EPID_ERROR(sts); + } + sts = Tpm2NvWrite(ctx, nv_index, sizeof(*pub_key), 0, pub_key); + BREAK_ON_EPID_ERROR(sts); + sts = Tpm2NvWrite(ctx, nv_index, sizeof(*credential), sizeof(*pub_key), + credential); + BREAK_ON_EPID_ERROR(sts); + } while (0); + if (kEpidNoErr != sts) Tpm2NvUndefineSpace(ctx, nv_index); + EpidZeroMemory(&tmp, sizeof(tmp)); + return sts; +} + +EpidStatus EpidNvReadMembershipCredential(Tpm2Ctx* ctx, uint32_t nv_index, + GroupPubKey* pub_key, + MembershipCredential* credential) { + EpidStatus sts = kEpidErr; + if (!ctx || !pub_key || !credential) return kEpidBadArgErr; + do { + sts = Tpm2NvRead(ctx, nv_index, sizeof(*pub_key), 0, pub_key); + BREAK_ON_EPID_ERROR(sts); + sts = Tpm2NvRead(ctx, nv_index, sizeof(*credential), sizeof(*pub_key), + credential); + BREAK_ON_EPID_ERROR(sts); + } while (0); + return sts; +} diff --git a/external/epid-sdk/epid/member/src/storage.h b/external/epid-sdk/epid/member/src/storage.h new file mode 100644 index 00000000..2db7a5c2 --- /dev/null +++ b/external/epid-sdk/epid/member/src/storage.h @@ -0,0 +1,72 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Member credentials storage helper API +/*! \file */ +#ifndef EPID_MEMBER_SRC_STORAGE_H_ +#define EPID_MEMBER_SRC_STORAGE_H_ + +#include +#include "epid/common/errors.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct GroupPubKey GroupPubKey; +typedef struct MembershipCredential MembershipCredential; +/// \endcond + +/// Write membership credential to TPM non-volatile memory. +/*! +Allocates TPM non volatile memory for nv_index for membership credentials. +Write group public key and member private key parameters A and x into +space allocated. + +\param[in] ctx +The TPM context. +\param[in] pub_key +Group public key. +\param[in] credential +Membership credential. +\param[in] nv_index +Handle of the data area to be defined. + +\returns ::EpidStatus + +\see EpidNvReadMembershipCredential +*/ +EpidStatus EpidNvWriteMembershipCredential( + Tpm2Ctx* ctx, GroupPubKey const* pub_key, + MembershipCredential const* credential, uint32_t nv_index); + +/// Read membership credential from TPM non-volatile memory. +/*! +\param[in] ctx +The TPM context. +\param[in] nv_index +Handle of the data area. +\param[out] pub_key +Group public key. +\param[out] credential +Membership credential. + +\returns ::EpidStatus + +\see EpidNvWriteMembershipCredential +*/ +EpidStatus EpidNvReadMembershipCredential(Tpm2Ctx* ctx, uint32_t nv_index, + GroupPubKey* pub_key, + MembershipCredential* credential); + +#endif // EPID_MEMBER_SRC_STORAGE_H_ diff --git a/external/epid-sdk/epid/member/src/validatekey.c b/external/epid-sdk/epid/member/src/validatekey.c new file mode 100644 index 00000000..d7c5bd25 --- /dev/null +++ b/external/epid-sdk/epid/member/src/validatekey.c @@ -0,0 +1,130 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Non-sensitive member context implementation +/*! \file */ + +#include "epid/member/src/validatekey.h" + +#include + +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/math/pairing.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" // MemberPrecomp +#include "epid/member/src/context.h" +#include "epid/member/src/privateexp.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +bool EpidMemberIsKeyValid(MemberCtx* ctx, G1ElemStr const* A_str, + FpElemStr const* x_str, G1ElemStr const* h1_str, + G2ElemStr const* w_str) { + bool key_is_valid = false; + EcPoint* t1 = NULL; + EcPoint* t2 = NULL; + FfElement* t3 = NULL; + FfElement* t4 = NULL; + EcPoint* A = NULL; + EcPoint* h1 = NULL; + EcPoint* w = NULL; + + if (!ctx || !A_str || !x_str || !h1_str || !w_str || !ctx->epid2_params) { + return false; + } + + do { + EpidStatus sts = kEpidErr; + EcGroup* G1 = ctx->epid2_params->G1; + EcGroup* G2 = ctx->epid2_params->G2; + FiniteField* GT = ctx->epid2_params->GT; + EcPoint* g1 = ctx->epid2_params->g1; + EcPoint* g2 = ctx->epid2_params->g2; + PairingState* ps_ctx = ctx->epid2_params->pairing_state; + + if (!ctx->is_provisioned && !ctx->is_initially_provisioned) { + sts = EpidMemberInitialProvision(ctx); + BREAK_ON_EPID_ERROR(sts); + } + + // 2. The member computes t1 = G2.sscmExp(g2, x). + sts = NewEcPoint(G2, &t1); + BREAK_ON_EPID_ERROR(sts); + + sts = EcSscmExp(G2, g2, (BigNumStr const*)x_str, t1); + BREAK_ON_EPID_ERROR(sts); + + // 3. The member computes t1 = G2.mul(t1, w). + sts = NewEcPoint(G2, &w); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G2, w_str, sizeof(*w_str), w); + BREAK_ON_EPID_ERROR(sts); + sts = EcMul(G2, t1, w, t1); + BREAK_ON_EPID_ERROR(sts); + + // 4. The member computes t3 = pairing(A, t1). + sts = NewFfElement(GT, &t3); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &A); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, A_str, sizeof(*A_str), A); + BREAK_ON_EPID_ERROR(sts); + sts = Pairing(ps_ctx, A, t1, t3); + BREAK_ON_EPID_ERROR(sts); + + // 5. The member computes t2 = G1.sscmExp(h1, f). + sts = NewEcPoint(G1, &t2); + BREAK_ON_EPID_ERROR(sts); + sts = NewEcPoint(G1, &h1); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, h1_str, sizeof(*h1_str), h1); + BREAK_ON_EPID_ERROR(sts); + sts = EpidPrivateExp(ctx, h1, t2); + BREAK_ON_EPID_ERROR(sts); + + // 6. The member computes t2 = G1.mul(t2, g1). + sts = EcMul(G1, t2, g1, t2); + BREAK_ON_EPID_ERROR(sts); + + // Step 7. The member computes t4 = pairing(t2, g2). + sts = NewFfElement(GT, &t4); + BREAK_ON_EPID_ERROR(sts); + sts = Pairing(ps_ctx, t2, g2, t4); + BREAK_ON_EPID_ERROR(sts); + + // 8. If GT.isEqual(t3, t4) = false, reports bad private key. + sts = FfIsEqual(GT, t3, t4, &key_is_valid); + if (kEpidNoErr != sts) { + key_is_valid = false; + BREAK_ON_EPID_ERROR(sts); + } + } while (0); + + DeleteEcPoint(&t1); + DeleteEcPoint(&t2); + DeleteFfElement(&t3); + DeleteFfElement(&t4); + DeleteEcPoint(&A); + DeleteEcPoint(&h1); + DeleteEcPoint(&w); + + return key_is_valid; +} diff --git a/external/epid-sdk/epid/member/src/validatekey.h b/external/epid-sdk/epid/member/src/validatekey.h new file mode 100644 index 00000000..b7ff66ed --- /dev/null +++ b/external/epid-sdk/epid/member/src/validatekey.h @@ -0,0 +1,64 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Non-sensitive member context APIs +/*! \file */ + +#ifndef EPID_MEMBER_SRC_VALIDATEKEY_H_ +#define EPID_MEMBER_SRC_VALIDATEKEY_H_ + +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct G1ElemStr G1ElemStr; +typedef struct G2ElemStr G2ElemStr; +typedef struct FpElemStr FpElemStr; +/// \endcond + +/// Checks if provided parameters result in a valid key +/*! + + + \param[in,out] ctx + The member context. + + \param[in] A_str + The A value of the member private key. + + \param[in] x_str + The x value of the member private key. + + \param[in] h1_str + The h1 value of the group public key. + + \param[in] w_str + The w value of the group public key. + + \retval true + if the input values would result in a valid member private key + + \retval false + if the input values would result in an invalid member private key + + \see MemberCreate + + */ +bool EpidMemberIsKeyValid(MemberCtx* ctx, G1ElemStr const* A_str, + FpElemStr const* x_str, G1ElemStr const* h1_str, + G2ElemStr const* w_str); + +#endif // EPID_MEMBER_SRC_VALIDATEKEY_H_ diff --git a/external/epid-sdk/epid/member/src/write_precomp.c b/external/epid-sdk/epid/member/src/write_precomp.c new file mode 100644 index 00000000..bd36983c --- /dev/null +++ b/external/epid-sdk/epid/member/src/write_precomp.c @@ -0,0 +1,36 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidMemberWritePrecomp implementation. +/*! \file */ +#include "epid/member/src/write_precomp.h" + +#include +#include + +#include "epid/member/src/context.h" + +EpidStatus EpidMemberWritePrecomp(MemberCtx const* ctx, + MemberPrecomp* precomp) { + if (!ctx) { + return kEpidBadArgErr; + } + if (!precomp) { + return kEpidBadArgErr; + } + + *precomp = ctx->precomp; + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/src/write_precomp.h b/external/epid-sdk/epid/member/src/write_precomp.h new file mode 100644 index 00000000..9cf2b5be --- /dev/null +++ b/external/epid-sdk/epid/member/src/write_precomp.h @@ -0,0 +1,46 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidMemberWritePrecomp interface. +/*! \file */ +#ifndef EPID_MEMBER_SRC_WRITE_PRECOMP_H_ +#define EPID_MEMBER_SRC_WRITE_PRECOMP_H_ + +#include "epid/common/errors.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct MemberPrecomp MemberPrecomp; +/// \endcond + +/// Serializes the pre-computed member settings. +/*! +\param[in] ctx +The member context. +\param[out] precomp +The Serialized pre-computed member settings. + +\returns ::EpidStatus + +\note +If the result is not ::kEpidNoErr, the content of precomp is undefined. + +\b Example + +\ref UserManual_GeneratingAnIntelEpidSignature +*/ +EpidStatus EpidMemberWritePrecomp(MemberCtx const* ctx, MemberPrecomp* precomp); + +#endif // EPID_MEMBER_SRC_WRITE_PRECOMP_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/efq.h b/external/epid-sdk/epid/member/tiny/math/efq.h new file mode 100644 index 00000000..f9805e11 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/efq.h @@ -0,0 +1,254 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of EFq math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_EFQ_H_ +#define EPID_MEMBER_TINY_MATH_EFQ_H_ +#include +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" + +/// \cond +typedef struct EccPointFq EccPointFq; +typedef struct EccPointJacobiFq EccPointJacobiFq; +typedef struct FpElem FpElem; +typedef struct FqElem FqElem; +/// \endcond + +/// Multiply two points in EFq. +/*! +This function is mitigated against software side-channel +attacks. + +\param[out] result of multiplying left and right. +\param[in] base The first operand to be multiplied. +\param[in] exp The second operand to be multiplied. +*/ +void EFqMulSSCM(EccPointJacobiFq* result, EccPointJacobiFq const* base, + FpElem const* exp); + +/// Exponentiate a point in EFq by an element of Fp. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. + +\returns 1 on success, 0 on failure +*/ +int EFqAffineExp(EccPointFq* result, EccPointFq const* base, FpElem const* exp); + +/// Sum the results of exponentiating two points in EFq by elements of Fp. +/*! +\param[out] result target. +\param[in] base0 the first base. +\param[in] exp0 the first exponent. +\param[in] base1 the second base. +\param[in] exp1 the second exponent. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqAffineMultiExp(EccPointFq* result, EccPointFq const* base0, + FpElem const* exp0, EccPointFq const* base1, + FpElem const* exp1); + +/// Sum the results of exponentiating two points in EFq by elements of Fp. +/*! +\param[out] result target. +\param[in] base0 the first base. +\param[in] exp0 the first exponent. +\param[in] base1 the second base. +\param[in] exp1 the second exponent. +\returns 1 on success, 0 on failure +*/ +void EFqMultiExp(EccPointJacobiFq* result, EccPointJacobiFq const* base0, + FpElem const* exp0, EccPointJacobiFq const* base1, + FpElem const* exp1); + +/// Add two points in EFq. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqAffineAdd(EccPointFq* result, EccPointFq const* left, + EccPointFq const* right); + +/// Double a point in EFq. +/*! +\param[out] result target. +\param[in] in the value to double. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqAffineDbl(EccPointFq* result, EccPointFq const* in); + +/// Double a point in EFq. +/*! +\param[out] result target. +\param[in] in the value to double. +*/ +void EFqDbl(EccPointJacobiFq* result, EccPointJacobiFq const* in); + +/// Add two points in EFq. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void EFqAdd(EccPointJacobiFq* result, EccPointJacobiFq const* left, + EccPointJacobiFq const* right); + +/// Generate a random point in EFq. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqRand(EccPointFq* result, BitSupplier rnd_func, void* rnd_param); + +/// Set a point's value. +/*! +\param[out] result target. +\param[in] x value to set. +\param[in] y value to set. +*/ +void EFqSet(EccPointJacobiFq* result, FqElem const* x, FqElem const* y); + +/// Test if a point is infinity. +/*! +\param[in] in the point to test. +\returns A value different from zero (i.e., true) indeed + the value is infinity. Zero (i.e., false) otherwise. +*/ +int EFqIsInf(EccPointJacobiFq const* in); + +/// Convert a point from Affine to Jacobi representation. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void EFqFromAffine(EccPointJacobiFq* result, EccPointFq const* in); + +/// Convert a point from Jacobi to Affine representation. +/*! +\param[out] result target. +\param[in] in value to set. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqToAffine(EccPointFq* result, EccPointJacobiFq const* in); + +/// Negate a point on EFq. +/*! +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void EFqNeg(EccPointJacobiFq* result, EccPointJacobiFq const* in); + +/// Test if two points on EFq are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int EFqEq(EccPointJacobiFq const* left, EccPointJacobiFq const* right); + +/// Hashes an arbitrary message to a point on EFq. +/*! +\param[out] result target. +\param[in] msg buffer to reinterpret. +\param[in] len length of msg in bytes. +\param[in] hashalg hash algorithm to use. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqHash(EccPointFq* result, unsigned char const* msg, size_t len, + HashAlg hashalg); + +/// Copy a point's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void EFqCp(EccPointFq* result, EccPointFq const* in); + +/// Test if two points on EFq are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int EFqEqAffine(EccPointFq const* left, EccPointFq const* right); + +/// Conditionally Set a point's value to one of two values. +/*! +\param[out] result target. +\param[in] true_val value to set if condition is true. +\param[in] false_val value to set if condition is false. +\param[in] truth_val value of condition. +*/ +void EFqCondSet(EccPointJacobiFq* result, EccPointJacobiFq const* true_val, + EccPointJacobiFq const* false_val, int truth_val); + +/// Copy a point's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void EFqJCp(EccPointJacobiFq* result, EccPointJacobiFq const* in); + +/// Set an element's value to infinity. +/*! +\param[out] result element to set. +*/ +void EFqInf(EccPointJacobiFq* result); + +/// Test if a point is on EFq. +/*! +\param[in] in the point to test. +\returns A value different from zero (i.e., true) indeed + the point is on the curve. Zero (i.e., false) otherwise. +*/ +int EFqOnCurve(EccPointFq const* in); + +/// Test if a point is on EFq. +/*! +\param[in] in the point to test. +\returns A value different from zero (i.e., true) indeed + the point is on the curve. Zero (i.e., false) otherwise. +*/ +int EFqJOnCurve(EccPointJacobiFq const* in); + +/// Generate a random point in EFq. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int EFqJRand(EccPointJacobiFq* result, BitSupplier rnd_func, void* rnd_param); + +#endif // EPID_MEMBER_TINY_MATH_EFQ_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/efq2.h b/external/epid-sdk/epid/member/tiny/math/efq2.h new file mode 100644 index 00000000..ca9dcb67 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/efq2.h @@ -0,0 +1,103 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of EFq2 math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_EFQ2_H_ +#define EPID_MEMBER_TINY_MATH_EFQ2_H_ + +/// \cond +typedef struct EccPointFq2 EccPointFq2; +typedef struct EccPointJacobiFq2 EccPointJacobiFq2; +typedef struct FpElem FpElem; +/// \endcond + +/// Test if a point is infinity. +/*! +\param[in] in the point to test. +\returns A value different from zero (i.e., true) indeed + the value is infinity. Zero (i.e., false) otherwise. +*/ +int EFq2IsInf(EccPointJacobiFq2 const* in); + +/// Convert a point from Affine to Jacobi representation. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void EFq2FromAffine(EccPointJacobiFq2* result, EccPointFq2 const* in); + +/// Convert a point from Jacobi to Affine representation. +/*! +\param[out] result target. +\param[in] in value to set. +\returns 1 on success, 0 on failure +*/ +int EFq2ToAffine(EccPointFq2* result, EccPointJacobiFq2 const* in); + +/// Double a point in EFq2. +/*! +\param[out] result target. +\param[in] in the value to double. +*/ +void EFq2Dbl(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in); + +/// Add two points in EFq2. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void EFq2Add(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, + EccPointJacobiFq2 const* right); + +/// Negate a point on EFq2. +/*! +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void EFq2Neg(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in); + +/// Multiply two points in EFq. +/*! +This function is mitigated against software side-channel +attacks. + +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void EFq2MulSSCM(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, + FpElem const* right); + +/// Test if two points on EFq2 are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int EFq2Eq(EccPointJacobiFq2 const* left, EccPointJacobiFq2 const* right); + +/// Test if a point is in EFq2. +/*! +\param[in] in the point to test. +\returns A value different from zero (i.e., true) indeed + the point is on the curve. Zero (i.e., false) otherwise. +*/ +int EFq2OnCurve(EccPointFq2 const* in); + +#endif // EPID_MEMBER_TINY_MATH_EFQ2_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/fp.h b/external/epid-sdk/epid/member/tiny/math/fp.h new file mode 100644 index 00000000..00820f52 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/fp.h @@ -0,0 +1,135 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Fp math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_FP_H_ +#define EPID_MEMBER_TINY_MATH_FP_H_ + +#include +#include +#include "epid/common/bitsupplier.h" + +/// \cond +typedef struct FpElem FpElem; +typedef struct VeryLargeInt VeryLargeInt; +/// \endcond + +/// Test if an element is in Fp +/*! +\param[in] in the element to test +\returns A value different from zero (i.e., true) indeed + the value is in the field. Zero (i.e., false) otherwise. +*/ +int FpInField(FpElem const* in); + +/// Add two elements of Fp +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void FpAdd(FpElem* result, FpElem const* left, FpElem const* right); + +/// Multiply two elements of Fp. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void FpMul(FpElem* result, FpElem const* left, FpElem const* right); + +/// Subtract two elements of Fp. +/*! +\param[out] result of subtracting left from right. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +*/ +void FpSub(FpElem* result, FpElem const* left, FpElem const* right); + +/// Exponentiate an element of Fp by a large integer. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +*/ +void FpExp(FpElem* result, FpElem const* base, VeryLargeInt const* exp); + +/// Negate an element of Fp. +/*! +\param[out] result target. +\param[in] in the value to negate. +*/ +void FpNeg(FpElem* result, FpElem const* in); + +/// Test if two elements in Fp are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int FpEq(FpElem const* left, FpElem const* right); + +/// Invert an element of Fp. +/*! +\param[out] result target. +\param[in] in the value to invert. +*/ +void FpInv(FpElem* result, FpElem const* in); + +/// Generate a random element of Fp. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int FpRand(FpElem* result, BitSupplier rnd_func, void* rnd_param); + +/// Generate a non-zero random element of Fp. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int FpRandNonzero(FpElem* result, BitSupplier rnd_func, void* rnd_param); + +/// Clear an element of Fp. +/*! +\param[out] result value to clear. +*/ +void FpClear(FpElem* result); + +/// Set a element of Fp's value. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void FpSet(FpElem* result, uint32_t in); + +/// Reinterpret a buffer as an element of Fp +/*! +\param[out] result target. +\param[in] hash buffer to reinterpret. +\param[in] len length of hash in bytes. +*/ +void FpFromHash(FpElem* result, unsigned char const* hash, size_t len); + +#endif // EPID_MEMBER_TINY_MATH_FP_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/fq.h b/external/epid-sdk/epid/member/tiny/math/fq.h new file mode 100644 index 00000000..a813c41f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/fq.h @@ -0,0 +1,168 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Fq math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_FQ_H_ +#define EPID_MEMBER_TINY_MATH_FQ_H_ + +#include +#include +#include "epid/common/bitsupplier.h" + +/// \cond +typedef struct FqElem FqElem; +typedef struct VeryLargeInt VeryLargeInt; +/// \endcond + +/// Test if an element is in Fq. +/*! +\param[in] in the element to test. +\returns A value different from zero (i.e., true) indeed + the value is in the field. Zero (i.e., false) otherwise. +*/ +int FqInField(FqElem const* in); + +/// Add two elements of Fq. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void FqAdd(FqElem* result, FqElem const* left, FqElem const* right); + +/// Subtract two elements of Fq. +/*! +\param[out] result of subtracting left from right. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +*/ +void FqSub(FqElem* result, FqElem const* left, FqElem const* right); + +/// Multiply two elements of Fq. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void FqMul(FqElem* result, FqElem const* left, FqElem const* right); + +/// Exponentiate an element of Fq by a large integer. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +*/ +void FqExp(FqElem* result, FqElem const* base, VeryLargeInt const* exp); + +/// Copy an element's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void FqCp(FqElem* result, FqElem const* in); + +/// Test if an element is zero. +/*! +\param[in] value the element to test. +\returns A value different from zero (i.e., true) if indeed + the value is zero. Zero (i.e., false) otherwise. +*/ +int FqIsZero(FqElem const* value); + +/// Invert an element of Fq. +/*! +\param[out] result the inverse of the element. +\param[in] in the element to invert. +*/ +void FqInv(FqElem* result, FqElem const* in); + +/// Negate an element of Fq. +/*! +This function was formerly called as FqConst. + +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void FqNeg(FqElem* result, FqElem const* in); + +/// Square an element of Fq. +/*! +\param[out] result the square of the element. +\param[in] in the element to square. +*/ +void FqSquare(FqElem* result, FqElem const* in); + +/// Clear an element's value. +/*! +\param[out] result element to clear. +*/ +void FqClear(FqElem* result); + +/// Set an element's value. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void FqSet(FqElem* result, uint32_t in); + +/// Test if two elements in Fq are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int FqEq(FqElem const* left, FqElem const* right); + +/// Conditionally Set an element's value to one of two values. +/*! +\param[out] result target. +\param[in] true_val value to set if condition is true. +\param[in] false_val value to set if condition is false. +\param[in] truth_val value of condition. +*/ +void FqCondSet(FqElem* result, FqElem const* true_val, FqElem const* false_val, + int truth_val); + +/// Compute the Square root of an element of Fq. +/*! +\param[out] result the square root of the element. +\param[in] in the element to find the square root of. +\returns A value different from zero (i.e., true) if the square root + exists. Zero (i.e., false) otherwise. +*/ +int FqSqrt(FqElem* result, FqElem const* in); + +/// Generate a random element of Fq. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int FqRand(FqElem* result, BitSupplier rnd_func, void* rnd_param); + +/// Reinterpret a buffer as an element of Fq +/*! +\param[out] result target. +\param[in] hash buffer to reinterpret. +\param[in] len length of hash in bytes. +*/ +void FqFromHash(FqElem* result, unsigned char const* hash, size_t len); + +#endif // EPID_MEMBER_TINY_MATH_FQ_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/fq12.h b/external/epid-sdk/epid/member/tiny/math/fq12.h new file mode 100644 index 00000000..861596e1 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/fq12.h @@ -0,0 +1,165 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Fq12 math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_FQ12_H_ +#define EPID_MEMBER_TINY_MATH_FQ12_H_ + +#include + +/// \cond +typedef struct Fq12Elem Fq12Elem; +typedef struct VeryLargeInt VeryLargeInt; +/// \endcond + +/// Add two elements of Fq12. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void Fq12Add(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right); + +/// Subtract two elements of Fq12. +/*! +\param[out] result of subtracting left from right. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +*/ +void Fq12Sub(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right); + +/// Square an element of Fq12. +/*! +\param[out] result the square of the element. +\param[in] in the element to square. +*/ +void Fq12Square(Fq12Elem* result, Fq12Elem const* in); + +/// Multiply two elements of Fq12. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void Fq12Mul(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right); + +/// Invert an element of Fq12. +/*! +\param[out] result the inverse of the element. +\param[in] in the element to invert. +*/ +void Fq12Inv(Fq12Elem* result, Fq12Elem const* in); + +/// Negate an element of Fq12. +/*! +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void Fq12Neg(Fq12Elem* result, Fq12Elem const* in); + +/// Set an element's value. +/*! +\param[out] result target. +\param[in] val value to set. +*/ +void Fq12Set(Fq12Elem* result, uint32_t val); + +/// Exponentiate an element of Fq12 by a large integer. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +*/ +void Fq12Exp(Fq12Elem* result, Fq12Elem const* base, VeryLargeInt const* exp); + +/// Multiply of exponentiation of elements of Fq12 by a large integers. +/*! +\param[out] result target. +\param[in] base0 the base. +\param[in] exp0 the exponent. +\param[in] base1 the base. +\param[in] exp1 the exponent. +\param[in] base2 the base. +\param[in] exp2 the exponent. +\param[in] base3 the base. +\param[in] exp3 the exponent. +*/ +void Fq12MultiExp(Fq12Elem* result, Fq12Elem const* base0, + VeryLargeInt const* exp0, Fq12Elem const* base1, + VeryLargeInt const* exp1, Fq12Elem const* base2, + VeryLargeInt const* exp2, Fq12Elem const* base3, + VeryLargeInt const* exp3); + +/// Test if two elements in Fq12 are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int Fq12Eq(Fq12Elem const* left, Fq12Elem const* right); + +/// Calculate the conjugate of an element of Fq2. +/*! +\param[out] result the conjugate of the element. +\param[in] in the element. +*/ +void Fq12Conj(Fq12Elem* result, Fq12Elem const* in); + +/// Calculate the cyclotomic exponentiation of an element of Fq12 +/// by another element of Fq12. +/*! +\param[in,out] result the base of the exponentiation. This will + receive the result. +\param[in] in the exponent. +\param[in] t pairing parameter t +*/ +void Fq12ExpCyc(Fq12Elem* result, Fq12Elem const* in, VeryLargeInt const* t); + +/// Calculate the cyclotomic square of an element of fq12. +/*! +\param[in,out] result result of the cyclotomic square. +\param[in] in the base. +*/ +void Fq12SqCyc(Fq12Elem* result, Fq12Elem const* in); + +/// Multiply two elements of Fq12. +/*! +Requires that b[2] = b[4] = b[5] = 0. +where right = ((b[0], b[2], b[4]), (b[1], b[3], b[5])) + +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void Fq12MulSpecial(Fq12Elem* result, Fq12Elem const* left, + Fq12Elem const* right); + +/// Copy an element's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void Fq12Cp(Fq12Elem* result, Fq12Elem const* in); + +/// Clear an element's value. +/*! +\param[out] result element to clear. +*/ +void Fq12Clear(Fq12Elem* result); + +#endif // EPID_MEMBER_TINY_MATH_FQ12_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/fq2.h b/external/epid-sdk/epid/member/tiny/math/fq2.h new file mode 100644 index 00000000..02efb71a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/fq2.h @@ -0,0 +1,155 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Fq2 math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_FQ2_H_ +#define EPID_MEMBER_TINY_MATH_FQ2_H_ + +#include + +/// \cond +typedef struct Fq2Elem Fq2Elem; +typedef struct FqElem FqElem; +typedef struct VeryLargeInt VeryLargeInt; +/// \endcond + +/// Copy an element's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void Fq2Cp(Fq2Elem* result, Fq2Elem const* in); + +/// Set an element's value. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void Fq2Set(Fq2Elem* result, uint32_t in); + +/// Clear an element's value. +/*! +\param[out] result element to clear. +*/ +void Fq2Clear(Fq2Elem* result); + +/// Add two elements of Fq2. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void Fq2Add(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right); + +/// Exponentiate an element of Fq2 by a large integer. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +*/ +void Fq2Exp(Fq2Elem* result, Fq2Elem const* base, VeryLargeInt const* exp); + +/// Subtract two elements of Fq2. +/*! +\param[out] result of subtracting left from right. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +*/ +void Fq2Sub(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right); + +/// Multiply two elements of Fq2. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void Fq2Mul(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right); + +/// Invert an element of Fq2. +/*! +\param[out] result the inverse of the element. +\param[in] in the element to invert. +*/ +void Fq2Inv(Fq2Elem* result, Fq2Elem const* in); + +/// Negate an element of Fq2. +/*! +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void Fq2Neg(Fq2Elem* result, Fq2Elem const* in); + +/// Calculate the conjugate of an element of Fq2. +/*! +\param[out] result the conjugate of the element. +\param[in] in the element. +*/ +void Fq2Conj(Fq2Elem* result, Fq2Elem const* in); + +/// Square an element of Fq2. +/*! +\param[out] result the square of the element. +\param[in] in the element to square. +*/ +void Fq2Square(Fq2Elem* result, Fq2Elem const* in); + +/// Multiply an element of Fq2 by and element of Fq. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void Fq2MulScalar(Fq2Elem* result, Fq2Elem const* left, FqElem const* right); + +/// Conditionally Set an element's value to one of two values. +/*! +\param[out] result target. +\param[in] true_val value to set if condition is true. +\param[in] false_val value to set if condition is false. +\param[in] truth_val value of condition. +*/ +void Fq2CondSet(Fq2Elem* result, Fq2Elem const* true_val, + Fq2Elem const* false_val, int truth_val); + +/// Test if two elements in Fq2 are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int Fq2Eq(Fq2Elem const* left, Fq2Elem const* right); + +/// Multiply an element of Fq2 by xi. +/*! +This function was formerly called as Fq2Const. + +\param[out] result of multiplying in by xi. +\param[in] in The first operand to be multiplied. + +*/ +void Fq2MulXi(Fq2Elem* result, Fq2Elem const* in); + +/// Test if an element is zero. +/*! +\param[in] value the element to test. +\returns A value different from zero (i.e., true) if indeed + the value is zero. Zero (i.e., false) otherwise. +*/ +int Fq2IsZero(Fq2Elem const* value); + +#endif // EPID_MEMBER_TINY_MATH_FQ2_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/fq6.h b/external/epid-sdk/epid/member/tiny/math/fq6.h new file mode 100644 index 00000000..72901dd7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/fq6.h @@ -0,0 +1,137 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Fq6 math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_FQ6_H_ +#define EPID_MEMBER_TINY_MATH_FQ6_H_ +#include + +/// \cond +typedef struct Fq2Elem Fq2Elem; +typedef struct Fq6Elem Fq6Elem; +/// \endcond + +/// Add two elements of Fq6. +/*! +\param[out] result of adding left and right. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +*/ +void Fq6Add(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right); + +/// Subtract two elements of Fq6. +/*! +\param[out] result of subtracting left from right. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +*/ +void Fq6Sub(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right); + +/// Multiply two elements of Fq6. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void Fq6Mul(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right); + +/// Invert an element of Fq6. +/*! +\param[out] result the inverse of the element. +\param[in] in the element to invert. +*/ +void Fq6Inv(Fq6Elem* result, Fq6Elem const* in); + +/// Negate an element of Fq6. +/*! +\param[out] result the negative of the element. +\param[in] in the element to negate. +*/ +void Fq6Neg(Fq6Elem* result, Fq6Elem const* in); + +/// Clear an element's value. +/*! +\param[out] result element to clear. +*/ +void Fq6Clear(Fq6Elem* result); + +/// Multiply an element of Fq6 by and element of Fq2. +/*! +\param[out] result of multiplying left and right. +\param[in] in The first operand to be multiplied. +\param[in] scalar The second operand to be multiplied. +*/ +void Fq6MulScalar(Fq6Elem* result, Fq6Elem const* in, Fq2Elem const* scalar); + +/// Multiply an element of Fq6 by V. +/*! +This function was formerly called as Fq2Const. + +\param[out] result of multiplying in and V. +\param[in] in The first operand to be multiplied. +*/ +void Fq6MulV(Fq6Elem* result, Fq6Elem const* in); + +/// Test if two elements in Fq6 are equal +/*! +\param[in] left The first operand to be tested. +\param[in] right The second operand to be tested. +\returns A value different from zero (i.e., true) if indeed + the values are equal. Zero (i.e., false) otherwise. +*/ +int Fq6Eq(Fq6Elem const* left, Fq6Elem const* right); + +/// Test if an element is zero. +/*! +\param[in] in the element to test. +\returns A value different from zero (i.e., true) if indeed + the value is zero. Zero (i.e., false) otherwise. +*/ +int Fq6IsZero(Fq6Elem const* in); + +/// Square an element of Fq6. +/*! +\param[out] result the square of the element. +\param[in] in the element to square. +*/ +void Fq6Square(Fq6Elem* result, Fq6Elem const* in); + +/// Copy an element's value +/*! +\param[out] result copy target. +\param[in] in copy source. +*/ +void Fq6Cp(Fq6Elem* result, Fq6Elem const* in); + +/// Conditionally Set an element's value to one of two values. +/*! +\param[out] result target. +\param[in] true_val value to set if condition is true. +\param[in] false_val value to set if condition is false. +\param[in] truth_val value of condition. +*/ +void Fq6CondSet(Fq6Elem* result, Fq6Elem const* true_val, + Fq6Elem const* false_val, int truth_val); + +/// Set an element's value. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void Fq6Set(Fq6Elem* result, uint32_t in); + +#endif // EPID_MEMBER_TINY_MATH_FQ6_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/hashwrap.h b/external/epid-sdk/epid/member/tiny/math/hashwrap.h new file mode 100644 index 00000000..bbba01a8 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/hashwrap.h @@ -0,0 +1,109 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +#ifndef EPID_MEMBER_TINY_MATH_HASHWRAP_H_ +#define EPID_MEMBER_TINY_MATH_HASHWRAP_H_ +/// Decleration of hash wrap function +/*! \file */ +#include +#include "epid/common/types.h" +#include "epid/member/tiny/math/mathtypes.h" + +#define SHA512_SUPPORT +#define SHA256_SUPPORT + +#ifdef SHA512_SUPPORT +#include "epid/member/tiny/math/sha512.h" +#endif + +#ifdef SHA256_SUPPORT +#include "epid/member/tiny/math/sha256.h" +#endif + +/// Sha Digest Element +typedef union sha_digest { +#ifdef SHA512_SUPPORT + uint8_t sha512_digest[SHA512_DIGEST_SIZE]; ///< Support digest for sha512 +#endif +#ifdef SHA256_SUPPORT + uint8_t sha256_digest[SHA256_DIGEST_SIZE]; ///< Support digest for sha256 +#endif + uint8_t digest[1]; ///< Pointer to digest +} sha_digest; + +/// Tiny Sha wrapper Element +typedef struct tiny_sha { + union { +#ifdef SHA512_SUPPORT + sha512_state sha512s; ///< The state of sha512 if supported +#endif +#ifdef SHA256_SUPPORT + sha256_state sha256s; ///< The state of sha256 if supported +#endif + } sha_state_t; ///< Store state of hash algorithm + HashAlg hash_alg; ///< The hash algorithem which selected +} tiny_sha; + +/// Initializes the hash state +/*! + +\param[in] sha_type +Type of hash algorithm + +\param[in,out] s +The hash state to initialize. +*/ +void tinysha_init(HashAlg sha_type, tiny_sha* s); + +/// Hashes data into state using a chosen hash algorithm +/*! + +\param[in,out] s +The hash state. Must be non-null or behavior is undefined. + +\param[in] data +The data to hash into s. + +\param[in] data_length +The size of data in bytes. + + +*/ +void tinysha_update(tiny_sha* s, void const* data, size_t data_length); + +/// Computes the hash algorithm in the digest buffer +/*! + +\param[out] digest +The computed digest. Must be non-null or behavior is undefined. + +\param[in] s +The hash state. Must be non-null or behavior is undefined. +*/ +void tinysha_final(unsigned char* digest, tiny_sha* s); + +/// Returns size of digest depending on hash algorithm +/*! + +\param[in] s +The hash state. Must be non-null or behavior is undefined. + +\returns +Size of digest + +*/ +size_t tinysha_digest_size(tiny_sha* s); + +#endif // EPID_MEMBER_TINY_MATH_HASHWRAP_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/math.parts b/external/epid-sdk/epid/member/tiny/math/math.parts new file mode 100644 index 00000000..ff17e733 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/math.parts @@ -0,0 +1,51 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +"""Build configuration for tiny math library. +""" +Import('*') +env.PartName('math') + +env.DependsOn([ + Component('member.tiny_stdlib'), + Component('tinycommon', requires=REQ.HEADERS) +]) + +include_files = Pattern(src_dir='.', + includes=['*.h'], + recursive=False).files() + +src_files = Pattern(src_dir='src', + includes=['*.c'], + recursive=False).files() + +env.Append(CPPPATH='#') + +outputs = env.Library('${PART_SHORT_NAME}', src_files) + +sdk_outs = env.Sdk(outputs) +env.SdkInclude(include_files, sub_dir='${PART_SHORT_NAME}') + +if 'install_lib' in env['MODE'] and 'shared' not in env['MODE']: + env.InstallLib(outputs) + +is_utest_build = False +for i in BUILD_TARGETS: + if "utest::" in str(i): + is_utest_build = True +if is_utest_build: + env.Part(parts_file='unittests/utest.parts', + CONFIG=DefaultEnvironment().subst('$CONFIG')) diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/precomp.h b/external/epid-sdk/epid/member/tiny/math/mathdefs.h similarity index 66% rename from external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/precomp.h rename to external/epid-sdk/epid/member/tiny/math/mathdefs.h index afc43730..0331cf99 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/precomp.h +++ b/external/epid-sdk/epid/member/tiny/math/mathdefs.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,10 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ +/// Common public definitions for math headers +/*! \file */ -#ifndef __PRECOMP_H__ -#define __PRECOMP_H__ +#ifndef EPID_MEMBER_TINY_MATH_MATHDEFS_H_ +#define EPID_MEMBER_TINY_MATH_MATHDEFS_H_ -#include "owncp.h" +/// Return code representing failure of math function +#define MATH_FAIL 0 +/// Return code representing success of math function +#define MATH_SUCCESS 1 -#endif /* __PRECOMP_H__ */ +#endif // EPID_MEMBER_TINY_MATH_MATHDEFS_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/mathtypes.h b/external/epid-sdk/epid/member/tiny/math/mathtypes.h new file mode 100644 index 00000000..5ea1a491 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/mathtypes.h @@ -0,0 +1,101 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of math types in tiny Intel(R) EPID. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_MATHTYPES_H_ +#define EPID_MEMBER_TINY_MATH_MATHTYPES_H_ + +/// number of 32bit words in a very large integer +#define NUM_ECC_DIGITS 8 + +#include + +/// Large integer. +/*! +VeryLargeInt* is always expected to point to a buffer +with NUM_ECC_DIGITS uint32_t sized words. +*/ +typedef struct VeryLargeInt { + uint32_t word[NUM_ECC_DIGITS]; ///< Large integer data +} VeryLargeInt; + +/// Used for multiplication +typedef struct VeryLargeIntProduct { + uint32_t word[2 * NUM_ECC_DIGITS]; ///< Large integer data +} VeryLargeIntProduct; + +/// Element of Fp. +typedef struct FpElem { + VeryLargeInt limbs; ///< An integer in [0, p-1] +} FpElem; + +/// Element of Fq. +typedef struct FqElem { + VeryLargeInt limbs; ///< An integer in [0, q-1] +} FqElem; + +/// Element of Fq2. +typedef struct Fq2Elem { + FqElem x0; ///< A coefficent in Fq + FqElem x1; ///< A coefficent in Fq +} Fq2Elem; + +/// Point in EFq. +typedef struct EccPointFq { + FqElem x; ///< x coordinate + FqElem y; ///< y coordinate +} EccPointFq; + +/// Point in EFq2. +typedef struct EccPointFq2 { + Fq2Elem x; ///< x coordinate + Fq2Elem y; ///< y coordinate +} EccPointFq2; + +/// Element of Fq6. +typedef struct Fq6Elem { + Fq2Elem y0; ///< A coefficent in Fq2 + Fq2Elem y1; ///< A coefficent in Fq2 + Fq2Elem y2; ///< A coefficent in Fq2 +} Fq6Elem; + +/// Element of Fq12. +typedef struct Fq12Elem { + Fq6Elem z0; ///< A coefficent in Fq6 + Fq6Elem z1; ///< A coefficent in Fq6 +} Fq12Elem; + +/// Element of EFq in Jacobi format. +typedef struct EccPointJacobiFq { + FqElem X; ///< x coordinate + FqElem Y; ///< y coordinate + FqElem Z; ///< z coordinate +} EccPointJacobiFq; + +/// Element of EFq2 in Jacobi format. +typedef struct EccPointJacobiFq2 { + Fq2Elem X; ///< x coordinate + Fq2Elem Y; ///< y coordinate + Fq2Elem Z; ///< z coordinate +} EccPointJacobiFq2; + +/// A scratch buffer for stateful pairing calls. +typedef struct PairingState { + Fq2Elem g[3][5]; ///< pairing scratch data +} PairingState; + +#endif // EPID_MEMBER_TINY_MATH_MATHTYPES_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/pairing.h b/external/epid-sdk/epid/member/tiny/math/pairing.h new file mode 100644 index 00000000..a8a6de6a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/pairing.h @@ -0,0 +1,48 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Definition of pairing math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_PAIRING_H_ +#define EPID_MEMBER_TINY_MATH_PAIRING_H_ +/*! + * \file + * \brief Tiny portable implementations of standard library functions + */ +/// \cond +typedef struct Fq12Elem Fq12Elem; +typedef struct EccPointFq EccPointFq; +typedef struct EccPointFq2 EccPointFq2; +typedef struct PairingState PairingState; +/// \endcond + +/// Initializes pairing environment. +/*! +\param[out] state pairing state information. +*/ +void PairingInit(PairingState* state); + +/// Computes a pairing according to the Optimal Ate pairing computation +/*! +\param[out] d target, an element in GT. +\param[in] P an element in G1. +\param[in] Q an element in G2. +\param[in,out] state pairing state information. +*/ +void PairingCompute(Fq12Elem* d, EccPointFq const* P, EccPointFq2 const* Q, + PairingState const* state); + +#endif // EPID_MEMBER_TINY_MATH_PAIRING_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/serialize.h b/external/epid-sdk/epid/member/tiny/math/serialize.h new file mode 100644 index 00000000..6008f3cf --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/serialize.h @@ -0,0 +1,183 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of de/serialize functionality. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_SERIALIZE_H_ +#define EPID_MEMBER_TINY_MATH_SERIALIZE_H_ +#include +#include + +/// \cond +typedef struct OctStr32 OctStr32; + +typedef struct VeryLargeInt VeryLargeInt; +typedef struct BigNumStr BigNumStr; + +typedef struct FqElem FqElem; +typedef struct FqElemStr FqElemStr; + +typedef struct FpElem FpElem; +typedef struct FpElemStr FpElemStr; + +typedef struct EccPointFq EccPointFq; +typedef struct G1ElemStr G1ElemStr; + +typedef struct EccPointFq2 EccPointFq2; +typedef struct G2ElemStr G2ElemStr; + +typedef struct Fq12Elem Fq12Elem; +typedef struct Fq12ElemStr Fq12ElemStr; +/// \endcond + +#if !defined(UNOPTIMIZED_SERIALIZATION) + +/// Serialize or deserailize a sequence of math objects +/*! +Converts layouts between native and portable or between portable and +native of the following types: VeryLargeInt and BigNumStr, +FqElem and FqElemStr, FpElem and FpElemStr, EccPointFq and G1ElemStr, +Fq12Elem and Fq12ElemStr. + +If input contain multiple values of supported types all will be converted. + +\note The following types are not supported: VeryLargeIntProduct. + +\note This function have the assumptions that the input structures are packed +such that consequent 32 byte fields would have no gap in between. + +\param[out] dest target buffer +\param [in] dest_size size of dest buffer +\param [in] src source data +\param [in] src_size size of src buffer +*/ +void SwapNativeAndPortableLayout(void* dest, size_t dest_size, void const* src, + size_t src_size); +#endif // !defined(UNOPTIMIZED_SERIALIZATION) + +/// Write a uint32_t to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* Uint32Serialize(OctStr32* dest, uint32_t src); + +/// Read a uint32_t from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* Uint32Deserialize(uint32_t* dest, OctStr32 const* src); + +/// Write a large integer to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* VliSerialize(BigNumStr* dest, VeryLargeInt const* src); + +/// Read a large integer from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* VliDeserialize(VeryLargeInt* dest, BigNumStr const* src); + +/// Write an element of Fq to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* FqSerialize(FqElemStr* dest, FqElem const* src); + +/// Read an element of Fq from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* FqDeserialize(FqElem* dest, FqElemStr const* src); + +/// Write an element of Fq12 to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* Fq12Serialize(Fq12ElemStr* dest, Fq12Elem const* src); + +/// Read an element of Fq12 from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* Fq12Deserialize(Fq12Elem* dest, Fq12ElemStr const* src); + +/// Write an element of Fp to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* FpSerialize(FpElemStr* dest, FpElem const* src); + +/// Read an element of Fp from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* FpDeserialize(FpElem* dest, FpElemStr const* src); + +/// Write a point on EFq to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* EFqSerialize(G1ElemStr* dest, EccPointFq const* src); + +/// Read a point on EFq from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* EFqDeserialize(EccPointFq* dest, G1ElemStr const* src); + +/// Write a point on EFq2 to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data written to dest +*/ +void* EFq2Serialize(G2ElemStr* dest, EccPointFq2 const* src); + +/// Read a point on EFq2 from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\returns pointer to next byte after final data read from to src +*/ +void const* EFq2Deserialize(EccPointFq2* dest, G2ElemStr const* src); + +#endif // EPID_MEMBER_TINY_MATH_SERIALIZE_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/sha256.h b/external/epid-sdk/epid/member/tiny/math/sha256.h new file mode 100644 index 00000000..0c1e7cc6 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/sha256.h @@ -0,0 +1,133 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/* + * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * @brief Interface to a SHA-256 implementation. + * + * Overview: SHA-256 is a NIST approved cryptographic hashing algorithm + * specified in FIPS 180. A hash algorithm maps data of arbitrary + * size to data of fixed length. + * + * Security: SHA-256 provides 128 bits of security against collision attacks + * and 256 bits of security against pre-image attacks. SHA-256 does + * NOT behave like a random oracle, but it can be used as one if + * the string being hashed is prefix-free encoded before hashing. + * + * Usage: 1) call tc_sha256_init to initialize a struct + * tc_sha256_state_struct before hashing a new string. + * + * 2) call tc_sha256_update to hash the next string segment; + * tc_sha256_update can be called as many times as needed to hash + * all of the segments of a string; the order is important. + * + * 3) call tc_sha256_final to out put the digest from a hashing + * operation. + */ + +#ifndef EPID_MEMBER_TINY_MATH_SHA256_H_ +#define EPID_MEMBER_TINY_MATH_SHA256_H_ + +#include +#include + +/// Block size +#define SHA256_BLOCK_SIZE (64) +/// Digest size +#define SHA256_DIGEST_SIZE (32) +/// Number of blocks in state +#define SHA256_STATE_BLOCKS (SHA256_DIGEST_SIZE / 4) + +/// The SHA state +/// \cond +typedef struct sha256_state { + unsigned int iv[SHA256_STATE_BLOCKS]; + uint64_t bits_hashed; + uint8_t leftover[SHA256_BLOCK_SIZE]; + size_t leftover_offset; +} sha256_state; +/// \endcond + +/** + * @brief SHA256 initialization procedure + * Initializes s + * @param s Sha256 state struct + */ +void tc_sha256_init(sha256_state* s); + +/** + * @brief SHA256 update procedure + * Hashes data_length bytes addressed by data into state s + + * @note Assumes s has been initialized by tc_sha256_init + * @warning The state buffer 'leftover' is left in memory after processing + * If your application intends to have sensitive data in this + * buffer, remind to erase it after the data has been processed + * @param s Sha256 state struct + * @param data message to hash + * @param datalen length of message to hash + */ +void tc_sha256_update(sha256_state* s, const uint8_t* data, size_t datalen); + +/** + * @brief SHA256 final procedure + * Inserts the completed hash computation into digest + * @return returns 1 + * returns 0 if: + * s == NULL, + * s->iv == NULL, + * digest == NULL + * @note Assumes: s has been initialized by tc_sha256_init + * digest points to at least SHA256_DIGEST_SIZE bytes + * @warning The state buffer 'leftover' is left in memory after processing + * If your application intends to have sensitive data in this + * buffer, remind to erase it after the data has been processed + * @param digest unsigned eight bit integer + * @param s Sha256 state struct + */ +void tc_sha256_final(uint8_t* digest, sha256_state* s); + +#endif // EPID_MEMBER_TINY_MATH_SHA256_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/sha512.h b/external/epid-sdk/epid/member/tiny/math/sha512.h new file mode 100644 index 00000000..8aa152b5 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/sha512.h @@ -0,0 +1,89 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Interface to a SHA-512 implementation. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_SHA512_H_ +#define EPID_MEMBER_TINY_MATH_SHA512_H_ + +#include +#include + +/// block size +#define SHA512_BLOCK_SIZE (128) +/// digest size +#define SHA512_DIGEST_SIZE (64) +/// number of words in SHA state +#define SHA512_DIGEST_WORDS (8) + +/// The SHA state +/// \cond +typedef struct sha512_state { + uint64_t iv[SHA512_DIGEST_WORDS]; + uint64_t bits_hashed_low; + uint64_t bits_hashed_high; + unsigned char leftover[SHA512_BLOCK_SIZE]; + unsigned int leftover_offset; +} sha512_state; +/// \endcond + +/// Initializes the hash state +/*! + + \param[in,out] s + The hash state to initialize. + */ +void tinysha512_init(sha512_state* s); + +/// Hashes data into state using SHA-512 +/*! + + \warning + The state buffer 'leftover' is left in memory after processing. If + your application intends to have sensitive data in this buffer, + remember to erase it after the data has been processed + + \param[in,out] s + The hash state. Must be non-null or behavior is undefined. + + \param[in] data + The data to hash into s. + + \param[in] data_length + The size of data in bytes. + */ +void tinysha512_update(sha512_state* s, void const* data, size_t data_length); + +/// Computes the SHA-512 hash in the digest buffer +/*! + + \note Assumes SHA512_DIGEST_SIZE bytes are available to accept the + digest. + + \warning + The state buffer 'leftover' is left in memory after processing. If + your application intends to have sensitive data in this buffer, + remember to erase it after the data has been processed + + \param[out] digest + The computed digest. Must be non-null or behavior is undefined. + + \param[in] s + The hash state. Must be non-null or behavior is undefined. + */ +void tinysha512_final(unsigned char* digest, sha512_state* s); + +#endif // EPID_MEMBER_TINY_MATH_SHA512_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/src/efq.c b/external/epid-sdk/epid/member/tiny/math/src/efq.c new file mode 100644 index 00000000..90867dce --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/efq.c @@ -0,0 +1,412 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of EFq math +/*! \file */ + +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/hashwrap.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static int EFqMakePoint(EccPointFq* output, FqElem* in) { + FqElem fq_sqrt = {0}; + FqElem fq_tmp = {0}; + FqSet(&fq_tmp, 3); + FqSquare(&fq_sqrt, in); + FqMul(&fq_sqrt, &fq_sqrt, in); + FqAdd(&fq_sqrt, &fq_sqrt, &fq_tmp); + if (!FqSqrt(&output->y, &fq_sqrt)) { + return 0; + } + FqCp(&output->x, in); + + return 1; +} + +void EFqMulSSCM(EccPointJacobiFq* result, EccPointJacobiFq const* base, + FpElem const* exp) { + EccPointJacobiFq efqj_1; + EccPointJacobiFq efqj_2; + + uint32_t position; + EFqInf(&efqj_1); + EFqJCp(&efqj_2, base); + for (position = 32 * NUM_ECC_DIGITS; position > 0; --position) { + EFqDbl(&efqj_1, &efqj_1); + EFqAdd(&efqj_2, base, &efqj_1); + EFqCondSet(&efqj_1, &efqj_2, &efqj_1, + VliTestBit(&(exp->limbs), position - 1)); + } + EFqJCp(result, &efqj_1); +} + +int EFqAffineExp(EccPointFq* result, EccPointFq const* base, + FpElem const* exp) { + EccPointJacobiFq efqj; + EFqFromAffine(&efqj, base); + EFqMulSSCM(&efqj, &efqj, exp); + return EFqToAffine(result, &efqj); +} + +int EFqAffineMultiExp(EccPointFq* result, EccPointFq const* base0, + FpElem const* exp0, EccPointFq const* base1, + FpElem const* exp1) { + EccPointJacobiFq efqj_base0; + EccPointJacobiFq efqj_base1; + EFqFromAffine(&efqj_base0, base0); + EFqFromAffine(&efqj_base1, base1); + EFqMultiExp(&efqj_base0, &efqj_base0, exp0, &efqj_base1, exp1); + return EFqToAffine(result, &efqj_base0); +} + +void EFqMultiExp(EccPointJacobiFq* result, EccPointJacobiFq const* base0, + FpElem const* exp0, EccPointJacobiFq const* base1, + FpElem const* exp1) { + EccPointJacobiFq efqj_base0; + EccPointJacobiFq efqj_a; + EccPointJacobiFq efqj_b; + int i, j; + + EFqAdd(&efqj_base0, base0, base1); + EFqInf(&efqj_a); + for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) { + for (j = 31; j >= 0; j--) { + EFqAdd(&efqj_a, &efqj_a, &efqj_a); + EFqInf(&efqj_b); + EFqJCp(&efqj_b, base0); + + EFqCondSet(&efqj_b, base1, &efqj_b, + (int)((exp1->limbs.word[i] >> j) & (0x1))); + + EFqCondSet(&efqj_b, &efqj_base0, &efqj_b, + (int)((exp0->limbs.word[i] >> j) & (exp1->limbs.word[i] >> j) & + (0x1))); + + EFqAdd(&efqj_b, &efqj_a, &efqj_b); + + EFqCondSet(&efqj_a, &efqj_b, &efqj_a, (int)(((exp0->limbs.word[i] >> j) | + (exp1->limbs.word[i] >> j)) & + (0x1))); + } + } + EFqJCp(result, &efqj_a); +} + +int EFqAffineAdd(EccPointFq* result, EccPointFq const* left, + EccPointFq const* right) { + EccPointJacobiFq efqj_a; + EccPointJacobiFq efqj_b; + if (EFqEqAffine(left, right)) return EFqAffineDbl(result, left); + + EFqFromAffine(&efqj_a, left); + EFqFromAffine(&efqj_b, right); + EFqAdd(&efqj_a, &efqj_a, &efqj_b); + + return EFqToAffine(result, &efqj_a); +} + +int EFqAffineDbl(EccPointFq* result, EccPointFq const* in) { + EccPointJacobiFq efqj_a; + EFqFromAffine(&efqj_a, in); + EFqAdd(&efqj_a, &efqj_a, &efqj_a); + + return EFqToAffine(result, &efqj_a); +} + +void EFqDbl(EccPointJacobiFq* result, EccPointJacobiFq const* in) { + FqElem fq_a; + FqElem fq_b; + + FqAdd(&(result->Z), &(in->Z), &(in->Z)); + FqMul(&(result->Z), &(result->Z), &(in->Y)); + FqSquare(&fq_a, &(in->X)); + FqAdd(&fq_b, &fq_a, &fq_a); + FqAdd(&fq_b, &fq_b, &fq_a); + FqSquare(&fq_a, &(in->Y)); + FqAdd(&fq_a, &fq_a, &fq_a); + FqSquare(&(result->Y), &fq_a); + FqAdd(&(result->Y), &(result->Y), &(result->Y)); + FqAdd(&fq_a, &fq_a, &fq_a); + FqMul(&fq_a, &fq_a, &(in->X)); + FqSquare(&(result->X), &fq_b); + FqSub(&(result->X), &(result->X), &fq_a); + FqSub(&(result->X), &(result->X), &fq_a); + FqSub(&fq_a, &fq_a, &(result->X)); + FqMul(&fq_a, &fq_a, &fq_b); + FqSub(&(result->Y), &fq_a, &(result->Y)); +} + +void EFqAdd(EccPointJacobiFq* result, EccPointJacobiFq const* left, + EccPointJacobiFq const* right) { + FqElem fq0; + FqElem fq1; + FqElem fq2; + FqElem fq3; + FqElem fq4; + FqElem fq5; + + if (FqIsZero(&(left->Z))) { + EFqJCp(result, right); + return; + } + if (FqIsZero(&(right->Z))) { + EFqJCp(result, left); + return; + } + + FqSquare(&fq2, &(right->Z)); + FqSquare(&fq3, &(left->Z)); + // P.X * Q.Z^2 + FqMul(&fq0, &(left->X), &fq2); + // Q.X * P.Z^2 + FqMul(&fq1, &(right->X), &fq3); + // Q.X*P.Z^2 - P*X+Q*Z^2 + FqSub(&fq5, &fq1, &fq0); + FqMul(&fq3, &(right->Y), &fq3); + // P.Y * Q.Z^3 + FqMul(&fq3, &(left->Z), &fq3); + FqMul(&fq2, &(left->Y), &fq2); + // Q.Y * P.Z^3 + FqMul(&fq2, &(right->Z), &fq2); + FqSub(&fq4, &fq3, &fq2); + + if (FqIsZero(&fq5)) { + if (FqIsZero(&fq4)) { + EFqDbl(result, left); + return; + } else { + EFqInf(result); + return; + } + } + FqMul(&(result->Z), &(left->Z), &(right->Z)); + FqMul(&(result->Z), &(result->Z), &fq5); + // Q.X*P.Z^2 + P*X+Q*Z^2 + FqAdd(&fq1, &fq0, &fq1); + FqMul(&fq2, &fq2, &fq5); + FqSquare(&fq5, &fq5); + FqMul(&fq1, &fq1, &fq5); + FqSquare(&(result->X), &fq4); + FqSub(&(result->X), &(result->X), &fq1); + FqMul(&fq2, &fq2, &fq5); + FqMul(&fq0, &fq0, &fq5); + FqSub(&fq0, &fq0, &(result->X)); + FqMul(&(result->Y), &fq4, &fq0); + FqSub(&(result->Y), &(result->Y), &fq2); +} + +int EFqRand(EccPointFq* result, BitSupplier rnd_func, void* rnd_param) { + FqElem fq; + do { + if (!FqRand(&fq, rnd_func, rnd_param)) { + return 0; + } + } while (!EFqMakePoint(result, &fq)); + return 1; +} + +void EFqSet(EccPointJacobiFq* result, FqElem const* x, FqElem const* y) { + FqCp(&result->X, x); + FqCp(&result->Y, y); + FqSet(&result->Z, 1); +} + +int EFqIsInf(EccPointJacobiFq const* in) { + return FqIsZero(&in->X) && FqIsZero(&in->Z) && (!FqIsZero(&in->Y)); +} + +void EFqFromAffine(EccPointJacobiFq* result, EccPointFq const* in) { + FqCp(&result->X, &in->x); + FqCp(&result->Y, &in->y); + FqSet(&result->Z, 1); +} + +int EFqToAffine(EccPointFq* result, EccPointJacobiFq const* in) { + FqElem fq_inv; + if (EFqIsInf(in)) { + return 0; + } + FqInv(&fq_inv, &in->Z); + FqMul(&result->x, &in->X, &fq_inv); + FqMul(&result->x, &result->x, &fq_inv); + FqMul(&result->y, &in->Y, &fq_inv); + FqMul(&result->y, &result->y, &fq_inv); + FqMul(&result->y, &result->y, &fq_inv); + + return 1; +} + +void EFqNeg(EccPointJacobiFq* result, EccPointJacobiFq const* in) { + FqCp(&result->X, &in->X); + FqNeg(&result->Y, &in->Y); + FqCp(&result->Z, &in->Z); +} + +int EFqEq(EccPointJacobiFq const* left, EccPointJacobiFq const* right) { + FqElem fq1; + FqElem fq2; + FqElem fq3; + FqElem fq4; + if (EFqIsInf(left) && EFqIsInf(right)) { + return 1; + } + if (EFqIsInf(left) || EFqIsInf(right)) { + return 0; + } + // Z1^2 + FqSquare(&fq1, &left->Z); + // Z2^2 + FqSquare(&fq2, &right->Z); + // (Z1^2)*X2 + FqMul(&fq3, &fq1, &right->X); + // (Z2^2)*X1 + FqMul(&fq4, &fq2, &left->X); + // Z1^3 + FqMul(&fq1, &fq1, &left->Z); + // Z2^3 + FqMul(&fq2, &fq2, &right->Z); + // (Z1^3)*Y2 + FqMul(&fq1, &fq1, &right->Y); + // (Z2^3)*Y1 + FqMul(&fq2, &fq2, &left->Y); + // (Z1^2)*X2 == (Z2^2)*X1 && (Z1^3)*Y2 == (Z2^3)*Y1 + return FqEq(&fq1, &fq2) && FqEq(&fq3, &fq4); +} + +int EFqHash(EccPointFq* result, unsigned char const* msg, size_t len, + HashAlg hashalg) { + tiny_sha hash_context; + FqElem three; + FqElem tmp; + uint32_t hash_salt = 0; + uint32_t buf = 0; + sha_digest hash_buf; + // 1/q in Fq + FqElem montgomery_r = { + 0x512ccfed, 0x2cd6d224, 0xed67f57d, 0xf3239a04, + 0x118e5b60, 0xb91a0da1, 0x00030f32, 0, + }; + if ((kSha512 != hashalg) && (kSha256 != hashalg)) { + return 0; + } + FqSet(&three, 3); + + for (hash_salt = 0; hash_salt < 0xFFFFFFFF; ++hash_salt) { + tinysha_init(hashalg, &hash_context); + + Uint32Serialize((OctStr32*)&buf, hash_salt); + tinysha_update(&hash_context, &buf, sizeof(buf)); + tinysha_update(&hash_context, msg, len); + + tinysha_final(hash_buf.digest, &hash_context); + + FqFromHash(&result->x, hash_buf.digest, tinysha_digest_size(&hash_context)); + FqSquare(&tmp, &result->x); + FqMul(&tmp, &tmp, &result->x); + FqAdd(&tmp, &tmp, &three); + if (FqSqrt(&result->y, &tmp)) { + FqNeg(&tmp, &result->y); + // Verify and Non-tiny member use montgomery representation to determine + // if negation is needed: this is to be compatible with them + FqMul(&montgomery_r, &result->y, &montgomery_r); + FqCondSet(&result->y, &tmp, &result->y, montgomery_r.limbs.word[0] & 1); + return 1; + } + } + return 0; +} + +void EFqCp(EccPointFq* result, EccPointFq const* in) { + FqCp(&result->x, &in->x); + FqCp(&result->y, &in->y); +} + +int EFqEqAffine(EccPointFq const* left, EccPointFq const* right) { + return FqEq(&left->x, &right->x) && FqEq(&left->y, &right->y); +} + +void EFqCondSet(EccPointJacobiFq* result, EccPointJacobiFq const* true_val, + EccPointJacobiFq const* false_val, int truth_val) { + FqCondSet(&result->X, &true_val->X, &false_val->X, truth_val); + FqCondSet(&result->Y, &true_val->Y, &false_val->Y, truth_val); + FqCondSet(&result->Z, &true_val->Z, &false_val->Z, truth_val); +} + +void EFqJCp(EccPointJacobiFq* result, EccPointJacobiFq const* in) { + FqCp(&result->X, &in->X); + FqCp(&result->Y, &in->Y); + FqCp(&result->Z, &in->Z); +} + +void EFqInf(EccPointJacobiFq* result) { + FqSet(&result->X, 0); + FqSet(&result->Y, 1); + FqSet(&result->Z, 0); +} + +int EFqOnCurve(EccPointFq const* in) { + // test that Y^2 mod q == (X^3 + a*Z^4*X + b*Z^6) mod q + // This simplifies to: Y^2 mod q == (X^3 + 3) mod q + // since: Z = 1 + // a = 0 + // b = 3 + FqElem t1; + FqElem t2; + FqSquare(&t1, &in->x); + FqMul(&t2, &in->x, &t1); + FqSquare(&t1, &in->y); + FqSub(&t1, &t1, &t2); + t1.limbs.word[0] -= 3; // check equal to curve b + // this operation will not always + // result in the same value as T1 - 3 + // however it will always result in a correct + // value for the zero check below + return FqIsZero(&t1); +} + +int EFqJOnCurve(EccPointJacobiFq const* in) { + FqElem fq1; + FqElem fq2; + + FqSquare(&fq1, &in->Z); + FqSquare(&fq2, &fq1); + FqMul(&fq2, &fq2, &fq1); // T2 = Z^6 + FqAdd(&fq1, &fq2, &fq2); + FqAdd(&fq1, &fq1, &fq2); // T1 = 3 * Z^6 + FqSquare(&fq2, &in->X); + FqMul(&fq2, &fq2, &in->X); // T2 = X^3 + FqAdd(&fq1, &fq1, &fq2); // T1 = X^3 + 3 Z^6 + FqSquare(&fq2, &in->Y); + FqMul(&fq1, &fq1, &in->Z); + FqMul(&fq2, &fq2, &in->Z); + return FqEq(&fq1, &fq2); // check Y^2 = X^3 + 3 Z^6 +} + +int EFqJRand(EccPointJacobiFq* result, BitSupplier rnd_func, void* rnd_param) { + FqElem fq; + do { + if (!FqRand(&fq, rnd_func, rnd_param)) { + return 0; + } + } while (!EFqMakePoint((EccPointFq*)result, &fq)); + + FqSet(&result->Z, 1); + + return 1; +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/efq2.c b/external/epid-sdk/epid/member/tiny/math/src/efq2.c new file mode 100644 index 00000000..80c66fea --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/efq2.c @@ -0,0 +1,253 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of EFq2 math +/*! \file */ + +#include "epid/member/tiny/math/efq2.h" + +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/fq2.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/vli.h" + +static void EFq2CondSet(EccPointJacobiFq2* result, + EccPointJacobiFq2 const* true_val, + EccPointJacobiFq2 const* false_val, int truth_val) { + Fq2CondSet(&result->X, &true_val->X, &false_val->X, truth_val); + Fq2CondSet(&result->Y, &true_val->Y, &false_val->Y, truth_val); + Fq2CondSet(&result->Z, &true_val->Z, &false_val->Z, truth_val); +} + +static void EFq2Cp(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in) { + Fq2Cp(&result->X, &in->X); + Fq2Cp(&result->Y, &in->Y); + Fq2Cp(&result->Z, &in->Z); +} + +static void EFq2Inf(EccPointJacobiFq2* result) { + Fq2Set(&result->X, 0); + Fq2Set(&result->Y, 1); + Fq2Set(&result->Z, 0); +} + +int EFq2IsInf(EccPointJacobiFq2 const* in) { + return Fq2IsZero(&in->X) && Fq2IsZero(&in->Z) && (!Fq2IsZero(&in->Y)); +} + +void EFq2FromAffine(EccPointJacobiFq2* result, EccPointFq2 const* in) { + Fq2Cp(&result->X, &in->x); + Fq2Cp(&result->Y, &in->y); + Fq2Set(&result->Z, 1); +} + +int EFq2ToAffine(EccPointFq2* result, EccPointJacobiFq2 const* in) { + Fq2Elem inverted_z; + if (EFq2IsInf(in)) { + return 0; + } + Fq2Inv(&inverted_z, &in->Z); + Fq2Mul(&result->x, &in->X, &inverted_z); + Fq2Mul(&result->x, &result->x, &inverted_z); + Fq2Mul(&result->y, &in->Y, &inverted_z); + Fq2Mul(&result->y, &result->y, &inverted_z); + Fq2Mul(&result->y, &result->y, &inverted_z); + return 1; +} + +void EFq2Dbl(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in) { + Fq2Elem a; + Fq2Elem b; + // Z3 = 2Z1 + Fq2Add(&(result->Z), &(in->Z), &(in->Z)); + // Z3 = 2*Z1*Y1 + Fq2Mul(&(result->Z), &(result->Z), &(in->Y)); + // A = X1^2 + Fq2Square(&a, &(in->X)); + // B = 2(X1^2) + Fq2Add(&b, &a, &a); + // B = 3(X1^2) + Fq2Add(&b, &b, &a); + // A = Y1^2 + Fq2Square(&a, &(in->Y)); + // A = 2*(Y1^2) + Fq2Add(&a, &a, &a); + // Y3 = 4*(Y1^4) + Fq2Square(&(result->Y), &a); + // Y3 = 8*(Y1^4) + Fq2Add(&(result->Y), &(result->Y), &(result->Y)); + // A = 4(Y1^2) + Fq2Add(&a, &a, &a); + // A = 4(Y1^2)*X1 + Fq2Mul(&a, &a, &(in->X)); + // X3 = B^2 + Fq2Square(&(result->X), &b); + // X3 = (B^2) - A + Fq2Sub(&(result->X), &(result->X), &a); + // X3 = (B^2) - 2A + Fq2Sub(&(result->X), &(result->X), &a); + // A = A - X3 + Fq2Sub(&a, &a, &(result->X)); + // A = B*(A-X3) + Fq2Mul(&a, &a, &b); + // Y3 = B*(A-X3) - 8*(Y1^4) + Fq2Sub(&(result->Y), &a, &(result->Y)); +} + +void EFq2Add(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, + EccPointJacobiFq2 const* right) { + Fq2Elem A; + Fq2Elem B; + Fq2Elem C; + Fq2Elem D; + Fq2Elem W; + Fq2Elem V; + + if (Fq2IsZero(&left->Z)) { + // If P = O, set R = Q and return + EFq2Cp(result, right); + return; + } + if (Fq2IsZero(&right->Z)) { + // If Q = O, set R = P and return. + EFq2Cp(result, left); + return; + } + // A = P.X * Q.Z^2 + Fq2Square(&C, &right->Z); + Fq2Mul(&A, &left->X, &C); + // B = Q.X * P.Z^2 + Fq2Square(&D, &left->Z); + Fq2Mul(&B, &right->X, &D); + // C = P.Y * Q.Z^3 + Fq2Mul(&C, &right->Z, &C); + Fq2Mul(&C, &left->Y, &C); + // D = Q.Y * P.Z^3 + Fq2Mul(&D, &left->Z, &D); + Fq2Mul(&D, &right->Y, &D); + // W = B - A + Fq2Sub(&W, &B, &A); + // V = D - C + Fq2Sub(&V, &D, &C); + if (Fq2IsZero(&W)) { + if (Fq2IsZero(&V)) { + EFq2Dbl(result, left); + return; + } else { + EFq2Inf(result); + return; + } + } + // R.Z = P.Z * Q.Z * W + Fq2Mul(&result->Z, &left->Z, &right->Z); + Fq2Mul(&result->Z, &result->Z, &W); + // R.X = V^2 - (A + B) * W^2 + Fq2Square(&result->X, &V); + Fq2Add(&B, &A, &B); + // Before squaring W save (C * W) to use in compitation of R.Y + Fq2Mul(&C, &C, &W); + Fq2Square(&W, &W); + Fq2Mul(&B, &B, &W); + Fq2Sub(&result->X, &result->X, &B); + // R.Y = V * (A * W^2 - R.X) - C * W^3 + Fq2Mul(&A, &A, &W); + Fq2Sub(&A, &A, &result->X); + Fq2Mul(&result->Y, &V, &A); + Fq2Mul(&C, &C, &W); + Fq2Sub(&result->Y, &result->Y, &C); +} + +void EFq2Neg(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in) { + Fq2Cp(&result->X, &in->X); + Fq2Neg(&result->Y, &in->Y); + Fq2Cp(&result->Z, &in->Z); +} + +void EFq2MulSSCM(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, + FpElem const* right) { + int position; + EccPointJacobiFq2 nv; + EccPointJacobiFq2 mv; + EFq2Inf(&nv); + EFq2Cp(&mv, left); + for (position = 32 * NUM_ECC_DIGITS - 1; position >= 0; position--) { + EFq2Dbl(&nv, &nv); + EFq2Add(&mv, left, &nv); + EFq2CondSet(&nv, &mv, &nv, + (int)(VliTestBit(&right->limbs, (uint32_t)position))); + } + EFq2Cp(result, &nv); +} + +int EFq2Eq(EccPointJacobiFq2 const* left, EccPointJacobiFq2 const* right) { + Fq2Elem t1; + Fq2Elem t2; + Fq2Elem t3; + Fq2Elem t4; + + if (EFq2IsInf(left) && EFq2IsInf(right)) { + return 1; + } + // if either left or right equals to inf return 0 + if (EFq2IsInf(left) || EFq2IsInf(right)) { + return 0; + } + Fq2Square(&t1, &(left->Z)); + Fq2Square(&t2, &(right->Z)); + Fq2Mul(&t3, &t1, &(right->X)); + Fq2Mul(&t4, &t2, &(left->X)); + Fq2Mul(&t1, &t1, &(left->Z)); + Fq2Mul(&t2, &t2, &(right->Z)); + Fq2Mul(&t1, &t1, &(right->Y)); + Fq2Mul(&t2, &t2, &(left->Y)); + return Fq2Eq(&t1, &t2) && Fq2Eq(&t3, &t4); +} + +int EFq2OnCurve(EccPointFq2 const* in) { + // test that Y^2 mod q == (X^3 + a*Z^4*X + b'*Z^6) mod q + // This simplifies to: Y^2 mod q == (X^3 + b') mod q + // since: Z = 1 + // a = 0 + // b = 3 + Fq2Elem t1; + Fq2Elem t2; + FqElem three; + // Fq2xi + Fq2Elem bp = {{{{0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}}}, + {{{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}}}}; + Fq2Elem const* x = &in->x; + Fq2Elem const* y = &in->y; + + // b' = b * inv(x1) + FqSet(&three, 3); + Fq2Inv(&bp, &bp); + Fq2MulScalar(&bp, &bp, &three); + + // set t2 = X^3 + Fq2Square(&t1, x); + Fq2Mul(&t2, x, &t1); + // set t2 = X^3 + b' + Fq2Add(&t2, &t2, &bp); + + // set t1 = Y^2 + Fq2Square(&t1, y); + + // set t1 = Y^2 - (X^3 + b') + Fq2Sub(&t1, &t1, &t2); + // return if t1 is zero + return Fq2IsZero(&t1); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/fp.c b/external/epid-sdk/epid/member/tiny/math/src/fp.c new file mode 100644 index 00000000..a7851227 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/fp.c @@ -0,0 +1,120 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Fp math +/*! \file */ + +#include "epid/member/tiny/math/fp.h" + +#include // for CHAR_BIT +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +/// A security parameter. In this version of Intel(R) EPID SDK, slen = 128 +#define EPID_SLEN 128 +/// buffer size of random integer t in INT32 +#define RAND_NUM_WORDS \ + ((sizeof(FpElem) + EPID_SLEN / CHAR_BIT) / sizeof(uint32_t)) + +static VeryLargeInt const epid20_p = {{0xD10B500D, 0xF62D536C, 0x1299921A, + 0x0CDC65FB, 0xEE71A49E, 0x46E5F25E, + 0xFFFCF0CD, 0xFFFFFFFF}}; +static FpElem const one = {{{1, 0, 0, 0, 0, 0, 0, 0}}}; +static VeryLargeInt const p_minus_one = {{0xD10B500C, 0xF62D536C, 0x1299921A, + 0x0CDC65FB, 0xEE71A49E, 0x46E5F25E, + 0xFFFCF0CD, 0xFFFFFFFF}}; + +int FpInField(FpElem const* in) { return (VliCmp(&in->limbs, &epid20_p) < 0); } + +void FpAdd(FpElem* result, FpElem const* left, FpElem const* right) { + VliModAdd(&result->limbs, &left->limbs, &right->limbs, &epid20_p); +} + +void FpMul(FpElem* result, FpElem const* left, FpElem const* right) { + VliModMul(&result->limbs, &left->limbs, &right->limbs, &epid20_p); +} + +void FpSub(FpElem* result, FpElem const* left, FpElem const* right) { + VliModSub(&result->limbs, &left->limbs, &right->limbs, &epid20_p); +} + +void FpExp(FpElem* result, FpElem const* base, VeryLargeInt const* exp) { + VliModExp(&result->limbs, &base->limbs, exp, &epid20_p); +} + +void FpNeg(FpElem* result, FpElem const* in) { + VliCondSet(&result->limbs, &epid20_p, &in->limbs, VliIsZero(&in->limbs)); + VliSub(&result->limbs, &epid20_p, &result->limbs); +} + +int FpEq(FpElem const* left, FpElem const* right) { + return (VliCmp(&left->limbs, &right->limbs) == 0); +} + +void FpInv(FpElem* result, FpElem const* in) { + VliModInv(&result->limbs, &in->limbs, &epid20_p); +} + +int FpRand(FpElem* result, BitSupplier rnd_func, void* rnd_param) { + VeryLargeIntProduct deserialized_t = {{0}}; + uint32_t t[RAND_NUM_WORDS] = {0}; + OctStr32 const* src = (OctStr32 const*)t; + + int i; + if (rnd_func(t, sizeof(FpElem) * CHAR_BIT + EPID_SLEN, rnd_param)) { + return 0; + } + for (i = RAND_NUM_WORDS - 1; i >= 0; i--) { + src = Uint32Deserialize(deserialized_t.word + i, src); + } + VliModBarrett(&result->limbs, &deserialized_t, &epid20_p); + return 1; +} + +int FpRandNonzero(FpElem* result, BitSupplier rnd_func, void* rnd_param) { + VeryLargeIntProduct deserialized_t = {{0}}; + uint32_t t[RAND_NUM_WORDS] = {0}; + OctStr32 const* src = (OctStr32 const*)t; + int i; + if (rnd_func(t, sizeof(FpElem) * CHAR_BIT + EPID_SLEN, rnd_param)) { + return 0; + } + for (i = RAND_NUM_WORDS - 1; i >= 0; i--) { + src = Uint32Deserialize(deserialized_t.word + i, src); + } + VliModBarrett(&result->limbs, &deserialized_t, &p_minus_one); + // (t mod(p-1)) + 1 gives number in [1,p-1] + FpAdd(result, result, &one); + return 1; +} + +void FpClear(FpElem* result) { VliClear(&result->limbs); } + +void FpSet(FpElem* result, uint32_t in) { + FpClear(result); + *(uint32_t*)(result->limbs.word) = in; +} + +void FpFromHash(FpElem* result, unsigned char const* hash, size_t len) { + size_t i; + VeryLargeIntProduct vli; + memset(&vli, 0, sizeof(vli)); + for (i = 0; i < len; i++) { + ((uint8_t*)vli.word)[len - i - 1] = hash[i]; + } + VliModBarrett(&result->limbs, &vli, &epid20_p); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/fq.c b/external/epid-sdk/epid/member/tiny/math/src/fq.c new file mode 100644 index 00000000..33a7367b --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/fq.c @@ -0,0 +1,126 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Fq math +/*! \file */ + +#include "epid/member/tiny/math/fq.h" + +#include // for CHAR_BIT +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +/// A security parameter. In this version of Intel(R) EPID SDK, slen = 128 +#define EPID_SLEN 128 +/// buffer size of random integer t in INT32 +#define RAND_NUM_WORDS \ + ((sizeof(FpElem) + EPID_SLEN / CHAR_BIT) / sizeof(uint32_t)) + +static VeryLargeInt const epid20_q = {{0xAED33013, 0xD3292DDB, 0x12980A82, + 0x0CDC65FB, 0xEE71A49F, 0x46E5F25E, + 0xFFFCF0CD, 0xFFFFFFFF}}; + +int FqInField(FqElem const* in) { return (VliCmp(&in->limbs, &epid20_q) < 0); } + +void FqAdd(FqElem* result, FqElem const* left, FqElem const* right) { + VliModAdd(&result->limbs, &left->limbs, &right->limbs, &epid20_q); +} + +void FqSub(FqElem* result, FqElem const* left, FqElem const* right) { + VliModSub(&result->limbs, &left->limbs, &right->limbs, &epid20_q); +} + +void FqMul(FqElem* result, FqElem const* left, FqElem const* right) { + VliModMul(&result->limbs, &left->limbs, &right->limbs, &epid20_q); +} + +void FqExp(FqElem* result, FqElem const* base, VeryLargeInt const* exp) { + VliModExp(&result->limbs, &base->limbs, exp, &epid20_q); +} + +void FqCp(FqElem* result, FqElem const* in) { + VliSet(&result->limbs, &in->limbs); +} + +int FqIsZero(FqElem const* value) { return VliIsZero(&value->limbs); } + +void FqInv(FqElem* result, FqElem const* in) { + VliModInv(&result->limbs, &in->limbs, &epid20_q); +} + +void FqNeg(FqElem* result, FqElem const* in) { + VliCondSet(&result->limbs, &epid20_q, &in->limbs, VliIsZero(&in->limbs)); + VliSub(&result->limbs, &epid20_q, &result->limbs); +} + +void FqSquare(FqElem* result, FqElem const* in) { + VliModSquare(&result->limbs, &in->limbs, &epid20_q); +} + +void FqClear(FqElem* result) { VliClear(&result->limbs); } + +void FqSet(FqElem* result, uint32_t in) { + FqClear(result); + *(uint32_t*)(result->limbs.word) = in; +} + +int FqEq(FqElem const* left, FqElem const* right) { + return (VliCmp(&left->limbs, &right->limbs) == 0); +} + +void FqCondSet(FqElem* result, FqElem const* true_val, FqElem const* false_val, + int truth_val) { + VliCondSet(&result->limbs, &true_val->limbs, &false_val->limbs, truth_val); +} + +int FqSqrt(FqElem* result, FqElem const* in) { + VeryLargeInt tmp; + // Intel(R) EPID 2.0 parameter q meets q = 3 mod 4. + // Square root can be computed as in^((q+1)/4) mod q. + VliRShift(&tmp, &epid20_q, 2); // tmp = (q-3)/4 + (tmp.word[0])++; // tmp = (q+1)/4 + FqExp(result, in, &tmp); // result = in^((q+1)/4) mod q + // validate sqrt exists + VliModSquare(&tmp, &result->limbs, &epid20_q); + return 0 == VliCmp(&tmp, &in->limbs); +} + +int FqRand(FqElem* result, BitSupplier rnd_func, void* rnd_param) { + VeryLargeIntProduct deserialized_t = {{0}}; + uint32_t t[RAND_NUM_WORDS] = {0}; + OctStr32 const* src = (OctStr32 const*)t; + int i; + + if (rnd_func(t, sizeof(FpElem) * CHAR_BIT + EPID_SLEN, rnd_param)) { + return 0; + } + for (i = RAND_NUM_WORDS - 1; i >= 0; i--) { + src = Uint32Deserialize(deserialized_t.word + i, src); + } + VliModBarrett(&result->limbs, &deserialized_t, &epid20_q); + return 1; +} + +void FqFromHash(FqElem* result, unsigned char const* hash, size_t len) { + size_t i; + VeryLargeIntProduct vli; + memset(&vli, 0, sizeof(vli)); + for (i = 0; i < len; i++) { + ((uint8_t*)vli.word)[len - i - 1] = hash[i]; + } + VliModBarrett(&result->limbs, &vli, &epid20_q); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/fq12.c b/external/epid-sdk/epid/member/tiny/math/src/fq12.c new file mode 100644 index 00000000..dd7176b7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/fq12.c @@ -0,0 +1,282 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Fq12 math +/*! \file */ + +#include "epid/member/tiny/math/fq12.h" + +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/fq2.h" +#include "epid/member/tiny/math/fq6.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static void Fq12MulScalar(Fq12Elem* result, Fq12Elem const* left, + Fq6Elem const* right) { + Fq6Mul(&result->z0, &left->z0, right); + Fq6Mul(&result->z1, &left->z1, right); +} + +static void Fq4Square(Fq2Elem* out0, Fq2Elem* out1, Fq2Elem const* in0, + Fq2Elem const* in1) { + Fq2Elem tmp; + Fq2Elem* temp = &tmp; + Fq2Square(temp, in1); + Fq2Add(out1, in0, in1); + Fq2Square(out0, in0); + Fq2Square(out1, out1); + Fq2Sub(out1, out1, temp); + Fq2Sub(out1, out1, out0); + Fq2MulXi(temp, temp); + Fq2Add(out0, out0, temp); +} + +static void Fq12CondSet(Fq12Elem* result, Fq12Elem const* true_val, + Fq12Elem const* false_val, int truth_val) { + Fq6CondSet(&result->z0, &true_val->z0, &false_val->z0, truth_val); + Fq6CondSet(&result->z1, &true_val->z1, &false_val->z1, truth_val); +} + +void Fq12Add(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right) { + Fq6Add(&result->z0, &left->z0, &right->z0); + Fq6Add(&result->z1, &left->z1, &right->z1); +} + +void Fq12Sub(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right) { + Fq6Sub(&result->z0, &left->z0, &right->z0); + Fq6Sub(&result->z1, &left->z1, &right->z1); +} + +void Fq12Square(Fq12Elem* result, Fq12Elem const* in) { + Fq6Elem tmpa; + Fq6Elem* temp_a = &tmpa; + Fq6Square(temp_a, &in->z1); + Fq6Add(&result->z1, &in->z0, &in->z1); + Fq6Square(&result->z0, &in->z0); + Fq6Square(&result->z1, &result->z1); + Fq6Sub(&result->z1, &result->z1, (&result->z0)); + Fq6Sub(&result->z1, &result->z1, temp_a); + Fq6MulV(temp_a, temp_a); + Fq6Add((&result->z0), (&result->z0), temp_a); +} + +void Fq12Mul(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right) { + Fq6Elem A; + Fq6Elem B; + Fq6Elem* t0 = &A; + Fq6Elem* t1 = &B; + + Fq6Add(t0, &left->z0, &left->z1); + Fq6Add(t1, &right->z0, &right->z1); + Fq6Mul(t0, t0, t1); + Fq6Mul(&result->z0, &left->z0, &right->z0); + Fq6Sub(t0, t0, &result->z0); + Fq6Mul(t1, &left->z1, &right->z1); + Fq6Sub(&result->z1, t0, t1); + Fq6MulV(t1, t1); + Fq6Add(&result->z0, &result->z0, t1); +} + +void Fq12Inv(Fq12Elem* result, Fq12Elem const* in) { + Fq12Elem tmp3; + Fq12Elem tmp4; + Fq12Elem* const temp3 = &tmp3; + Fq12Elem* const temp4 = &tmp4; + Fq12Conj(temp3, in); + Fq12Mul(temp4, temp3, in); + Fq6Inv(&temp4->z0, &temp4->z0); + Fq12MulScalar(result, temp3, &temp4->z0); +} + +void Fq12Neg(Fq12Elem* result, Fq12Elem const* in) { + Fq6Neg(&result->z0, &in->z0); + Fq6Neg(&result->z1, &in->z1); +} + +void Fq12Set(Fq12Elem* result, uint32_t val) { + Fq12Clear(result); + FqSet(&(*result).z0.y0.x0, val); +} + +void Fq12Exp(Fq12Elem* result, Fq12Elem const* base, VeryLargeInt const* exp) { + int i; + Fq12Elem tmp, tmp2, *const temp = &tmp, *const temp2 = &tmp2; + Fq12Clear(temp); + temp->z0.y0.x0.limbs.word[0]++; + for (i = NUM_ECC_DIGITS * 32 - 1; i >= 0; i--) { + Fq12Square(temp, temp); + Fq12Mul(temp2, temp, base); + + Fq12CondSet(temp, temp2, temp, + (int)((exp->word[i / 32] >> (i & 31)) & (0x1))); + } + Fq12Cp(result, temp); +} + +void Fq12MultiExp(Fq12Elem* result, Fq12Elem const* base0, + VeryLargeInt const* exp0, Fq12Elem const* base1, + VeryLargeInt const* exp1, Fq12Elem const* base2, + VeryLargeInt const* exp2, Fq12Elem const* base3, + VeryLargeInt const* exp3) { + Fq12Elem tmp; + Fq12Exp(result, base0, exp0); + Fq12Exp(&tmp, base1, exp1); + Fq12Mul(result, result, &tmp); + Fq12Exp(&tmp, base2, exp2); + Fq12Mul(result, result, &tmp); + Fq12Exp(&tmp, base3, exp3); + Fq12Mul(result, result, &tmp); +} + +int Fq12Eq(Fq12Elem const* left, Fq12Elem const* right) { + return Fq6Eq(&left->z0, &right->z0) && Fq6Eq(&left->z0, &right->z0); +} + +void Fq12Conj(Fq12Elem* result, Fq12Elem const* in) { + Fq6Cp(&result->z0, &in->z0); + Fq6Neg(&result->z1, &in->z1); +} + +void Fq12ExpCyc(Fq12Elem* result, Fq12Elem const* in, VeryLargeInt const* t) { + int i = 0; + Fq12Elem ac; + Fq12Elem* const acc = ∾ + Fq12Cp(acc, in); + Fq12Cp(result, in); + + for (i = 61; i >= 0; i--) { + Fq12SqCyc(result, result); + + if (VliTestBit(t, (uint32_t)i)) { + Fq12Mul(result, result, acc); + } + } +} + +void Fq12SqCyc(Fq12Elem* result, Fq12Elem const* in) { + Fq2Elem const* a0 = &(in->z0).y0; + Fq2Elem const* a1 = &(in->z1).y0; + Fq2Elem const* a2 = &(in->z0).y1; + Fq2Elem const* a3 = &(in->z1).y1; + Fq2Elem const* a4 = &(in->z0).y2; + Fq2Elem const* a5 = &(in->z1).y2; + Fq2Elem* e0 = &(result->z0).y0; + Fq2Elem* e1 = &(result->z1).y0; + Fq2Elem* e2 = &(result->z0).y1; + Fq2Elem* e3 = &(result->z1).y1; + Fq2Elem* e4 = &(result->z0).y2; + Fq2Elem* e5 = &(result->z1).y2; + Fq2Elem tmp1; + Fq2Elem tmp2; + Fq2Elem tmp3; + Fq2Elem tmp4; + Fq2Elem* temp1 = &tmp1; + Fq2Elem* temp2 = &tmp2; + Fq2Elem* temp3 = &tmp3; + Fq2Elem* temp4 = &tmp4; + + Fq4Square(temp1, temp2, a0, a3); // t00,t11 = sq(a0,a3) + Fq2Add(e0, a0, a0); // e0 = 3*t00 - 2*a0 + Fq2Sub(e0, temp1, e0); + Fq2Add(e0, temp1, e0); + Fq2Add(e0, temp1, e0); + Fq2Add(e3, a3, a3); // e3 = 3*t11 - 2*a3 + Fq2Add(e3, temp2, e3); + Fq2Add(e3, temp2, e3); + Fq2Add(e3, temp2, e3); + + Fq4Square(temp1, temp2, a2, a5); // t02, t10 = sq(a2,a5) + Fq2MulXi(temp2, temp2); + Fq4Square(temp3, temp4, a1, a4); // t01, t12 = sq(a1,a4) + + Fq2Add(e4, a4, a4); + Fq2Sub(e4, temp1, e4); + Fq2Add(e4, temp1, e4); + Fq2Add(e4, temp1, e4); + Fq2Add(e1, a1, a1); + Fq2Add(e1, temp2, e1); + Fq2Add(e1, temp2, e1); + Fq2Add(e1, temp2, e1); + + Fq2Add(e2, a2, a2); + Fq2Sub(e2, temp3, e2); + Fq2Add(e2, temp3, e2); + Fq2Add(e2, temp3, e2); + Fq2Add(e5, a5, a5); + Fq2Add(e5, temp4, e5); + Fq2Add(e5, temp4, e5); + Fq2Add(e5, temp4, e5); +} + +void Fq12MulSpecial(Fq12Elem* result, Fq12Elem const* left, + Fq12Elem const* right) { + Fq2Elem T3; + Fq2Elem* t3 = &T3; + Fq2Elem const* b0 = &(right->z0.y0); + Fq2Elem const* b1 = &right->z1.y0; + Fq2Elem const* b3 = &right->z1.y1; + Fq6Elem T0; + Fq6Elem T1; + Fq6Elem T2; + Fq6Elem* t0 = &T0; + Fq6Elem* t1 = &T1; + Fq6Elem* t2 = &T2; + Fq6Elem const* a0 = &left->z0; + Fq6Elem const* a1 = &left->z1; + Fq6Elem* r0 = &result->z0; + Fq6Elem* r1 = &result->z1; + +#if defined(DEBUG) + // validate algorithm precondition + if (!Fq2IsZero(&right->z0.y1) || !Fq2IsZero(&right->z0.y2) || + !Fq2IsZero(&right->z1.y2)) { + memset(&result, 0xff, sizeof(result)); + return; + } +#endif // defined(DEBUG) + + Fq6Add(t0, a0, a1); + Fq2Add(t3, b0, b1); + Fq6MulScalar(t0, t0, t3); + + Fq6MulScalar(t2, a1, b3); + Fq6MulV(t2, t2); + + Fq6MulScalar(t1, a1, b1); + Fq6Sub(t0, t0, t1); + Fq6Add(t2, t2, t1); + Fq6MulV(t2, t2); + + Fq6MulScalar(t1, a0, b0); + Fq6Add(t2, t2, t1); + Fq6Sub(t0, t0, t1); + + Fq6MulScalar(t1, a0, b3); + Fq6MulV(t1, t1); + Fq6Add(r1, t1, t0); + Fq6Cp(r0, t2); +} + +void Fq12Cp(Fq12Elem* result, Fq12Elem const* in) { + Fq6Cp(&result->z0, &in->z0); + Fq6Cp(&result->z1, &in->z1); +} + +void Fq12Clear(Fq12Elem* result) { + Fq6Clear(&result->z0); + Fq6Clear(&result->z1); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/fq2.c b/external/epid-sdk/epid/member/tiny/math/src/fq2.c new file mode 100644 index 00000000..754c334f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/fq2.c @@ -0,0 +1,150 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Fq2 math +/*! \file */ + +#include "epid/member/tiny/math/fq2.h" + +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/mathtypes.h" + +void Fq2Cp(Fq2Elem* result, Fq2Elem const* in) { + FqCp(&(result->x0), &(in->x0)); + FqCp(&(result->x1), &(in->x1)); +} + +void Fq2Set(Fq2Elem* result, uint32_t in) { + FqSet(&(result->x0), in); + FqClear(&(result->x1)); +} + +void Fq2Clear(Fq2Elem* result) { + FqClear(&result->x0); + FqClear(&result->x1); +} + +void Fq2Add(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right) { + FqAdd(&(result->x0), &(left->x0), &(right->x0)); + FqAdd(&(result->x1), &(left->x1), &(right->x1)); +} + +void Fq2Exp(Fq2Elem* result, Fq2Elem const* base, VeryLargeInt const* exp) { + int i, j; + Fq2Elem tmp; + Fq2Elem tmp2; + Fq2Elem* temp = &tmp; + Fq2Elem* temp2 = &tmp2; + FqSet(&(temp->x0), 1); + FqClear(&(temp->x1)); + for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) { + for (j = 31; j >= 0; j--) { + Fq2Square(temp, temp); + Fq2Mul(temp2, temp, base); + + Fq2CondSet(temp, temp2, temp, (int)((exp->word[i] >> j) & (0x1))); + } + } + Fq2Cp(result, temp); +} + +void Fq2Sub(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right) { + FqSub(&(result->x0), &(left->x0), &(right->x0)); + FqSub(&(result->x1), &(left->x1), &(right->x1)); +} + +void Fq2Mul(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right) { + FqElem A; + FqElem B; + FqElem* a = &A; + FqElem* b = &B; + + FqAdd(a, &left->x0, &left->x1); + FqAdd(b, &right->x0, &right->x1); + FqMul(a, a, b); + FqMul(&result->x0, &left->x0, &right->x0); + FqSub(a, a, &result->x0); + FqMul(b, &left->x1, &right->x1); + FqSub(&result->x1, a, b); + FqNeg(b, b); // b = b*beta + FqAdd(&result->x0, &result->x0, b); +} + +void Fq2Inv(Fq2Elem* result, Fq2Elem const* in) { + FqElem tmp; + FqElem tmp2; + FqElem* temp = &tmp; + FqElem* temp2 = &tmp2; + FqSquare(temp, &in->x1); + FqSquare(temp2, &in->x0); + FqAdd(temp, temp, temp2); + FqInv(temp, temp); + FqMul(&result->x0, temp, &in->x0); + FqNeg(temp, temp); + FqMul(&result->x1, temp, &in->x1); +} + +void Fq2Neg(Fq2Elem* result, Fq2Elem const* in) { + FqNeg(&(result->x0), &(in->x0)); + FqNeg(&(result->x1), &(in->x1)); +} + +void Fq2Conj(Fq2Elem* result, Fq2Elem const* in) { + FqCp(&result->x0, &in->x0); + FqNeg(&result->x1, &in->x1); +} + +void Fq2Square(Fq2Elem* result, Fq2Elem const* in) { + FqElem tmpa; + FqElem* temp_a = &tmpa; + FqElem tmpb; + FqElem* temp_b = &tmpb; + FqAdd(temp_a, &in->x0, &in->x1); + FqMul(temp_b, &in->x0, &in->x1); + FqSub(&result->x0, &in->x0, &in->x1); + FqMul(&result->x0, temp_a, &result->x0); + FqAdd(&result->x1, temp_b, temp_b); +} + +void Fq2MulScalar(Fq2Elem* result, Fq2Elem const* left, FqElem const* right) { + FqMul(&(result->x0), &(left->x0), right); + FqMul(&(result->x1), &(left->x1), right); +} + +void Fq2CondSet(Fq2Elem* result, Fq2Elem const* true_val, + Fq2Elem const* false_val, int truth_val) { + FqCondSet(&(result->x0), &(true_val->x0), &(false_val->x0), truth_val); + FqCondSet(&(result->x1), &(true_val->x1), &(false_val->x1), truth_val); +} + +int Fq2Eq(Fq2Elem const* left, Fq2Elem const* right) { + return FqEq(&(left->x0), &(right->x0)) && FqEq(&(left->x1), &(right->x1)); +} + +void Fq2MulXi(Fq2Elem* result, Fq2Elem const* in) { + // has the same effect as Fq2Mul(result, in, &Fq2xi) with better speed, low + // space; + FqElem tmp; + FqElem* temp = &tmp; + FqAdd(temp, &in->x0, &in->x0); + FqSub(temp, temp, &in->x1); + FqAdd(&result->x1, &in->x1, &in->x1); + FqAdd(&result->x1, &result->x1, &in->x0); + FqCp(&result->x0, temp); +} + +int Fq2IsZero(Fq2Elem const* value) { + return FqIsZero(&value->x0) && FqIsZero(&value->x1); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/fq6.c b/external/epid-sdk/epid/member/tiny/math/src/fq6.c new file mode 100644 index 00000000..b013037a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/fq6.c @@ -0,0 +1,192 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Fq6 math +/*! \file */ + +#include "epid/member/tiny/math/fq6.h" + +#include "epid/member/tiny/math/fq2.h" +#include "epid/member/tiny/math/mathtypes.h" + +void Fq6Add(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right) { + Fq2Add(&result->y0, &left->y0, &right->y0); + Fq2Add(&result->y1, &left->y1, &right->y1); + Fq2Add(&result->y2, &left->y2, &right->y2); +} + +void Fq6Sub(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right) { + Fq2Sub(&result->y0, &left->y0, &right->y0); + Fq2Sub(&result->y1, &left->y1, &right->y1); + Fq2Sub(&result->y2, &left->y2, &right->y2); +} + +void Fq6Mul(Fq6Elem* result, Fq6Elem const* left, Fq6Elem const* right) { + Fq2Elem tmpa; + Fq2Elem tmpb; + Fq2Elem tmpc; + Fq2Elem tmpd; + Fq2Elem tmpe; + Fq2Elem* temp_a = &tmpa; + Fq2Elem* temp_b = &tmpb; + Fq2Elem* temp_c = &tmpc; + Fq2Elem* temp_d = &tmpd; + Fq2Elem* temp_e = &tmpe; + Fq2Mul(temp_a, &left->y0, &right->y0); // temp_a = t0 = a[0] * b[0] + Fq2Mul(temp_b, &left->y1, &right->y1); // temp_b = t1 + Fq2Mul(temp_c, &left->y2, &right->y2); // temp_c = t2 + Fq2Add(temp_d, &left->y1, &left->y2); // temp_d = t3 + Fq2Add(temp_e, &right->y1, &right->y2); // temp_e = t4 + Fq2Mul(temp_d, temp_d, temp_e); // temp_d = t3 + Fq2Sub(temp_d, temp_d, temp_b); + Fq2Sub(temp_d, temp_d, temp_c); + Fq2MulXi(temp_e, temp_d); + Fq2Add(temp_d, &left->y0, &left->y1); + Fq2Add(&result->y1, &right->y0, &right->y1); // &result->y1 = t4 + Fq2Mul(temp_d, temp_d, &result->y1); + Fq2MulXi(&result->y1, temp_c); // result->y1 = Fq2.mulXi(t2) + Fq2Add(&result->y1, &result->y1, temp_d); + Fq2Sub(&result->y1, &result->y1, temp_a); + Fq2Sub(&result->y1, &result->y1, temp_b); + Fq2Add(temp_d, &left->y0, &left->y2); + Fq2Sub(temp_b, temp_b, temp_c); + Fq2Add(temp_c, &right->y0, &right->y2); + Fq2Add(&result->y0, temp_e, temp_a); // temp_e = e[0], reordered instruction + Fq2Mul(temp_d, temp_d, temp_c); + Fq2Sub(temp_d, temp_d, temp_a); + Fq2Add(&result->y2, temp_d, temp_b); +} + +void Fq6Inv(Fq6Elem* result, Fq6Elem const* in) { + Fq2Elem tmpa; + Fq2Elem tmpb; + Fq2Elem tmpc; + Fq2Elem tmpd; + Fq2Elem* temp_a = &tmpa; + Fq2Elem* temp_b = &tmpb; + Fq2Elem* temp_c = &tmpc; + Fq2Elem* temp_d = &tmpd; + Fq2Square(temp_a, &in->y0); + Fq2Mul(temp_d, &in->y1, &in->y2); + Fq2MulXi(temp_d, temp_d); + Fq2Sub(temp_a, temp_a, temp_d); + Fq2Square(temp_b, &in->y2); + Fq2Mul(temp_d, &in->y0, &in->y1); + Fq2MulXi(temp_b, temp_b); + Fq2Sub(temp_b, temp_b, temp_d); + Fq2Square(temp_c, &in->y1); + Fq2Mul(temp_d, &in->y0, &in->y2); + Fq2Sub(temp_c, temp_c, temp_d); + // using the results as temporary variables + Fq2Mul(&result->y0, &in->y0, temp_a); + Fq2Mul(&result->y1, &in->y1, temp_c); + Fq2Mul(&result->y2, &in->y2, temp_b); + Fq2MulXi(&result->y1, &result->y1); + Fq2MulXi(&result->y2, &result->y2); + Fq2Add(temp_d, &result->y0, &result->y1); + Fq2Add(temp_d, temp_d, &result->y2); + Fq2Inv(temp_d, temp_d); + Fq2Mul(&result->y0, temp_a, temp_d); + Fq2Mul(&result->y1, temp_b, temp_d); + Fq2Mul(&result->y2, temp_c, temp_d); +} + +void Fq6Neg(Fq6Elem* result, Fq6Elem const* in) { + Fq2Neg(&result->y0, &in->y0); + Fq2Neg(&result->y1, &in->y1); + Fq2Neg(&result->y2, &in->y2); +} + +void Fq6Clear(Fq6Elem* result) { + Fq2Clear(&result->y0); + Fq2Clear(&result->y1); + Fq2Clear(&result->y2); +} + +void Fq6MulScalar(Fq6Elem* result, Fq6Elem const* in, Fq2Elem const* scalar) { + Fq2Mul(&result->y0, &in->y0, scalar); + Fq2Mul(&result->y1, &in->y1, scalar); + Fq2Mul(&result->y2, &in->y2, scalar); +} + +void Fq6MulV(Fq6Elem* result, Fq6Elem const* in) { + Fq2Elem tmp; + Fq2Elem* temp = &tmp; + Fq2MulXi(temp, &in->y2); + Fq2Cp(&result->y2, &in->y1); + Fq2Cp(&result->y1, &in->y0); + Fq2Cp(&result->y0, temp); +} + +int Fq6Eq(Fq6Elem const* left, Fq6Elem const* right) { + return Fq2Eq(&left->y0, &right->y0) && Fq2Eq(&left->y1, &right->y1) && + Fq2Eq(&left->y2, &right->y2); +} + +int Fq6IsZero(Fq6Elem const* in) { + return Fq2IsZero(&in->y0) && Fq2IsZero(&in->y1) && Fq2IsZero(&in->y2); +} + +void Fq6Square(Fq6Elem* result, Fq6Elem const* in) { + Fq2Elem T0; + Fq2Elem T2; + Fq2Elem T3; + Fq2Elem* t0 = &T0; + Fq2Elem* t1 = &result->y1; + Fq2Elem* t2 = &T2; + Fq2Elem* t3 = &T3; + Fq2Add(t0, &in->y1, &in->y2); + Fq2Square(t3, &in->y1); + Fq2Add(t1, &in->y0, &in->y1); + Fq2Add(t2, &in->y0, &in->y2); + Fq2Square(t0, t0); + Fq2Square(t1, t1); + Fq2Square(t2, t2); + + // using result from Fq2Square(t3, in->y1): + Fq2Sub(t0, t0, t3); + Fq2Sub(t1, t1, t3); + Fq2Add(t2, t2, t3); + + Fq2Square(t3, &in->y2); + Fq2Sub(t0, t0, t3); + Fq2Sub(t2, t2, t3); + Fq2MulXi(t3, t3); + Fq2Add(t1, t1, t3); + + Fq2Square(t3, &in->y0); + Fq2MulXi(t0, t0); + Fq2Add(&result->y0, t0, t3); + Fq2Sub(&result->y1, t1, t3); + Fq2Sub(&result->y2, t2, t3); +} + +void Fq6Cp(Fq6Elem* result, Fq6Elem const* in) { + Fq2Cp(&result->y0, &in->y0); + Fq2Cp(&result->y1, &in->y1); + Fq2Cp(&result->y2, &in->y2); +} + +void Fq6CondSet(Fq6Elem* result, Fq6Elem const* true_val, + Fq6Elem const* false_val, int truth_val) { + Fq2CondSet(&result->y0, &true_val->y0, &false_val->y0, truth_val); + Fq2CondSet(&result->y1, &true_val->y1, &false_val->y1, truth_val); + Fq2CondSet(&result->y2, &true_val->y2, &false_val->y2, truth_val); +} + +void Fq6Set(Fq6Elem* result, uint32_t in) { + Fq6Clear(result); + Fq2Set(&result->y0, in); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/hashwrap.c b/external/epid-sdk/epid/member/tiny/math/src/hashwrap.c new file mode 100644 index 00000000..7f3c8be3 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/hashwrap.c @@ -0,0 +1,86 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of hash wrap function +/*! \file */ +#include "epid/member/tiny/math/hashwrap.h" + +void tinysha_init(HashAlg sha_type, tiny_sha* s) { + switch (sha_type) { +#ifdef SHA512_SUPPORT + case kSha512: + tinysha512_init(&s->sha_state_t.sha512s); + break; +#endif +#ifdef SHA256_SUPPORT + case kSha256: + tc_sha256_init(&s->sha_state_t.sha256s); + break; +#endif + default: + s->hash_alg = kInvalidHashAlg; + return; + } + s->hash_alg = sha_type; +} + +void tinysha_update(tiny_sha* s, void const* data, size_t data_length) { + switch (s->hash_alg) { +#ifdef SHA512_SUPPORT + case kSha512: + tinysha512_update(&s->sha_state_t.sha512s, data, data_length); + break; +#endif +#ifdef SHA256_SUPPORT + case kSha256: + tc_sha256_update(&s->sha_state_t.sha256s, data, data_length); + break; +#endif + default: + break; + } +} + +void tinysha_final(unsigned char* digest, tiny_sha* s) { + switch (s->hash_alg) { +#ifdef SHA512_SUPPORT + case kSha512: + tinysha512_final(digest, &s->sha_state_t.sha512s); + break; +#endif +#ifdef SHA256_SUPPORT + case kSha256: + tc_sha256_final(digest, &s->sha_state_t.sha256s); + break; +#endif + default: + break; + } +} + +size_t tinysha_digest_size(tiny_sha* s) { + switch (s->hash_alg) { +#ifdef SHA512_SUPPORT + case kSha512: + return SHA512_DIGEST_SIZE; +#endif +#ifdef SHA256_SUPPORT + case kSha256: + return SHA256_DIGEST_SIZE; +#endif + default: + return 0; + } +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/pairing.c b/external/epid-sdk/epid/member/tiny/math/src/pairing.c new file mode 100644 index 00000000..6b2f2612 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/pairing.c @@ -0,0 +1,300 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Implementation of Tate pairing +/*! \file */ + +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/fq12.h" +#include "epid/member/tiny/math/fq2.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/vli.h" + +static const VeryLargeInt epid_e = {{0xf2788803, 0x7886dcf9, 0x2dc401c0, + 0xd77a10ff, 0x27bd9b6f, 0x367ba865, + 0xaaaa2822, 0x2aaaaaaa}}; +static const VeryLargeInt epid_t = {{0x30B0A801, 0x6882F5C0, 0, 0, 0, 0, 0, 0}}; +static const Fq2Elem epid_xi = { + {{{0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}, + {{{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}}; +static const int neg = 1; + +void PairingInit(PairingState* state) { + int i; + Fq2Exp(&state->g[0][0], &epid_xi, &epid_e); + for (i = 1; i < 5; i++) { + Fq2Mul(&state->g[0][i], &state->g[0][i - 1], &state->g[0][0]); + } + for (i = 0; i < 5; i++) { + FqSquare(&state->g[1][i].x0, &state->g[0][i].x0); + FqSquare(&state->g[1][i].x1, &state->g[0][i].x1); + FqAdd(&state->g[1][i].x0, &state->g[1][i].x0, &state->g[1][i].x1); + FqClear(&state->g[1][i].x1); + Fq2Mul(&state->g[2][i], &state->g[0][i], &state->g[1][i]); + } +} + +static void piOp(EccPointFq2* Qout, EccPointFq2 const* Qin, int e, + PairingState const* scratch) { + if (e == 1) { + Fq2Conj(&Qout->x, &Qin->x); + Fq2Conj(&Qout->y, &Qin->y); + } else { + Fq2Cp(&Qout->x, &Qin->x); + Fq2Cp(&Qout->y, &Qin->y); + } + Fq2Mul(&Qout->x, &Qout->x, &scratch->g[e - 1][1]); + Fq2Mul(&Qout->y, &Qout->y, &scratch->g[e - 1][2]); +} + +/* + * Computes the Frobenius endomorphism Pout = Pin^(p^e) + */ +static void frob_op(Fq12Elem* Pout, Fq12Elem const* Pin, int e, + PairingState const* state) { + if (e == 1 || e == 3) { + Fq2Conj(&Pout->z0.y0, &Pin->z0.y0); + Fq2Conj(&Pout->z1.y0, &Pin->z1.y0); + Fq2Conj(&Pout->z0.y1, &Pin->z0.y1); + Fq2Conj(&Pout->z1.y1, &Pin->z1.y1); + Fq2Conj(&Pout->z0.y2, &Pin->z0.y2); + Fq2Conj(&Pout->z1.y2, &Pin->z1.y2); + } else { + Fq2Cp(&Pout->z0.y0, &Pin->z0.y0); + Fq2Cp(&Pout->z1.y0, &Pin->z1.y0); + Fq2Cp(&Pout->z0.y1, &Pin->z0.y1); + Fq2Cp(&Pout->z1.y1, &Pin->z1.y1); + Fq2Cp(&Pout->z0.y2, &Pin->z0.y2); + Fq2Cp(&Pout->z1.y2, &Pin->z1.y2); + } + Fq2Mul(&Pout->z1.y0, &Pout->z1.y0, &state->g[e - 1][0]); + Fq2Mul(&Pout->z0.y1, &Pout->z0.y1, &state->g[e - 1][1]); + Fq2Mul(&Pout->z1.y1, &Pout->z1.y1, &state->g[e - 1][2]); + Fq2Mul(&Pout->z0.y2, &Pout->z0.y2, &state->g[e - 1][3]); + Fq2Mul(&Pout->z1.y2, &Pout->z1.y2, &state->g[e - 1][4]); +} + +static void finalExp(Fq12Elem* f, PairingState const* state) { + Fq12Elem t3; + Fq12Elem t2; + Fq12Elem t1; + Fq12Elem t0; + + Fq12Conj(&t1, f); + Fq12Inv(&t2, f); + Fq12Mul(f, &t1, &t2); + frob_op(&t2, f, 2, state); + Fq12Mul(f, f, &t2); + Fq12ExpCyc(&t1, f, &epid_t); + if (neg) { + Fq12Conj(&t1, &t1); + } + Fq12ExpCyc(&t3, &t1, &epid_t); + if (neg) { + Fq12Conj(&t3, &t3); + } + Fq12ExpCyc(&t0, &t3, &epid_t); + if (neg) { + Fq12Conj(&t0, &t0); + } + frob_op(&t2, &t0, 1, state); + Fq12Mul(&t2, &t2, &t0); + Fq12Conj(&t2, &t2); + Fq12SqCyc(&t0, &t2); + frob_op(&t2, &t3, 1, state); + Fq12Mul(&t2, &t2, &t1); + Fq12Conj(&t2, &t2); + Fq12Mul(&t0, &t0, &t2); + Fq12Conj(&t2, &t3); + Fq12Mul(&t0, &t0, &t2); + frob_op(&t1, &t1, 1, state); + Fq12Conj(&t1, &t1); + Fq12Mul(&t1, &t1, &t2); + Fq12Mul(&t1, &t1, &t0); + frob_op(&t2, &t3, 2, state); + Fq12Mul(&t0, &t0, &t2); + Fq12SqCyc(&t1, &t1); + Fq12Mul(&t1, &t1, &t0); + Fq12SqCyc(&t1, &t1); + Fq12Conj(&t2, f); + Fq12Mul(&t0, &t1, &t2); + frob_op(&t2, f, 1, state); + Fq12Mul(&t1, &t1, &t2); + frob_op(&t2, f, 2, state); + Fq12Mul(&t1, &t1, &t2); + frob_op(&t2, f, 3, state); + Fq12Mul(&t1, &t1, &t2); + Fq12SqCyc(&t0, &t0); + Fq12Mul(f, &t1, &t0); +} + +static void pair_tangent(Fq12Elem* f, Fq2Elem* X, Fq2Elem* Y, Fq2Elem* Z, + Fq2Elem* Z2, EccPointFq const* P) { + Fq2Mul(&f->z0.y0, X, X); + Fq2Add(&f->z0.y2, &f->z0.y0, &f->z0.y0); + Fq2Add(&f->z0.y2, &f->z0.y2, &f->z0.y0); + Fq2Add(&f->z1.y1, X, &f->z0.y2); + Fq2Mul(&f->z1.y1, &f->z1.y1, &f->z1.y1); + Fq2Sub(&f->z1.y1, &f->z1.y1, &f->z0.y0); + Fq2Mul(&f->z0.y1, Y, Y); + Fq2Add(&f->z1.y0, &f->z0.y1, X); + Fq2Mul(&f->z1.y0, &f->z1.y0, &f->z1.y0); + Fq2Sub(&f->z1.y0, &f->z1.y0, &f->z0.y0); + Fq2Mul(&f->z0.y0, &f->z0.y1, &f->z0.y1); + Fq2Sub(&f->z1.y0, &f->z1.y0, &f->z0.y0); + Fq2Add(&f->z1.y0, &f->z1.y0, &f->z1.y0); + Fq2Mul(&f->z1.y2, &f->z0.y2, &f->z0.y2); + Fq2Add(Z, Y, Z); + Fq2Mul(Z, Z, Z); + Fq2Sub(Z, Z, &f->z0.y1); + Fq2Sub(Z, Z, Z2); + Fq2Add(&f->z0.y1, &f->z0.y1, &f->z0.y1); + Fq2Add(&f->z0.y1, &f->z0.y1, &f->z0.y1); + Fq2Sub(&f->z1.y1, &f->z1.y1, &f->z1.y2); + Fq2Sub(&f->z1.y1, &f->z1.y1, &f->z0.y1); + Fq2Sub(X, &f->z1.y2, &f->z1.y0); + Fq2Sub(X, X, &f->z1.y0); + Fq2Add(&f->z0.y0, &f->z0.y0, &f->z0.y0); + Fq2Add(&f->z0.y0, &f->z0.y0, &f->z0.y0); + Fq2Add(&f->z0.y0, &f->z0.y0, &f->z0.y0); + Fq2Sub(Y, &f->z1.y0, X); + Fq2Mul(Y, Y, &f->z0.y2); + Fq2Sub(Y, Y, &f->z0.y0); + Fq2Mul(&f->z1.y0, &f->z0.y2, Z2); + Fq2Neg(&f->z1.y0, &f->z1.y0); + Fq2Add(&f->z1.y0, &f->z1.y0, &f->z1.y0); + Fq2MulScalar(&f->z1.y0, &f->z1.y0, &P->x); + Fq2Mul(&f->z0.y0, Z, Z2); + Fq2Add(&f->z0.y0, &f->z0.y0, &f->z0.y0); + Fq2MulScalar(&f->z0.y0, &f->z0.y0, &P->y); + Fq2Mul(Z2, Z, Z); + Fq2Clear(&f->z0.y1); + Fq2Clear(&f->z0.y2); + Fq2Clear(&f->z1.y2); + Fq2Square(Z2, Z); +} + +static void pair_line(Fq12Elem* f, Fq2Elem* X, Fq2Elem* Y, Fq2Elem* Z, + Fq2Elem* Z2, EccPointFq const* P, EccPointFq2 const* Q) { + Fq2Mul(&f->z0.y1, &Q->x, Z2); + Fq2Add(&f->z1.y0, &Q->y, Z); + Fq2Mul(&f->z1.y0, &f->z1.y0, &f->z1.y0); + Fq2Square(&f->z0.y0, &Q->y); + Fq2Sub(&f->z1.y0, &f->z1.y0, &f->z0.y0); + Fq2Sub(&f->z1.y0, &f->z1.y0, Z2); + Fq2Mul(&f->z1.y0, &f->z1.y0, Z2); + Fq2Sub(&f->z0.y1, &f->z0.y1, X); + Fq2Mul(&f->z0.y2, &f->z0.y1, &f->z0.y1); + Fq2Add(Z, Z, &f->z0.y1); + Fq2Square(Z, Z); + Fq2Sub(Z, Z, Z2); + Fq2Sub(Z, Z, &f->z0.y2); + Fq2Mul(Z2, Z, Z); + Fq2Add(&f->z1.y2, &Q->y, Z); + Fq2Mul(&f->z1.y2, &f->z1.y2, &f->z1.y2); + Fq2Sub(&f->z1.y2, &f->z1.y2, &f->z0.y0); + Fq2Sub(&f->z1.y2, &f->z1.y2, Z2); + Fq2Sub(&f->z1.y0, &f->z1.y0, Y); + Fq2Sub(&f->z1.y0, &f->z1.y0, Y); + Fq2Mul(&f->z1.y1, &f->z1.y0, &Q->x); + Fq2Add(&f->z1.y1, &f->z1.y1, &f->z1.y1); + Fq2Sub(&f->z1.y1, &f->z1.y1, &f->z1.y2); + Fq2Add(&f->z0.y2, &f->z0.y2, &f->z0.y2); + Fq2Add(&f->z0.y2, &f->z0.y2, &f->z0.y2); + Fq2Mul(&f->z0.y1, &f->z0.y2, &f->z0.y1); + Fq2Mul(&f->z0.y2, X, &f->z0.y2); + Fq2Mul(X, &f->z1.y0, &f->z1.y0); + Fq2Sub(X, X, &f->z0.y1); + Fq2Sub(X, X, &f->z0.y2); + Fq2Sub(X, X, &f->z0.y2); + Fq2Sub(&f->z0.y2, &f->z0.y2, X); + Fq2Mul(&f->z0.y2, &f->z0.y2, &f->z1.y0); + Fq2Mul(&f->z0.y1, Y, &f->z0.y1); + Fq2Add(&f->z0.y1, &f->z0.y1, &f->z0.y1); + Fq2Sub(Y, &f->z0.y2, &f->z0.y1); + Fq2MulScalar(&f->z0.y0, Z, &P->y); + Fq2Add(&f->z0.y0, &f->z0.y0, &f->z0.y0); + Fq2Neg(&f->z1.y0, &f->z1.y0); + Fq2MulScalar(&f->z1.y0, &f->z1.y0, &P->x); + Fq2Add(&f->z1.y0, &f->z1.y0, &f->z1.y0); + Fq2Clear(&f->z0.y1); + Fq2Clear(&f->z0.y2); + Fq2Clear(&f->z1.y2); +} + +void PairingCompute(Fq12Elem* d, EccPointFq const* P, EccPointFq2 const* Q, + PairingState const* state) { + Fq2Elem X; + Fq2Elem Y; + Fq2Elem Z; + Fq2Elem Z2; + EccPointFq2 Qp; + Fq12Elem f; + VeryLargeInt s; + const VeryLargeInt two = {{2}}; + uint32_t i; + + VliAdd(&s, &epid_t, &epid_t); // s = 2*t + VliAdd(&s, &s, &epid_t); // s = 3*t + VliAdd(&s, &s, &s); // s = 6*t + if (neg) { + VliSub(&s, &s, &two); + } else { + VliAdd(&s, &s, &two); + } + Fq2Cp(&X, &Q->x); + Fq2Cp(&Y, &Q->y); + Fq2Set(&Z, 1); + Fq2Set(&Z2, 1); + Fq12Set(d, 1); + + Fq12Clear(&f); + // s has 66 bits, 0 through 65, so starting point is bit 64 + i = 65; + while (i > 0) { + i -= 1; + pair_tangent(&f, &X, &Y, &Z, &Z2, P); + Fq12Square(d, d); + Fq12MulSpecial(d, d, &f); + if (VliTestBit(&s, i)) { + pair_line(&f, &X, &Y, &Z, &Z2, P, Q); + Fq12MulSpecial(d, d, &f); + } + } + if (neg) { + Fq2Neg(&Y, &Y); + Fq12Conj(d, d); + } + piOp(&Qp, Q, 1, state); + pair_line(&f, &X, &Y, &Z, &Z2, P, &Qp); + Fq12MulSpecial(d, d, &f); + piOp(&Qp, Q, 2, state); + Fq2Neg(&Qp.y, &Qp.y); + pair_line(&f, &X, &Y, &Z, &Z2, P, &Qp); + Fq12MulSpecial(d, d, &f); + finalExp(d, state); + // s doesn't have secret information; no need to clear it. + Fq12Clear(&f); + Fq2Clear(&X); + Fq2Clear(&Y); + Fq2Clear(&Z); + Fq2Clear(&Z2); + Fq2Clear(&Qp.x); + Fq2Clear(&Qp.y); +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/serialize.c b/external/epid-sdk/epid/member/tiny/math/src/serialize.c new file mode 100644 index 00000000..3cdc5e9f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/serialize.c @@ -0,0 +1,232 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Implementation of de/serialize functionality. +/*! \file */ + +#include "epid/member/tiny/math/serialize.h" +#include +#include +#include "epid/common/types.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/stdlib/endian.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +#if !defined(UNOPTIMIZED_SERIALIZATION) +void SwapNativeAndPortableLayout(void* dest, size_t dest_size, void const* src, + size_t src_size) { + size_t i, j; +#if defined(DEBUG) + if (dest_size != src_size || 0 != src_size % 32) { + memset(dest, 0xff, dest_size); + return; + } +#else // defined(DEBUG) + (void)dest_size; +#endif // defined(DEBUG) + for (i = 0; i < src_size; i += 32) { + for (j = 0; j < 32 / 2; j += sizeof(uint32_t)) { + uint32_t tmp = htobe32( + *(uint32_t*)((uint8_t*)src + i + j)); // handle src==dest case + *(uint32_t*)((uint8_t*)dest + i + j) = + htobe32(*(uint32_t*)((uint8_t*)src + i + 32 - sizeof(uint32_t) - j)); + *(uint32_t*)((uint8_t*)dest + i + 32 - sizeof(uint32_t) - j) = tmp; + } + } +} +#endif // !defined(UNOPTIMIZED_SERIALIZATION) + +void* Uint32Serialize(OctStr32* dest, uint32_t src) { + int i; + for (i = 0; i < 4; i++) + dest->data[i] = + (char)((src >> (24 - 8 * i)) & + 0x000000FF); // get the ith byte of num, in little-endian order + return dest->data + 4; +} + +void const* Uint32Deserialize(uint32_t* dest, OctStr32 const* src) { + int i; + *dest = 0; + for (i = 0; i < 4; i++) { + *dest <<= 8; + *dest |= (uint32_t)(*(&src->data[i]) & 0x000000FF); + } + return src->data + 4; +} + +void* VliSerialize(BigNumStr* dest, VeryLargeInt const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + int i; + for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) { + dest = Uint32Serialize((OctStr32*)dest, src->word[i]); + } + return dest; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* VliDeserialize(VeryLargeInt* dest, BigNumStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + int i; + for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) { + src = Uint32Deserialize(dest->word + i, (OctStr32 const*)src); + } + return src; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* FqSerialize(FqElemStr* dest, FqElem const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + dest = VliSerialize((BigNumStr*)dest, &src->limbs); + return dest; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* FqDeserialize(FqElem* dest, FqElemStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + src = VliDeserialize(&dest->limbs, (BigNumStr const*)src); + return src; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +#if defined(UNOPTIMIZED_SERIALIZATION) +static void* Fq2Serialize(Fq2ElemStr* dest, Fq2Elem const* src) { + FqSerialize(&dest->a[0], &src->x0); + FqSerialize(&dest->a[1], &src->x1); + return dest + sizeof(*dest); +} + +static void const* Fq2Deserialize(Fq2Elem* dest, Fq2ElemStr const* src) { + FqDeserialize(&dest->x0, &src->a[0]); + FqDeserialize(&dest->x1, &src->a[1]); + return src + sizeof(*src); +} + +static void* Fq6Serialize(Fq6ElemStr* dest, Fq6Elem const* src) { + Fq2Serialize(&dest->a[0], &src->y0); + Fq2Serialize(&dest->a[1], &src->y1); + Fq2Serialize(&dest->a[2], &src->y2); + return dest + sizeof(*dest); +} + +static void const* Fq6Deserialize(Fq6Elem* dest, Fq6ElemStr const* src) { + Fq2Deserialize(&dest->y0, &src->a[0]); + Fq2Deserialize(&dest->y1, &src->a[1]); + Fq2Deserialize(&dest->y2, &src->a[2]); + return src + sizeof(*src); +} +#endif // defined(UNOPTIMIZED_SERIALIZATION) + +void const* Fq12Deserialize(Fq12Elem* dest, Fq12ElemStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + Fq6Deserialize(&dest->z0, &src->a[0]); + Fq6Deserialize(&dest->z1, &src->a[1]); + return src + sizeof(*src); +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* Fq12Serialize(Fq12ElemStr* dest, Fq12Elem const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + Fq6Serialize(&dest->a[0], &src->z0); + Fq6Serialize(&dest->a[1], &src->z1); + return dest + sizeof(*dest); +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* FpSerialize(FpElemStr* dest, FpElem const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + dest = VliSerialize((BigNumStr*)dest, &src->limbs); + return dest; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* FpDeserialize(FpElem* dest, FpElemStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + src = VliDeserialize(&dest->limbs, (BigNumStr const*)src); + return src; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* EFqSerialize(G1ElemStr* dest, EccPointFq const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + dest = FqSerialize((FqElemStr*)dest, &src->x); + dest = FqSerialize((FqElemStr*)dest, &src->y); + return dest; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* EFqDeserialize(EccPointFq* dest, G1ElemStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + src = FqDeserialize(&dest->x, (FqElemStr const*)src); + src = FqDeserialize(&dest->y, (FqElemStr const*)src); + return src; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* EFq2Serialize(G2ElemStr* dest, EccPointFq2 const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + dest = FqSerialize((FqElemStr*)dest, &src->x.x0); + dest = FqSerialize((FqElemStr*)dest, &src->x.x1); + dest = FqSerialize((FqElemStr*)dest, &src->y.x0); + dest = FqSerialize((FqElemStr*)dest, &src->y.x1); + return dest; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* EFq2Deserialize(EccPointFq2* dest, G2ElemStr const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + src = FqDeserialize(&dest->x.x0, (FqElemStr const*)src); + src = FqDeserialize(&dest->x.x1, (FqElemStr const*)src); + src = FqDeserialize(&dest->y.x0, (FqElemStr const*)src); + src = FqDeserialize(&dest->y.x1, (FqElemStr const*)src); + return src; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/sha256.c b/external/epid-sdk/epid/member/tiny/math/src/sha256.c new file mode 100644 index 00000000..22b6fd19 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/sha256.c @@ -0,0 +1,225 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/* + * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/// A SHA-256 implementation. +/*! \file */ + +#include "epid/member/tiny/math/sha256.h" + +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static void sha256_compress(unsigned int* iv, const uint8_t* data); + +void tc_sha256_init(sha256_state* s) { + /* + * Setting the initial state values. + * These values correspond to the first 32 bits of the fractional parts + * of the square roots of the first 8 primes: 2, 3, 5, 7, 11, 13, 17 + * and 19. + */ + (void)memset((uint8_t*)s, 0x00, sizeof(*s)); + s->iv[0] = 0x6a09e667; + s->iv[1] = 0xbb67ae85; + s->iv[2] = 0x3c6ef372; + s->iv[3] = 0xa54ff53a; + s->iv[4] = 0x510e527f; + s->iv[5] = 0x9b05688c; + s->iv[6] = 0x1f83d9ab; + s->iv[7] = 0x5be0cd19; +} + +void tc_sha256_update(sha256_state* s, const uint8_t* data, size_t datalen) { + while (datalen-- > 0) { + s->leftover[s->leftover_offset++] = *(data++); + if (s->leftover_offset >= SHA256_BLOCK_SIZE) { + sha256_compress(s->iv, s->leftover); + s->leftover_offset = 0; + s->bits_hashed += (SHA256_BLOCK_SIZE << 3); + } + } +} + +void tc_sha256_final(uint8_t* digest, sha256_state* s) { + unsigned int i; + + s->bits_hashed += (s->leftover_offset << 3); + + s->leftover[s->leftover_offset++] = 0x80; /* always room for one byte */ + if (s->leftover_offset > (sizeof(s->leftover) - 8)) { + /* there is not room for all the padding in this block */ + (void)memset(s->leftover + s->leftover_offset, 0x00, + sizeof(s->leftover) - s->leftover_offset); + sha256_compress(s->iv, s->leftover); + s->leftover_offset = 0; + } + + /* add the padding and the length in big-Endian format */ + (void)memset(s->leftover + s->leftover_offset, 0x00, + sizeof(s->leftover) - 8 - s->leftover_offset); + s->leftover[sizeof(s->leftover) - 1] = (uint8_t)(s->bits_hashed); + s->leftover[sizeof(s->leftover) - 2] = (uint8_t)(s->bits_hashed >> 8); + s->leftover[sizeof(s->leftover) - 3] = (uint8_t)(s->bits_hashed >> 16); + s->leftover[sizeof(s->leftover) - 4] = (uint8_t)(s->bits_hashed >> 24); + s->leftover[sizeof(s->leftover) - 5] = (uint8_t)(s->bits_hashed >> 32); + s->leftover[sizeof(s->leftover) - 6] = (uint8_t)(s->bits_hashed >> 40); + s->leftover[sizeof(s->leftover) - 7] = (uint8_t)(s->bits_hashed >> 48); + s->leftover[sizeof(s->leftover) - 8] = (uint8_t)(s->bits_hashed >> 56); + + /* hash the padding and length */ + sha256_compress(s->iv, s->leftover); + + /* copy the iv out to digest */ + for (i = 0; i < SHA256_STATE_BLOCKS; ++i) { + unsigned int t = *((unsigned int*)&s->iv[i]); + *digest++ = (uint8_t)(t >> 24); + *digest++ = (uint8_t)(t >> 16); + *digest++ = (uint8_t)(t >> 8); + *digest++ = (uint8_t)(t); + } + + /* destroy the current state */ + (void)memset(s, 0, sizeof(*s)); +} + +/* + * Initializing SHA-256 Hash constant words K. + * These values correspond to the first 32 bits of the fractional parts of the + * cube roots of the first 64 primes between 2 and 311. + */ +static const unsigned int k256[64] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, + 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, + 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, + 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, + 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; + +static unsigned int ROTR(unsigned int a, unsigned int n) { + return (((a) >> n) | ((a) << (32 - n))); +} + +#define Sigma0(a) (ROTR((a), 2) ^ ROTR((a), 13) ^ ROTR((a), 22)) +#define Sigma1(a) (ROTR((a), 6) ^ ROTR((a), 11) ^ ROTR((a), 25)) +#define sigma0(a) (ROTR((a), 7) ^ ROTR((a), 18) ^ ((a) >> 3)) +#define sigma1(a) (ROTR((a), 17) ^ ROTR((a), 19) ^ ((a) >> 10)) + +#define Ch(a, b, c) (((a) & (b)) ^ ((~(a)) & (c))) +#define Maj(a, b, c) (((a) & (b)) ^ ((a) & (c)) ^ ((b) & (c))) + +static unsigned int BigEndian(const uint8_t** c) { + unsigned int n = 0; + + n = (((unsigned int)(*((*c)++))) << 24); + n |= ((unsigned int)(*((*c)++)) << 16); + n |= ((unsigned int)(*((*c)++)) << 8); + n |= ((unsigned int)(*((*c)++))); + return n; +} + +static void sha256_compress(unsigned int* iv, const uint8_t* data) { + unsigned int a, b, c, d, e, f, g, h; + unsigned int s0, s1; + unsigned int t1, t2; + unsigned int work_space[16]; + unsigned int n; + unsigned int i; + + a = iv[0]; + b = iv[1]; + c = iv[2]; + d = iv[3]; + e = iv[4]; + f = iv[5]; + g = iv[6]; + h = iv[7]; + + for (i = 0; i < 16; ++i) { + n = BigEndian(&data); + t1 = work_space[i] = n; + t1 += h + Sigma1(e) + Ch(e, f, g) + k256[i]; + t2 = Sigma0(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + + for (; i < 64; ++i) { + s0 = work_space[(i + 1) & 0x0f]; + s0 = sigma0(s0); + s1 = work_space[(i + 14) & 0x0f]; + s1 = sigma1(s1); + + t1 = work_space[i & 0xf] += s0 + s1 + work_space[(i + 9) & 0xf]; + t1 += h + Sigma1(e) + Ch(e, f, g) + k256[i]; + t2 = Sigma0(a) + Maj(a, b, c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + + iv[0] += a; + iv[1] += b; + iv[2] += c; + iv[3] += d; + iv[4] += e; + iv[5] += f; + iv[6] += g; + iv[7] += h; +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/sha512.c b/external/epid-sdk/epid/member/tiny/math/src/sha512.c new file mode 100644 index 00000000..e18cd039 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/sha512.c @@ -0,0 +1,169 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// A SHA-512 implementation. +/*! \file */ + +#include "epid/member/tiny/math/sha512.h" + +#include +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static void sha512_compress(uint64_t* iv, void const* in); + +void tinysha512_init(sha512_state* s) { + s->iv[0] = 0x6a09e667f3bcc908ULL; + s->iv[1] = 0xbb67ae8584caa73bULL; + s->iv[2] = 0x3c6ef372fe94f82bULL; + s->iv[3] = 0xa54ff53a5f1d36f1ULL; + s->iv[4] = 0x510e527fade682d1ULL; + s->iv[5] = 0x9b05688c2b3e6c1fULL; + s->iv[6] = 0x1f83d9abfb41bd6bULL; + s->iv[7] = 0x5be0cd19137e2179ULL; + + s->bits_hashed_high = s->bits_hashed_low = (uint64_t)0; + s->leftover_offset = 0; +} + +void tinysha512_update(sha512_state* s, void const* data, size_t data_length) { + unsigned char const* tmp_data = (unsigned char const*)data; + + while (data_length-- > 0) { + s->leftover[s->leftover_offset++] = *(tmp_data++); + if (s->leftover_offset >= SHA512_BLOCK_SIZE) { + sha512_compress(s->iv, s->leftover); + s->leftover_offset = 0; + s->bits_hashed_low += (SHA512_BLOCK_SIZE << 3); + } + } +} + +void tinysha512_final(unsigned char* digest, sha512_state* s) { + size_t i, j; + + s->bits_hashed_low += (s->leftover_offset << 3); + + s->leftover[s->leftover_offset++] = 0x80; + /* there is always room for one byte */ + if (s->leftover_offset > (sizeof(s->leftover) - 16)) { + /* the data's bit length cannot be encoded in the last block */ + (void)memset(s->leftover + s->leftover_offset, 0x00, + sizeof(s->leftover) - s->leftover_offset); + sha512_compress(s->iv, s->leftover); + s->leftover_offset = 0; + } + + (void)memset(s->leftover + s->leftover_offset, 0x00, + sizeof(s->leftover) - 16 - s->leftover_offset); + for (i = 0; i < 8; i++) { + s->leftover[sizeof(s->leftover) - (i + 1)] = + (unsigned char)(s->bits_hashed_low >> (8 * i)); + s->leftover[sizeof(s->leftover) - (i + 1) - 8] = + (unsigned char)(s->bits_hashed_high >> (8 * i)); + } + sha512_compress(s->iv, s->leftover); + + for (i = 0; i < SHA512_DIGEST_WORDS; ++i) { + uint64_t w = s->iv[i]; + for (j = 0; j < 8; j++) { + digest[j] = (unsigned char)(w >> (8 * (7 - j))); + } + digest += 8; + } +} + +#define B(x, j) \ + (((uint64_t)(*(((unsigned char const*)(&x)) + j))) << ((7 - j) * 8)) + +static uint64_t pull64(const uint64_t x) { + int16_t i; + uint64_t result = 0; + for (i = 0; i < 8; i++) result |= B(x, i); + return result; +} +static uint64_t ROTR(const uint64_t x, unsigned char s) { + return (x >> s) | (x << (64 - s)); +} + +#define Sigma0(x) (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39)) + +#define Sigma1(x) (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41)) +#define sigma0(x) (ROTR((x), 1) ^ ROTR((x), 8) ^ ((x) >> 7)) +#define sigma1(x) (ROTR((x), 19) ^ ROTR((x), 61) ^ ((x) >> 6)) + +#define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) +#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +static const uint64_t k512[80] = { + 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, + 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, + 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL, + 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, + 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, + 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, + 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL, + 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, + 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, + 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, + 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL, + 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, + 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, + 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, + 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL, + 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, + 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, + 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, + 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL, + 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, + 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, + 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, + 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL, + 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, + 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, + 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, + 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL}; + +static void sha512_compress(uint64_t* iv, void const* in) { + const uint64_t* w = (const uint64_t*)in; + uint64_t a, e, t; + uint64_t work_space[80 + 9]; + uint64_t* work_ptr; + int i; + volatile int j; + + work_ptr = work_space + 80; + // j is declared volatile to prevent the optimizer from replacing the for loop + // with a memcpy + for (j = 0; j < 8; j++) work_ptr[j] = iv[j]; + + for (i = 0; i < 80; i++, work_ptr--) { + if (i < 16) { + t = pull64(w[i]); + } else { + t = sigma0(work_ptr[8 + 16 - 1]); + t += sigma1(work_ptr[8 + 16 - 14]); + t += work_ptr[8 + 16] + work_ptr[8 + 16 - 9]; + } + work_ptr[8] = t; + t += work_ptr[7] + Sigma1(work_ptr[4]) + + Ch(work_ptr[4], work_ptr[5], work_ptr[6]) + k512[i]; + e = work_ptr[3] + t; + a = t + Sigma0(work_ptr[0]) + Maj(work_ptr[0], work_ptr[1], work_ptr[2]); + work_ptr[-1] = a; + work_ptr[3] = e; + } + + for (i = 0; i < 8; i++) iv[i] += work_ptr[i]; +} diff --git a/external/epid-sdk/epid/member/tiny/math/src/vli.c b/external/epid-sdk/epid/member/tiny/math/src/vli.c new file mode 100644 index 00000000..1ec94002 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/src/vli.c @@ -0,0 +1,316 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/* +=============================================================================== + +Copyright (c) 2013, Kenneth MacKay +All rights reserved. +https://github.com/kmackay/micro-ecc + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================== +*/ +/// Implementation of Large Integer math + +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" + +uint32_t VliAdd(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right) { + uint32_t carry = 0; + uint32_t i; + for (i = 0; i < NUM_ECC_DIGITS; ++i) { + uint32_t sum = left->word[i] + right->word[i] + carry; + carry = (sum < left->word[i]) | ((sum == left->word[i]) && carry); + result->word[i] = sum; + } + return carry; +} + +void VliMul(VeryLargeIntProduct* result, VeryLargeInt const* left, + VeryLargeInt const* right) { + uint64_t tmp_r1 = 0; + uint32_t tmp_r2 = 0; + uint32_t i, k; + /* Compute each digit of result in sequence, maintaining the carries. */ + for (k = 0; k < (uint32_t)(NUM_ECC_DIGITS * 2 - 1); ++k) { + uint32_t min_idx = + (k < (uint32_t)NUM_ECC_DIGITS ? 0 : (k + 1) - NUM_ECC_DIGITS); + for (i = min_idx; i <= k && i < (uint32_t)NUM_ECC_DIGITS; ++i) { + uint64_t product = (uint64_t)left->word[i] * right->word[k - i]; + tmp_r1 += product; + tmp_r2 += (tmp_r1 < product); + } + result->word[k] = (uint32_t)tmp_r1; + tmp_r1 = (tmp_r1 >> 32) | (((uint64_t)tmp_r2) << 32); + tmp_r2 = 0; + } + result->word[NUM_ECC_DIGITS * 2 - 1] = (uint32_t)tmp_r1; +} + +void VliRShift(VeryLargeInt* result, VeryLargeInt const* in, uint32_t shift) { + uint32_t i; + for (i = 0; i < NUM_ECC_DIGITS - 1; i++) { + result->word[i] = (in->word[i] >> shift) | in->word[i + 1] << (32 - shift); + } + result->word[NUM_ECC_DIGITS - 1] = in->word[NUM_ECC_DIGITS - 1] >> shift; +} + +uint32_t VliSub(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right) { + uint32_t borrow = 0; + + int i; + for (i = 0; i < NUM_ECC_DIGITS; ++i) { + uint32_t diff = left->word[i] - right->word[i] - borrow; + borrow = (diff > left->word[i]) | ((diff == left->word[i]) && borrow); + result->word[i] = diff; + } + return borrow; +} + +void VliSet(VeryLargeInt* result, VeryLargeInt const* in) { + uint32_t i; + for (i = 0; i < NUM_ECC_DIGITS; ++i) { + result->word[i] = in->word[i]; + } +} + +void VliClear(VeryLargeInt* result) { + uint32_t i; + for (i = 0; i < NUM_ECC_DIGITS; ++i) { + result->word[i] = 0; + } +} + +int VliIsZero(VeryLargeInt const* in) { + uint32_t i, acc = 0; + for (i = 0; i < NUM_ECC_DIGITS; ++i) { + acc += (in->word[i] != 0); + } + return (!acc); +} + +void VliCondSet(VeryLargeInt* result, VeryLargeInt const* true_val, + VeryLargeInt const* false_val, int truth_val) { + int i; + for (i = 0; i < NUM_ECC_DIGITS; i++) + result->word[i] = (!truth_val) * false_val->word[i] + + (truth_val != 0) * true_val->word[i]; +} + +uint32_t VliTestBit(VeryLargeInt const* in, uint32_t bit) { + return ((in->word[bit >> 5] >> (bit & 31)) & + 1); // p_bit % 32 = p_bit & 0x0000001F = 31 +} + +int VliRand(VeryLargeInt* result, BitSupplier rnd_func, void* rnd_param) { + uint32_t t[NUM_ECC_DIGITS] = {0}; + if (rnd_func(t, sizeof(VeryLargeInt) * 8, rnd_param)) { + return 0; + } + VliDeserialize(result, (BigNumStr const*)t); + return 1; +} + +int VliCmp(VeryLargeInt const* left, VeryLargeInt const* right) { + int i, cmp = 0; + for (i = NUM_ECC_DIGITS - 1; i >= 0; --i) { + cmp |= + ((left->word[i] > right->word[i]) - (left->word[i] < right->word[i])) * + (!cmp); + } + return cmp; +} + +void VliModAdd(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod) { + VeryLargeInt tmp; + uint32_t carry = VliAdd(result, left, right); + carry = VliSub(&tmp, result, mod) - carry; + VliCondSet(result, result, &tmp, carry); +} + +void VliModSub(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod) { + VeryLargeInt tmp; + uint32_t borrow = VliSub(result, left, right); + VliAdd(&tmp, result, mod); + VliCondSet(result, &tmp, result, borrow); +} + +void VliModMul(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod) { + VeryLargeIntProduct product; + VliMul(&product, left, right); + VliModBarrett(result, &product, mod); +} + +static void vliSquare(VeryLargeIntProduct* p_result, + VeryLargeInt const* p_left) { + uint64_t tmp_r1 = 0; + uint32_t tmp_r2 = 0; + uint32_t i, k; + for (k = 0; k < NUM_ECC_DIGITS * 2 - 1; ++k) { + uint32_t min_idx = (k < NUM_ECC_DIGITS ? 0 : (k + 1) - NUM_ECC_DIGITS); + for (i = min_idx; i <= k && i <= k - i; ++i) { + uint64_t l_product = (uint64_t)p_left->word[i] * p_left->word[k - i]; + if (i < k - i) { + tmp_r2 += l_product >> 63; + l_product *= 2; + } + tmp_r1 += l_product; + tmp_r2 += (tmp_r1 < l_product); + } + p_result->word[k] = (uint32_t)tmp_r1; + tmp_r1 = (tmp_r1 >> 32) | (((uint64_t)tmp_r2) << 32); + tmp_r2 = 0; + } + + p_result->word[NUM_ECC_DIGITS * 2 - 1] = (uint32_t)tmp_r1; +} + +void VliModExp(VeryLargeInt* result, VeryLargeInt const* base, + VeryLargeInt const* exp, VeryLargeInt const* mod) { + VeryLargeInt acc, tmp; + VeryLargeIntProduct product; + uint32_t j; + int i; + VliClear(&acc); + acc.word[0] = 1; + for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) { + for (j = 1U << 31; j > 0; j = j >> 1) { + vliSquare(&product, &acc); + VliModBarrett(&acc, &product, mod); + VliMul(&product, &acc, base); + VliModBarrett(&tmp, &product, mod); + VliCondSet(&acc, &tmp, &acc, j & (exp->word[i])); + } + } + VliSet(result, &acc); +} + +void VliModInv(VeryLargeInt* result, VeryLargeInt const* input, + VeryLargeInt const* mod) { + VeryLargeInt power; + VliSet(&power, mod); + power.word[0] -= 2; + VliModExp(result, input, &power, mod); +} + +void VliModSquare(VeryLargeInt* result, VeryLargeInt const* input, + VeryLargeInt const* mod) { + VeryLargeIntProduct product; + vliSquare(&product, input); + VliModBarrett(result, &product, mod); +} + +/* Computes p_result = p_in << c, returning carry. + * Can modify in place (if p_result == p_in). 0 < p_shift < 32. */ +static uint32_t vliLShift(VeryLargeIntProduct* p_result, + VeryLargeIntProduct const* p_in, uint32_t p_shift) { + int i; + uint32_t carry = p_in->word[NUM_ECC_DIGITS * 2 - 1]; + for (i = NUM_ECC_DIGITS * 2 - 1; i > 0; --i) + p_result->word[i] = + ((p_in->word[i] << p_shift) | (p_in->word[i - 1] >> (32 - p_shift))); + p_result->word[0] = p_in->word[0] << p_shift; + return carry >> (32 - p_shift); +} + +static void vliScalarMult(VeryLargeInt* p_result, VeryLargeInt* p_left, + uint32_t p_right) { + int i; + uint64_t tmpresult; + uint32_t left = 0, right; + for (i = 0; i < NUM_ECC_DIGITS - 1; i++) { + tmpresult = p_left->word[i] * ((uint64_t)p_right); + right = left + ((uint32_t)tmpresult); + left = (right < left) + ((uint32_t)(tmpresult >> 32)); + p_result->word[i] = right; + } + p_result->word[NUM_ECC_DIGITS - 1] = left; +} + +static void vliProdRShift(VeryLargeIntProduct* result, + VeryLargeIntProduct const* in, uint32_t shift, + uint32_t len) { + uint32_t i; + for (i = 0; i < len - 1; i++) { + result->word[i] = (in->word[i] >> shift) | in->word[i + 1] << (32 - shift); + } + result->word[len - 1] = in->word[len - 1] >> shift; +} + +/* WARNING THIS METHOD MAKES STRONG ASSUMPTIONS ABOUT THE INVOLVED PRIMES + * All primes used for computations in Intel(R) EPID 2.0 begin with 32 ones. + * This method assumes 2^256 - p_mod + * begins with 32 zeros, and is tuned to this assumption. Violating this + * assumption will cause it not + * to work. It also assumes that it does not end with 32 zeros. + */ +void VliModBarrett(VeryLargeInt* result, VeryLargeIntProduct const* input, + VeryLargeInt const* mod) { + int i; + VeryLargeIntProduct tmpprod; + VeryLargeInt negprime, linear; + uint32_t carry = 0; + VliSet((VeryLargeInt*)&tmpprod.word[0], (VeryLargeInt const*)&input->word[0]); + VliSet((VeryLargeInt*)&tmpprod.word[NUM_ECC_DIGITS], + (VeryLargeInt const*)&input->word[NUM_ECC_DIGITS]); + // negative prime is ~q + 1, so we store this in + for (i = 0; i < NUM_ECC_DIGITS - 1; i++) negprime.word[i] = ~mod->word[i]; + negprime.word[0]++; + for (i = 0; i < NUM_ECC_DIGITS; i++) { + vliScalarMult(&linear, &negprime, tmpprod.word[2 * NUM_ECC_DIGITS - 1]); + tmpprod.word[2 * NUM_ECC_DIGITS - 1] = 0; + tmpprod.word[2 * NUM_ECC_DIGITS - 1] = + VliAdd((VeryLargeInt*)&tmpprod.word[NUM_ECC_DIGITS - 1], + (VeryLargeInt const*)&tmpprod.word[7], &linear); + vliLShift(&tmpprod, &tmpprod, 31); + } + // shift the 256+32-NUM_ECC_DIGITS-1 bits in the largest 9 limbs back to the + // base + vliProdRShift(&tmpprod, + (VeryLargeIntProduct const*)&tmpprod.word[NUM_ECC_DIGITS - 1], + (31 * 8) % 32, NUM_ECC_DIGITS + 1); + vliScalarMult(&linear, &negprime, tmpprod.word[NUM_ECC_DIGITS]); + carry = VliAdd((VeryLargeInt*)&tmpprod.word[0], + (VeryLargeInt const*)&tmpprod.word[0], + (VeryLargeInt const*)&linear); + carry |= (-1 < VliCmp((VeryLargeInt const*)&tmpprod.word[0], mod)); + vliScalarMult(&linear, &negprime, carry); + VliAdd(result, (VeryLargeInt const*)&tmpprod.word[0], &linear); +} diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.cc b/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.cc new file mode 100644 index 00000000..8956f75e --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.cc @@ -0,0 +1,71 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Comparators for tiny math types. +/*! \file */ + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +#include + +extern "C" { +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +bool operator==(VeryLargeInt const& lhs, VeryLargeInt const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(VeryLargeIntProduct const& lhs, + VeryLargeIntProduct const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} +bool operator==(FpElem const& lhs, FpElem const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(FqElem const& lhs, FqElem const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(Fq2Elem const& lhs, Fq2Elem const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(Fq6Elem const& lhs, Fq6Elem const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(Fq12Elem const& lhs, Fq12Elem const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(EccPointFq const& lhs, EccPointFq const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(EccPointJacobiFq const& lhs, EccPointJacobiFq const& rhs) { + return 0 != EFqEq(&lhs, &rhs); +} + +bool operator==(EccPointFq2 const& lhs, EccPointFq2 const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(EccPointJacobiFq2 const& lhs, EccPointJacobiFq2 const& rhs) { + return 0 != EFq2Eq(&lhs, &rhs); +} diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.h b/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.h new file mode 100644 index 00000000..c8a688f7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/cmp-testhelper.h @@ -0,0 +1,65 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Comparators for tiny math types. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_UNITTESTS_CMP_TESTHELPER_H_ +#define EPID_MEMBER_TINY_MATH_UNITTESTS_CMP_TESTHELPER_H_ + +typedef struct VeryLargeInt VeryLargeInt; +typedef struct VeryLargeIntProduct VeryLargeIntProduct; +typedef struct FpElem FpElem; +typedef struct FqElem FqElem; +typedef struct Fq2Elem Fq2Elem; +typedef struct Fq6Elem Fq6Elem; +typedef struct Fq12Elem Fq12Elem; +typedef struct EccPointFq EccPointFq; +typedef struct EccPointJacobiFq EccPointJacobiFq; +typedef struct EccPointFq2 EccPointFq2; +typedef struct EccPointJacobiFq2 EccPointJacobiFq2; + +/// compares VeryLargeInt values +bool operator==(VeryLargeInt const& lhs, VeryLargeInt const& rhs); +bool operator==(VeryLargeIntProduct const& lhs, VeryLargeIntProduct const& rhs); + +/// compares FpElem values +bool operator==(FpElem const& lhs, FpElem const& rhs); + +/// compares FqElem values +bool operator==(FqElem const& lhs, FqElem const& rhs); + +/// compares Fq2Elem values +bool operator==(Fq2Elem const& lhs, Fq2Elem const& rhs); + +/// compares Fq6Elem values +bool operator==(Fq6Elem const& lhs, Fq6Elem const& rhs); + +/// compares Fq12Elem values +bool operator==(Fq12Elem const& lhs, Fq12Elem const& rhs); + +/// compares EccPointFq values +bool operator==(EccPointFq const& lhs, EccPointFq const& rhs); + +/// compares EccPointJacobiFq values +bool operator==(EccPointJacobiFq const& lhs, EccPointJacobiFq const& rhs); + +/// compares EccPointFq2 values +bool operator==(EccPointFq2 const& lhs, EccPointFq2 const& rhs); + +/// compares EccPointJacobiFq2 values +bool operator==(EccPointJacobiFq2 const& lhs, EccPointJacobiFq2 const& rhs); + +#endif // EPID_MEMBER_TINY_MATH_UNITTESTS_CMP_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/efq-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/efq-test.cc new file mode 100644 index 00000000..b33e5d6f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/efq-test.cc @@ -0,0 +1,714 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of EFq implementation. +/*! \file */ + +#include +#include +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" +#include "epid/member/tiny/math/unittests/onetimepad.h" + +extern "C" { +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/vli.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// EFqMulSSCM +TEST(TinyEFqTest, EFqMulSSCMWorks) { + const EccPointJacobiFq expected = { + {0xacd848b1, 0xe3d60553, 0x69271cd1, 0x7cf6090e, 0x16c63bcd, 0xdb0c6cf0, + 0x2ab60283, 0x38fc72a8}, + {0xf7e0f7d1, 0x6b0cf194, 0x5cf18c77, 0x82a4b960, 0xa6c40a30, 0xf0b3b20f, + 0x5f1a477b, 0x7e2a6668}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + const EccPointJacobiFq left = { + {0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, 0x4780716c, + 0xffd94b0f, 0x5e643124}, + {0x5e9cb480, 0x6d4aaf9c, 0x99f1f606, 0x222d89b0, 0x30b79eab, 0x88844bd6, + 0xc65e7c30, 0x4830c4ec}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + const FpElem power = {0x0adf9a12, 0x5cbc9ef4, 0x91762984, 0xa08a22fb, + 0x52a6fddf, 0xf51e743e, 0x7b47b24b, 0x389f865f}; + + EccPointJacobiFq actual = {0}; + + EFqMulSSCM(&actual, &left, &power); + EXPECT_EQ(expected, actual); +} + +TEST(TinyEFqTest, EFqMulSSCMWorksInPlace) { + const EccPointJacobiFq expected = { + {0xacd848b1, 0xe3d60553, 0x69271cd1, 0x7cf6090e, 0x16c63bcd, 0xdb0c6cf0, + 0x2ab60283, 0x38fc72a8}, + {0xf7e0f7d1, 0x6b0cf194, 0x5cf18c77, 0x82a4b960, 0xa6c40a30, 0xf0b3b20f, + 0x5f1a477b, 0x7e2a6668}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + EccPointJacobiFq left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x5e9cb480, 0x6d4aaf9c, 0x99f1f606, 0x222d89b0, + 0x30b79eab, 0x88844bd6, 0xc65e7c30, 0x4830c4ec}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}; + const FpElem power = {0x0adf9a12, 0x5cbc9ef4, 0x91762984, 0xa08a22fb, + 0x52a6fddf, 0xf51e743e, 0x7b47b24b, 0x389f865f}; + + EFqMulSSCM(&left, &left, &power); + EXPECT_EQ(expected, left); +} +//////////////////////////////////////////////////////////////////////// +// EFqMultiExp + +TEST(TinyEFqTest, EFqAffineExpWorks) { + EccPointFq efq_left = {0}; + EccPointFq efq_right = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq efq_expect = {{{0x79171d4b, 0x0f5ac562, 0x3b911d03, 0x0992a2dc, + 0x3130dd84, 0x16344c80, 0x436ca13c, 0xaf1d9819}}, + {{0x742268cd, 0x070b4ac7, 0x7f2b13b7, 0xe167da7f, + 0xd84d16af, 0x9e824ebe, 0x6b5dc0f0, 0x90bd1aa3}}}; + + FpElem fp_exp = {3}; + + EFqAffineExp(&efq_left, &efq_right, &fp_exp); + + EXPECT_EQ(efq_expect, efq_left); +} +TEST(TinyEFqTest, EFqAffineExpWorksInPlace) { + EccPointFq efq_right = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq efq_expect = {{{0x79171d4b, 0x0f5ac562, 0x3b911d03, 0x0992a2dc, + 0x3130dd84, 0x16344c80, 0x436ca13c, 0xaf1d9819}}, + {{0x742268cd, 0x070b4ac7, 0x7f2b13b7, 0xe167da7f, + 0xd84d16af, 0x9e824ebe, 0x6b5dc0f0, 0x90bd1aa3}}}; + + FpElem fp_exp = {3}; + + EFqAffineExp(&efq_right, &efq_right, &fp_exp); + + EXPECT_EQ(efq_expect, efq_right); +} +//////////////////////////////////////////////////////////////////////// +// EFqAffineMultiExp +TEST(TinyEFqTest, EFqAffineMultiExpWorks) { + // eFq2^3*eFq2^3 + EccPointFq efq_left = {0}; + EccPointFq efq_right = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq efq_expect = {{{0x1a178986, 0xeeb06c08, 0x857d79f0, 0x246d0ed6, + 0xed31a3b2, 0x7bf832a0, 0x81a8a27b, 0x3d0cab80}}, + {{0xfe2a1509, 0x41cda394, 0x42b33efb, 0x2811fa22, + 0x0ad56486, 0xe52b1a56, 0xf6dc881c, 0x6fee593f}}}; + + FpElem fp_exp = {3}; + + EFqAffineMultiExp(&efq_left, &efq_right, &fp_exp, &efq_right, &fp_exp); + + EXPECT_EQ(efq_expect, efq_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqMultiExp +TEST(TinyEFqTest, EFqMultiExpWorks) { + EccPointFq efq_left = {0}; + EccPointFq efq_right = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq efq_expect = {{{0x1a178986, 0xeeb06c08, 0x857d79f0, 0x246d0ed6, + 0xed31a3b2, 0x7bf832a0, 0x81a8a27b, 0x3d0cab80}}, + {{0xfe2a1509, 0x41cda394, 0x42b33efb, 0x2811fa22, + 0x0ad56486, 0xe52b1a56, 0xf6dc881c, 0x6fee593f}}}; + + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq efqj_right; + + FpElem fp_exp = {3}; + + EFqFromAffine(&efqj_right, &efq_right); + EFqMultiExp(&efqj_left, &efqj_right, &fp_exp, &efqj_right, &fp_exp); + EFqToAffine(&efq_left, &efqj_left); + + EXPECT_EQ(efq_expect, efq_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqAffineAdd +TEST(TinyEFqTest, EFqAffineAddWorks) { + EccPointFq efq_left = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq const efq_expect = { + {{0x7305f782, 0x84101559, 0xe065da04, 0xfd373fcf, 0x31d2f725, 0x9b420bdc, + 0x622ac9c3, 0xba0ef378}}, + {{0x97b2adf0, 0x2935c14b, 0xfc6415b0, 0x48ba036a, 0x61ca7383, 0xcff7f03d, + 0x23a2c3e6, 0x0df0d4a5}}}; + + EFqAffineAdd(&efq_left, &efq_left, &efq_left); + EXPECT_EQ(efq_expect, efq_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqAffineDbl +TEST(TinyEFqTest, EFqAffineDblWorks) { + EccPointFq efq_left = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, + 0x0ac0b46b, 0x557a5f30, 0xaf075250, 0x786528cb}}}; + + EccPointFq const efq_expect = { + {{0x7305f782, 0x84101559, 0xe065da04, 0xfd373fcf, 0x31d2f725, 0x9b420bdc, + 0x622ac9c3, 0xba0ef378}}, + {{0x97b2adf0, 0x2935c14b, 0xfc6415b0, 0x48ba036a, 0x61ca7383, 0xcff7f03d, + 0x23a2c3e6, 0x0df0d4a5}}}; + + EFqAffineDbl(&efq_left, &efq_left); + EXPECT_EQ(efq_expect, efq_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqDbl +TEST(TinyEFqTest, EFqDblWorks) { + EccPointJacobiFq efqj_left = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EccPointJacobiFq const efqj_expect = { + {{0x7305f782, 0x84101559, 0xe065da04, 0xfd373fcf, 0x31d2f725, 0x9b420bdc, + 0x622ac9c3, 0xba0ef378}}, + {{0x97b2adf0, 0x2935c14b, 0xfc6415b0, 0x48ba036a, 0x61ca7383, 0xcff7f03d, + 0x23a2c3e6, 0x0df0d4a5}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EFqDbl(&efqj_left, &efqj_left); + EXPECT_EQ(efqj_expect, efqj_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqAdd +TEST(TinyEFqTest, EFqAddWorks) { + EccPointJacobiFq efqj_left = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EccPointJacobiFq const efqj_expect = { + {{0x7305f782, 0x84101559, 0xe065da04, 0xfd373fcf, 0x31d2f725, 0x9b420bdc, + 0x622ac9c3, 0xba0ef378}}, + {{0x97b2adf0, 0x2935c14b, 0xfc6415b0, 0x48ba036a, 0x61ca7383, 0xcff7f03d, + 0x23a2c3e6, 0x0df0d4a5}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EFqAdd(&efqj_left, &efqj_left, &efqj_left); + EXPECT_EQ(efqj_expect, efqj_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqRand + +// Checks if EFqRand can generate points with Y >= q+1 +TEST(TinyEFqTest, EFqRandCanGenerateBigY) { + OneTimePad otp({ + 0x25, 0xeb, 0x8c, 0x48, 0xff, 0x89, 0xcb, 0x85, 0x4f, 0xc0, 0x90, 0x81, + 0xcc, 0x47, 0xed, 0xfc, 0x86, 0x19, 0xb2, 0x14, 0xfe, 0x65, 0x92, 0xd4, + 0x8b, 0xfc, 0xea, 0x9c, 0x9d, 0x8e, 0x32, 0x44, 0xd7, 0xd7, 0xe9, 0xf1, + 0xf7, 0xde, 0x60, 0x56, 0x8d, 0xe9, 0x89, 0x07, 0x3f, 0x3d, 0x16, 0x39, + }); + + // expected.y >= q+1 + EccPointFq expected = {{0xd78542d3, 0xf824c127, 0x81eea621, 0x6990833d, + 0x9d843df6, 0x3df36126, 0x435e8eda, 0x2d267586}, + {0x1B8DC14B, 0x5967C520, 0x61CECE5D, 0x0290B5BC, + 0x49278859, 0x2C523D9A, 0x6D0AE6DE, 0xAE5590C9}}; + + EccPointFq actual = {0}; + EXPECT_TRUE(EFqRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +// Checks if EFqRand can generate points with Y <= q-1 +TEST(TinyEFqTest, EFqRandCanGenerateSmallY) { + OneTimePad otp({ + 0x47, 0xe7, 0xb0, 0x36, 0x0f, 0x85, 0x91, 0xaa, 0x14, 0x76, 0xb0, 0x16, + 0xe5, 0x8d, 0xf1, 0x72, 0x61, 0xb5, 0x54, 0x0a, 0x60, 0xb7, 0x3d, 0x38, + 0xd9, 0x95, 0xe7, 0x60, 0xf9, 0xd3, 0x19, 0xf1, 0x8e, 0x8d, 0xd4, 0x74, + 0x2b, 0x86, 0xcd, 0xb8, 0xbb, 0x8f, 0x18, 0xfb, 0x89, 0xc2, 0xc7, 0x35, + }); + + // expected.y <= q-1 + EccPointFq expected = {{0x5f65199e, 0x59366f56, 0xb1d35d89, 0xf42fdc1f, + 0x07fd66d6, 0x95f32cb3, 0xc4ef7101, 0xeb426988}, + {0x834171f5, 0xca1c1f05, 0xdcb4d142, 0xbe060756, + 0x9185652b, 0xb3b9ede1, 0x671f682e, 0x22d0c94c}}; + + EccPointFq actual = {0}; + EXPECT_TRUE(EFqRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +TEST(TinyEFqTest, EFqRandWorksForFailedSquareRoot) { + // Only last 48 bytes of the given otp will result in x such that + // Fq.sqrt of (x^3 + a*x + b) exists. + OneTimePad otp({ + 0x01, 0x80, 0x3c, 0xd1, 0x08, 0xd8, 0x8d, 0x73, 0xaf, 0xea, 0x79, 0xc8, + 0x1e, 0x47, 0x83, 0xc6, 0x95, 0x31, 0x39, 0x03, 0xc4, 0x18, 0xf1, 0x2b, + 0x4c, 0x1a, 0x34, 0x50, 0x6d, 0x73, 0x29, 0xd2, 0x0f, 0x40, 0xc4, 0x19, + 0x6f, 0xe2, 0xd7, 0x87, 0x1a, 0x99, 0x68, 0x16, 0x09, 0xc3, 0xe7, 0x7e, + 0x17, 0x7d, 0x64, 0x9b, 0xa5, 0x39, 0x53, 0xa6, 0x88, 0x20, 0xa2, 0x0a, + 0x17, 0x8f, 0xef, 0x57, 0x19, 0xc7, 0xf3, 0x5c, 0x4a, 0xbe, 0x2e, 0xa0, + 0xd8, 0x97, 0xb7, 0x41, 0x71, 0x4d, 0x03, 0x80, 0xf8, 0xfd, 0xcd, 0x06, + 0x34, 0xd5, 0xc6, 0x02, 0x4c, 0xdb, 0x95, 0xcb, 0x07, 0x4d, 0xc8, 0x4b, + 0x4c, 0x2b, 0x14, 0x1e, 0x24, 0x67, 0x07, 0x2d, 0xc4, 0x39, 0xf0, 0xfc, + 0xd2, 0x60, 0x0d, 0x0a, 0x17, 0x7c, 0x51, 0x87, 0x79, 0x98, 0xca, 0xdc, + 0x94, 0xa0, 0x8c, 0xc1, 0x5e, 0x3c, 0xe9, 0x98, 0x52, 0x73, 0x61, 0x82, + 0xec, 0xdc, 0x67, 0x62, 0x0a, 0xb6, 0x60, 0xe9, 0x52, 0xd6, 0xc6, 0xc2, + 0x47, 0xe7, 0xb0, 0x36, 0x0f, 0x85, 0x91, 0xaa, 0x14, 0x76, 0xb0, 0x16, + 0xe5, 0x8d, 0xf1, 0x72, 0x61, 0xb5, 0x54, 0x0a, 0x60, 0xb7, 0x3d, 0x38, + 0xd9, 0x95, 0xe7, 0x60, 0xf9, 0xd3, 0x19, 0xf1, 0x8e, 0x8d, 0xd4, 0x74, + 0x2b, 0x86, 0xcd, 0xb8, 0xbb, 0x8f, 0x18, 0xfb, 0x89, 0xc2, 0xc7, 0x35, + }); + + EccPointFq expected = {{0x5f65199e, 0x59366f56, 0xb1d35d89, 0xf42fdc1f, + 0x07fd66d6, 0x95f32cb3, 0xc4ef7101, 0xeb426988}, + {0x834171f5, 0xca1c1f05, 0xdcb4d142, 0xbe060756, + 0x9185652b, 0xb3b9ede1, 0x671f682e, 0x22d0c94c}}; + + EccPointFq actual = {0}; + + EXPECT_TRUE(EFqRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(1536u, otp.BitsConsumed()); +} + +//////////////////////////////////////////////////////////////////////// +// EFqSet + +TEST(TinyEFqTest, EFqSetWorks) { + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq const efqj_expect = {{{1}}, {{2}}, {{1}}}; + + FqElem x = {1}; + FqElem y = {2}; + + EFqSet(&efqj_left, &x, &y); + EXPECT_EQ(efqj_expect, efqj_left); +} + +//////////////////////////////////////////////////////////////////////// +// EFqIsInf +TEST(TinyEFqTest, EFqIsInfPasses) { + EccPointJacobiFq const efqj_inf = {{{0}}, {{1}}, {{0}}}; + + EXPECT_TRUE(EFqIsInf(&efqj_inf)); +} + +TEST(TinyEFqTest, EFqIsInfFails) { + EccPointJacobiFq const efqj_noninf = {{{1}}, {{2}}, {{1}}}; + + EXPECT_FALSE(EFqIsInf(&efqj_noninf)); +} + +//////////////////////////////////////////////////////////////////////// +// EFqFromAffine +TEST(TinyEFqTest, FqFromAffineWorks) { + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq const efqj_expect = {{{1}}, {{2}}, {{1}}}; + EccPointFq efq_left = {{{1}}, {{2}}}; + + EFqFromAffine(&efqj_left, &efq_left); + EXPECT_EQ(efqj_expect, efqj_left); +} +//////////////////////////////////////////////////////////////////////// +// EFqToAffine + +TEST(TinyEFqTest, EFqToAffineWorks) { + EccPointFq efq_left = {0}; + EccPointFq const efq_expect = {{{1}}, {{2}}}; + EccPointJacobiFq efqj_left = {{{1}}, {{2}}, {{1}}}; + + EFqToAffine(&efq_left, &efqj_left); + EXPECT_EQ(efq_expect, efq_left); +} + +//////////////////////////////////////////////////////////////////////// +// EFqNeg + +TEST(TinyEFqTest, EFqNegWorks) { + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq efqj_right = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EccPointJacobiFq const efqj_expect = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x8f98a4d1, 0x0a561b5c, 0xa50112b5, 0x226c8304, 0xe3b0f033, 0xf16b932e, + 0x50f59e7c, 0x879ad734}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EFqNeg(&efqj_left, &efqj_right); + + EXPECT_EQ(efqj_expect, efqj_left); +} + +//////////////////////////////////////////////////////////////////////// +// EFqEq + +TEST(TinyEFqTest, EFqEqPasses) { + EccPointJacobiFq const efqj_left = {{{1}}, {{2}}, {{1}}}; + + EccPointJacobiFq const efqj_right = {{{1}}, {{2}}, {{1}}}; + + EXPECT_TRUE(EFqEq(&efqj_left, &efqj_right)); +} + +TEST(TinyEFqTest, EFqEqFails) { + EccPointJacobiFq const efqj_left = {{{1}}, {{2}}, {{1}}}; + + EccPointJacobiFq const efqj_right = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EXPECT_FALSE(EFqEq(&efqj_left, &efqj_right)); +} + +//////////////////////////////////////////////////////////////////////// +// EFqHash + +TEST(TinyEFqTest, EFqHashWithSha512Works) { + EccPointFq efq_result = {0}; + EccPointFq efq_expect = {{{0x992a96e4, 0x42f7b394, 0xf3bada9c, 0xb4033d83, + 0x21979b9b, 0xbc82a6a2, 0x55555586, 0x8c62a02d}}, + {{0x406c8f03, 0xe691d8f3, 0xadf2f27b, 0x69540cc6, + 0xe02b87f7, 0x217d5424, 0x17b9fbe5, 0x4c0ea762}}}; + unsigned char const msg_buf[] = {'a', 'b', 'c'}; + size_t len = sizeof(msg_buf); + HashAlg hashalg = kSha512; + EXPECT_TRUE(EFqHash(&efq_result, msg_buf, len, hashalg)); + EXPECT_EQ(efq_expect, efq_result); +} + +TEST(TinyEFqTest, EFqHashWithSha256Works) { + EccPointFq efq_result = {0}; + EccPointFq efq_expect = {{{0x8008953d, 0xd54a103c, 0x70e6186b, 0x54f5a62a, + 0xadbe836e, 0xf3716581, 0x88ff2562, 0x2ebb504d}}, + {{0xdc48f9f7, 0x48aa0d6c, 0x623e2c1f, 0x7ecdf02e, + 0x07f07a32, 0xbd6738b1, 0xb13f3cb4, 0x8a43a104}}}; + unsigned char const msg_buf[] = {'a', 'b', 'c'}; + size_t len = sizeof(msg_buf); + HashAlg hashalg = kSha256; + EXPECT_TRUE(EFqHash(&efq_result, msg_buf, len, hashalg)); + EXPECT_EQ(efq_expect, efq_result); +} + +TEST(TinyEFqTest, HashWorksForResultYSmallerThanHalfOfQAndEven) { + std::vector msg = {'a', 'a', 'd'}; + EccPointFq result; + EccPointFq expected = {{0xb315d67e, 0x1924ae56, 0xcf527861, 0xebb789b6, + 0x3f429d2a, 0xb193bf9a, 0x6bd8502f, 0x5e73be39}, + {0x0bd51968, 0x0f13472d, 0xc96b5096, 0xa9cd4491, + 0x4ab668cf, 0x2123d56c, 0xf30af180, 0x0db43c33}}; + EXPECT_TRUE(EFqHash(&result, msg.data(), msg.size(), kSha512)); + EXPECT_EQ(expected, result); +} +TEST(TinyEFqTest, HashWorksForResultYSmallerThanHalfOfQAndOdd) { + std::vector msg = {'a', 'a', 'c'}; + EccPointFq result; + EccPointFq expected = {{0x81D359E2, 0xF438B2AC, 0xAA4342EB, 0x80042B18, + 0x850E1C62, 0x90860717, 0xC79A1AB8, 0xF8F4F2F6}, + {0xC1A2BA30, 0x369C0D70, 0x03EAF9DD, 0x4F93FC67, + 0xBB6E5D10, 0x441B22F9, 0xEC70C946, 0xE8D39BD4}}; + EXPECT_TRUE(EFqHash(&result, msg.data(), msg.size(), kSha512)); + EXPECT_EQ(expected, result); +} + +TEST(TinyEFqTest, HashWorksForResultYLargerThanHalfOfQAndOdd) { + std::vector msg = {'a', 'a', 'b'}; + EccPointFq result; + EccPointFq expected = {{0x31F874DA, 0x62DB014E, 0x4A4FC69A, 0xC1DCC122, + 0xC423DAF8, 0x27AB3AAC, 0xF1DE0993, 0x07906282}, + {0x8DA507A4, 0x568E1D1E, 0x6D373E90, 0x99A18DA4, + 0xC5717AA2, 0x98C222F5, 0x0A2ADDF2, 0xA1212A44}}; + EFqHash(&result, msg.data(), msg.size(), kSha512); + EXPECT_EQ(expected, result); +} + +TEST(TinyEFqTest, HashWorksForResultYLargerThanHalfOfQAndEven) { + std::vector msg = {'a', 'a', 'e'}; + EccPointFq result; + EccPointFq expected = {{0xA798F97C, 0xF24EC264, 0xD4C051F4, 0xBA4A5B45, + 0xD2CF5996, 0x121A3F66, 0x222279F0, 0x208E4FD4}, + {0x3C816617, 0x6CF621EB, 0x8B8DAFC4, 0x63EB39C7, + 0xE6C8AF5C, 0x32C732D0, 0xC5C46152, 0x114E8AE0}}; + EFqHash(&result, msg.data(), msg.size(), kSha512); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// EFqCp + +TEST(TinyEFqTest, EFqCpWorks) { + const EccPointFq ecfq_point = { + {{0x76ABB18A, 0x92C0F7B9, 0x2C1A37E0, 0x7FDF6CA1, 0xE3401760, 0x66EB7D52, + 0x918D50A7, 0x12A65BD6}}, + {{0x1F3A8B42, 0xC8D3127F, 0x6D96F7CD, 0xEA6FE2F6, 0x0AC0B46B, 0x557A5F30, + 0xAF075250, 0x786528CB}}}; + EccPointFq result_ecfq_point = {0}; + EFqCp(&result_ecfq_point, &ecfq_point); + EXPECT_EQ(ecfq_point, result_ecfq_point); +} + +//////////////////////////////////////////////////////////////////////// +// EFqEqAffine + +TEST(TinyEFqTest, EFqEqAffinePasses) { + EccPointFq efq_left = {{{1}}, {{2}}}; + EccPointFq efq_right = {{{1}}, {{2}}}; + + EXPECT_TRUE(EFqEqAffine(&efq_left, &efq_right)); +} + +TEST(TinyEFqTest, EFqEqAffineFails) { + EccPointFq efq_left = {{{1}}, {{2}}}; + EccPointFq efq_right = {{{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}, + {{0x8f98a4d1, 0x0a561b5c, 0xa50112b5, 0x226c8304, + 0xe3b0f033, 0xf16b932e, 0x50f59e7c, 0x879ad734}}}; + + EXPECT_FALSE(EFqEqAffine(&efq_left, &efq_right)); +} +//////////////////////////////////////////////////////////////////////// +// EFqCondSet + +TEST(TinyEFqTest, EFqCondSetWorksForTrue) { +#define TRUE 1 + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq efqj_right = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointJacobiFq efqj_expect = {{{1}}, {{2}}, {{1}}}; + + EFqCondSet(&efqj_left, &efqj_expect, &efqj_right, TRUE); + EXPECT_EQ(efqj_left, efqj_expect); +} + +TEST(TinyEFqTest, EFqCondSetWorksForFalse) { +#define FALSE 0 + EccPointJacobiFq efqj_left = {0}; + EccPointJacobiFq efqj_right = {{{1}}, {{2}}, {{1}}}; + EccPointJacobiFq efqj_expect = { + {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, 0x66eb7d52, + 0x918d50a7, 0x12a65bd6}}, + {{0x1f3a8b42, 0xc8d3127f, 0x6d96f7cd, 0xea6fe2f6, 0x0ac0b46b, 0x557a5f30, + 0xaf075250, 0x786528cb}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + + EFqCondSet(&efqj_left, &efqj_right, &efqj_expect, FALSE); + EXPECT_EQ(efqj_left, efqj_expect); +} + +//////////////////////////////////////////////////////////////////////// +// EFqJCp + +TEST(TinyEFqTest, EFqJCpWorks) { + const EccPointJacobiFq efqj = {{{1}}, {{2}}, {{1}}}; + EccPointJacobiFq efqj_result = {0}; + EFqJCp(&efqj_result, &efqj); + EXPECT_EQ(efqj, efqj_result); +} + +//////////////////////////////////////////////////////////////////////// +// EFqInf + +TEST(TinyEFqTest, EFqInfWorks) { + EccPointJacobiFq efqj_left; + EccPointJacobiFq efqj_expect = {{{0}}, {{1}}, {{0}}}; + EFqInf(&efqj_left); + + EXPECT_EQ(efqj_expect, efqj_left); +} + +//////////////////////////////////////////////////////////////////////// +// EFqOnCurve + +TEST(TinyEFqTest, EFqOnCurvePasses) { + const EccPointFq ecfq_point = { + {{0x76ABB18A, 0x92C0F7B9, 0x2C1A37E0, 0x7FDF6CA1, 0xE3401760, 0x66EB7D52, + 0x918D50A7, 0x12A65BD6}}, + {{0x1F3A8B42, 0xC8D3127F, 0x6D96F7CD, 0xEA6FE2F6, 0x0AC0B46B, 0x557A5F30, + 0xAF075250, 0x786528CB}}}; + EXPECT_EQ(1, EFqOnCurve(&ecfq_point)); +} + +TEST(TinyEFqTest, EFqOnCurveFails) { + EccPointFq bad_ecfq_point = { + {{0x76ABB18A, 0x92C0F7B9, 0x2C1A37E0, 0x7FDF6CA1, 0xE3401760, 0x66EB7D52, + 0x918D50A7, 0x12A65BD6}}, + {{0x1F3A8B42, 0xC8D3127F, 0x6D96F7CD, 0xEA6FE2F6, 0x0AC0B46B, 0x557A5F30, + 0xAF075250, 0x786528CB}}}; + uint8_t* ecpq_vec = (uint8_t*)bad_ecfq_point.x.limbs.word; + ecpq_vec[31]++; + EXPECT_EQ(0, EFqOnCurve(&bad_ecfq_point)); +} + +//////////////////////////////////////////////////////////////////////// +// EFqJOnCurve + +TEST(TinyEFqTest, EFqJOnCurvePasses) { + EccPointJacobiFq efqj = {{{1}}, {{2}}, {{1}}}; + + EXPECT_TRUE(EFqJOnCurve(&efqj)); +} + +TEST(TinyEFqTest, EFqJOnCurveFails) { + EccPointJacobiFq efqj = {{{1}}, {{4}}, {{1}}}; + + EXPECT_FALSE(EFqJOnCurve(&efqj)); +} + +TEST(TinyEFqTest, EFqJOnCurveAcceptsPointAtInfinity) { + EccPointJacobiFq infinity = {{{0}}, {{1}}, {{0}}}; + + EXPECT_TRUE(EFqJOnCurve(&infinity)); +} + +//////////////////////////////////////////////////////////////////////// +// EFqJRand + +// Checks if EFqJRand can generate points with Y >= q+1 +TEST(TinyEFqTest, EFqJRandCanGenerateBigY) { + OneTimePad otp({ + 0x25, 0xeb, 0x8c, 0x48, 0xff, 0x89, 0xcb, 0x85, 0x4f, 0xc0, 0x90, 0x81, + 0xcc, 0x47, 0xed, 0xfc, 0x86, 0x19, 0xb2, 0x14, 0xfe, 0x65, 0x92, 0xd4, + 0x8b, 0xfc, 0xea, 0x9c, 0x9d, 0x8e, 0x32, 0x44, 0xd7, 0xd7, 0xe9, 0xf1, + 0xf7, 0xde, 0x60, 0x56, 0x8d, 0xe9, 0x89, 0x07, 0x3f, 0x3d, 0x16, 0x39, + }); + + // expected.y >= q+1 + EccPointJacobiFq expected = { + {0xd78542d3, 0xf824c127, 0x81eea621, 0x6990833d, 0x9d843df6, 0x3df36126, + 0x435e8eda, 0x2d267586}, + {0x1B8DC14B, 0x5967C520, 0x61CECE5D, 0x0290B5BC, 0x49278859, 0x2C523D9A, + 0x6D0AE6DE, 0xAE5590C9}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + + EccPointJacobiFq actual = {0}; + EXPECT_TRUE(EFqJRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +// Checks if EFqJRand can generate points with Y <= q-1 +TEST(TinyEFqTest, EFqJRandCanGenerateSmallY) { + OneTimePad otp({ + 0x47, 0xe7, 0xb0, 0x36, 0x0f, 0x85, 0x91, 0xaa, 0x14, 0x76, 0xb0, 0x16, + 0xe5, 0x8d, 0xf1, 0x72, 0x61, 0xb5, 0x54, 0x0a, 0x60, 0xb7, 0x3d, 0x38, + 0xd9, 0x95, 0xe7, 0x60, 0xf9, 0xd3, 0x19, 0xf1, 0x8e, 0x8d, 0xd4, 0x74, + 0x2b, 0x86, 0xcd, 0xb8, 0xbb, 0x8f, 0x18, 0xfb, 0x89, 0xc2, 0xc7, 0x35, + }); + + // expected.y <= q-1 + EccPointJacobiFq expected = { + {0x5f65199e, 0x59366f56, 0xb1d35d89, 0xf42fdc1f, 0x07fd66d6, 0x95f32cb3, + 0xc4ef7101, 0xeb426988}, + {0x834171f5, 0xca1c1f05, 0xdcb4d142, 0xbe060756, 0x9185652b, 0xb3b9ede1, + 0x671f682e, 0x22d0c94c}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + + EccPointJacobiFq actual = {0}; + EXPECT_TRUE(EFqJRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +TEST(TinyEFqTest, EFqJRandWorksForFailedSquareRoot) { + // Only last 48 bytes of the given otp will result in x such that + // Fq.sqrt of (x^3 + a*x + b) exists. + OneTimePad otp({ + 0x01, 0x80, 0x3c, 0xd1, 0x08, 0xd8, 0x8d, 0x73, 0xaf, 0xea, 0x79, 0xc8, + 0x1e, 0x47, 0x83, 0xc6, 0x95, 0x31, 0x39, 0x03, 0xc4, 0x18, 0xf1, 0x2b, + 0x4c, 0x1a, 0x34, 0x50, 0x6d, 0x73, 0x29, 0xd2, 0x0f, 0x40, 0xc4, 0x19, + 0x6f, 0xe2, 0xd7, 0x87, 0x1a, 0x99, 0x68, 0x16, 0x09, 0xc3, 0xe7, 0x7e, + 0x17, 0x7d, 0x64, 0x9b, 0xa5, 0x39, 0x53, 0xa6, 0x88, 0x20, 0xa2, 0x0a, + 0x17, 0x8f, 0xef, 0x57, 0x19, 0xc7, 0xf3, 0x5c, 0x4a, 0xbe, 0x2e, 0xa0, + 0xd8, 0x97, 0xb7, 0x41, 0x71, 0x4d, 0x03, 0x80, 0xf8, 0xfd, 0xcd, 0x06, + 0x34, 0xd5, 0xc6, 0x02, 0x4c, 0xdb, 0x95, 0xcb, 0x07, 0x4d, 0xc8, 0x4b, + 0x4c, 0x2b, 0x14, 0x1e, 0x24, 0x67, 0x07, 0x2d, 0xc4, 0x39, 0xf0, 0xfc, + 0xd2, 0x60, 0x0d, 0x0a, 0x17, 0x7c, 0x51, 0x87, 0x79, 0x98, 0xca, 0xdc, + 0x94, 0xa0, 0x8c, 0xc1, 0x5e, 0x3c, 0xe9, 0x98, 0x52, 0x73, 0x61, 0x82, + 0xec, 0xdc, 0x67, 0x62, 0x0a, 0xb6, 0x60, 0xe9, 0x52, 0xd6, 0xc6, 0xc2, + 0x47, 0xe7, 0xb0, 0x36, 0x0f, 0x85, 0x91, 0xaa, 0x14, 0x76, 0xb0, 0x16, + 0xe5, 0x8d, 0xf1, 0x72, 0x61, 0xb5, 0x54, 0x0a, 0x60, 0xb7, 0x3d, 0x38, + 0xd9, 0x95, 0xe7, 0x60, 0xf9, 0xd3, 0x19, 0xf1, 0x8e, 0x8d, 0xd4, 0x74, + 0x2b, 0x86, 0xcd, 0xb8, 0xbb, 0x8f, 0x18, 0xfb, 0x89, 0xc2, 0xc7, 0x35, + }); + + EccPointJacobiFq expected = { + {0x5f65199e, 0x59366f56, 0xb1d35d89, 0xf42fdc1f, 0x07fd66d6, 0x95f32cb3, + 0xc4ef7101, 0xeb426988}, + {0x834171f5, 0xca1c1f05, 0xdcb4d142, 0xbe060756, 0x9185652b, 0xb3b9ede1, + 0x671f682e, 0x22d0c94c}, + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}; + + EccPointJacobiFq actual = {0}; + + EXPECT_TRUE(EFqJRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); + EXPECT_EQ(1536u, otp.BitsConsumed()); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/efq2-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/efq2-test.cc new file mode 100644 index 00000000..0aef7371 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/efq2-test.cc @@ -0,0 +1,406 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of EFq2 implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// EFq2IsInf + +TEST(TinyEFq2Test, EFq2IsInfAcceptsPointAtInfinity) { + const EccPointJacobiFq2 infinity = { + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}, + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EXPECT_TRUE(EFq2IsInf(&infinity)); +} + +TEST(TinyEFq2Test, EFq2IsInfRejectsPointNotAtInfinity) { + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EXPECT_FALSE(EFq2IsInf(&left)); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2FromAffine + +TEST(TinyEFq2Test, EFq2FromAffineWorks) { + const EccPointJacobiFq2 expected = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointFq2 left_affine = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}}; + EccPointJacobiFq2 actual = {0}; + EFq2FromAffine(&actual, &left_affine); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2ToAffine + +TEST(TinyEFq2Test, EFq2ToAffineWorks) { + const EccPointFq2 expected = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}}; + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointFq2 actual = {0}; + EFq2ToAffine(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2Dbl + +TEST(TinyEFq2Test, EFq2DblWorks) { + const EccPointJacobiFq2 expected = { + {{0xca2899c2, 0x38294bdb, 0xcf0b6b44, 0x270787b1, 0x28e6e40a, 0x2b848c15, + 0x03729665, 0xd042f637}, + {0xda226e33, 0x9e951b73, 0x7df4afb1, 0x4b44fcd5, 0x133d08f1, 0x703ec2c1, + 0x93fe9a4c, 0x014c1d38}}, + {{0xbd697392, 0x2bed001e, 0xde312107, 0x1c7a00ac, 0xc1c7c40e, 0xd720bece, + 0x6e98a67e, 0xaac006b6}, + {0x43a25c32, 0x51296e80, 0x318d99a6, 0xd60e60d3, 0xdb3084d0, 0x0625d792, + 0x25f4ca7e, 0x0a310fe4}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointJacobiFq2 actual = {0}; + EFq2Dbl(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2Add + +TEST(TinyEFq2Test, EFq2AddWorks) { + const EccPointJacobiFq2 expected = { + {{0x39d576f0, 0x314c3e0a, 0xdc7933c4, 0xb93a1af7, 0xa0b903f1, 0xd5648523, + 0x4745740d, 0xcd182581}, + {0x32365bad, 0x8351f42f, 0xd587f58a, 0x46b5c664, 0x11a71e4f, 0x8fde4189, + 0xa0dbb9b6, 0x35a921cf}}, + {{0xb1d07f87, 0x27fca861, 0xeb87751b, 0x40dee15b, 0x7abc2d89, 0xde6431b7, + 0x23bcc963, 0x79a7d75a}, + {0x5adc76e4, 0xb6a78fa4, 0xb4e50dbd, 0xd503cacd, 0xf188a97f, 0xc89769d8, + 0xd3da3cb0, 0x4e50dbe9}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 right = { + {{0x4103138f, 0xfa13e67e, 0x6837bfdf, 0x00565944, 0x11264453, 0x23f40661, + 0x673da0e0, 0xed12700d}, + {0x98f68547, 0x9cb87218, 0xc5ec70e5, 0x0c893388, 0x21dd4d22, 0x53386c5c, + 0x2b310753, 0xeca20f0e}}, + {{0x17a5237e, 0x3f8bfc68, 0xfd8f3ccc, 0xa630561a, 0xbf57703a, 0x68135f32, + 0xe230d781, 0xd544af99}, + {0x92ebeb94, 0x99b0cff6, 0xeebac3e7, 0x7d7aa73f, 0x7064674d, 0x25d8834a, + 0x7c64ff8b, 0x97e6a2ac}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointJacobiFq2 actual = {0}; + EFq2Add(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2Neg + +TEST(TinyEFq2Test, EFq2NegWorks) { + const EccPointJacobiFq2 expected = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x876cdaca, 0x1d7a77aa, 0x730fb243, 0x1817c20a, 0x66f6a147, 0x7a82f2b1, + 0xb83b6256, 0x08963678}, + {0xd6e605ff, 0x3585805b, 0x9ecba21a, 0x921d0bd7, 0x033c1324, 0x8b6f68a7, + 0xb9cb5b5f, 0xb8809ef0}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointJacobiFq2 actual = {0}; + EFq2Neg(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2MulSSCM + +TEST(TinyEFq2Test, EFq2MultSSCMWorks) { + const EccPointJacobiFq2 expected = { + {{0x75e057c7, 0x324aeb39, 0x0246ce8a, 0xe467356d, 0x4fcae21a, 0xeb58c86e, + 0x12447362, 0x1c02af0c}, + {0xfc9e5806, 0x790f79e8, 0xeffb940f, 0x44b942aa, 0xce364572, 0x8f1d0b6d, + 0xf2238fe0, 0x4c281551}}, + {{0x8e525052, 0x840bf78d, 0xf0a1e53a, 0xd43b1688, 0x1566bee6, 0x715cb6d2, + 0x27f8a10c, 0x62806aa5}, + {0xfe573502, 0x1b24a341, 0xffab4d71, 0x445e2e0c, 0x7f3aa342, 0x3013d966, + 0x69b239fa, 0x074a471c}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const FpElem power = {0xeb515e82, 0xda641a2f, 0x642e3fdc, 0x242d1caf, + 0xfd1cd76b, 0x60558750, 0x13fd607c, 0xd4a85a40}; + EccPointJacobiFq2 actual = {0}; + EFq2MulSSCM(&actual, &left, &power); + EXPECT_EQ(expected, actual); +} + +TEST(TinyEFq2Test, EFq2MultSSCMWorksInPlace) { + const EccPointJacobiFq2 expected = { + {{0x75e057c7, 0x324aeb39, 0x0246ce8a, 0xe467356d, 0x4fcae21a, 0xeb58c86e, + 0x12447362, 0x1c02af0c}, + {0xfc9e5806, 0x790f79e8, 0xeffb940f, 0x44b942aa, 0xce364572, 0x8f1d0b6d, + 0xf2238fe0, 0x4c281551}}, + {{0x8e525052, 0x840bf78d, 0xf0a1e53a, 0xd43b1688, 0x1566bee6, 0x715cb6d2, + 0x27f8a10c, 0x62806aa5}, + {0xfe573502, 0x1b24a341, 0xffab4d71, 0x445e2e0c, 0x7f3aa342, 0x3013d966, + 0x69b239fa, 0x074a471c}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EccPointJacobiFq2 left = {{{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, + 0x5303da83, 0x693bbb16, 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, + 0xa7b61e37, 0x209517cf, 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, + 0x877b0357, 0xcc62ffad, 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, + 0xeb35917a, 0xbb7689b7, 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}; + const FpElem power = {0xeb515e82, 0xda641a2f, 0x642e3fdc, 0x242d1caf, + 0xfd1cd76b, 0x60558750, 0x13fd607c, 0xd4a85a40}; + EFq2MulSSCM(&left, &left, &power); + EXPECT_EQ(expected, left); +} +//////////////////////////////////////////////////////////////////////// +// EFq2Eq + +TEST(TinyEFq2Test, EFq2EqConfirmsPointsAreEqual) { + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 left_2 = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EXPECT_TRUE(EFq2Eq(&left, &left_2)); +} + +TEST(TinyEFq2Test, EFq2EqDeniesPointsAreEqual) { + const EccPointJacobiFq2 left = { + {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16, + 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf, + 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad, + 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7, + 0x4631956d, 0x477f610f}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + const EccPointJacobiFq2 right = { + {{0x4103138f, 0xfa13e67e, 0x6837bfdf, 0x00565944, 0x11264453, 0x23f40661, + 0x673da0e0, 0xed12700d}, + {0x98f68547, 0x9cb87218, 0xc5ec70e5, 0x0c893388, 0x21dd4d22, 0x53386c5c, + 0x2b310753, 0xeca20f0e}}, + {{0x17a5237e, 0x3f8bfc68, 0xfd8f3ccc, 0xa630561a, 0xbf57703a, 0x68135f32, + 0xe230d781, 0xd544af99}, + {0x92ebeb94, 0x99b0cff6, 0xeebac3e7, 0x7d7aa73f, 0x7064674d, 0x25d8834a, + 0x7c64ff8b, 0x97e6a2ac}}, + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + EXPECT_FALSE(EFq2Eq(&left, &right)); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2OnCurve + +TEST(TinyEFq2Test, EFq2OnCurveConfirmsPointOnCurve) { + const EccPointFq2 left = {{{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, + 0x5303da83, 0x693bbb16, 0x679b2a8a, 0x06f54dd4}, + {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, + 0xa7b61e37, 0x209517cf, 0x534cd776, 0x4759d7f6}}, + {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, + 0x877b0357, 0xcc62ffad, 0x47c18e76, 0xf769c987}, + {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, + 0xeb35917a, 0xbb7689b7, 0x4631956d, 0x477f610f}}}; + EXPECT_TRUE(EFq2OnCurve(&left)); +} + +TEST(TinyEFq2Test, EFq2OnCurveRejectsPointOffCurve) { + const EccPointFq2 invalid = { + {{0x705eb0a4, 0xf30863e3, 0x6127e751, 0x15adee42, 0xb00baac0, 0x194dee74, + 0xb39bf2f3, 0x88b75019}, + {0x60d7ec1d, 0xd80f96dd, 0x731c01d7, 0xbf697161, 0x087e5f87, 0x91f4fe08, + 0xd1942d15, 0x62b03177}}, + {{0x38f6d02a, 0xae5274db, 0xb7eddcf3, 0xcf4ff611, 0x589140a6, 0xcbacb49c, + 0x48c50543, 0x1da802e9}, + {0x45b0c6f3, 0x52393bf1, 0xc70746b0, 0xa08caeba, 0x5cb44254, 0x53ebeb2a, + 0x620ea440, 0x2c3a40f1}}}; + EXPECT_FALSE(EFq2OnCurve(&invalid)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/fp-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/fp-test.cc new file mode 100644 index 00000000..b13d2334 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/fp-test.cc @@ -0,0 +1,263 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of Fp implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" +#include "epid/member/tiny/math/unittests/onetimepad.h" + +extern "C" { +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// FpInField + +TEST(TinyFpTest, FpInFieldPasses) { + FpElem zero = {0}; + FpElem p_minus_one = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_TRUE(FpInField(&zero)); + EXPECT_TRUE(FpInField(&p_minus_one)); +} + +TEST(TinyFpTest, FpInFieldFails) { + FpElem p = {{0xD10B500D, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_FALSE(FpInField(&p)); +} + +//////////////////////////////////////////////////////////////////////// +// FpAdd + +TEST(TinyFpTest, FpAddWorks) { + FpElem result = {0}, expected = {0}, left = {0}, right = {0}; + left.limbs.word[5] = 1; + right.limbs.word[5] = 2; + expected.limbs.word[5] = 3; + FpAdd(&result, &left, &right); + EXPECT_EQ(expected, result); + + FpElem p_minus_one = {0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + right = {2, 0, 0, 0, 0, 0, 0, 0}; + expected = {1, 0, 0, 0, 0, 0, 0, 0}; + FpAdd(&result, &p_minus_one, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FpMul + +TEST(TinyFpTest, FpMultWorks) { + FpElem left = {0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}; + FpElem right = {0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}; + FpElem expected = {0x3f172ebf, 0xf2219fce, 0x73591802, 0x7a7dbc7f, + 0xf82ed0df, 0xb8c0c56d, 0x3395ff68, 0x83d64983}; + FpElem result = {0}; + FpMul(&result, &left, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FpSub + +TEST(TinyFpTest, FpSubWorks) { + FpElem result = {0}, expected = {0}, left = {0}, right = {0}; + left.limbs.word[4] = 2; + right.limbs.word[4] = 1; + expected.limbs.word[4] = 1; + FpSub(&result, &left, &right); + EXPECT_EQ(expected, result); + + left = {1, 0, 0, 0, 0, 0, 0, 0}; + right = {2, 0, 0, 0, 0, 0, 0, 0}; + FpElem p_minus_one = {0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + FpSub(&result, &left, &right); + EXPECT_EQ(p_minus_one, result); +} + +//////////////////////////////////////////////////////////////////////// +// FpExp +TEST(TinyFpTest, FpExpWorks) { + FpElem result = {0}, expected = {0}, in = {0}; + VeryLargeInt exp = {0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + in.limbs.word[0] = 1; + expected.limbs.word[0] = 1; + FpExp(&result, &in, &exp); + EXPECT_EQ(expected, result); + + exp = {4, 0, 0, 0, 0, 0, 0, 0}; + in = {{0x0000007B, 0, 0, 0, 0, 0, 0, 0}}; + expected = {{0x0DA48871, 0, 0, 0, 0, 0, 0, 0}}; + FpExp(&result, &in, &exp); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FpNeg +TEST(TinyFpTest, FpNegWorks) { + FpElem const pairing_p = {{0xD10B500D, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpElem neg_value = {0}; + FpElem one = {{1, 0, 0, 0, 0, 0, 0, 0}}; + FpElem minus_one = pairing_p; + --minus_one.limbs.word[0]; + FpNeg(&neg_value, &one); + EXPECT_EQ(minus_one, neg_value); + + FpElem value = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpNeg(&neg_value, &value); + FpNeg(&neg_value, &neg_value); + EXPECT_EQ(value, neg_value); +} + +//////////////////////////////////////////////////////////////////////// +// FpEq + +TEST(TinyFpTest, FpEqPasses) { + FpElem a = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpElem c = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_TRUE(FpEq(&a, &c)); +} + +TEST(TinyFpTest, FpEqFails) { + FpElem a = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpElem b = {{0, 0, 0, 0, 0, 0, 1, 0}}; + EXPECT_FALSE(FpEq(&a, &b)); +} + +//////////////////////////////////////////////////////////////////////// +// FpInv + +TEST(TinyFpTest, FpInvWorks) { + FpElem a = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}}; + FpElem expected = {{0xd97deaf7, 0xa6011d83, 0x3c381713, 0x92472e34, + 0x997861e8, 0xc1dfdc87, 0x157eb11b, 0xc9cd1238}}; + FpElem result; + FpInv(&result, &a); + EXPECT_EQ(result, expected); +} + +//////////////////////////////////////////////////////////////////////// +// FpRand + +TEST(TinyFpTest, FpRandConsumes384BitsOfEntropy) { + OneTimePad otp(64); + FpElem actual = {0}; + EXPECT_TRUE(FpRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +TEST(TinyFpTest, FpRandWorks) { + OneTimePad otp({// slen bits + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // p + 1 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, + 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, + 0x12, 0x99, 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, + 0x50, 0x0E}); + FpElem expected = {{1, 0, 0, 0, 0, 0, 0, 0}}; + FpElem actual = {0}; + EXPECT_TRUE(FpRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// FpRandNonzero + +TEST(TinyFpTest, FpRandNonzeroConsumes384BitsOfEntropy) { + OneTimePad otp(64); + FpElem actual = {0}; + EXPECT_TRUE(FpRandNonzero(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +TEST(TinyFpTest, FpRandNonzeroWorks) { + OneTimePad otp({// slen bits + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // p - 1 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, + 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, + 0x12, 0x99, 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, + 0x50, 0x0C}); + FpElem expected = {{1, 0, 0, 0, 0, 0, 0, 0}}; + FpElem actual = {0}; + EXPECT_TRUE(FpRandNonzero(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// FpClear + +TEST(TinyFpTest, FpClearWorks) { + FpElem zero = {0}; + FpElem a = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpClear(&a); + EXPECT_EQ(zero, a); +} + +//////////////////////////////////////////////////////////////////////// +// FpSet + +TEST(TinyFpTest, FpSetWorks) { + uint32_t small = 0xffffffff; + FpElem expected = {{small, 0, 0, 0, 0, 0, 0, 0}}; + FpElem result = {{0xD10B500C, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FpSet(&result, small); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FpFromHash + +TEST(TinyFpTest, FpFromHashWorks) { + FpElem p_mod_p; + FpElem zero = {0}; + uint8_t p_str[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9E, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A, + 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}; + FpFromHash(&p_mod_p, p_str, sizeof(p_str)); + EXPECT_EQ(zero, p_mod_p); + + FpElem one = {{1, 0, 0, 0, 0, 0, 0, 0}}; + uint8_t one_str[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + FpElem one_mod_p; + FpFromHash(&one_mod_p, one_str, sizeof(one_str)); + EXPECT_EQ(one, one_mod_p); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/fq-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/fq-test.cc new file mode 100644 index 00000000..4db75e28 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/fq-test.cc @@ -0,0 +1,329 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of Fq implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" +#include "epid/member/tiny/math/unittests/onetimepad.h" + +extern "C" { +#include "epid/member/tiny/math/fq.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// FqInField + +TEST(TinyFqTest, FqInFieldPasses) { + FqElem zero = {0}; + FqElem q_minus_one = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_TRUE(FqInField(&zero)); + EXPECT_TRUE(FqInField(&q_minus_one)); +} + +TEST(TinyFqTest, FqInFieldFails) { + FqElem q = {{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_FALSE(FqInField(&q)); +} + +//////////////////////////////////////////////////////////////////////// +// FqAdd + +TEST(TinyFqTest, FqAddWorks) { + FqElem result = {0}, expected = {0}, left = {0}, right = {0}; + left.limbs.word[5] = 1; + right.limbs.word[5] = 2; + expected.limbs.word[5] = 3; + FqAdd(&result, &left, &right); + EXPECT_EQ(expected, result); + + FqElem q_minus_one = {0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + right = {2, 0, 0, 0, 0, 0, 0, 0}; + expected = {1, 0, 0, 0, 0, 0, 0, 0}; + FqAdd(&result, &q_minus_one, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqSub + +TEST(TinyFqTest, FqSubWorks) { + FqElem result = {0}, expected = {0}, left = {0}, right = {0}; + left.limbs.word[4] = 2; + right.limbs.word[4] = 1; + expected.limbs.word[4] = 1; + FqSub(&result, &left, &right); + EXPECT_EQ(expected, result); + + left = {1, 0, 0, 0, 0, 0, 0, 0}; + right = {2, 0, 0, 0, 0, 0, 0, 0}; + FqElem q_minus_one = {0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + FqSub(&result, &left, &right); + EXPECT_EQ(q_minus_one, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqMul + +TEST(TinyFqTest, FqMulWorks) { + FqElem left = {0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}; + FqElem right = {0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}; + FqElem expected = {0x28f2f1dd, 0x2cb2b611, 0xa24767b3, 0x4e880c0e, + 0xed7f7b9e, 0x6ff4a7f2, 0x25fb15d0, 0x7b8c4fed}; + FqElem result = {0}; + FqMul(&result, &left, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqExp +TEST(TinyFqTest, FqExpWorks) { + FqElem result = {0}, expected = {0}, in = {0}; + VeryLargeInt exp = {0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + in.limbs.word[0] = 1; + expected.limbs.word[0] = 1; + FqExp(&result, &in, &exp); + EXPECT_EQ(expected, result); + + exp = {4, 0, 0, 0, 0, 0, 0, 0}; + in = {{0x0000007B, 0, 0, 0, 0, 0, 0, 0}}; + expected = {{0x0DA48871, 0, 0, 0, 0, 0, 0, 0}}; + FqExp(&result, &in, &exp); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqCp + +TEST(TinyFqTest, FqCpWorks) { + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem result = {0}; + FqCp(&result, &a); + EXPECT_EQ(a, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqIsZero + +TEST(TinyFqTest, FqIsZeroPasses) { + FqElem zero = {0}; + EXPECT_TRUE(FqIsZero(&zero)); +} + +TEST(TinyFqTest, FqIsZeroFails) { + FqElem non_zero = {{0, 0, 0, 0, 0, 0, 1, 0}}; + EXPECT_FALSE(FqIsZero(&non_zero)); +} + +//////////////////////////////////////////////////////////////////////// +// FqInv + +TEST(TinyFqTest, FqInvWorks) { + FqElem a = {{0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, 0xe3401760, + 0x66eb7d52, 0x918d50a7, 0x12a65bd6}}; + FqElem expected = {{0x5a686df6, 0x56b6ab63, 0xdf907c6f, 0x44ad8d51, + 0xa5513462, 0xc597ef78, 0x93711b39, 0x15171a1e}}; + FqElem result; + FqInv(&result, &a); + EXPECT_EQ(result, expected); +} + +//////////////////////////////////////////////////////////////////////// +// FqNeg +TEST(TinyFqTest, FqNegWorks) { + FqElem const pairing_q = {{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem neg_value = {0}; + FqElem one = {{1, 0, 0, 0, 0, 0, 0, 0}}; + FqElem minus_one = pairing_q; + --minus_one.limbs.word[0]; + FqNeg(&neg_value, &one); + EXPECT_EQ(minus_one, neg_value); + + FqElem value = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqNeg(&neg_value, &value); + FqNeg(&neg_value, &neg_value); + EXPECT_EQ(value, neg_value); +} + +//////////////////////////////////////////////////////////////////////// +// FqSquare + +TEST(TinyFqTest, FqSquareWorks) { + FqElem const pairing_q = {{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem four = {{4, 0, 0, 0, 0, 0, 0, 0}}, result = {0}; + FqElem minus_two = pairing_q; + minus_two.limbs.word[0] -= 2; + FqSquare(&result, &minus_two); + EXPECT_EQ(four, result); + + FqElem in = {{0x00003039, 0, 0, 0, 0, 0, 0, 0}}; + FqElem expected = {{0x09156CB1, 0, 0, 0, 0, 0, 0, 0}}; + FqSquare(&result, &in); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqClear + +TEST(TinyFqTest, FqClearWorks) { + FqElem zero = {0}; + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqClear(&a); + EXPECT_EQ(zero, a); +} + +//////////////////////////////////////////////////////////////////////// +// FqSet + +TEST(TinyFqTest, FqSetWorks) { + uint32_t small = 0xffffffff; + FqElem expected = {{small, 0, 0, 0, 0, 0, 0, 0}}; + FqElem result = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqSet(&result, small); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqEq + +TEST(TinyFqTest, FqEqPasses) { + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem c = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + EXPECT_TRUE(FqEq(&a, &c)); +} + +TEST(TinyFqTest, FqEqFails) { + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem b = {{0, 0, 0, 0, 0, 0, 1, 0}}; + EXPECT_FALSE(FqEq(&a, &b)); +} + +//////////////////////////////////////////////////////////////////////// +// FqCondSet + +TEST(TinyFqTest, FqCondSetWorksForTrue) { + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem b = {{0, 0, 0, 0, 0, 0, 1, 0}}; + FqElem result = {0}; + FqCondSet(&result, &a, &b, true); + EXPECT_EQ(a, result); +} + +TEST(TinyFqTest, FqCondSetWorksForFalse) { + FqElem a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem b = {{0, 0, 0, 0, 0, 0, 1, 0}}; + FqElem result = {0}; + FqCondSet(&result, &a, &b, false); + EXPECT_EQ(b, result); +} + +//////////////////////////////////////////////////////////////////////// +// FqSqrt + +TEST(TinyFqTest, FqSqrtWorks) { + FqElem actual = {0}; + FqElem in = {0x02869F4A, 0xDF28D8AC, 0x2B4BD20F, 0xB158EA77, + 0x89D86073, 0x4D6F2CE1, 0x0211F496, 0x9C977A80}; + FqElem expected = {0x0E41765B, 0x7E2AEDF6, 0x7C01BC1B, 0xB1C0F3E4, + 0x95CB5637, 0x8B275494, 0x3FBF1556, 0x8DAE1450}; + + EXPECT_TRUE(FqSqrt(&actual, &in)); + EXPECT_EQ(expected, actual); +} +TEST(TinyFqTest, FqSqrtWorksForFour) { + FqElem actual = {0}; + FqElem in = {0x00000004, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}; + FqElem expected = {0xAED33011, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + EXPECT_TRUE(FqSqrt(&actual, &in)); + EXPECT_EQ(expected, actual); +} +TEST(TinyFqTest, FqSqrtFailsForFive) { + FqElem actual = {0}; + FqElem in = {0x00000005, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}; + EXPECT_FALSE(FqSqrt(&actual, &in)); +} +//////////////////////////////////////////////////////////////////////// +// FqRand + +TEST(TinyFqTest, FqRandConsumes384BitsOfEntropy) { + OneTimePad otp(64); + FqElem actual = {0}; + EXPECT_TRUE(FqRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(384u, otp.BitsConsumed()); +} + +TEST(TinyFqTest, FqRandWorks) { + OneTimePad otp({// slen bits + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // q + 1 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, + 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, + 0x12, 0x98, 0x0A, 0x82, 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, + 0x30, 0x14}); + FqElem expected = {{1, 0, 0, 0, 0, 0, 0, 0}}; + FqElem actual = {0}; + EXPECT_TRUE(FqRand(&actual, OneTimePad::Generate, &otp)); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// FqFromHash + +TEST(TinyFqTest, FqFromHashWorks) { + FqElem q_mod_q; + FqElem zero = {0}; + uint8_t q_str[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, + 0x46, 0xE5, 0xF2, 0x5E, 0xEE, 0x71, 0xA4, 0x9F, + 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82, + 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}; + FqFromHash(&q_mod_q, q_str, sizeof(q_str)); + EXPECT_EQ(zero, q_mod_q); + + FqElem one = {{1, 0, 0, 0, 0, 0, 0, 0}}; + uint8_t one_str[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + FqElem one_mod_q; + FqFromHash(&one_mod_q, one_str, sizeof(one_str)); + EXPECT_EQ(one, one_mod_q); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/fq12-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/fq12-test.cc new file mode 100644 index 00000000..9ec6d66a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/fq12-test.cc @@ -0,0 +1,1058 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of Fq12 implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/member/tiny/math/fq12.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// Fq12Add + +TEST(TinyFq12Test, Fq12AddWorks) { + Fq12Elem expected = {{{{0xf8898202, 0xb45883e0, 0x8d18168d, 0xf67a4288, + 0xec7c2a8a, 0xfa6f0441, 0xff5583e2, 0x32d88286}, + {0x304722d5, 0x113e09d3, 0xeaf32297, 0x32d71c16, + 0x1cb0685b, 0xe3315524, 0xafd38377, 0xfeae3272}}, + {{0xc82d8518, 0x99cec06c, 0xe8d7d62b, 0x2f00d5c5, + 0x0620146e, 0x2741e62b, 0x9e7557ca, 0xeb019297}, + {0x15cfc66e, 0x55ba87c0, 0xf1060150, 0xb91180f6, + 0xb0d77f5f, 0xc7fa8733, 0x7dc697f1, 0x1e6b8e24}}, + {{0x1400db26, 0x0760a0b1, 0x1a64565f, 0x27b5641e, + 0xd96484ed, 0x54b02297, 0xa2a57172, 0xc3a04c1c}, + {0x17ff87fb, 0x6294fcdb, 0x8f7c4bc2, 0xd0802fe6, + 0xee3d7f1b, 0xf19d63af, 0xdb1d00ae, 0x80df53e6}}}, + {{{0xc8c6cded, 0x0a290583, 0xd4ab7f8b, 0x867f6ac5, + 0x791662bb, 0x893f1baa, 0xfc911068, 0xe97be9e3}, + {0xdb9666f2, 0x1ff150ee, 0xd8691261, 0x5efee8a7, + 0x0c67c4e5, 0x1501f7e4, 0xde7e72d8, 0x01ab1a71}}, + {{0x85a5659c, 0xcfd4464f, 0xea3b0e64, 0x4a85994f, + 0x0e842121, 0x939ca516, 0x55e1a4b6, 0xb92af8fa}, + {0xb2bfc7eb, 0x71e5dd9d, 0x16b23032, 0x8590e174, + 0x88a246af, 0x7d317c63, 0xc8f3a39a, 0x903a091d}}, + {{0xf0df5efe, 0x5a88ee12, 0xb0d81569, 0x70172a9f, + 0xa330fbf2, 0x36a7ea66, 0x95287dc2, 0x99c6386b}, + {0x875888c7, 0xa3fa338b, 0x52d41dbe, 0x36960893, + 0xfdf09874, 0x3986d2ba, 0xa9eb891e, 0x5cf05c6f}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, + 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, + 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, + 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, + 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, + 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}, + {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2, + 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23}, + {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5, + 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}}, + {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6, + 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd}, + {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c, + 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}}, + {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57, + 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f}, + {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff, + 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}}; + Fq12Elem actual = {0}; + Fq12Add(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Sub + +TEST(TinyFq12Test, Fq12SubWorks) { + Fq12Elem expected = {{{{0x4d162b42, 0x9377da5b, 0x1d041212, 0xda2d8e91, + 0x72d07c24, 0x9491de97, 0x005d123b, 0x89efdfc3}, + {0x69ff7029, 0x1ffd54c7, 0x2a986659, 0x3830a949, + 0x4d0a4447, 0x5440929c, 0x8c6aff8a, 0x169a8577}}, + {{0x970c6506, 0x259580a0, 0x4547416c, 0xbc76db4c, + 0xb4522362, 0xea130cd9, 0xc0e74ff6, 0xeeace017}, + {0x97b9f013, 0xc4ec0fd2, 0x1dcfb36c, 0x97f1207d, + 0x00b72659, 0x218e308a, 0xc0c7c429, 0x093f2175}}, + {{0x318f88cb, 0x503725ee, 0x5c9a3d68, 0xba67a76b, + 0xf1bd2bc6, 0x6413020d, 0xa06fe769, 0xecbd7182}, + {0xa54e2ad8, 0xd2613407, 0x5c778439, 0x2bd154d5, + 0x4e0d6476, 0xe6ae1ad3, 0x18b00add, 0xaf4062dc}}}, + {{{0x895b6360, 0xbad96b00, 0xb6c8d2df, 0xe15e273b, + 0x3aab5ff8, 0x40f55dd1, 0xc9e3101d, 0x6e83119c}, + {0x85987e44, 0xb3e77da4, 0x4c55cf1c, 0xf44ba4d2, + 0xd099adc5, 0x4a2563a4, 0x4668136c, 0x78fc1bd7}}, + {{0xcc1109f3, 0xcd8e61ad, 0x3ce74606, 0x0da593de, + 0x3185c168, 0xc6f603ce, 0x698abd6c, 0xf89d797f}, + {0xc63c954e, 0x656d3e55, 0x5250e94d, 0x1aa544b5, + 0xe0591afd, 0x1defc6e8, 0xb2ee48c2, 0x3735901f}}, + {{0x743f55f2, 0xb78d7ece, 0x96a97857, 0x660dcdf0, + 0x691d005b, 0x5b550556, 0xe3dd962e, 0x357fc1eb}, + {0xb403019e, 0xd85f7340, 0xc1d63b46, 0xde3f288e, + 0x8154cdf8, 0xaa09925b, 0xdfba6822, 0x1f99db4d}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, + 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, + 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, + 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, + 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, + 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}, + {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2, + 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23}, + {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5, + 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}}, + {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6, + 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd}, + {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c, + 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}}, + {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57, + 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f}, + {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff, + 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}}; + Fq12Elem actual = {0}; + Fq12Sub(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Square + +TEST(TinyFq12Test, Fq12SquareWorks) { + Fq12Elem expected = {{{{0xb2718e2f, 0x5acdc81c, 0x00964828, 0x20087676, + 0x5ae15b61, 0x4fd4da11, 0xe092dfeb, 0x58534fb6}, + {0xccc9dc07, 0x1004c642, 0x4d95229d, 0x82350b1c, + 0x9771ce95, 0xd9a24ede, 0xbd10467b, 0xc7ed3445}}, + {{0xbde22884, 0x8354762f, 0x86ba1554, 0x63db32bb, + 0x0bae02fd, 0x6d0d96e8, 0xcf9ffd11, 0xb8fe4b31}, + {0x2d04f196, 0x23e1a987, 0x99e976e3, 0xa037f309, + 0xe90221d9, 0x201fec2a, 0x46d79de9, 0xc93a6bd2}}, + {{0x5c58af07, 0xd9343489, 0xb4f19136, 0xff508b82, + 0xc14265f4, 0xa4d22c7b, 0x6e928f38, 0xe279749e}, + {0xa1d790b2, 0xcf37602c, 0xc842e733, 0x72c2773a, + 0xc4d0ad50, 0x707594fb, 0x969b8864, 0x0979561b}}}, + {{{0x24a687fb, 0xfb396e79, 0xc34718eb, 0x2b491ee6, + 0xba812deb, 0xc6dfa2d8, 0x4c2bd958, 0x692fc435}, + {0x0b3d5a09, 0xb3310b79, 0xcb0179fe, 0x8e8a4e82, + 0x79cf9278, 0x1b884773, 0xe7bfdc35, 0xb64b17bf}}, + {{0x7928c472, 0xbc2fe39f, 0xa4eff880, 0xd700813f, + 0x555725f0, 0x43a4f63e, 0x857b8b39, 0x96614e14}, + {0x0ba1d9bb, 0x78f7e930, 0x13c1d603, 0xe2f9587b, + 0x19c67a04, 0x3931bdf3, 0x3c6271ae, 0xdde60cd5}}, + {{0xa376e35d, 0xd157352f, 0x040e0af6, 0x0e36afd1, + 0x9cfbfb84, 0x9cd3d83a, 0x94b83ec5, 0x1de41161}, + {0xf1424d67, 0x5ecaee6f, 0x25a809b2, 0x00abd96d, + 0x2b2da6c7, 0xbcfeab22, 0x6072fb3a, 0x75474592}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + + Fq12Elem actual = {0}; + Fq12Square(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Mul + +TEST(TinyFq12Test, Fq12MultWorks) { + Fq12Elem expected = {{{{0x054b2248, 0x40490d13, 0xa309fba1, 0xcda4a1ef, + 0xe6efd6b9, 0x6dbdd131, 0xfde112e9, 0xaf90b12e}, + {0x4e21c944, 0x03e20ec3, 0xed4543f5, 0x7a577659, + 0x81d1fd42, 0xea9a8c1c, 0x791b36af, 0x870740ff}}, + {{0x8d2c2a6e, 0xe8ce5ca0, 0xe528c957, 0x84cd9406, + 0x34a3c63a, 0x2b928ab5, 0x66655119, 0x91ff61ee}, + {0x4c30c782, 0x4fd5522a, 0xfd8d17f1, 0xa3a6f430, + 0x37bf9b7b, 0x72928155, 0x66037689, 0x4c8e67bc}}, + {{0x35a5ce87, 0x1b25e22e, 0x2313705b, 0x9e3e6eb6, + 0x8675e450, 0x33d9cdc4, 0x569c1b3e, 0xd9027fce}, + {0x4f74f503, 0xecbc164d, 0x48ce7250, 0x32b9fb72, + 0x8b726b18, 0xc0872542, 0xcb8d6a0b, 0xfecc8ed3}}}, + {{{0x1a907f78, 0x04356cb2, 0x03360ad2, 0xba867ae8, + 0xa1d5266f, 0xb5896fcf, 0x7013d8a3, 0x587b138f}, + {0x30de9fe0, 0xacde6ad3, 0xdb1dcd3d, 0x765f2eac, + 0x7f665d4e, 0xedc431a0, 0xd9057e43, 0x1bd63b89}}, + {{0x16e913c4, 0xdc0a393e, 0xa9780dac, 0xa0e35293, + 0x99e4eb2f, 0x80654405, 0x9a51d4b9, 0x890d2fa3}, + {0x7a415a23, 0x7252917f, 0xb05a73ac, 0xe8a7f092, + 0x9e68afd0, 0xfe5b63d2, 0x68ecfa20, 0xe3a9f4e0}}, + {{0x3a77ca45, 0x282422b7, 0x613276da, 0x5bc45097, + 0x95ea8ee4, 0x4a7a7633, 0xc9bb3324, 0xe396b7b4}, + {0xf37c26a1, 0x8009faaa, 0x0779b7c1, 0x6ef10242, + 0xcd5a86eb, 0x2dd2897e, 0x2b5f0b01, 0x0b79178d}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, + 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, + 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, + 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, + 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, + 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}, + {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2, + 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23}, + {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5, + 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}}, + {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6, + 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd}, + {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c, + 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}}, + {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57, + 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f}, + {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff, + 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}}; + Fq12Elem actual = {0}; + Fq12Mul(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Inv + +TEST(TinyFq12Test, Fq12InvWorks) { + Fq12Elem expected = {{{{0xcf7ba426, 0x4bb2c4c3, 0xfb50fa73, 0xb70c280d, + 0xb5cf02c7, 0xb047bc29, 0x7cd8b4d1, 0xc238e14d}, + {0xd1bc45de, 0xc113277d, 0x5189b836, 0x49694d5b, + 0xc4084edb, 0xc837f717, 0xf65566eb, 0x519dad22}}, + {{0x62b12d6e, 0xc2a49558, 0x0f36f3b8, 0x2274fc44, + 0xd7ef63a2, 0x7a0f59da, 0xc4fa06c3, 0x812be980}, + {0xc887fc84, 0xbeb1803c, 0x5ec3d49f, 0x7c32ae46, + 0x97fb66b2, 0x470acb13, 0x2e9d2992, 0x88dd93d5}}, + {{0x47087924, 0x143c1bba, 0x4fe23ddb, 0x6be4e322, + 0x3cabd640, 0xdf2f66c9, 0x2d309380, 0xa244260f}, + {0xf899db8a, 0xb5a83982, 0x264e1961, 0xe8a8ce8c, + 0xe94ceacf, 0xd18bd271, 0x67f10894, 0xc82e0f88}}}, + {{{0x61170257, 0x9740a14e, 0xdd90ec1f, 0xfc1a7d8b, + 0x2a37d62c, 0xa6577bc2, 0xe610b5d6, 0xe0b70389}, + {0x8192b447, 0x2fd37cbc, 0xc3f80c5b, 0x618f95a1, + 0x21e22c0c, 0xf35bd82b, 0xbf635e7d, 0x990ac1f2}}, + {{0x790d6584, 0xf40c0f6e, 0x83ca3d0f, 0x96f7c28d, + 0x8a2662fa, 0xc83bfe45, 0x8be01843, 0x87a00b86}, + {0x6020320a, 0x73199db4, 0x4d5dd850, 0x14cf247d, + 0x34fb1d44, 0x8ababc0d, 0x7c849de5, 0x81226e85}}, + {{0x6453b966, 0xbbd595ea, 0x704c45e2, 0x5d4cd2a1, + 0x8ee6cc5e, 0x336a21d8, 0x87955196, 0xc9e0915a}, + {0x83330d6a, 0x200dbac0, 0x6b9e8ee8, 0xe6a33cf8, + 0x4dc48908, 0xd0a02fdb, 0x0f715987, 0x5f4b9d5b}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem actual = {0}; + Fq12Inv(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Neg + +TEST(TinyFq12Test, Fq12NegWorks) { + Fq12Elem expected = {{{{0x8c035971, 0xaf40febd, 0x3d89f632, 0x24887d6e, + 0x3ecb5147, 0xff6580f2, 0x0023a5bd, 0xa19bcedb}, + {0x61afe694, 0xba8b7e8e, 0x07d2460a, 0xd758834b, + 0xb9944e4d, 0x2b2cfe7e, 0xe1ddaf4c, 0x755ba40a}}, + {{0xff363b04, 0xf3770d54, 0xfb887eb6, 0x97208d71, + 0x913888b6, 0xbe3b78dc, 0x504e9cec, 0x1328c6a8}, + {0x80a4bcc9, 0xdc414b24, 0x81e12ae2, 0xddece243, + 0x9e717f72, 0x2eae9d50, 0xe0b74a59, 0x6c2aa832}}, + {{0xe3749624, 0x90f1e179, 0xe064c5e0, 0xa23c1333, + 0x80199e94, 0x0df7593b, 0x5e70bcc6, 0xa7d12130}, + {0x2795eeb3, 0x2242ac58, 0xa5ea27c6, 0x9521d69a, + 0xc7850525, 0x7e332c4c, 0x8614e36d, 0xe7f0249e}}}, + {{{0x5d2baf76, 0xda3c8c87, 0xd629e68e, 0x5f5bcff7, + 0x8bc99594, 0x053eaed0, 0x9cc158f1, 0xd400823f}, + {0xfe3bbd78, 0xe93cc691, 0x003899c3, 0x63371f3e, + 0x7ff0eb49, 0x1752449a, 0x6d89adab, 0xc2ac64db}}, + {{0xdd619055, 0x6e0c70ca, 0x8852e58e, 0xe7350261, + 0x45a585a9, 0x3d0f971c, 0x20453822, 0xa71bc6c3}, + {0x1aeb696d, 0x7deb08f4, 0xd4ca7881, 0x36531fe8, + 0x42bb2179, 0x55e25789, 0x420d8238, 0x1c483361}}, + {{0xfc43d59b, 0x4a1df76a, 0xeed743a2, 0x21c9e9b2, + 0x684aa678, 0xfde77a80, 0x4379e6d4, 0x985d02d4}, + {0xb9bbd2d7, 0xab67c387, 0x7ef6d8be, 0xfc039a6c, + 0x37961f18, 0x31aac6a4, 0x3b2b7fc6, 0x41bae421}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem actual = {0}; + Fq12Neg(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Set + +TEST(TinyFq12Test, Fq12SetWorks) { + Fq12Elem result = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem expected = {{{{0x00000010, 0}, {0}}}}; + uint32_t val = 0x10; + Fq12Set(&result, val); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Exp + +TEST(TinyFq12Test, Fq12ExpWorks) { + Fq12Elem expected = {{{{0x07770c93, 0x5820d5a9, 0x65189432, 0x5f5d67ff, + 0xe257644a, 0x41318fa0, 0x6ab6be96, 0xf104adf8}, + {0x6d5cae3a, 0x2e43c14b, 0xede9dbfe, 0x6743d276, + 0x35d13a61, 0xf25d3672, 0x6a36930c, 0x9bdbed9d}}, + {{0x12fc551f, 0x9ff0f349, 0x4131b828, 0x50c353ed, + 0x785d7e8b, 0xbb894c96, 0xee86c2d1, 0x8af21330}, + {0x45a7337a, 0xb0f0d8c5, 0xacfb0dbd, 0x1f775366, + 0x12303719, 0x6f7208bd, 0x68c1bf17, 0x14b60ae7}}, + {{0xcdf00f9c, 0xbd6529d8, 0x693b8a51, 0xcb9eb968, + 0x46c25f48, 0x39cbf307, 0xd7283cd4, 0x8cbb7dd9}, + {0xb18b24c2, 0x5a98714f, 0x0782ea19, 0x8af18c94, + 0x22373570, 0xe24e7fef, 0x0510369a, 0xc5399438}}}, + {{{0x141a7578, 0x05e94e05, 0x08ec385f, 0x3a5ae1ef, + 0xccd4f61a, 0x3291d9f6, 0xb7b07242, 0xb1742404}, + {0xec5f69b1, 0x68fbad6b, 0x167e8ec8, 0x67c97e56, + 0x1ac21584, 0x783e2b30, 0x8c2dd9dd, 0xd4ed7488}}, + {{0xb591926f, 0x97f68a1f, 0xd3bccfb8, 0x9a58152b, + 0x9e12cf14, 0x0a82dfd6, 0x8c246e88, 0x94bcbc8a}, + {0xa95962fe, 0x342b7e99, 0xddc1c0d9, 0x15a4e0f8, + 0x64475d29, 0xbce1bd39, 0xa79dd2ee, 0xee505176}}, + {{0xdb49f8cf, 0x10cdb302, 0xf5c48053, 0x83ce1f18, + 0x988d4d5c, 0xd305fb4e, 0xbb11f2bb, 0x2f391894}, + {0x084c02ad, 0x26eae084, 0x4d81e78d, 0x9750454d, + 0xdb062196, 0xae6ad23e, 0x18588c31, 0xb3d78420}}}}; + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + VeryLargeInt exponent = {0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}; + Fq12Elem actual = {0}; + Fq12Exp(&actual, &left, &exponent); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12MultiExp + +TEST(TinyFq12Test, Fq12MultiExpWorks) { + Fq12Elem expected = {{{{0x9b800ac0, 0x1fb360b8, 0x9af601c4, 0x4931f447, + 0x31152f7c, 0x7f6b2489, 0x2fbeed91, 0xcc7a6ac0}, + {0xb76c0d77, 0x5b09b4be, 0x4a8fc1d4, 0x2e5222d1, + 0x6b6e41e6, 0x9ea53fff, 0x6daabae4, 0x591274a2}}, + {{0xb669c611, 0xc8b0430b, 0xa7c054c3, 0x360bd4bc, + 0xf09ef81c, 0x4d5bb8b1, 0x9333c78f, 0x32ff73b8}, + {0x90ec74e4, 0xe1e77b28, 0xb453b94a, 0xf7bf242c, + 0xdbee7487, 0x29b8c962, 0x31bcb2b5, 0x06737ced}}, + {{0x26f4def9, 0xc706336d, 0x18aae9bf, 0x9b568de1, + 0x4e0fa721, 0x10695d37, 0x44a446e4, 0x1f90fc31}, + {0xec9525dc, 0x4f63a5d6, 0x07e9f19c, 0x982ac0b8, + 0x818c07fc, 0x2603a2c4, 0x44e6a144, 0xb8a617a5}}}, + {{{0x34f08dcb, 0x0afd33cc, 0x38921139, 0x10c707ef, + 0x1bcd1d79, 0x1cee939a, 0x08831471, 0x2318f2b4}, + {0x8e4f9261, 0x37304a70, 0xb24df55d, 0xd93a8a20, + 0x32ff13b2, 0x342ce4a7, 0x25185cd0, 0xd974dca3}}, + {{0x0a83a8aa, 0xf2e71e4e, 0x0e0af78b, 0x85363dfa, + 0xf825e945, 0x01d733f5, 0xf54d7f42, 0x3c77fa71}, + {0xb5a7931b, 0x25c5c577, 0x6d21b52e, 0xbc951e9b, + 0x51dd45b9, 0x743e886f, 0x6bc839d4, 0xd7deccd5}}, + {{0x947af194, 0xd0239f95, 0x1dde9421, 0x59369d3e, + 0xd9863881, 0xb9c24b75, 0xcbdb4021, 0x4c940810}, + {0x96070307, 0x4f68fbf2, 0x5a719a10, 0x73b7cc22, + 0x4ef192e7, 0xbb5b635e, 0xdeb5746b, 0x89b5a530}}}}; + Fq12Elem pairing_out = {{{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed, + 0xad5ee231, 0x4fc0a501, 0x468be932, 0xba101ff6}, + {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0, + 0xcb0454f2, 0xc4077c42, 0xebde30b6, 0x15eb79f4}}, + {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c, + 0x1c0def81, 0x80e14649, 0x4657b6e7, 0xf18b84d1}, + {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb, + 0x6fd516b6, 0xb7190100, 0xc1fa4e50, 0x3fee7c43}}, + {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d, + 0x138bb1b6, 0x87cf70ba, 0xbbef8650, 0xe3b31829}, + {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173, + 0xcdc3182a, 0x1ecb0486, 0xd5a961a5, 0xda0e5787}}}, + {{{0x0b13b454, 0xa62f5fbf, 0xa4bed641, 0xd3632805, + 0xe8010941, 0x72cebb51, 0x8aaa0095, 0x669e804d}, + {0xe49b7149, 0x8fc69d31, 0x956d88ab, 0x265c926b, + 0x3bb2f1d4, 0xbfc206ea, 0x6f29d6da, 0x5b5065dc}}, + {{0x0ff0848e, 0x1f3fdf5c, 0xb3533098, 0x1a434003, + 0xc80d2a60, 0x4ac6aa4a, 0xc99fbca8, 0xe0ce978f}, + {0x3357d172, 0xf5f8a018, 0x5908b3da, 0xe540395c, + 0xb654a226, 0x89cef58e, 0x47786d9f, 0x5a5d41d2}}, + {{0x788a3989, 0x49a5f719, 0x5a0042e3, 0x92f94303, + 0x1bd0e6c8, 0x81c5ac15, 0xe8a05ec8, 0xbbba6ced}, + {0x6d17dc8e, 0xaf351b75, 0xba6e2c36, 0x2a04ea26, + 0x421e1737, 0x16fd0bfe, 0x4bb33376, 0x32aebf4d}}}}; + Fq12Elem pairing_inv = {{{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed, + 0xad5ee231, 0x4fc0a501, 0x468be932, 0xba101ff6}, + {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0, + 0xcb0454f2, 0xc4077c42, 0xebde30b6, 0x15eb79f4}}, + {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c, + 0x1c0def81, 0x80e14649, 0x4657b6e7, 0xf18b84d1}, + {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb, + 0x6fd516b6, 0xb7190100, 0xc1fa4e50, 0x3fee7c43}}, + {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d, + 0x138bb1b6, 0x87cf70ba, 0xbbef8650, 0xe3b31829}, + {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173, + 0xcdc3182a, 0x1ecb0486, 0xd5a961a5, 0xda0e5787}}}, + {{{0xa3bf7bbf, 0x2cf9ce1c, 0x6dd93441, 0x39793df5, + 0x06709b5d, 0xd417370d, 0x7552f037, 0x99617fb2}, + {0xca37beca, 0x436290a9, 0x7d2a81d7, 0xe67fd38f, + 0xb2beb2ca, 0x8723eb74, 0x90d319f2, 0xa4af9a23}}, + {{0x9ee2ab85, 0xb3e94e7f, 0x5f44d9ea, 0xf29925f7, + 0x26647a3e, 0xfc1f4814, 0x365d3424, 0x1f316870}, + {0x7b7b5ea1, 0xdd308dc3, 0xb98f56a7, 0x279c2c9e, + 0x381d0278, 0xbd16fcd0, 0xb884832d, 0xa5a2be2d}}, + {{0x3648f68a, 0x898336c2, 0xb897c79f, 0x79e322f7, + 0xd2a0bdd6, 0xc5204649, 0x175c9204, 0x44459312}, + {0x41bb5385, 0x23f41266, 0x5829de4c, 0xe2d77bd4, + 0xac538d67, 0x2fe8e660, 0xb449bd57, 0xcd5140b2}}}}; + VeryLargeInt exponent = {0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}; + Fq12Elem b1 = pairing_inv; + Fq12Elem b2 = pairing_out; + Fq12Elem b3 = pairing_out; + VeryLargeInt e1 = exponent; + VeryLargeInt e2 = {0}; + VeryLargeInt e3 = exponent; + // pairing_out^exp * pairing_out^(-exp) * pairing_out^0 * pairing_out^exp == + // pairing_out^exp + Fq12Elem actual = {0}; + Fq12MultiExp(&actual, &pairing_out, &exponent, &b1, &e1, &b2, &e2, &b3, &e3); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Eq + +TEST(TinyFq12Test, Fq12EqPasses) { + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem left2 = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + EXPECT_TRUE(Fq12Eq(&left, &left2)); +} + +TEST(TinyFq12Test, Fq12EqFails) { + Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, + 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, + 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, + 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, + 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, + 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}, + {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2, + 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23}, + {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5, + 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}}, + {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6, + 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd}, + {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c, + 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}}, + {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57, + 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f}, + {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff, + 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}}; + EXPECT_FALSE(Fq12Eq(&left, &right)); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Conj + +TEST(TinyFq12Test, Fq12ConjWorks) { + Fq12Elem expected = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x5d2baf76, 0xda3c8c87, 0xd629e68e, 0x5f5bcff7, + 0x8bc99594, 0x053eaed0, 0x9cc158f1, 0xd400823f}, + {0xfe3bbd78, 0xe93cc691, 0x003899c3, 0x63371f3e, + 0x7ff0eb49, 0x1752449a, 0x6d89adab, 0xc2ac64db}}, + {{0xdd619055, 0x6e0c70ca, 0x8852e58e, 0xe7350261, + 0x45a585a9, 0x3d0f971c, 0x20453822, 0xa71bc6c3}, + {0x1aeb696d, 0x7deb08f4, 0xd4ca7881, 0x36531fe8, + 0x42bb2179, 0x55e25789, 0x420d8238, 0x1c483361}}, + {{0xfc43d59b, 0x4a1df76a, 0xeed743a2, 0x21c9e9b2, + 0x684aa678, 0xfde77a80, 0x4379e6d4, 0x985d02d4}, + {0xb9bbd2d7, 0xab67c387, 0x7ef6d8be, 0xfc039a6c, + 0x37961f18, 0x31aac6a4, 0x3b2b7fc6, 0x41bae421}}}}; + Fq12Elem input = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, + 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, + 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, + 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, + 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, + 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, + 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, + 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, + 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, + 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, + 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, + 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem actual = {0}; + Fq12Conj(&actual, &input); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12ExpCyc + +TEST(TinyFq12Test, Fq12ExpCycWorks) { + Fq12Elem expected = {{{{0x44415742, 0xce586503, 0xe5cc514f, 0x731d97a3, + 0xe8c98357, 0xb1de361d, 0x15cf9bfc, 0x4ca54124}, + {0x7decae5a, 0x572ae946, 0x4244f518, 0x1490b9e4, + 0xbbbafdb2, 0xb2d13f3f, 0xae1de024, 0xe224dc2f}}, + {{0x876377f0, 0x2c75d3ab, 0x5aa65a1d, 0x42ff41fa, + 0x2729ff86, 0x8f76d40f, 0x2c224666, 0xce3d5926}, + {0x4f0b47eb, 0xa45887d9, 0xf4407be2, 0xaaedbf4a, + 0x9f8a426e, 0x809a601a, 0xea000edd, 0x4fe97056}}, + {{0x7eb3ea97, 0xd6769b11, 0x2f2bed07, 0x6fbb5801, + 0x1e67136e, 0x2fd1e9a3, 0x242559de, 0x5a018155}, + {0xb66ad800, 0x51924848, 0xdecddaa8, 0x3eed0649, + 0xcf7f3edb, 0x17dcaa6e, 0x27cd41c7, 0x055a6039}}}, + {{{0x09d45f4f, 0x3d360f00, 0x7561c4fb, 0x70500d0f, + 0x20851a64, 0x5c5ed2a6, 0x6118fe9e, 0xfa05dc75}, + {0x57b872d1, 0x9a19e54d, 0x3395e069, 0x29d98c64, + 0xcdbdda55, 0x001f07e7, 0x8aeaca7f, 0x747c1dc8}}, + {{0x0c0cb22d, 0x75ca59be, 0x202684e4, 0xec1b56c5, + 0x46434c3f, 0x55f52f7a, 0xfcb5686b, 0x0a1172be}, + {0xf0b043af, 0xbb2ae039, 0xccbdac3c, 0x8f42a6f2, + 0x06c264ab, 0xa47599b7, 0xc6a8c454, 0xa5b257e3}}, + {{0x8700f8b7, 0x4090b69d, 0x20e35539, 0xfd30e911, + 0xa08ecbf5, 0xb038eb7b, 0x6ea872c3, 0xdfa0f669}, + {0x5600be7b, 0x43ec3905, 0xc830ae6e, 0xd9780bec, + 0xe7d288c3, 0xcff72a6e, 0x059b9c31, 0x66ebb803}}}}; + Fq12Elem input = {{{{0x4200e30a, 0xebf627b9, 0x607ebce6, 0x7848a894, + 0xe1b736d1, 0x4c9dd307, 0x9e1301e3, 0x07256eb7}, + {0xe17a0b54, 0x0e02f2d5, 0x3df772e0, 0x9155aaa2, + 0x3c5ffcc6, 0x8427940b, 0x362f51ee, 0x331e0c73}}, + {{0x954eecdb, 0x970bc820, 0x92d1776a, 0x02f81e51, + 0x8a7a9216, 0x6172111f, 0x9bd29665, 0x9612d47d}, + {0x8fceb2c7, 0xb3f7eced, 0xa3d0a21e, 0xd66c6583, + 0xf273f385, 0x827df9e6, 0x503de81c, 0x5b2cae32}}, + {{0xf08207ed, 0x7ab76686, 0xb681b701, 0x9d19d066, + 0x81956e08, 0x2ca17f37, 0x65d1d24e, 0x0cff7cb8}, + {0xf9cd6e9e, 0x4821363b, 0xb0bc2b8c, 0xa380ecbb, + 0x7b04aea0, 0x396f0948, 0x93619efe, 0x42aa1fd4}}}, + {{{0x805b8aa4, 0x23ab6f9a, 0x937ea209, 0x9dba1ab2, + 0x426d02b7, 0x36782ff4, 0xe371d373, 0x66873347}, + {0x51d27dea, 0xd40cd434, 0xd5627a4d, 0xbcc747de, + 0xa54b31ec, 0x3e2c2fa4, 0x4f07b689, 0xb33b79bc}}, + {{0xfeea300c, 0x26ab30d9, 0x92c098e9, 0x192c191b, + 0xeefd498c, 0x3cd4e4ac, 0xe9a3f142, 0x00bdca46}, + {0xeb1edad0, 0xd4c2439e, 0x51025e46, 0x006cfb7c, + 0x04b6efda, 0x159f7c19, 0xa1085a5e, 0x459833d5}}, + {{0xeb08632d, 0x3c4ecf58, 0x02624178, 0xf65dbcf5, + 0xeb320af5, 0xce34c3db, 0x799ea805, 0x1f944aa2}, + {0x6f488ba6, 0x07f9f8dc, 0x690e6d4b, 0xa45b11be, + 0x8d39f017, 0x96619fec, 0x6100af71, 0x16201c36}}}}; + VeryLargeInt pairing_t = {0x30b0a801, 0x6882f5c0, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}; + Fq12Elem actual = {0}; + Fq12ExpCyc(&actual, &input, &pairing_t); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12SqCyc + +TEST(TinyFq12Test, Fq12SqCycWorks) { + const Fq12Elem a = {{{{0x4200e30a, 0xebf627b9, 0x607ebce6, 0x7848a894, + 0xe1b736d1, 0x4c9dd307, 0x9e1301e3, 0x07256eb7}, + {0xe17a0b54, 0x0e02f2d5, 0x3df772e0, 0x9155aaa2, + 0x3c5ffcc6, 0x8427940b, 0x362f51ee, 0x331e0c73}}, + {{0x954eecdb, 0x970bc820, 0x92d1776a, 0x02f81e51, + 0x8a7a9216, 0x6172111f, 0x9bd29665, 0x9612d47d}, + {0x8fceb2c7, 0xb3f7eced, 0xa3d0a21e, 0xd66c6583, + 0xf273f385, 0x827df9e6, 0x503de81c, 0x5b2cae32}}, + {{0xf08207ed, 0x7ab76686, 0xb681b701, 0x9d19d066, + 0x81956e08, 0x2ca17f37, 0x65d1d24e, 0x0cff7cb8}, + {0xf9cd6e9e, 0x4821363b, 0xb0bc2b8c, 0xa380ecbb, + 0x7b04aea0, 0x396f0948, 0x93619efe, 0x42aa1fd4}}}, + {{{0x805b8aa4, 0x23ab6f9a, 0x937ea209, 0x9dba1ab2, + 0x426d02b7, 0x36782ff4, 0xe371d373, 0x66873347}, + {0x51d27dea, 0xd40cd434, 0xd5627a4d, 0xbcc747de, + 0xa54b31ec, 0x3e2c2fa4, 0x4f07b689, 0xb33b79bc}}, + {{0xfeea300c, 0x26ab30d9, 0x92c098e9, 0x192c191b, + 0xeefd498c, 0x3cd4e4ac, 0xe9a3f142, 0x00bdca46}, + {0xeb1edad0, 0xd4c2439e, 0x51025e46, 0x006cfb7c, + 0x04b6efda, 0x159f7c19, 0xa1085a5e, 0x459833d5}}, + {{0xeb08632d, 0x3c4ecf58, 0x02624178, 0xf65dbcf5, + 0xeb320af5, 0xce34c3db, 0x799ea805, 0x1f944aa2}, + {0x6f488ba6, 0x07f9f8dc, 0x690e6d4b, 0xa45b11be, + 0x8d39f017, 0x96619fec, 0x6100af71, 0x16201c36}}}}; + const Fq12Elem expected = { + {{{0x526a44b5, 0x9ad9e0d5, 0x7fc8d87d, 0xdac7f569, 0xb7160629, 0xc5073804, + 0x217aac0c, 0x71b7efa7}, + {0xd0accd40, 0x66aed48f, 0x3e8cb003, 0x54d56ad9, 0x5f6d6996, 0x0be42117, + 0xa36948ed, 0xbb155b11}}, + {{0x806eec23, 0xf4e66785, 0xaffdc175, 0xa19e8e95, 0xa11edc9d, 0xfad5f701, + 0x4bf831bc, 0xe743b59e}, + {0xfc57a415, 0xb843987c, 0x3aabe4e3, 0xb23ed43d, 0xc418a1cd, 0xc46cc003, + 0xb646c6b0, 0x32af93c9}}, + {{0x20c76439, 0xc9915b9f, 0x34fae4ad, 0x952c702a, 0xf2edbbd9, 0x06aa03db, + 0x10219f83, 0x905d0b4c}, + {0xab64286e, 0xb368606d, 0xa469d731, 0xbc1f7604, 0xeae89f06, 0xd6d6b335, + 0x68da2258, 0x4ab0021e}}}, + {{{0xa69a08d7, 0xbac72f6e, 0xaf9c76c7, 0x67d54f71, 0x41aea080, 0x36129b92, + 0xd25549e1, 0xa261f5ef}, + {0xd663885e, 0xd0de96b5, 0x6631c5ab, 0x1826eea2, 0xab116580, 0xc41e9bd7, + 0x935a4539, 0x1283ccf4}}, + {{0xc279b3a5, 0x750dcbe7, 0x8f96e4ba, 0xd3321942, 0xf837f073, 0x11ed32b8, + 0x26691990, 0x06c077da}, + {0x4d690c41, 0x47d447a7, 0xb0ecd6ca, 0xbab6e94b, 0xb1984cb4, 0xb104eb7f, + 0xd0b8e924, 0xe8c70bef}}, + {{0x1c750b7c, 0x9923d34c, 0xc88a0dda, 0x2e14c6ca, 0x6748bad3, 0x50d05e2b, + 0x14f32504, 0x2dc7a9d3}, + {0xa1c4328d, 0x9e8f16d8, 0xd31d739a, 0x0c9da028, 0x613f8c91, 0x75fbf7f3, + 0x78575301, 0x496c9a7b}}}}; + Fq12Elem res; + Fq12SqCyc(&res, &a); + EXPECT_EQ(expected, res); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12MulSpecial + +TEST(TinyFq12Test, Fq12MulSpecialWorks) { + const Fq12Elem left = {{{{0xbee28a1d, 0x57d6402c, 0x61cd0458, 0x194e2452, + 0x1c223de9, 0x6546ced9, 0xdcd0878f, 0xc55048e3}, + {0x6a8d5fe2, 0xfcf17083, 0xb608693b, 0x981bd9fe, + 0x54a9e8fa, 0x0e8250f4, 0x93430f47, 0xf862d9af}}, + {{0x57975e42, 0xf57416a0, 0x08a35031, 0x9d28f11c, + 0xa9467df1, 0x58159cfa, 0x48cb43f1, 0x7f6f1e63}, + {0xb6199d76, 0xf0ee74eb, 0xc2413051, 0x5ee7af00, + 0xed646e81, 0xa34adbc8, 0xb30cb947, 0xc256758a}}, + {{0xd2100f2c, 0x34bef28c, 0xe6ffd998, 0x3f8de361, + 0x711229db, 0x143ccdbf, 0x4fad6107, 0x35365f92}, + {0xea2fbf36, 0x14a160b2, 0x5051bd0f, 0x6f056434, + 0x2d53ef9f, 0x00d84656, 0xc8535c97, 0x23aaa4e4}}}, + {{{0xfa291b36, 0xdff94440, 0xc016a92d, 0xe44a0e69, + 0xdb2d97f6, 0xb1747475, 0x1cbc7fc4, 0x0e94ef53}, + {0x0ea6037c, 0x9a639210, 0xd84404c5, 0x4b8c16ef, + 0xfc9e6161, 0x3914ae4c, 0xd1b76423, 0x63ef638b}}, + {{0xfbe030a1, 0x2a114147, 0x6639fbac, 0x0349a4a5, + 0x5c7d47de, 0x63888f75, 0x7224cc85, 0x4c1bfeb3}, + {0xb214f453, 0x403afc2f, 0xa61d5e45, 0x4392c48a, + 0xc4f5aec3, 0xce77b85a, 0xc8d59c7e, 0xd0060196}}, + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}}; + const Fq12Elem right = {{{{0xd878f624, 0xb6e07457, 0x64c79fdf, 0x0b8cebe9, + 0x97be762b, 0xbc4aea64, 0xf72d75cc, 0xdc8ed85d}, + {0x65847e3a, 0x2a2ff0f3, 0x87af7204, 0xfb4cba91, + 0x0df3d736, 0x77e1a4e0, 0x138efcca, 0xc427f6ab}}, + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}, + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}, + {{{0x163784b5, 0x2a7d4fd5, 0x1f5a1a18, 0xe89cba68, + 0xc233b435, 0xa20456c0, 0x6397ae08, 0x7b76d157}, + {0xb68f8337, 0x079302c1, 0x99e4326a, 0xc14686de, + 0x866e7108, 0x685e797e, 0x3a4b03e5, 0x9aab4042}}, + {{0x2cd4fe4d, 0xb4660e9a, 0xf99f415d, 0x627f9703, + 0x902301e4, 0xcf3c4224, 0xaca9779d, 0x917a2609}, + {0x9da1e8ac, 0xadb15382, 0x6d31577a, 0xcfd95901, + 0xf4fdf69b, 0x8ebf8ef3, 0xc15f4a65, 0x0d6458ec}}, + {{0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}}; + const Fq12Elem expected = { + {{{0x9f8d4cd8, 0x00fcb121, 0xb1383622, 0xff83d7d7, 0xa4b229fb, 0xcece9321, + 0x81ef1f73, 0x05137d4e}, + {0x9f6177a7, 0x050a266e, 0x73bb8d3b, 0xc99e1d33, 0x678d1f52, 0xc63568f1, + 0x1920273f, 0x11a25307}}, + {{0xcf70c64d, 0x99892381, 0xf6f6a6de, 0xfec24fa5, 0x8d18873e, 0x4f621aad, + 0x7d3599d0, 0x128407fe}, + {0x33e6c086, 0xa85bf06c, 0x2edfd568, 0xc2426dbe, 0xdbbd397c, 0x2b6e80b2, + 0x63dd5f45, 0x98bc904e}}, + {{0xb56c9e77, 0x84063128, 0x830da180, 0xa3d9be01, 0x7ec1cfe7, 0x817c7cc1, + 0x409da3aa, 0xb05dcc43}, + {0x356380bf, 0x72eb335a, 0xb6f2b26c, 0x080613dc, 0x67720d78, 0x488a988f, + 0xee0e1bff, 0x0758479e}}}, + {{{0xa640a57d, 0xc171805c, 0xd1c81064, 0xef2644a8, 0xe28b6e89, 0xd031ff2f, + 0xf734a21b, 0x0d8e465e}, + {0x609de07b, 0x1d248226, 0x19fed7c8, 0x2b378e3d, 0xd55d1461, 0x719d0037, + 0x6fe515b8, 0x34f03c08}}, + {{0xdcdcb9d0, 0x814badfe, 0x01405a2a, 0x2e1a5295, 0x3d08cb46, 0xd0dc0d2b, + 0x4ca64738, 0x2b2e5180}, + {0x503385b0, 0x030d5f71, 0xd24ad48c, 0x4f246e0b, 0x9e904a36, 0x302748d6, + 0x1c034d23, 0xf6aa74f6}}, + {{0x05fc0305, 0xfb7ba8fd, 0x4a8425a1, 0xd69ff60a, 0x356d1941, 0x4559a790, + 0xcf1088e9, 0x63784e99}, + {0xa8a6d207, 0x6e6ed383, 0xf8a9804e, 0x0be13d11, 0xcef9010b, 0x90c8c91a, + 0x0b1302ef, 0xe2ce5b67}}}}; + Fq12Elem res; + Fq12MulSpecial(&res, &left, &right); + EXPECT_EQ(expected, res); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Cp + +TEST(TinyFq12Test, Fq12CpWorks) { + Fq12Elem a = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, 0x62a80f0a, + 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, 0x6e80b955, + 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, 0xa8cc1ef5, + 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, 0xabb68325, + 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, 0x8626fe26, + 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, 0xb6db8586, + 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Elem result = {0}; + Fq12Cp(&result, &a); + EXPECT_EQ(a, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Clear + +TEST(TinyFq12Test, Fq12ClearWorks) { + Fq12Elem zero = {0}; + Fq12Elem a = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}, + {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, 0x62a80f0a, + 0x41a7438e, 0x633b97dc, 0x2bff7dc0}, + {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, 0x6e80b955, + 0x2f93adc4, 0x92734322, 0x3d539b24}}, + {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, 0xa8cc1ef5, + 0x09d65b42, 0xdfb7b8ab, 0x58e4393c}, + {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, 0xabb68325, + 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}}, + {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, 0x8626fe26, + 0x48fe77de, 0xbc8309f8, 0x67a2fd2b}, + {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, 0xb6db8586, + 0x153b2bba, 0xc4d17107, 0xbe451bde}}}}; + Fq12Clear(&a); + EXPECT_EQ(zero, a); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/fq2-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/fq2-test.cc new file mode 100644 index 00000000..3e33b635 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/fq2-test.cc @@ -0,0 +1,352 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of Fq2 implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/member/tiny/math/fq2.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// Fq2Cp + +TEST(TinyFq2Test, Fq2CpWorks) { + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem a = {fq, fq}; + Fq2Elem result = {0}; + Fq2Cp(&result, &a); + EXPECT_EQ(a, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Set + +TEST(TinyFq2Test, Fq2SetWorks) { + uint32_t small = 0xffffffff; + Fq2Elem expected = {0}; + expected.x0.limbs.word[0] = small; + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem result = {fq, fq}; + Fq2Set(&result, small); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Clear + +TEST(TinyFq2Test, Fq2ClearWorks) { + Fq2Elem expected = {0}; + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem result = {fq, fq}; + Fq2Clear(&result); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Add + +TEST(TinyFq2Test, Fq2AddWorks) { + Fq2Elem result = {0}; + Fq2Elem left = {{0, 0, 0, 0, 0, 5, 0, 0}, {0, 0, 0, 0, 0, 0, 9, 0}}; + Fq2Elem right = {{0, 0, 0, 0, 0, 20, 0, 0}, {0, 0, 0, 0, 0, 0, 30, 0}}; + Fq2Elem expected = {{0, 0, 0, 0, 0, 25, 0, 0}, {0, 0, 0, 0, 0, 0, 39, 0}}; + Fq2Add(&result, &left, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Exp + +TEST(TinyFq2Test, Fq2ExpWorks) { + Fq2Elem one = {1}; + Fq2Elem in = {0}; + VeryLargeInt exp = {0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + Fq2Elem result = {{0xb06f3418, 0x16043dfc, 0x7884a9ca, 0x0ab1a427, 0x309307b5, + 0x23133f6d, 0x250c3dc4, 0x005c4818}, + {0x3b6f652c, 0x6435c0fd, 0x509b8d30, 0x13fe4bef, 0x5f4ffc14, + 0x81dde5fd, 0x02b77b89, 0x5b38b2a5}}; + Fq2Exp(&result, &in, &exp); + EXPECT_EQ(in, result); + + in = {exp, exp}; + exp = {0}; + Fq2Exp(&result, &in, &exp); + EXPECT_EQ(one, result); + + exp = {2}; + in = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, 0x4780716c, + 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, 0x1bb8f3e0, + 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem expected = {{0xb06f3418, 0x16043dfc, 0x7884a9ca, 0x0ab1a427, + 0x309307b5, 0x23133f6d, 0x250c3dc4, 0x005c4818}, + {0x3b6f652c, 0x6435c0fd, 0x509b8d30, 0x13fe4bef, + 0x5f4ffc14, 0x81dde5fd, 0x02b77b89, 0x5b38b2a5}}; + Fq2Exp(&result, &in, &exp); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Sub + +TEST(TinyFq2Test, Fq2SubWorks) { + Fq2Elem result = {0}; + Fq2Elem left = {{0, 0, 0, 0, 0, 20, 0, 0}, {0, 0, 0, 0, 0, 0, 30, 0}}; + Fq2Elem right = {{0, 0, 0, 0, 0, 5, 0, 0}, {0, 0, 0, 0, 0, 0, 9, 0}}; + Fq2Elem expected = {{0, 0, 0, 0, 0, 15, 0, 0}, {0, 0, 0, 0, 0, 0, 21, 0}}; + Fq2Sub(&result, &left, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Mul + +TEST(TinyFq2Test, Fq2MultWorks) { + Fq2Elem expected = {{0x37861727, 0x52822db7, 0x8005ec64, 0xc0b0bc96, + 0xd60e07a4, 0x65eee0a2, 0x780dbc26, 0x7b36e4cb}, + {0x8201d4ed, 0xbf8ed473, 0xc5c09cbe, 0xba9d0095, + 0x3d91414a, 0xa8ebb728, 0x66bc029b, 0x5b6ca52b}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem right = {{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, 0x2b477bd2, + 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, 0xe7d31209, + 0xc7786143, 0x91b441f6, 0x7409d67d}}; + Fq2Elem actual = {0}; + Fq2Mul(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Inv + +TEST(TinyFq2Test, Fq2InvWorks) { + Fq2Elem expected = {{0xffa2241d, 0x37481517, 0x4bc3ad3a, 0x3c57cefe, + 0xb7a57680, 0xaef8eb15, 0x6a1f7923, 0x2e6a7077}, + {0xdc8eb865, 0xe264dc4c, 0xa2a174dc, 0xa18b8fe8, + 0x31ee8433, 0xdea6fa81, 0x7ec16a0e, 0x1b0f8f81}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem actual = {0}; + Fq2Inv(&actual, &left); + EXPECT_EQ(expected, actual); +} + +TEST(TinyFq2Test, Fq2InvWorksInPlace) { + Fq2Elem expected = {{0xffa2241d, 0x37481517, 0x4bc3ad3a, 0x3c57cefe, + 0xb7a57680, 0xaef8eb15, 0x6a1f7923, 0x2e6a7077}, + {0xdc8eb865, 0xe264dc4c, 0xa2a174dc, 0xa18b8fe8, + 0x31ee8433, 0xdea6fa81, 0x7ec16a0e, 0x1b0f8f81}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Inv(&left, &left); + EXPECT_EQ(expected, left); +} +//////////////////////////////////////////////////////////////////////// +// Fq2Neg + +TEST(TinyFq2Test, Fq2NegWorks) { + FqElem const q = {{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem neg_value = {0}; + Fq2Elem one = {{1}, {1}}; + Fq2Elem minus_one = {q, q}; + --minus_one.x0.limbs.word[0]; + --minus_one.x1.limbs.word[0]; + Fq2Neg(&neg_value, &one); + EXPECT_EQ(minus_one, neg_value); + + Fq2Elem value = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}, + {0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Neg(&neg_value, &value); + Fq2Neg(&neg_value, &neg_value); + EXPECT_EQ(value, neg_value); + value = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem expected = {{0x8c035971, 0xaf40febd, 0x3d89f632, 0x24887d6e, + 0x3ecb5147, 0xff6580f2, 0x0023a5bd, 0xa19bcedb}, + {0x61afe694, 0xba8b7e8e, 0x07d2460a, 0xd758834b, + 0xb9944e4d, 0x2b2cfe7e, 0xe1ddaf4c, 0x755ba40a}}; + Fq2Neg(&neg_value, &value); + EXPECT_EQ(expected, neg_value); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Conj + +TEST(TinyFq2Test, Fq2ConjWorks) { + Fq2Elem expected = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, + 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x61afe694, 0xba8b7e8e, 0x07d2460a, 0xd758834b, + 0xb9944e4d, 0x2b2cfe7e, 0xe1ddaf4c, 0x755ba40a}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem actual = {0}; + Fq2Conj(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Square + +TEST(TinyFq2Test, Fq2SquareWorks) { + Fq2Elem expected = {{0xb06f3418, 0x16043dfc, 0x7884a9ca, 0x0ab1a427, + 0x309307b5, 0x23133f6d, 0x250c3dc4, 0x005c4818}, + {0x3b6f652c, 0x6435c0fd, 0x509b8d30, 0x13fe4bef, + 0x5f4ffc14, 0x81dde5fd, 0x02b77b89, 0x5b38b2a5}}; + Fq2Elem result = {0}; + Fq2Elem in = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Square(&result, &in); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2MulScalar + +TEST(TinyFq2Test, Fq2MulScalarWorks) { + Fq2Elem expected = {{0x28f2f1dd, 0x2cb2b611, 0xa24767b3, 0x4e880c0e, + 0xed7f7b9e, 0x6ff4a7f2, 0x25fb15d0, 0x7b8c4fed}, + {0}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0}}; + FqElem scalar = {0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}; + Fq2Elem actual = {0}; + Fq2MulScalar(&actual, &left, &scalar); + EXPECT_EQ(expected, actual); +} + +TEST(TinyFq2Test, Fq2MulScalarWorksInPlace) { + Fq2Elem expected = {{0x28f2f1dd, 0x2cb2b611, 0xa24767b3, 0x4e880c0e, + 0xed7f7b9e, 0x6ff4a7f2, 0x25fb15d0, 0x7b8c4fed}, + {0}}; + Fq2Elem left = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0}}; + FqElem scalar = {0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, + 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161}; + Fq2MulScalar(&left, &left, &scalar); + EXPECT_EQ(expected, left); +} +//////////////////////////////////////////////////////////////////////// +// Fq2CondSet + +TEST(TinyFq2Test, Fq2CondSetWorksForTrue) { + Fq2Elem a = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e64364}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem b = {{0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 0}}; + Fq2Elem result = {0}; + Fq2CondSet(&result, &a, &b, true); + EXPECT_EQ(a, result); +} + +TEST(TinyFq2Test, Fq2CondSetWorksForFalse) { + Fq2Elem a = {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e64364}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}; + Fq2Elem b = {{0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 0}}; + Fq2Elem result = {0}; + Fq2CondSet(&result, &a, &b, false); + EXPECT_EQ(b, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2Eq + +TEST(TinyFq2Test, Fq2EqPasses) { + FqElem fq_a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem fq_b = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem a = {fq_a, fq_a}; + Fq2Elem b = {fq_b, fq_b}; + EXPECT_TRUE(Fq2Eq(&a, &b)); +} + +TEST(TinyFq2Test, Fq2EqFails) { + FqElem fq_a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem fq_b = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq2Elem a = {fq_a, fq_a}; + Fq2Elem b = {fq_b, fq_b}; + --b.x1.limbs.word[5]; + EXPECT_FALSE(Fq2Eq(&a, &b)); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2MulXi + +TEST(TinyFq2Test, Fq2MultXiWorks) { + const Fq2Elem a = {{0xbca2b7aa, 0xc0e43294, 0x6199e561, 0xefdb7a39, + 0xd57bcbba, 0x03154f2a, 0xdf9e1797, 0xf52d29c1}, + {0x77cb909b, 0x906d8657, 0xfea2ffb3, 0x7810e964, + 0x022e47c1, 0x862bdbe6, 0xe4f5d59b, 0xa677247d}}; + const Fq2Elem expected = {{0x52a6aea6, 0x1e31b0f6, 0xb1f8c08d, 0x5ac9a512, + 0xba57ab15, 0x3918d010, 0xda4968c5, 0x43e32f05}, + {0x4e9378ba, 0x3b6ce38c, 0x39afcfc3, 0xc644810d, + 0xfcf511ff, 0x81a12238, 0xa98fe133, 0x421b72bd}}; + + Fq2Elem res; + Fq2MulXi(&res, &a); + EXPECT_EQ(expected, res); +} + +//////////////////////////////////////////////////////////////////////// +// Fq2IsZero + +TEST(TinyFq2Test, Fq2IsZeroPasses) { + Fq2Elem zero = {0}; + EXPECT_TRUE(Fq2IsZero(&zero)); +} + +TEST(TinyFq2Test, Fq2IsZeroFails) { + Fq2Elem non_zero = {0}; + ++non_zero.x0.limbs.word[6]; + EXPECT_FALSE(Fq2IsZero(&non_zero)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/fq6-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/fq6-test.cc new file mode 100644 index 00000000..5a47bbfd --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/fq6-test.cc @@ -0,0 +1,452 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of Fq6 implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/member/tiny/math/fq6.h" +#include "epid/member/tiny/math/mathtypes.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// Fq6Add + +TEST(TinyFq6Test, Fq6AddWorks) { + Fq6Elem expected = {{{0xf8898202, 0xb45883e0, 0x8d18168d, 0xf67a4288, + 0xec7c2a8a, 0xfa6f0441, 0xff5583e2, 0x32d88286}, + {0x304722d5, 0x113e09d3, 0xeaf32297, 0x32d71c16, + 0x1cb0685b, 0xe3315524, 0xafd38377, 0xfeae3272}}, + {{0xc82d8518, 0x99cec06c, 0xe8d7d62b, 0x2f00d5c5, + 0x0620146e, 0x2741e62b, 0x9e7557ca, 0xeb019297}, + {0x15cfc66e, 0x55ba87c0, 0xf1060150, 0xb91180f6, + 0xb0d77f5f, 0xc7fa8733, 0x7dc697f1, 0x1e6b8e24}}, + {{0x1400db26, 0x0760a0b1, 0x1a64565f, 0x27b5641e, + 0xd96484ed, 0x54b02297, 0xa2a57172, 0xc3a04c1c}, + {0x17ff87fb, 0x6294fcdb, 0x8f7c4bc2, 0xd0802fe6, + 0xee3d7f1b, 0xf19d63af, 0xdb1d00ae, 0x80df53e6}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem right = {{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, 0x2b477bd2, + 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, 0xe7d31209, + 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, 0x97589d24, + 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, 0x4f48fed2, + 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, 0x6b0c7ee2, + 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, 0xc750dfa2, + 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}; + Fq6Elem actual = {0}; + Fq6Add(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Sub + +TEST(TinyFq6Test, Fq6SubWorks) { + Fq6Elem expected = {{{0x4d162b42, 0x9377da5b, 0x1d041212, 0xda2d8e91, + 0x72d07c24, 0x9491de97, 0x005d123b, 0x89efdfc3}, + {0x69ff7029, 0x1ffd54c7, 0x2a986659, 0x3830a949, + 0x4d0a4447, 0x5440929c, 0x8c6aff8a, 0x169a8577}}, + {{0x970c6506, 0x259580a0, 0x4547416c, 0xbc76db4c, + 0xb4522362, 0xea130cd9, 0xc0e74ff6, 0xeeace017}, + {0x97b9f013, 0xc4ec0fd2, 0x1dcfb36c, 0x97f1207d, + 0x00b72659, 0x218e308a, 0xc0c7c429, 0x093f2175}}, + {{0x318f88cb, 0x503725ee, 0x5c9a3d68, 0xba67a76b, + 0xf1bd2bc6, 0x6413020d, 0xa06fe769, 0xecbd7182}, + {0xa54e2ad8, 0xd2613407, 0x5c778439, 0x2bd154d5, + 0x4e0d6476, 0xe6ae1ad3, 0x18b00add, 0xaf4062dc}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem right = {{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, 0x2b477bd2, + 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, 0xe7d31209, + 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, 0x97589d24, + 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, 0x4f48fed2, + 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, 0x6b0c7ee2, + 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, 0xc750dfa2, + 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}; + Fq6Elem actual = {0}; + Fq6Sub(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Mul + +TEST(TinyFq6Test, Fq6MultWorks) { + Fq6Elem expected = {{{0xf45502f6, 0x81c1eb6d, 0xb43cb376, 0xd0da40d4, + 0xd6156988, 0x6cd4b676, 0x68079d3e, 0x5030f7d9}, + {0x8e5857ea, 0x042705fb, 0xac87e99c, 0x10dba783, + 0xc8a7141b, 0xf742b852, 0x007d20f9, 0x0f6497d4}}, + {{0xf30a6588, 0xa558efef, 0xe2dac9b0, 0x1586ed6a, + 0x21de4041, 0xc02e9d19, 0x6707fbb5, 0xbe0be53f}, + {0x13920431, 0x4935916a, 0x939a8ef8, 0x12230898, + 0xecbf17a9, 0x0934361c, 0x148c5974, 0x73a766d6}}, + {{0xb989db6c, 0xc1c3c771, 0xc1a12757, 0xad67b5d9, + 0xed10d66b, 0x9611f300, 0x3874e3cf, 0x9384e9bf}, + {0x7acace21, 0x0efe39f0, 0x495ed747, 0xd48f3503, + 0x6b032eeb, 0xb6430ee5, 0x1a864a16, 0xe497f2b6}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem right = {{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, 0x2b477bd2, + 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, 0xe7d31209, + 0xc7786143, 0x91b441f6, 0x7409d67d}}, + {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337, 0x97589d24, + 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f}, + {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a, 0x4f48fed2, + 0xf6a92484, 0x5e7de24a, 0x8a963657}}, + {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156, 0x6b0c7ee2, + 0x1bc18974, 0x01193d6b, 0x6b716d4d}, + {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086, 0xc750dfa2, + 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}}; + Fq6Elem actual = {0}; + Fq6Mul(&actual, &left, &right); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Inv + +TEST(TinyFq6Test, Fq6InvWorks) { + Fq6Elem expected = {{{0x4b9d2361, 0x22a3edb2, 0x4234b1bc, 0x15d4ba45, + 0x035c34fb, 0xd041dd56, 0x0ac1e096, 0x0352ad8d}, + {0x4e25c70f, 0x3dc912a9, 0x97a1aa56, 0x32b6e93d, + 0x19c793ce, 0x951b4bb8, 0x3982345f, 0xec9e815e}}, + {{0x3d413679, 0x4cdeca84, 0x33e1c617, 0xc8851545, + 0x51625f1e, 0xcb8421ce, 0xd0a7ea78, 0xbb8a0cd6}, + {0x77d7ca2e, 0x6a51fadc, 0xec063983, 0xf9a311be, + 0x28fe40b2, 0x30433e0f, 0x1ed97598, 0x9a82a67f}}, + {{0x58db3fa8, 0xa999913c, 0x5bef2263, 0x1dba2103, + 0x0082518b, 0x3d5a20fc, 0x41913c0f, 0x708bddf4}, + {0x20a372b3, 0x2ebb41eb, 0x9fdb3fa2, 0x473986ff, + 0x0f5835a9, 0x06121385, 0x8e24ac7e, 0x95b8ca14}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem actual = {0}; + Fq6Inv(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Neg + +TEST(TinyFq6Test, Fq6NegWorks) { + Fq6Elem expected = {{{0x8c035971, 0xaf40febd, 0x3d89f632, 0x24887d6e, + 0x3ecb5147, 0xff6580f2, 0x0023a5bd, 0xa19bcedb}, + {0x61afe694, 0xba8b7e8e, 0x07d2460a, 0xd758834b, + 0xb9944e4d, 0x2b2cfe7e, 0xe1ddaf4c, 0x755ba40a}}, + {{0xff363b04, 0xf3770d54, 0xfb887eb6, 0x97208d71, + 0x913888b6, 0xbe3b78dc, 0x504e9cec, 0x1328c6a8}, + {0x80a4bcc9, 0xdc414b24, 0x81e12ae2, 0xddece243, + 0x9e717f72, 0x2eae9d50, 0xe0b74a59, 0x6c2aa832}}, + {{0xe3749624, 0x90f1e179, 0xe064c5e0, 0xa23c1333, + 0x80199e94, 0x0df7593b, 0x5e70bcc6, 0xa7d12130}, + {0x2795eeb3, 0x2242ac58, 0xa5ea27c6, 0x9521d69a, + 0xc7850525, 0x7e332c4c, 0x8614e36d, 0xe7f0249e}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem actual = {0}; + Fq6Neg(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Clear + +TEST(TinyFq6Test, Fq6ClearWorks) { + Fq6Elem expected = {0}; + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq6Elem result = {fq, fq, fq, fq, fq, fq}; + Fq6Clear(&result); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6MulScalar + +TEST(TinyFq6Test, Fq6MulScalarWorks) { + Fq6Elem expected = {{{0x37861727, 0x52822db7, 0x8005ec64, 0xc0b0bc96, + 0xd60e07a4, 0x65eee0a2, 0x780dbc26, 0x7b36e4cb}, + {0x8201d4ed, 0xbf8ed473, 0xc5c09cbe, 0xba9d0095, + 0x3d91414a, 0xa8ebb728, 0x66bc029b, 0x5b6ca52b}}, + {{0x37861727, 0x52822db7, 0x8005ec64, 0xc0b0bc96, + 0xd60e07a4, 0x65eee0a2, 0x780dbc26, 0x7b36e4cb}, + {0x8201d4ed, 0xbf8ed473, 0xc5c09cbe, 0xba9d0095, + 0x3d91414a, 0xa8ebb728, 0x66bc029b, 0x5b6ca52b}}, + {{0}, {0}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0}, {0}}}; + Fq2Elem scalar = {{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6, 0x2b477bd2, + 0xf9d48534, 0xff7929a0, 0xd4745161}, + {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966, 0xe7d31209, + 0xc7786143, 0x91b441f6, 0x7409d67d}}; + Fq6Elem actual = {0}; + Fq6MulScalar(&actual, &left, &scalar); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6MulV + +TEST(TinyFq6Test, Fq6MulVWorks) { + const Fq6Elem a = {{{0x747a9232, 0xb91bf0cd, 0x1c5aa24e, 0x1c3c7860, + 0x40b4d7ca, 0x26094519, 0xe29e50db, 0x67da0b88}, + {0x1e540333, 0xc03c243c, 0x55d91627, 0xfcc36017, + 0x5876fc39, 0xf0590ba2, 0x47ce59ac, 0x9cc0760e}}, + {{0xaf2c16be, 0x4036bf3d, 0xd8ecc7eb, 0x4fdd0128, + 0x4faf6ca1, 0xc55bc411, 0xa26b3ac5, 0x1338fc1c}, + {0x0936baf1, 0xc2254b98, 0x84993186, 0xa7a46e79, + 0xf2ed3380, 0xa1a5dad1, 0x2046667a, 0x348362a5}}, + {{0xbca2b7aa, 0xc0e43294, 0x6199e561, 0xefdb7a39, + 0xd57bcbba, 0x03154f2a, 0xdf9e1797, 0xf52d29c1}, + {0x77cb909b, 0x906d8657, 0xfea2ffb3, 0x7810e964, + 0x022e47c1, 0x862bdbe6, 0xe4f5d59b, 0xa677247d}}}; + const Fq6Elem expected = {{{0x52a6aea6, 0x1e31b0f6, 0xb1f8c08d, 0x5ac9a512, + 0xba57ab15, 0x3918d010, 0xda4968c5, 0x43e32f05}, + {0x4e9378ba, 0x3b6ce38c, 0x39afcfc3, 0xc644810d, + 0xfcf511ff, 0x81a12238, 0xa98fe133, 0x421b72bd}}, + {{0x747a9232, 0xb91bf0cd, 0x1c5aa24e, 0x1c3c7860, + 0x40b4d7ca, 0x26094519, 0xe29e50db, 0x67da0b88}, + {0x1e540333, 0xc03c243c, 0x55d91627, 0xfcc36017, + 0x5876fc39, 0xf0590ba2, 0x47ce59ac, 0x9cc0760e}}, + {{0xaf2c16be, 0x4036bf3d, 0xd8ecc7eb, 0x4fdd0128, + 0x4faf6ca1, 0xc55bc411, 0xa26b3ac5, 0x1338fc1c}, + {0x0936baf1, 0xc2254b98, 0x84993186, 0xa7a46e79, + 0xf2ed3380, 0xa1a5dad1, 0x2046667a, 0x348362a5}}}; + + Fq6Elem res; + Fq6MulV(&res, &a); + EXPECT_EQ(expected, res); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Eq + +TEST(TinyFq6Test, Fq6EqPasses) { + FqElem fq_a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem fq_b = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq6Elem a = {fq_a, fq_a, fq_a, fq_a, fq_a, fq_a}; + Fq6Elem b = {fq_b, fq_b, fq_b, fq_b, fq_b, fq_b}; + EXPECT_TRUE(Fq6Eq(&a, &b)); +} + +TEST(TinyFq6Test, Fq6EqFails) { + FqElem fq_a = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + FqElem fq_b = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq6Elem a = {fq_a, fq_a, fq_a, fq_a, fq_a, fq_a}; + Fq6Elem b = {fq_b, fq_b, fq_b, fq_b, fq_b, fq_b}; + --b.y2.x1.limbs.word[5]; + EXPECT_FALSE(Fq6Eq(&a, &b)); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6IsZero + +TEST(TinyFq6Test, Fq6IsZeroPasses) { + Fq6Elem zero = {0}; + EXPECT_TRUE(Fq6IsZero(&zero)); +} + +TEST(TinyFq6Test, Fq6IsZeroFails) { + Fq6Elem non_zero = {0}; + ++non_zero.y2.x1.limbs.word[4]; + EXPECT_FALSE(Fq6IsZero(&non_zero)); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Square + +TEST(TinyFq6Test, Fq6SquareWorks) { + Fq6Elem expected = {{{0xd33e098c, 0xf56a0ddf, 0x1a07b1f1, 0x5c9f80e4, + 0x0f4cab4b, 0x18c856b8, 0x4c614650, 0xdd44c9f1}, + {0x5210a238, 0x934c3474, 0x8d6f7915, 0x7bfe3252, + 0x907c0c7d, 0x6cb28259, 0xeab6a4de, 0xb37400f3}}, + {{0xed8e6c82, 0xfcb0be62, 0x686dcd3b, 0xfdfbb0b6, + 0x30744d0a, 0x408cd48e, 0x1cd63084, 0xa246ad21}, + {0xc823a4b3, 0x4add0b26, 0x68c1bd68, 0x67140391, + 0xb0fe9dd7, 0xbae08890, 0xac5aac76, 0xb2547efa}}, + {{0xb1eae872, 0xc22e7b27, 0x3b972d7a, 0x894e0e3a, + 0xbc67f9b5, 0xc8a56674, 0x82ba5f56, 0xfbeb546b}, + {0x6e6c8c17, 0x634cdd65, 0xc3678b6f, 0x08e820dc, + 0x166dbab9, 0xb0c34885, 0x0b952acd, 0xffc1173e}}}; + Fq6Elem left = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e643124}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem actual = {0}; + Fq6Square(&actual, &left); + EXPECT_EQ(expected, actual); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Cp + +TEST(TinyFq6Test, Fq6CpWorks) { + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq6Elem a = {fq, fq, fq, fq, fq, fq}; + Fq6Elem result = {0}; + Fq6Cp(&result, &a); + EXPECT_EQ(a, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6CondSet + +TEST(TinyFq6Test, Fq6CondSetWorksForTrue) { + Fq6Elem a = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e64364}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c66, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem b = {{{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}}, + {{0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}}, + {{0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}}}; + + Fq6Elem result = {0}; + Fq6CondSet(&result, &a, &b, true); + EXPECT_EQ(a, result); +} + +TEST(TinyFq6Test, Fq6CondSetWorksForFalse) { + Fq6Elem a = {{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357, + 0x4780716c, 0xffd94b0f, 0x5e64364}, + {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651, + 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}}, + {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8, + 0x88aa7982, 0xafae53e0, 0xecd73957}, + {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c, + 0x1837550e, 0x1f45a674, 0x93d557cd}}, + {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a, + 0x38ee9923, 0xa18c3407, 0x582edecf}, + {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79, + 0xc8b2c66, 0x79e80d5f, 0x180fdb61}}}; + Fq6Elem b = {{{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}}, + {{0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}}, + {{0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}}}; + + Fq6Elem result = {0}; + Fq6CondSet(&result, &a, &b, false); + EXPECT_EQ(b, result); +} + +//////////////////////////////////////////////////////////////////////// +// Fq6Set + +TEST(TinyFq6Test, Fq6SetWorks) { + uint32_t small = 0xffffffff; + Fq6Elem expected = {0}; + expected.y0.x0.limbs.word[0] = small; + FqElem fq = {{0xAED33012, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}; + Fq6Elem result = {fq, fq, fq, fq, fq, fq}; + Fq6Set(&result, small); + EXPECT_EQ(expected, result); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/internal/onetimepad-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/internal/onetimepad-test.cc new file mode 100644 index 00000000..66907e06 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/internal/onetimepad-test.cc @@ -0,0 +1,130 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests for OneTimePad. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/onetimepad.h" + +namespace { + +TEST(OneTimePadTest, GenerateFailsWhenDefaultConstructedWithoutInit) { + OneTimePad otp; + EXPECT_EQ(0u, otp.BitsConsumed()); + std::vector actual({0, 0}); + EXPECT_NE(0, OneTimePad::Generate(actual.data(), 8, &otp)); +} + +TEST(OneTimePadTest, GeneratesCorrectDataWhenConstructedWithUint8s) { + std::vector actual1({0, 0}); + std::vector actual2({0, 0}); + const std::vector expected1({0x07050301, 0}); + const std::vector expected2({0x0e0c0a09, 0}); + OneTimePad otp({0x01, 0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0e}); + EXPECT_EQ(0u, otp.BitsConsumed()); + EXPECT_EQ(0, OneTimePad::Generate(actual1.data(), 32, &otp)); + EXPECT_EQ(expected1, actual1); + EXPECT_EQ(32u, otp.BitsConsumed()); + EXPECT_EQ(0, OneTimePad::Generate(actual2.data(), 32, &otp)); + EXPECT_EQ(expected2, actual2); + EXPECT_EQ(64u, otp.BitsConsumed()); +} + +TEST(OneTimePadTest, GeneratesCorrectDataWhenInitilizedWithUint8s) { + std::vector actual1({0, 0}); + std::vector actual2({0, 0}); + const std::vector expected1({0x07050301, 0}); + const std::vector expected2({0x0e0c0a09, 0}); + OneTimePad otp; + otp.InitUint8({0x01, 0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0e}); + EXPECT_EQ(0u, otp.BitsConsumed()); + EXPECT_EQ(0, OneTimePad::Generate(actual1.data(), 32, &otp)); + EXPECT_EQ(expected1, actual1); + EXPECT_EQ(32u, otp.BitsConsumed()); + EXPECT_EQ(0, OneTimePad::Generate(actual2.data(), 32, &otp)); + EXPECT_EQ(expected2, actual2); + EXPECT_EQ(64u, otp.BitsConsumed()); +} +TEST(OneTimePadTest, GeneratesCorrectDataWhenInitilizedWithUint32s) { + std::vector actual({0x00}); + const std::vector expected({0x01}); + std::vector actual2({0x00}); + const std::vector expected2({0x01020304}); + OneTimePad otp({0x01, 0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0e}); + otp.InitUint32({0x01, 0x01020304}); + EXPECT_EQ(0u, otp.BitsConsumed()); + EXPECT_EQ(0, OneTimePad::Generate(actual.data(), 32, &otp)); + EXPECT_EQ(32u, otp.BitsConsumed()); + EXPECT_EQ(expected, actual); + EXPECT_EQ(0, OneTimePad::Generate(actual2.data(), 32, &otp)); + EXPECT_EQ(expected2, actual2); + EXPECT_EQ(64u, otp.BitsConsumed()); +} +TEST(OneTimePadTest, GeneratesSingleBytesCorrectly) { + OneTimePad otp({0x01, 0x03, 0x05, 0x07, 0x09, 0x0a, 0x0c, 0x0e}); + std::vector expected1({0x01, 0x00, 0x00, 0x00}); + std::vector expected2({0x03, 0x00, 0x00, 0x00}); + std::vector expected3({0x05, 0x00, 0x00, 0x00}); + std::vector actual({0, 0, 0, 0}); + EXPECT_EQ(0, OneTimePad::Generate((uint32_t*)actual.data(), 8, &otp)); + EXPECT_EQ(8u, otp.BitsConsumed()); + EXPECT_EQ(expected1, actual); + EXPECT_EQ(0, OneTimePad::Generate((uint32_t*)actual.data(), 8, &otp)); + EXPECT_EQ(16u, otp.BitsConsumed()); + EXPECT_EQ(expected2, actual); + EXPECT_EQ(0, OneTimePad::Generate((uint32_t*)actual.data(), 8, &otp)); + EXPECT_EQ(24u, otp.BitsConsumed()); + EXPECT_EQ(expected3, actual); +} + +TEST(OneTimePadTest, GenerateRejectsNullPtr) { + OneTimePad otp(8); + EXPECT_NE(0, OneTimePad::Generate(nullptr, 32, &otp)); +} +TEST(OneTimePadTest, GenerateRejectsNegativeBits) { + OneTimePad otp(8); + std::vector actual({0, 0}); + EXPECT_NE(0, OneTimePad::Generate(actual.data(), -32, &otp)); +} +TEST(OneTimePadTest, GenerateRejectsZeroBits) { + OneTimePad otp(8); + std::vector actual({0, 0}); + EXPECT_NE(0, OneTimePad::Generate(actual.data(), 0, &otp)); +} +TEST(OneTimePadTest, GenerateRejectsTooLargeRequest) { + OneTimePad otp(8); + std::vector actual({0, 0}); + EXPECT_EQ(0, OneTimePad::Generate(actual.data(), 32, &otp)); + EXPECT_EQ(0, OneTimePad::Generate(actual.data(), 32, &otp)); + EXPECT_NE(0, OneTimePad::Generate(actual.data(), 32, &otp)); +} + +TEST(OneTimePadTest, GenerateRejectsUnsupportedBitRequest) { + OneTimePad otp(8); + std::vector actual({0, 0}); + EXPECT_NE(0, OneTimePad::Generate(actual.data(), 31, &otp)); +} + +TEST(OneTimePadTest, GenerateCoddlesDevelopersWhoDoNotCheckReturnValues) { + OneTimePad otp(4); + uint32_t word; + EXPECT_EQ(0, OneTimePad::Generate(&word, 32, &otp)); + EXPECT_NE(0, OneTimePad::Generate(&word, 32, &otp)); + EXPECT_THROW(OneTimePad::Generate(&word, 32, &otp), std::runtime_error); +} + +} // namespace diff --git a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/main-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/main-testhelper.cc similarity index 83% rename from external/epid-sdk-3.0.0/epid/common-testhelper/unittests/main-test.cc rename to external/epid-sdk/epid/member/tiny/math/unittests/main-testhelper.cc index 70f2d3a1..c67c612e 100644 --- a/external/epid-sdk-3.0.0/epid/common-testhelper/unittests/main-test.cc +++ b/external/epid-sdk/epid/member/tiny/math/unittests/main-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,14 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ -/*! - * \file - * \brief Main entry point for unit tests. - */ +/// Main entry point for tiny math unit tests +/*! \file */ -#include "gtest/gtest.h" +#include -int main(int argc, char** argv) { +int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/onetimepad.h b/external/epid-sdk/epid/member/tiny/math/unittests/onetimepad.h new file mode 100644 index 00000000..24215e18 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/onetimepad.h @@ -0,0 +1,122 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// One time pad class +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_UNITTESTS_ONETIMEPAD_H_ +#define EPID_MEMBER_TINY_MATH_UNITTESTS_ONETIMEPAD_H_ + +#include // for CHAR_BIT +#include +#include +#include +#include + +#if defined(_WIN32) || defined(_WIN64) +#define __STDCALL __stdcall +#else +#define __STDCALL +#endif + +/// One time pad with Bitsupplier interface +class OneTimePad { + public: + /// Default constructor + OneTimePad() : bytes_consumed_(0), reported_having_no_data_(false) {} + /// Construct using mersenne twister + explicit OneTimePad(size_t num_bytes) + : bytes_consumed_(0), reported_having_no_data_(false) { + data_.resize(num_bytes); + std::mt19937 generator; + generator.seed(1); + for (size_t i = 0; i < num_bytes; i++) + data_[i] = static_cast(generator() & 0x000000ff); + } + /// Construct with data + explicit OneTimePad(std::vector const& uint8_data) + : reported_having_no_data_(false) { + InitUint8(uint8_data); + } + /// Re-initialize with unit8 data + void InitUint8(std::vector const& uint8_data) { + if (uint8_data.size() > SIZE_MAX / CHAR_BIT) + throw std::invalid_argument("input exceeded SIZE_MAX bits"); + bytes_consumed_ = 0; + data_.clear(); + data_ = uint8_data; + reported_having_no_data_ = false; + } + /// Re-initialize with unit32 data + void InitUint32(std::vector const& uint32_data) { + if (uint32_data.size() * sizeof(uint32_t) > SIZE_MAX / CHAR_BIT) + throw std::invalid_argument("input exceeded SIZE_MAX bits"); + bytes_consumed_ = 0; + data_.clear(); + for (auto u32 : uint32_data) { + data_.push_back((uint8_t)(u32 & 0xFF)); + data_.push_back((uint8_t)((u32 & 0xFF00) >> 8)); + data_.push_back((uint8_t)((u32 & 0xFF0000) >> 16)); + data_.push_back((uint8_t)((u32 & 0xFF000000) >> 24)); + reported_having_no_data_ = false; + } + } + /// Destructor + ~OneTimePad() {} + /// returns bits consumed + size_t BitsConsumed() const { return bytes_consumed_ * CHAR_BIT; } + /// Generates random number + static int __STDCALL Generate(unsigned int* random_data, int num_bits, + void* user_data) { + size_t num_bytes = num_bits / CHAR_BIT; + size_t extra_bits = num_bits % CHAR_BIT; + uint8_t* random_bytes = reinterpret_cast(random_data); + OneTimePad* myprng = (OneTimePad*)user_data; + if ((!random_data) || (num_bits <= 0)) { + return -5; // bad arg + } + if (myprng->reported_having_no_data_) { + throw std::runtime_error( + "request for random data after being informed random data was " + "exhausted"); + } + if ((size_t)num_bits > myprng->BitsAvailable()) { + // cause an exception to be thrown on next invocation + myprng->reported_having_no_data_ = true; + return -1; // out of random data + } + if (0 != extra_bits) { + // can only handle even number of byte requests + return -5; + } + + for (unsigned int n = 0; n < num_bytes; n++) { + random_bytes[n] = myprng->data_[myprng->bytes_consumed_++]; + } + return 0; + } + + private: + /// returns bits available + size_t BitsAvailable() const { + return (data_.size() - bytes_consumed_) * CHAR_BIT; + } + + size_t bytes_consumed_ = 0; + std::vector data_; + bool reported_having_no_data_ = false; +}; + +#endif // EPID_MEMBER_TINY_MATH_UNITTESTS_ONETIMEPAD_H_ diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/pairing-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/pairing-test.cc new file mode 100644 index 00000000..c9763341 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/pairing-test.cc @@ -0,0 +1,79 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of pairing implementation. +/*! \file */ + +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/pairing.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// PairingCompute + +TEST(TinyPairingTest, PairingComputeWorks) { + const EccPointFq a = {{0xf67c8483, 0xbaceaf8d, 0xfcaa5567, 0x8ac94411, + 0x7d91c375, 0x0fcaa603, 0x210f0997, 0xd7e2f937}, + {0x0f93424b, 0x88e246d6, 0x4859033f, 0x3ff08258, + 0xf613c944, 0xaf6cd00a, 0x9f0d2673, 0x04b7a6ff}}; + const EccPointFq2 b = {{{0xa3c3fd4c, 0xad5323dc, 0x3770e217, 0x91a68d51, + 0xdcfbda35, 0x6fb2b5c1, 0xbc72b09c, 0x3f4cb52d}, + {0xb6f87404, 0xb8fb89d1, 0xb0c1d7f9, 0x49dff54f, + 0x7fb08a69, 0x5e8ef4ce, 0xcb35f350, 0x90fa4fa2}}, + {{0xc801fb5b, 0xfbbd005f, 0x1620b9cc, 0x444c5486, + 0x083e43a1, 0x80f44b97, 0x62f3175a, 0xefc66005}, + {0xeb618b01, 0x448994a3, 0x3aca949c, 0xdfba9b6f, + 0x35140ec9, 0xa2aa865a, 0xe20470eb, 0xc16e2b46}}}; + const Fq12Elem expected = { + {{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed, 0xad5ee231, 0x4fc0a501, + 0x468be932, 0xba101ff6}, + {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0, 0xcb0454f2, 0xc4077c42, + 0xebde30b6, 0x15eb79f4}}, + {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c, 0x1c0def81, 0x80e14649, + 0x4657b6e7, 0xf18b84d1}, + {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb, 0x6fd516b6, 0xb7190100, + 0xc1fa4e50, 0x3fee7c43}}, + {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d, 0x138bb1b6, 0x87cf70ba, + 0xbbef8650, 0xe3b31829}, + {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173, 0xcdc3182a, 0x1ecb0486, + 0xd5a961a5, 0xda0e5787}}}, + {{{0x0b13b454, 0xa62f5fbf, 0xa4bed641, 0xd3632805, 0xe8010941, 0x72cebb51, + 0x8aaa0095, 0x669e804d}, + {0xe49b7149, 0x8fc69d31, 0x956d88ab, 0x265c926b, 0x3bb2f1d4, 0xbfc206ea, + 0x6f29d6da, 0x5b5065dc}}, + {{0x0ff0848e, 0x1f3fdf5c, 0xb3533098, 0x1a434003, 0xc80d2a60, 0x4ac6aa4a, + 0xc99fbca8, 0xe0ce978f}, + {0x3357d172, 0xf5f8a018, 0x5908b3da, 0xe540395c, 0xb654a226, 0x89cef58e, + 0x47786d9f, 0x5a5d41d2}}, + {{0x788a3989, 0x49a5f719, 0x5a0042e3, 0x92f94303, 0x1bd0e6c8, 0x81c5ac15, + 0xe8a05ec8, 0xbbba6ced}, + {0x6d17dc8e, 0xaf351b75, 0xba6e2c36, 0x2a04ea26, 0x421e1737, 0x16fd0bfe, + 0x4bb33376, 0x32aebf4d}}}}; + + PairingState ps; + PairingInit(&ps); + Fq12Elem res = {0}; + PairingCompute(&res, &a, &b, &ps); + EXPECT_EQ(expected, res); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/serialize-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/serialize-test.cc new file mode 100644 index 00000000..66e188b3 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/serialize-test.cc @@ -0,0 +1,423 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of serialization implementation. +/*! \file */ + +#include +#include +#include +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" + +extern "C" { +#include "epid/common/types.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +} + +bool operator==(OctStr32 const& lhs, OctStr32 const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(BigNumStr const& lhs, BigNumStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(FqElemStr const& lhs, FqElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(G2ElemStr const& lhs, G2ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(Fq12ElemStr const& lhs, Fq12ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +namespace { +//////////////////////////////////////////////////////////////////////// +// Uint32Serialize + +TEST(TinySerializeTest, Uint32SerializeWorks) { + OctStr32 octstr = {0}; + const OctStr32 expected_octstr = {0x01, 0x02, 0x03, 0x04}; + const uint32_t num = 0x01020304; + Uint32Serialize(&octstr, num); + EXPECT_EQ(expected_octstr, octstr); +} + +//////////////////////////////////////////////////////////////////////// +// Uint32Deserialize + +TEST(TinySerializeTest, Uint32DeserializeWorks) { + const OctStr32 octstr = {0x01, 0x02, 0x03, 0x04}; + uint32_t num = 0; + const uint32_t expected_num = 0x01020304; + Uint32Deserialize(&num, &octstr); + EXPECT_EQ(expected_num, num); +} + +//////////////////////////////////////////////////////////////////////// +// VliSerialize + +TEST(TinySerializeTest, VliSerializeWorks) { + const VeryLargeInt vli = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + BigNumStr serialize_vli = {0}; + const BigNumStr expected_serialize_vli = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + VliSerialize(&serialize_vli, &vli); + EXPECT_EQ(expected_serialize_vli, serialize_vli); +} + +//////////////////////////////////////////////////////////////////////// +// VliDeserialize + +TEST(TinySerializeTest, VliDeserializeWorks) { + VeryLargeInt vli = {0}; + const VeryLargeInt expected_vli = {0x01020304, 0x05060708, 0x090A0B0C, + 0x0D0E0F10, 0x11121314, 0x15161718, + 0x191A1B1C, 0x1D1E1F20}; + const BigNumStr serialize_vli = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + VliDeserialize(&vli, &serialize_vli); + EXPECT_EQ(expected_vli, vli); +} + +//////////////////////////////////////////////////////////////////////// +// FqSerialize + +TEST(TinySerializeTest, FqSerializeWorks) { + const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + FqElemStr serialize_fqelm = {0}; + const FqElemStr expected_serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + FqSerialize(&serialize_fqelm, &fqelm); + EXPECT_EQ(expected_serialize_fqelm, serialize_fqelm); +} + +//////////////////////////////////////////////////////////////////////// +// FqDeserialize + +TEST(TinySerializeTest, FqDeserializeWorks) { + const FqElemStr serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + FqElem fqelm = {0}; + const FqElem expected_fqelm = {0x01020304, 0x05060708, 0x090A0B0C, + 0x0D0E0F10, 0x11121314, 0x15161718, + 0x191A1B1C, 0x1D1E1F20}; + FqDeserialize(&fqelm, &serialize_fqelm); + EXPECT_EQ(expected_fqelm, fqelm); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Serialize + +TEST(TinySerializeTest, Fq12SerializeWorks) { + const Fq12Elem fq12elm = { + {{ + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }}, + {{ + {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }}}; + Fq12ElemStr serialized_fq12elm = {0}; + const Fq12ElemStr expected_serialized_fq12elm = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + Fq12Serialize(&serialized_fq12elm, &fq12elm); + EXPECT_EQ(expected_serialized_fq12elm, serialized_fq12elm); +} + +//////////////////////////////////////////////////////////////////////// +// Fq12Deserialize + +TEST(TinySerializeTest, Fq12DeserializeWorks) { + const Fq12ElemStr serialized_fq12elm = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + Fq12Elem fq12elm = {0}; + const Fq12Elem expected_fq12elm = { + {{ + {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }}, + {{ + {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }, + { + {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000}, + }}}; + Fq12Deserialize(&fq12elm, &serialized_fq12elm); + EXPECT_EQ(expected_fq12elm, fq12elm); +} + +//////////////////////////////////////////////////////////////////////// +// FpSerialize + +TEST(TinySerializeTest, FpSerializeWorks) { + const FpElem fpelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + FpElemStr serialize_fpelm = {0}; + const FpElemStr expected_serialize_fpelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + FpSerialize(&serialize_fpelm, &fpelm); + EXPECT_EQ(expected_serialize_fpelm, serialize_fpelm); +} + +//////////////////////////////////////////////////////////////////////// +// FpDeserialize + +TEST(TinySerializeTest, FpDeserializeWorks) { + const FpElemStr serialize_fpelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + FpElem fpelm = {0}; + const FpElem expected_fpelm = {0x01020304, 0x05060708, 0x090A0B0C, + 0x0D0E0F10, 0x11121314, 0x15161718, + 0x191A1B1C, 0x1D1E1F20}; + FpDeserialize(&fpelm, &serialize_fpelm); + EXPECT_EQ(expected_fpelm, fpelm); +} + +//////////////////////////////////////////////////////////////////////// +// EFqSerialize + +TEST(TinySerializeTest, EFqSerializeWorks) { + const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + const EccPointFq efq_point = {fqelm, fqelm}; + const FqElemStr serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + G1ElemStr efq_point_serialize = {0}; + const G1ElemStr expected_efq_point_serialize = {serialize_fqelm, + serialize_fqelm}; + EFqSerialize(&efq_point_serialize, &efq_point); + EXPECT_EQ(expected_efq_point_serialize, efq_point_serialize); +} + +//////////////////////////////////////////////////////////////////////// +// EFqDeserialize + +TEST(TinySerializeTest, EFqDeserializeWorks) { + const FqElemStr serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + const G1ElemStr serialize_efq_point = {serialize_fqelm, serialize_fqelm}; + EccPointFq efq_point = {0}; + const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + const EccPointFq expected_efq_point = {fqelm, fqelm}; + EFqDeserialize(&efq_point, &serialize_efq_point); + EXPECT_EQ(expected_efq_point, efq_point); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2Serialize + +TEST(TinySerializeTest, EFq2SerializeWorks) { + const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + const EccPointFq2 efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}}; + const FqElemStr serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + G2ElemStr efq2_point_serialize = {0}; + const G2ElemStr expected_efq2_point_serialize = { + {serialize_fqelm, serialize_fqelm}, {serialize_fqelm, serialize_fqelm}}; + EFq2Serialize(&efq2_point_serialize, &efq2_point); + EXPECT_EQ(expected_efq2_point_serialize, efq2_point_serialize); +} + +//////////////////////////////////////////////////////////////////////// +// EFq2Deserialize + +TEST(TinySerializeTest, EFq2DeserializeWorks) { + const FqElemStr serialize_fqelm = { + 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17, + 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A, + 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04}; + const G2ElemStr serialize_efq2_point = {{serialize_fqelm, serialize_fqelm}, + {serialize_fqelm, serialize_fqelm}}; + EccPointFq2 efq2_point = {0}; + const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10, + 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20}; + const EccPointFq2 expected_efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}}; + EFq2Deserialize(&efq2_point, &serialize_efq2_point); + EXPECT_EQ(expected_efq2_point, efq2_point); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/sha256-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/sha256-test.cc new file mode 100644 index 00000000..532c27e1 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/sha256-test.cc @@ -0,0 +1,350 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/* + * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + DESCRIPTION + This module tests the following SHA256 routines: + + Scenarios tested include: + - NIST SHA256 test vectors +*/ +#include + +namespace { +extern "C" { +#include "epid/member/tiny/math/sha256.h" +} + +TEST(TinySha256Test, tc_sha256_update_SucceedsGivenZeroMessageLength) { + const uint8_t expected[32] = {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, + 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, + 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, + 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; + const char* m = ""; + sha256_state s; + uint8_t digest[32]; + tc_sha256_init(&s); + tc_sha256_update(&s, (const uint8_t*)m, 0); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} +/* + * NIST SHA256 test vector 1. + */ +TEST(TinySha256Test, tc_sha256_WorksGivenNistTestVector1) { + const uint8_t expected[32] = {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, + 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, + 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, + 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}; + const char* m = "abc"; + uint8_t digest[32]; + sha256_state s; + + tc_sha256_init(&s); + tc_sha256_update(&s, (const uint8_t*)m, strlen(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +/* + * NIST SHA256 test vector 2. + */ +TEST(TinySha256Test, tc_sha256_WorksGivenNistTestVector2) { + const uint8_t expected[32] = {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, + 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, + 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, + 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1}; + const char* m = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + uint8_t digest[32]; + sha256_state s; + + tc_sha256_init(&s); + tc_sha256_update(&s, (const uint8_t*)m, strlen(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven1NonZeroChar) { + const uint8_t expected[32] = {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, + 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70, + 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, + 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b}; + const uint8_t m[1] = {0xbd}; + uint8_t digest[32]; + sha256_state s; + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven4NonZeroChars) { + const uint8_t expected[32] = {0x7a, 0xbc, 0x22, 0xc0, 0xae, 0x5a, 0xf2, 0x6c, + 0xe9, 0x3d, 0xbb, 0x94, 0x43, 0x3a, 0x0e, 0x0b, + 0x2e, 0x11, 0x9d, 0x01, 0x4f, 0x8e, 0x7f, 0x65, + 0xbd, 0x56, 0xc6, 0x1c, 0xcc, 0xcd, 0x95, 0x04}; + const uint8_t m[4] = {0xc9, 0x8c, 0x8e, 0x55}; + uint8_t digest[32]; + sha256_state s; + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven55ZeroChars) { + const uint8_t expected[32] = {0x02, 0x77, 0x94, 0x66, 0xcd, 0xec, 0x16, 0x38, + 0x11, 0xd0, 0x78, 0x81, 0x5c, 0x63, 0x3f, 0x21, + 0x90, 0x14, 0x13, 0x08, 0x14, 0x49, 0x00, 0x2f, + 0x24, 0xaa, 0x3e, 0x80, 0xf0, 0xb8, 0x8e, 0xf7}; + uint8_t m[55]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven56ZeroChars) { + const uint8_t expected[32] = {0xd4, 0x81, 0x7a, 0xa5, 0x49, 0x76, 0x28, 0xe7, + 0xc7, 0x7e, 0x6b, 0x60, 0x61, 0x07, 0x04, 0x2b, + 0xbb, 0xa3, 0x13, 0x08, 0x88, 0xc5, 0xf4, 0x7a, + 0x37, 0x5e, 0x61, 0x79, 0xbe, 0x78, 0x9f, 0xbb}; + uint8_t m[56]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven57ZeroChars) { + const uint8_t expected[32] = {0x65, 0xa1, 0x6c, 0xb7, 0x86, 0x13, 0x35, 0xd5, + 0xac, 0xe3, 0xc6, 0x07, 0x18, 0xb5, 0x05, 0x2e, + 0x44, 0x66, 0x07, 0x26, 0xda, 0x4c, 0xd1, 0x3b, + 0xb7, 0x45, 0x38, 0x1b, 0x23, 0x5a, 0x17, 0x85}; + uint8_t m[57]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven64ZeroChars) { + const uint8_t expected[32] = {0xf5, 0xa5, 0xfd, 0x42, 0xd1, 0x6a, 0x20, 0x30, + 0x27, 0x98, 0xef, 0x6e, 0xd3, 0x09, 0x97, 0x9b, + 0x43, 0x00, 0x3d, 0x23, 0x20, 0xd9, 0xf0, 0xe8, + 0xea, 0x98, 0x31, 0xa9, 0x27, 0x59, 0xfb, 0x4b}; + uint8_t m[64]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven1000ZeroChars) { + const uint8_t expected[32] = {0x54, 0x1b, 0x3e, 0x9d, 0xaa, 0x09, 0xb2, 0x0b, + 0xf8, 0x5f, 0xa2, 0x73, 0xe5, 0xcb, 0xd3, 0xe8, + 0x01, 0x85, 0xaa, 0x4e, 0xc2, 0x98, 0xe7, 0x65, + 0xdb, 0x87, 0x74, 0x2b, 0x70, 0x13, 0x8a, 0x53}; + uint8_t m[1000]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven1000NonZeroChars) { + const uint8_t expected[32] = {0xc2, 0xe6, 0x86, 0x82, 0x34, 0x89, 0xce, 0xd2, + 0x01, 0x7f, 0x60, 0x59, 0xb8, 0xb2, 0x39, 0x31, + 0x8b, 0x63, 0x64, 0xf6, 0xdc, 0xd8, 0x35, 0xd0, + 0xa5, 0x19, 0x10, 0x5a, 0x1e, 0xad, 0xd6, 0xe4}; + uint8_t m[1000]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x41, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven1005NonZeroChars) { + const uint8_t expected[32] = {0xf4, 0xd6, 0x2d, 0xde, 0xc0, 0xf3, 0xdd, 0x90, + 0xea, 0x13, 0x80, 0xfa, 0x16, 0xa5, 0xff, 0x8d, + 0xc4, 0xc5, 0x4b, 0x21, 0x74, 0x06, 0x50, 0xf2, + 0x4a, 0xfc, 0x41, 0x20, 0x90, 0x35, 0x52, 0xb0}; + uint8_t m[1005]; + uint8_t digest[32]; + sha256_state s; + + (void)memset(m, 0x55, sizeof(m)); + + tc_sha256_init(&s); + tc_sha256_update(&s, m, sizeof(m)); + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, tc_sha256_WorksGiven1000ZeroCharsUpdated1000Times) { + const uint8_t expected[32] = {0xd2, 0x97, 0x51, 0xf2, 0x64, 0x9b, 0x32, 0xff, + 0x57, 0x2b, 0x5e, 0x0a, 0x9f, 0x54, 0x1e, 0xa6, + 0x60, 0xa5, 0x0f, 0x94, 0xff, 0x0b, 0xee, 0xdf, + 0xb0, 0xb6, 0x92, 0xb9, 0x24, 0xcc, 0x80, 0x25}; + uint8_t m[1000]; + uint8_t digest[32]; + sha256_state s; + unsigned int i; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + for (i = 0; i < 1000; ++i) { + tc_sha256_update(&s, m, sizeof(m)); + } + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, + DISABLED_SLOW_tc_sha256_WorksGiven32768NonZeroCharsUpdated16384Times) { + const uint8_t expected[32] = {0x15, 0xa1, 0x86, 0x8c, 0x12, 0xcc, 0x53, 0x95, + 0x1e, 0x18, 0x23, 0x44, 0x27, 0x74, 0x47, 0xcd, + 0x09, 0x79, 0x53, 0x6b, 0xad, 0xcc, 0x51, 0x2a, + 0xd2, 0x4c, 0x67, 0xe9, 0xb2, 0xd4, 0xf3, 0xdd}; + uint8_t m[32768]; + uint8_t digest[32]; + sha256_state s; + unsigned int i; + + (void)memset(m, 0x5a, sizeof(m)); + + tc_sha256_init(&s); + for (i = 0; i < 16384; ++i) { + tc_sha256_update(&s, m, sizeof(m)); + } + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha256Test, + DISABLED_SLOW_tc_sha256_WorksGiven32768NonZeroCharsUpdated33280Times) { + const uint8_t expected[32] = {0x46, 0x1c, 0x19, 0xa9, 0x3b, 0xd4, 0x34, 0x4f, + 0x92, 0x15, 0xf5, 0xec, 0x64, 0x35, 0x70, 0x90, + 0x34, 0x2b, 0xc6, 0x6b, 0x15, 0xa1, 0x48, 0x31, + 0x7d, 0x27, 0x6e, 0x31, 0xcb, 0xc2, 0x0b, 0x53}; + uint8_t m[32768]; + uint8_t digest[32]; + sha256_state s; + unsigned int i; + + (void)memset(m, 0x00, sizeof(m)); + + tc_sha256_init(&s); + for (i = 0; i < 33280; ++i) { + tc_sha256_update(&s, m, sizeof(m)); + } + tc_sha256_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/sha512-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/sha512-test.cc new file mode 100644 index 00000000..654c057e --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/sha512-test.cc @@ -0,0 +1,108 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of SHA-512 implementation. +/*! \file */ + +#include + +namespace { +extern "C" { +#include "epid/member/tiny/math/sha512.h" +} + +TEST(TinySha512Test, WorksGivenTinyTestVector1) { + const uint8_t expected[SHA512_DIGEST_SIZE] = { + 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, 0xcc, 0x41, 0x73, + 0x49, 0xae, 0x20, 0x41, 0x31, 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, + 0x7e, 0xa2, 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, 0x21, + 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, + 0xa3, 0xfe, 0xeb, 0xbd, 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, + 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f}; + const char* m = "abc"; + uint8_t digest[SHA512_DIGEST_SIZE]; + sha512_state s; + + tinysha512_init(&s); + tinysha512_update(&s, (const uint8_t*)m, strlen(m)); + tinysha512_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha512Test, WorksGivenTinyTestVector2) { + const uint8_t expected[SHA512_DIGEST_SIZE] = { + 0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd, 0xf1, 0x54, 0x28, + 0x50, 0xd6, 0x6d, 0x80, 0x07, 0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, + 0x15, 0xdc, 0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c, 0xe9, 0xce, 0x47, + 0xd0, 0xd1, 0x3c, 0x5d, 0x85, 0xf2, 0xb0, 0xff, 0x83, 0x18, 0xd2, + 0x87, 0x7e, 0xec, 0x2f, 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, + 0x81, 0xa5, 0x38, 0x32, 0x7a, 0xf9, 0x27, 0xda, 0x3e}; + const char* m = ""; + uint8_t digest[SHA512_DIGEST_SIZE]; + sha512_state s; + + tinysha512_init(&s); + tinysha512_update(&s, (const uint8_t*)m, strlen(m)); + tinysha512_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha512Test, WorksGivenTinyTestVector3) { + const uint8_t expected[SHA512_DIGEST_SIZE] = { + 0x20, 0x4a, 0x8f, 0xc6, 0xdd, 0xa8, 0x2f, 0x0a, 0x0c, 0xed, 0x7b, + 0xeb, 0x8e, 0x08, 0xa4, 0x16, 0x57, 0xc1, 0x6e, 0xf4, 0x68, 0xb2, + 0x28, 0xa8, 0x27, 0x9b, 0xe3, 0x31, 0xa7, 0x03, 0xc3, 0x35, 0x96, + 0xfd, 0x15, 0xc1, 0x3b, 0x1b, 0x07, 0xf9, 0xaa, 0x1d, 0x3b, 0xea, + 0x57, 0x78, 0x9c, 0xa0, 0x31, 0xad, 0x85, 0xc7, 0xa7, 0x1d, 0xd7, + 0x03, 0x54, 0xec, 0x63, 0x12, 0x38, 0xca, 0x34, 0x45}; + const char* m = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + uint8_t digest[SHA512_DIGEST_SIZE]; + sha512_state s; + + tinysha512_init(&s); + tinysha512_update(&s, (const uint8_t*)m, strlen(m)); + tinysha512_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +TEST(TinySha512Test, WorksGivenTinyTestVector4) { + const uint8_t expected[SHA512_DIGEST_SIZE] = { + 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, 0x8c, 0xf4, 0xf7, + 0x28, 0x14, 0xfc, 0x14, 0x3f, 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, + 0x7f, 0xa1, 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18, 0x50, + 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4, 0x33, 0x1b, 0x99, 0xde, + 0xc4, 0xb5, 0x43, 0x3a, 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, + 0x54, 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09}; + const char* m = + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnop" + "jklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + uint8_t digest[SHA512_DIGEST_SIZE]; + sha512_state s; + + tinysha512_init(&s); + tinysha512_update(&s, (const uint8_t*)m, strlen(m)); + tinysha512_final(digest, &s); + EXPECT_TRUE(0 == memcmp(expected, digest, sizeof(digest))) + << digest << std::endl + << expected; +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/utest.parts b/external/epid-sdk/epid/member/tiny/math/unittests/utest.parts new file mode 100644 index 00000000..2709baf0 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/utest.parts @@ -0,0 +1,47 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +"""Build configuration for unit test of tiny math library. +""" +Import('*') +env.PartName('utest') + +env.DependsOn([Component('gtest'), + Component(env.subst('${PART_PARENT_NAME}'))]) + +utest_files = Pattern(src_dir='.', + includes=['*-test.cc', + '*-testhelper.cc'], + recursive=True).files() + +env.Append(CPPPATH='#') + +env['UNIT_TEST_TARGET_NAME'] = "${PART_PARENT_NAME}-${UNIT_TEST_TARGET}" + +utest = env.UnitTest('${PART_SHORT_NAME}', + utest_files, + command_args=[ + '--gtest_filter=**', + '--gtest_color=yes', + '--gtest_print_time=1', + '--gtest_output=xml', + #'--gtest_break_on_failure', + #'--gtest_catch_exceptions=0', + ], + data_src=[], + make_pdb=(env.isConfigBasedOn('debug')), + INSTALL_BIN='${INSTALL_TEST_BIN}', + ) diff --git a/external/epid-sdk/epid/member/tiny/math/unittests/vli-test.cc b/external/epid-sdk/epid/member/tiny/math/unittests/vli-test.cc new file mode 100644 index 00000000..0d15c101 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/unittests/vli-test.cc @@ -0,0 +1,379 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Unit tests of large integer implementation. +/*! \file */ + +#include +#include // for CHAR_BIT +#include +#include + +#include "epid/member/tiny/math/unittests/cmp-testhelper.h" +#include "epid/member/tiny/math/unittests/onetimepad.h" + +extern "C" { +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/vli.h" +} + +namespace { + +//////////////////////////////////////////////////////////////////////// +// VliAdd + +TEST(TinyVliTest, VliAddWorks) { + VeryLargeInt result = {0}; + VeryLargeInt expected = {0}; + VeryLargeInt left = {0}; + VeryLargeInt right = {0}; + left.word[0] = 1; + right.word[0] = 2; + expected.word[0] = 3; + VliAdd(&result, &left, &right); + EXPECT_EQ(expected, result); +} +TEST(TinyVliTest, VliAddCalculatesCarry) { + VeryLargeInt left = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VeryLargeInt right = {{0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1}}; + VeryLargeInt expected = {{0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1}}; + uint32_t expected_carry = 0x1; + uint32_t carry = 0; + VeryLargeInt result = {0}; + carry = VliAdd(&result, &left, &right); + EXPECT_EQ(expected, result); + EXPECT_EQ(expected_carry, carry); +} +//////////////////////////////////////////////////////////////////////// +// VliMul +TEST(TinyVliTest, VliMultWorks) { + VeryLargeIntProduct result = {0}; + VeryLargeIntProduct expected = {0}; + VeryLargeInt left = {0}, right = {0}; + left.word[0] = 2; + right.word[0] = 2; + expected.word[0] = 4; + VliMul(&result, &left, &right); + EXPECT_EQ(expected, result); +} +TEST(TinyVliTest, VliMultWorksWithOverflow) { + VeryLargeIntProduct result = {0}; + VeryLargeIntProduct expected = { + {0xfffffffe, 0xfffffffd, 0xfffffffd, 0xfffffffd, 0xfffffffd, 0xfffffffd, + 0xfffffffd, 0xfffffffd, 0x1, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}}; + VeryLargeInt left = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VeryLargeInt right = {{0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}}; + VliMul(&result, &left, &right); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliRShift +TEST(TinyVliTest, VliRShiftWorks) { + VeryLargeInt result = {0}, expected = {0}; + VeryLargeInt in = {0}; + uint32_t shift = 1; + in.word[0] = 4; + expected.word[0] = 2; + VliRShift(&result, &in, shift); + EXPECT_EQ(expected, result); +} +TEST(TinyVliTest, VliRShiftWorksWithOverlap) { + VeryLargeInt result = {0}, expected = {0}; + VeryLargeInt in = {0}; + uint32_t shift = 4; + in.word[0] = 0x00000008; + in.word[1] = 0xffffffff; + expected.word[0] = 0xf0000000; + expected.word[1] = 0x0fffffff; + VliRShift(&result, &in, shift); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliSub +TEST(TinyVliTest, VliSubWorks) { + VeryLargeInt result = {0}, expected = {0}; + VeryLargeInt left = {0}, right = {0}; + uint32_t borrow = 0; + uint32_t expected_borrow = 0; + left.word[0] = 4; + right.word[0] = 2; + expected.word[0] = 2; + borrow = VliSub(&result, &left, &right); + EXPECT_EQ(expected, result); + EXPECT_EQ(expected_borrow, borrow); +} +TEST(TinyVliTest, VliSubWorksWithBorrow) { + VeryLargeInt result = {0}; + VeryLargeInt expected = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VeryLargeInt left = {0}, right = {0}; + uint32_t borrow = 0; + uint32_t expected_borrow = 1; + left.word[0] = 2; + right.word[0] = 3; + borrow = VliSub(&result, &left, &right); + EXPECT_EQ(expected, result); + EXPECT_EQ(expected_borrow, borrow); +} + +//////////////////////////////////////////////////////////////////////// +// VliSet + +TEST(TinyVliTest, VliSetWorks) { + VeryLargeInt result = {0}; + VeryLargeInt in = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VliSet(&result, &in); + EXPECT_EQ(in, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliClear + +TEST(TinyVliTest, VliClearWorks) { + VeryLargeInt expected = {0}; + VeryLargeInt in_out = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VliClear(&in_out); + EXPECT_EQ(expected, in_out); +} + +//////////////////////////////////////////////////////////////////////// +// VliIsZero + +TEST(TinyVliTest, VliIsZeroAcceptsZero) { + int is_zero = 0; + VeryLargeInt in_zero = {0}; + is_zero = VliIsZero(&in_zero); + EXPECT_TRUE(is_zero); +} +TEST(TinyVliTest, VliIsZeroRejectsNonZero) { + int is_zero = 0; + VeryLargeInt in_nonzero = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + is_zero = VliIsZero(&in_nonzero); + EXPECT_FALSE(is_zero); +} + +//////////////////////////////////////////////////////////////////////// +// VliCondSet + +TEST(TinyVliTest, VliCondSetWorksForTrue) { + VeryLargeInt result = {0}; + VeryLargeInt true_val = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VeryLargeInt false_val = {{0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, + 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa}}; + VliCondSet(&result, &true_val, &false_val, 1); + EXPECT_EQ(true_val, result); +} +TEST(TinyVliTest, VliCondSetWorksForFalse) { + VeryLargeInt result = {0}; + VeryLargeInt true_val = {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}}; + VeryLargeInt false_val = {{0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, + 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa}}; + VliCondSet(&result, &true_val, &false_val, 0); + EXPECT_EQ(false_val, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliTestBit + +TEST(TinyVliTest, VliTestBitWorks) { + VeryLargeInt in = {0}; + uint32_t bit_set = 0; + in.word[0] = 4; + bit_set = VliTestBit(&in, 1); + EXPECT_EQ((uint32_t)0, bit_set); + bit_set = VliTestBit(&in, 2); + EXPECT_EQ((uint32_t)1, bit_set); +} + +//////////////////////////////////////////////////////////////////////// +// VliRand + +TEST(TinyVliTest, VliRandWorks) { + OneTimePad my_prng; + VeryLargeInt expected_rand_val1 = {{1, 0, 0, 0, 0, 0, 0, 0}}; + my_prng.InitUint8({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}); + VeryLargeInt rand_val1 = {0}; + EXPECT_TRUE(VliRand(&rand_val1, &OneTimePad::Generate, &my_prng)); + EXPECT_EQ(expected_rand_val1, rand_val1); + EXPECT_EQ(256u, my_prng.BitsConsumed()); + + VeryLargeInt expected_rand_val2 = {{0x1c6f5a0f, 0xeaa878b3, 0xc71dab6b, + 0x1a101ad6, 0x1fe6394f, 0x1bec36ab, + 0x07a3e97f, 0x36507914}}; + VeryLargeInt rand_val2 = {0}; + my_prng.InitUint32({0x14795036, 0x7fe9a307, 0xab36ec1b, 0x4f39e61f, + 0xd61a101a, 0x6bab1dc7, 0xb378a8ea, 0x0f5a6f1c}); + EXPECT_TRUE(VliRand(&rand_val2, &OneTimePad::Generate, &my_prng)); + EXPECT_EQ(expected_rand_val2, rand_val2); + EXPECT_EQ(256u, my_prng.BitsConsumed()); +} + +//////////////////////////////////////////////////////////////////////// +// VliCmp + +TEST(TinyVliTest, VliCmpWorksForLessThan) { + VeryLargeInt in_val1 = {0}; + VeryLargeInt in_val2 = {0}; + int res = 0; + in_val1.word[0] = 1; + in_val2.word[0] = 2; + res = VliCmp(&in_val1, &in_val2); + EXPECT_EQ(-1, res); +} +TEST(TinyVliTest, VliCmpWorksForEqual) { + VeryLargeInt in_val1 = {0}; + VeryLargeInt in_val2 = {0}; + int res = 0; + in_val1.word[0] = 2; + in_val2.word[0] = 2; + res = VliCmp(&in_val1, &in_val2); + EXPECT_EQ(0, res); +} +TEST(TinyVliTest, VliCmpWorksGreaterThan) { + VeryLargeInt in_val1 = {0}; + VeryLargeInt in_val2 = {0}; + int res = 0; + in_val1.word[0] = 1; + in_val2.word[0] = 2; + res = VliCmp(&in_val2, &in_val1); + EXPECT_EQ(1, res); +} + +//////////////////////////////////////////////////////////////////////// +// VliModAdd + +TEST(TinyVliTest, VliModAddWorks) { + VeryLargeInt result = {0}; + VeryLargeInt left = {0}; + VeryLargeInt right = {0}; + VeryLargeInt expected = {0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + left.word[0] = 0x9; + right.word[0] = 0x8; + expected.word[0] = 0x11; + VliModAdd(&result, &left, &right, &mod); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliModSub + +TEST(TinyVliTest, VliModSubWorks) { + VeryLargeInt result = {0}; + VeryLargeInt left = {0}; + VeryLargeInt right = {0}; + VeryLargeInt expected = {0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + left.word[0] = 0x18; + right.word[0] = 0x12; + expected.word[0] = 0x6; + VliModSub(&result, &left, &right, &mod); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliModMul + +TEST(TinyVliTest, VliModMultWorks) { + VeryLargeInt result = {0}; + VeryLargeInt left = {0}; + VeryLargeInt right = {0}; + VeryLargeInt expected = {0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + left.word[0] = 0x10; + right.word[0] = 0x2; + expected.word[0] = 0x20; + VliModMul(&result, &left, &right, &mod); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliModExp + +TEST(TinyVliTest, VliModExpWorks) { + VeryLargeInt result = {0}; + VeryLargeInt base = {0}; + VeryLargeInt exp = {0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + VeryLargeInt expected = {0}; + base.word[0] = 0x4; + exp.word[0] = 0x2; + expected.word[0] = 0x10; + VliModExp(&result, &base, &exp, &mod); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliModInv + +TEST(TinyVliTest, VliModInvWorks) { + VeryLargeInt a = {0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1, + 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6}; + VeryLargeInt q = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + VeryLargeInt expected = {0x5a686df6, 0x56b6ab63, 0xdf907c6f, 0x44ad8d51, + 0xa5513462, 0xc597ef78, 0x93711b39, 0x15171a1e}; + VeryLargeInt result; + VliModInv(&result, &a, &q); + EXPECT_EQ(result, expected); +} + +//////////////////////////////////////////////////////////////////////// +// VliModSquare + +TEST(TinyVliTest, VliModSquareWorks) { + VeryLargeInt result = {0}; + VeryLargeInt input = {0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + VeryLargeInt expected = {0}; + input.word[0] = 0x4; + expected.word[0] = 0x10; + VliModSquare(&result, &input, &mod); + EXPECT_EQ(expected, result); +} + +//////////////////////////////////////////////////////////////////////// +// VliModBarrett + +TEST(TinyVliTest, VliModBarrettWorks) { + VeryLargeInt result = {0}; + VeryLargeIntProduct product = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF, + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0}; + VeryLargeInt mod = {0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, + 0xEE71A49F, 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}; + VeryLargeInt expected = {0}; + product.word[0] += 0xF; + expected.word[0] = 0xF; + VliModBarrett(&result, &product, &mod); + EXPECT_EQ(expected, result); +} +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/math/vli.h b/external/epid-sdk/epid/member/tiny/math/vli.h new file mode 100644 index 00000000..5ea61dbd --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/math/vli.h @@ -0,0 +1,196 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of Large Integer math +/*! \file */ + +#ifndef EPID_MEMBER_TINY_MATH_VLI_H_ +#define EPID_MEMBER_TINY_MATH_VLI_H_ + +#include +#include "epid/common/bitsupplier.h" +/// \cond +typedef struct VeryLargeInt VeryLargeInt; +typedef struct VeryLargeIntProduct VeryLargeIntProduct; +/// \endcond + +/// Add two large integers. +/*! +\param[out] result target. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. + +\returns the carry portion of the addition. +*/ +uint32_t VliAdd(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right); + +/// Multiply two large integers. +/*! +\param[out] result of multiplying left and right. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +*/ +void VliMul(VeryLargeIntProduct* result, VeryLargeInt const* left, + VeryLargeInt const* right); + +/// Right shift a large integers. +/*! +\param[out] result target. +\param[in] in The value to be shifted. +\param[in] shift The number of bits to shift. +*/ +void VliRShift(VeryLargeInt* result, VeryLargeInt const* in, uint32_t shift); + +/// Subtract two large integers. +/*! +\param[out] result target. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +\returns 1 on success, 0 on failure +*/ +uint32_t VliSub(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right); + +/// Set a large integer's value. +/*! +\param[out] result target. +\param[in] in value to set. +*/ +void VliSet(VeryLargeInt* result, VeryLargeInt const* in); + +/// Clear a large integer's value. +/*! +\param[out] result value to clear. +*/ +void VliClear(VeryLargeInt* result); + +/// Test if a large integer is zero. +/*! +\param[in] in the value to test. +\returns A value different from zero (i.e., true) if indeed + the value is zero. Zero (i.e., false) otherwise. +*/ +int VliIsZero(VeryLargeInt const* in); + +/// Conditionally Set a large inter's value to one of two values. +/*! +\param[out] result target. +\param[in] true_val value to set if condition is true. +\param[in] false_val value to set if condition is false. +\param[in] truth_val value of condition. +*/ +void VliCondSet(VeryLargeInt* result, VeryLargeInt const* true_val, + VeryLargeInt const* false_val, int truth_val); + +/// Test the value of a bit in a large integer. +/*! +\param[in] in the value to test. +\param[in] bit the bit index. + +\returns value of the bit (1 or 0). +*/ +uint32_t VliTestBit(VeryLargeInt const* in, uint32_t bit); + +/// Generate a random large integer. +/*! +\param[in] result the random value. +\param[in] rnd_func Random number generator. +\param[in] rnd_param Pass through context data for rnd_func. +\returns A value different from zero (i.e., true) if on success. + Zero (i.e., false) otherwise. +*/ +int VliRand(VeryLargeInt* result, BitSupplier rnd_func, void* rnd_param); + +/// compare two large integers. +/*! +\param[in] left the left hand value. +\param[in] right the right hand value. + +\returns the sign of left - right +*/ +int VliCmp(VeryLargeInt const* left, VeryLargeInt const* right); + +/// Add two large integers modulo a value. +/*! +\param[out] result target. +\param[in] left The first operand to be added. +\param[in] right The second operand to be added. +\param[in] mod The modulo. +*/ +void VliModAdd(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod); + +/// Subtract two large integers modulo a value. +/*! +\param[out] result target. +\param[in] left The operand to be subtracted from. +\param[in] right The operand to subtract. +\param[in] mod The modulo. +*/ +void VliModSub(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod); + +/// Multiply two large integers modulo a value. +/*! +\param[out] result target. +\param[in] left The first operand to be multiplied. +\param[in] right The second operand to be multiplied. +\param[in] mod The modulo. +*/ +void VliModMul(VeryLargeInt* result, VeryLargeInt const* left, + VeryLargeInt const* right, VeryLargeInt const* mod); + +/// Exponentiate a large integer modulo a value. +/*! +\param[out] result target. +\param[in] base the base. +\param[in] exp the exponent. +\param[in] mod The modulo. +*/ +void VliModExp(VeryLargeInt* result, VeryLargeInt const* base, + VeryLargeInt const* exp, VeryLargeInt const* mod); + +/// Invert a large integer modulo a value. +/*! +\param[out] result target. +\param[in] input the value to invert. +\param[in] mod The modulo. +*/ +void VliModInv(VeryLargeInt* result, VeryLargeInt const* input, + VeryLargeInt const* mod); + +/// Square a large integer modulo a value. +/*! +\param[out] result target. +\param[in] input the base. +\param[in] mod The modulo. +*/ +void VliModSquare(VeryLargeInt* result, VeryLargeInt const* input, + VeryLargeInt const* mod); + +/// Reduce a value to a modulo. +/*! +\param[out] result target. +\param[in] input the base. +\param[in] mod The modulo. + +\warning This function makes significant assumptions about +the range of values input +*/ +void VliModBarrett(VeryLargeInt* result, VeryLargeIntProduct const* input, + VeryLargeInt const* mod); + +#endif // EPID_MEMBER_TINY_MATH_VLI_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/allowed_basenames.c b/external/epid-sdk/epid/member/tiny/src/allowed_basenames.c new file mode 100644 index 00000000..9812988a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/allowed_basenames.c @@ -0,0 +1,76 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename management implementation +/*! \file */ + +#include "epid/member/tiny/src/allowed_basenames.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +#if defined(SHA256_SUPPORT) +#define BASENAME_SHA_ALG kSha256 +#elif defined(SHA512_SUPPORT) +#define BASENAME_SHA_ALG kSha512 +#endif + +size_t BasenamesGetSize(size_t num_basenames) { + return sizeof(AllowedBasenames) - sizeof(sha_digest) + + sizeof(sha_digest) * (num_basenames); +} + +void InitBasenames(AllowedBasenames* basename_container, size_t num_basenames) { + basename_container->current_bsn_number = 0; + basename_container->max_bsn_number = num_basenames; + memset(basename_container->basename_digest->digest, 0, + sizeof(basename_container->basename_digest) * num_basenames); +} + +int IsBasenameAllowed(AllowedBasenames const* basename_container, + void const* basename, size_t length) { + size_t d = 0; + tiny_sha sha_state; + sha_digest digest; + // calculate hash of input basename + tinysha_init(BASENAME_SHA_ALG, &sha_state); + tinysha_update(&sha_state, basename, length); + tinysha_final(digest.digest, &sha_state); + // compare hash of input basename with stored hashes + for (d = 0; d < basename_container->current_bsn_number; d++) { + if (!memcmp(digest.digest, &basename_container->basename_digest[d].digest, + tinysha_digest_size(&sha_state))) { + return 1; + } + } + return 0; +} + +int AllowBasename(AllowedBasenames* basename_container, void const* basename, + size_t length) { + tiny_sha sha_state; + sha_digest digest; + if (basename_container->max_bsn_number <= + basename_container->current_bsn_number) { + return 0; + } + // calculate hash of input basename + tinysha_init(BASENAME_SHA_ALG, &sha_state); + tinysha_update(&sha_state, basename, length); + tinysha_final(digest.digest, &sha_state); + // copy hash of input basename into digest buffer + basename_container->basename_digest[basename_container->current_bsn_number] = + digest; + basename_container->current_bsn_number++; + return 1; +} diff --git a/external/epid-sdk/epid/member/tiny/src/allowed_basenames.h b/external/epid-sdk/epid/member/tiny/src/allowed_basenames.h new file mode 100644 index 00000000..aed9c6c6 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/allowed_basenames.h @@ -0,0 +1,46 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Basename management APIs +/*! \file */ + +#ifndef EPID_MEMBER_TINY_SRC_ALLOWED_BASENAMES_H_ +#define EPID_MEMBER_TINY_SRC_ALLOWED_BASENAMES_H_ + +#include +#include "epid/member/tiny/math/hashwrap.h" + +typedef struct AllowedBasenames { + size_t current_bsn_number; ///< Number of basenames registered + size_t max_bsn_number; ///< Maximum number of basenames to store + sha_digest + basename_digest[1]; ///< digest of registrered basenames (flexible array) +} AllowedBasenames; + +/// Get allowed basenames container size +size_t BasenamesGetSize(size_t num_basenames); + +/// Initilize allowed basenames container +void InitBasenames(AllowedBasenames* basename_container, size_t num_basenames); + +/// Checks if given basename is allowed +int IsBasenameAllowed(AllowedBasenames const* basename_container, + void const* basename, size_t length); + +/// Adds a new allowed basename +int AllowBasename(AllowedBasenames* basename_container, void const* basename, + size_t length); + +#endif // EPID_MEMBER_TINY_SRC_ALLOWED_BASENAMES_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/context.h b/external/epid-sdk/epid/member/tiny/src/context.h new file mode 100644 index 00000000..1627026b --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/context.h @@ -0,0 +1,75 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Member context interface. +/*! \file */ +#ifndef EPID_MEMBER_TINY_SRC_CONTEXT_H_ +#define EPID_MEMBER_TINY_SRC_CONTEXT_H_ +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/src/allowed_basenames.h" +#include "epid/member/tiny/src/native_types.h" + +/// Size of SigRl with zero entries +#define MIN_SIGRL_SIZE (sizeof(SigRl) - sizeof(SigRlEntry)) + +#ifdef USE_SIGRL_BY_REFERENCE + +// SIZE_MAX is not guaranteed in C89/90 +#define SIZE_T_MAX ((size_t)(-1)) + +/// Maximum number of possible entries in SigRl used by reference +#define MAX_SIGRL_ENTRIES ((SIZE_T_MAX - MIN_SIGRL_SIZE) / sizeof(SigRlEntry)) + +/// Maximum space needed to store SigRl data in context +#define SIGRL_HEAP_SIZE (0) + +#else // !defined(USE_SIGRL_BY_REFERENCE) + +#ifndef MAX_SIGRL_ENTRIES +/// Maximum number of possible entries in SigRl copied by value +#define MAX_SIGRL_ENTRIES (5) +#endif + +/// Maximum space needed to store SigRl data in context +#define SIGRL_HEAP_SIZE \ + (MIN_SIGRL_SIZE + MAX_SIGRL_ENTRIES * sizeof(SigRlEntry)) + +#endif // !defined(USE_SIGRL_BY_REFERENCE) + +#ifndef MAX_ALLOWED_BASENAMES +/// Maximum number of allowed base names +#define MAX_ALLOWED_BASENAMES (5) +#endif + +/// Member context definition +typedef struct MemberCtx { + GroupPubKey pub_key; ///< group public key + HashAlg hash_alg; ///< Hash algorithm to use + MembershipCredential credential; ///< Membership credential + FpElem f; ///< secret f value + NativeMemberPrecomp precomp; ///< Precomputed pairing values + PairingState pairing_state; ///< pairing state + int f_is_set; ///< f initialized + int is_provisioned; ///< member fully provisioned with key material + BitSupplier rnd_func; ///< Pseudo random number generation function + void* rnd_param; ///< Pointer to user context for rnd_func + AllowedBasenames* allowed_basenames; ///< Allowed basenames + SigRl* sig_rl; ///< Pointer to Signature based revocation list + unsigned char heap[1]; ///< Bulk storage space (flexible array) +} MemberCtx; + +#endif // EPID_MEMBER_TINY_SRC_CONTEXT_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/createjoinrequest.c b/external/epid-sdk/epid/member/tiny/src/createjoinrequest.c new file mode 100644 index 00000000..0dee7097 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/createjoinrequest.c @@ -0,0 +1,121 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member CreateJoinRequest implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +#include "epid/common/types.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/hashwrap.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/validate.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static const FpElemStr epid20_p_str = { + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + +static const G2ElemStr epid20_g2_str = { + {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, + 0x13, 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, + 0x47, 0x0E, 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, + {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, + 0x25, 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, + 0x53, 0xE2, 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, + {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, + 0x03, 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, + 0x68, 0x38, 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, + {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, + 0xF8, 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, + 0xD6, 0x13, 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; + +static const G1ElemStr epid20_g1_str = { + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + +EpidStatus EPID_API EpidCreateJoinRequest(MemberCtx* ctx, + GroupPubKey const* pub_key, + IssuerNonce const* ni, + JoinRequest* join_request) { + EccPointFq F; + EccPointFq R_str; + FpElem r; + FpElem c; + FpElem t; + tiny_sha sha_state; + sha_digest digest; + G1ElemStr g1_str; + NativeGroupPubKey deserialized_pkey; + + if (!ctx || !pub_key || !ni || !join_request) { + return kEpidBadArgErr; + } + if (!ctx->f_is_set) { + return kEpidBadArgErr; + } + + GroupPubKeyDeserialize(&deserialized_pkey, pub_key); + if (!GroupPubKeyIsInRange(&deserialized_pkey)) { + return kEpidBadArgErr; + } + // pick number r between 1 - (p-1) + if (!FpRandNonzero(&r, ctx->rnd_func, ctx->rnd_param)) { + return kEpidMathErr; + } + + // F = h1^f + EFqAffineExp(&F, &deserialized_pkey.h1, &ctx->f); + // R_str = h1^r + EFqAffineExp(&R_str, &deserialized_pkey.h1, &r); + + // c = hash(p || g1 || g2 || h1 || h2 || w || F || R || NI) mod p + tinysha_init(ctx->hash_alg, &sha_state); + tinysha_update(&sha_state, (void const*)&epid20_p_str, sizeof(epid20_p_str)); + tinysha_update(&sha_state, (void const*)&epid20_g1_str, + sizeof(epid20_g1_str)); + tinysha_update(&sha_state, (void const*)&epid20_g2_str, + sizeof(epid20_g2_str)); + tinysha_update(&sha_state, (void const*)&pub_key->h1, sizeof(pub_key->h1)); + tinysha_update(&sha_state, (void const*)&pub_key->h2, sizeof(pub_key->h2)); + tinysha_update(&sha_state, (void const*)&pub_key->w, sizeof(pub_key->w)); + EFqSerialize(&join_request->F, &F); + tinysha_update(&sha_state, (void const*)&join_request->F, + sizeof(join_request->F)); + EFqSerialize(&g1_str, &R_str); + tinysha_update(&sha_state, (void const*)&g1_str, sizeof(g1_str)); + tinysha_update(&sha_state, (void const*)ni, sizeof(*ni)); + tinysha_final(digest.digest, &sha_state); + FpFromHash(&c, digest.digest, tinysha_digest_size(&sha_state)); + FpSerialize(&join_request->c, &c); + + // computes s = (r + c * f) mod p + FpMul(&t, &c, &ctx->f); + FpAdd(&t, &t, &r); + FpSerialize(&join_request->s, &t); + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/decompresskey.c b/external/epid-sdk/epid/member/tiny/src/decompresskey.c new file mode 100644 index 00000000..2af6e7db --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/decompresskey.c @@ -0,0 +1,29 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member DecompressPrivKey implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +EpidStatus EPID_API EpidDecompressPrivKey( + GroupPubKey const* pub_key, CompressedPrivKey const* compressed_privkey, + PrivKey* priv_key) { + (void)pub_key; + (void)compressed_privkey; + (void)priv_key; + return kEpidNotImpl; +} diff --git a/external/epid-sdk/epid/member/tiny/src/init.c b/external/epid-sdk/epid/member/tiny/src/init.c new file mode 100644 index 00000000..845d0a1f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/init.c @@ -0,0 +1,94 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member Init/Deinit implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +#include +#include "epid/common/types.h" +#include "epid/member/software_member.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +EpidStatus EPID_API EpidMemberGetSize(MemberParams const* params, + size_t* context_size) { + const size_t kMinContextSize = + sizeof(MemberCtx) - sizeof(((MemberCtx*)0)->heap); + if (!params || !context_size) { + return kEpidBadArgErr; + } + *context_size = kMinContextSize + SIGRL_HEAP_SIZE + + BasenamesGetSize(MAX_ALLOWED_BASENAMES); + return kEpidNoErr; +} + +EpidStatus EPID_API EpidMemberInit(MemberParams const* params, MemberCtx* ctx) { + EpidStatus sts = kEpidNoErr; + size_t context_size = 0; + if (!params || !ctx) { + return kEpidBadArgErr; + } + + sts = EpidMemberGetSize(params, &context_size); + if (sts != kEpidNoErr) { + return sts; + } + + memset(ctx, 0, context_size); + + ctx->is_provisioned = 0; + ctx->f_is_set = 0; + + // set the default hash algorithm to sha512 + ctx->hash_alg = kSha512; + ctx->f_is_set = 0; + // set allowed basenames pointer to the heap + ctx->allowed_basenames = (AllowedBasenames*)&ctx->heap[SIGRL_HEAP_SIZE]; + InitBasenames(ctx->allowed_basenames, MAX_ALLOWED_BASENAMES); + if (params->f) { + FpDeserialize(&ctx->f, params->f); + if (!FpInField(&ctx->f)) { + memset(&ctx->f, 0, sizeof(ctx->f)); + return kEpidBadArgErr; + } + ctx->f_is_set = 1; + } + ctx->rnd_func = params->rnd_func; + ctx->rnd_param = params->rnd_param; + PairingInit(&ctx->pairing_state); + return kEpidNoErr; +} + +void EPID_API EpidMemberDeinit(MemberCtx* ctx) { + (void)ctx; + return; +} + +EpidStatus EPID_API EpidMemberCreate(MemberParams const* params, + MemberCtx** ctx) { + (void)params; + (void)ctx; + return kEpidNotImpl; +} + +void EPID_API EpidMemberDelete(MemberCtx** ctx) { (void)ctx; } diff --git a/external/epid-sdk/epid/member/tiny/src/native_types.h b/external/epid-sdk/epid/member/tiny/src/native_types.h new file mode 100644 index 00000000..1ce611a6 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/native_types.h @@ -0,0 +1,64 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Types in the native format +/*! \file */ +#ifndef EPID_MEMBER_TINY_SRC_NATIVE_TYPES_H_ +#define EPID_MEMBER_TINY_SRC_NATIVE_TYPES_H_ + +#include "epid/common/types.h" +#include "epid/member/tiny/math/mathtypes.h" + +/// Group public key in unserialized format +typedef struct NativeGroupPubKey { + GroupId gid; ///< group ID + EccPointFq h1; ///< an element in G1 + EccPointFq h2; ///< an element in G1 + EccPointFq2 w; ///< an element in G2 +} NativeGroupPubKey; + +/// Membership credential in unserialized format +typedef struct NativeMembershipCredential { + GroupId gid; ///< group ID + EccPointFq A; ///< an element in G1 + FpElem x; ///< an integer between [0, p-1] +} NativeMembershipCredential; + +/// Private key in unserialized format +typedef struct NativePrivKey { + NativeMembershipCredential cred; ///< membership credential + FpElem f; ///< an integer between [0, p-1] +} NativePrivKey; + +/// Precomputed pairing values +typedef struct NativeMemberPrecomp { + Fq12Elem e12; ///< an element in GT + Fq12Elem e22; ///< an element in GT + Fq12Elem e2w; ///< an element in GT + Fq12Elem ea2; ///< an element in GT +} NativeMemberPrecomp; + +/// Intel(R) EPID Basic Signature +typedef struct NativeBasicSignature { + EccPointFq B; ///< an element in G1 + EccPointFq K; ///< an element in G1 + EccPointFq T; ///< an element in G1 + FpElem c; ///< an integer between [0, p-1] + FpElem sx; ///< an integer between [0, p-1] + FpElem sf; ///< an integer between [0, p-1] + FpElem sa; ///< an integer between [0, p-1] + FpElem sb; ///< an integer between [0, p-1] +} NativeBasicSignature; +#endif // EPID_MEMBER_TINY_SRC_NATIVE_TYPES_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/nrprove.c b/external/epid-sdk/epid/member/tiny/src/nrprove.c new file mode 100644 index 00000000..c9124652 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/nrprove.c @@ -0,0 +1,136 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny EpidNrProve implementation. +/*! \file */ + +#include "epid/member/tiny/src/nrprove.h" +#include "epid/common/errors.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/hashwrap.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +static const FpElem epid20_p = { + {{0xD10B500D, 0xF62D536C, 0x1299921A, 0x0CDC65FB, 0xEE71A49E, 0x46E5F25E, + 0xFFFCF0CD, 0xFFFFFFFF}}}; +static const EccPointFq epid20_g1 = { + {{{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}, + {{{0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}}; +EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, + NativeBasicSignature const* sig, + SigRlEntry const* sigrl_entry, NrProof* proof) { + EpidStatus sts = kEpidBadArgErr; + FpElem mu; + FpElem rmu; + FpElem smu; + FpElem nu; + FpElem rnu; + FpElem snu; + EccPointFq tmp_efq; + EccPointFq B_tick; + EccPointFq K_tick; + BigNumStr p; + G1ElemStr tmp_str; + G1ElemStr T_str; + G1ElemStr R1_str; + G1ElemStr R2_str; + FpElem c; + tiny_sha sha_state; + sha_digest digest; + EFqDeserialize(&B_tick, &sigrl_entry->b); + EFqDeserialize(&K_tick, &sigrl_entry->k); + if (!EFqOnCurve(&B_tick) || !EFqOnCurve(&K_tick) || !EFqOnCurve(&sig->B) || + !EFqOnCurve(&sig->K)) { + return kEpidBadArgErr; + } + // 1. The member chooses random mu from [1, p-1]. + if (!FpRandNonzero(&mu, ctx->rnd_func, ctx->rnd_param)) { + return kEpidMathErr; + } + // 2. The member computes nu = (- f * mu) mod p. + FpNeg(&rmu, &ctx->f); + FpMul(&nu, &rmu, &mu); + do { + // 3. The member computes T = G1.sscmMultiExp(K', mu, B', nu). If + // G1.isIdentity(T) = true, the member also outputs "failed". + if (!EFqAffineMultiExp(&tmp_efq, &K_tick, &mu, &B_tick, &nu)) { + sts = kEpidSigRevokedInSigRl; + break; + } + EFqSerialize(&T_str, &tmp_efq); + // 4. The member chooses rmu, rnu randomly from[1, p - 1]. + if (!FpRandNonzero(&rmu, ctx->rnd_func, ctx->rnd_param)) { + sts = kEpidMathErr; + break; + } + if (!FpRandNonzero(&rnu, ctx->rnd_func, ctx->rnd_param)) { + sts = kEpidMathErr; + break; + } + // 5. The member computes R1 = G1.sscmMultiExp(K, rmu, B, rnu). + if (!EFqAffineMultiExp(&tmp_efq, &sig->K, &rmu, &sig->B, &rnu)) { + break; + } + EFqSerialize(&R1_str, &tmp_efq); + // 6. The member computes R2 = G1.sscmMultiExp(K', rmu, B', rnu). + if (!EFqAffineMultiExp(&tmp_efq, &K_tick, &rmu, &B_tick, &rnu)) { + break; + } + EFqSerialize(&R2_str, &tmp_efq); + // 7. The member computes c = Fp.hash(p || g1 || B || K || B' || K' || T || + // R1 || R2 || m) + tinysha_init(ctx->hash_alg, &sha_state); + VliSerialize(&p, &(epid20_p.limbs)); + tinysha_update(&sha_state, (void const*)&p, sizeof(p)); + EFqSerialize(&tmp_str, &epid20_g1); + tinysha_update(&sha_state, (void const*)&tmp_str, sizeof(tmp_str)); + EFqSerialize(&tmp_str, &sig->B); + tinysha_update(&sha_state, (void const*)&tmp_str, sizeof(tmp_str)); + EFqSerialize(&tmp_str, &sig->K); + tinysha_update(&sha_state, (void const*)&tmp_str, sizeof(tmp_str)); + tinysha_update(&sha_state, (void const*)&sigrl_entry->b, + sizeof(sigrl_entry->b)); + tinysha_update(&sha_state, (void const*)&sigrl_entry->k, + sizeof(sigrl_entry->k)); + tinysha_update(&sha_state, (void const*)&T_str, sizeof(T_str)); + tinysha_update(&sha_state, (void const*)&R1_str, sizeof(R1_str)); + tinysha_update(&sha_state, (void const*)&R2_str, sizeof(R2_str)); + tinysha_update(&sha_state, msg, msg_len); + tinysha_final(digest.digest, &sha_state); + FpFromHash(&c, digest.digest, tinysha_digest_size(&sha_state)); + // 8. The member computes smu = (rmu + c * mu) mod p. + FpMul(&smu, &c, &mu); + FpAdd(&smu, &rmu, &smu); + // 9. The member computes snu = (rnu + c * nu) mod p. + FpMul(&snu, &c, &nu); + FpAdd(&snu, &rnu, &snu); + // 10. The member outputs proof = (T, c, smu, snu), a non - revoked proof + FpSerialize(&proof->c, &c); + FpSerialize(&proof->smu, &smu); + FpSerialize(&proof->snu, &snu); + proof->T = T_str; + sts = kEpidNoErr; + } while (0); + FpClear(&mu); + FpClear(&nu); + FpClear(&rmu); + FpClear(&rnu); + return sts; +} diff --git a/external/epid-sdk/epid/member/tiny/src/nrprove.h b/external/epid-sdk/epid/member/tiny/src/nrprove.h new file mode 100644 index 00000000..b6e200a3 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/nrprove.h @@ -0,0 +1,66 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// EpidNrProve interface. +/*! \file */ +#ifndef EPID_MEMBER_TINY_SRC_NRPROVE_H_ +#define EPID_MEMBER_TINY_SRC_NRPROVE_H_ + +#include +#include "epid/common/errors.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct NativeBasicSignature NativeBasicSignature; +typedef struct SigRlEntry SigRlEntry; +typedef struct NrProof NrProof; +/// \endcond + +/// Calculates a non-revoked proof for a single signature based revocation +/// list entry. +/*! + Used in constrained environments where, due to limited memory, it may not + be possible to process through a large and potentially unbounded revocation + list. + + \param[in] ctx + The member context. + \param[in] msg + The message. + \param[in] msg_len + The length of message in bytes. + \param[in] sig + The basic signature. + \param[in] sigrl_entry + The signature based revocation list entry. + \param[out] proof + The generated non-revoked proof. + + \returns ::EpidStatus + + \note + This function should be used in conjunction with EpidSignBasic(). + + \note + If the result is not ::kEpidNoErr, the content of proof is undefined. + + \see EpidMemberInit + \see EpidSignBasic + */ +EpidStatus EpidNrProve(MemberCtx const* ctx, void const* msg, size_t msg_len, + NativeBasicSignature const* sig, + SigRlEntry const* sigrl_entry, NrProof* proof); + +#endif // EPID_MEMBER_TINY_SRC_NRPROVE_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/presig.c b/external/epid-sdk/epid/member/tiny/src/presig.c new file mode 100644 index 00000000..a27c78bc --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/presig.c @@ -0,0 +1,31 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Precomputed signature management implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +EpidStatus EPID_API EpidAddPreSigs(MemberCtx* ctx, size_t number_presigs) { + (void)ctx; + (void)number_presigs; + return kEpidNotImpl; +} + +size_t EPID_API EpidGetNumPreSigs(MemberCtx const* ctx) { + (void)ctx; + return 0; +} diff --git a/external/epid-sdk/epid/member/tiny/src/presig_compute.c b/external/epid-sdk/epid/member/tiny/src/presig_compute.c new file mode 100644 index 00000000..2093ad92 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/presig_compute.c @@ -0,0 +1,100 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Precomputed signature computation. +/*! \file */ + +#include "epid/member/tiny/src/presig_compute.h" + +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/fq12.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/math/vli.h" +#include "epid/member/tiny/src/context.h" + +static const EccPointFq epid20_g1 = { + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}, + {{0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; +static const FpElem epid20_p = {{0xD10B500D, 0xF62D536C, 0x1299921A, 0x0CDC65FB, + 0xEE71A49E, 0x46E5F25E, 0xFFFCF0CD, + 0xFFFFFFFF}}; + +EpidStatus EpidMemberComputePreSig(MemberCtx const* ctx, + PreComputedSignatureData* presig) { + /* B and K are not computed by this precomputation. + *This differs from the Intel(R) EPID 2.0 spec. + *On IoT and especially accelerated platforms, + *the extra latency is likely less expensive + *than the space and possibly redundant computation + *needed to compute and store these values. + */ + EpidStatus sts = kEpidMathErr; + EccPointFq t; + + EccPointJacobiFq tmp1; + EccPointJacobiFq tmp2; + do { + if (!FpRandNonzero(&presig->a, ctx->rnd_func, ctx->rnd_param)) { + break; + } + + // T = A * h2^a + EFqDeserialize(&t, &ctx->pub_key.h2); + EFqFromAffine(&tmp1, &t); + EFqMulSSCM(&tmp2, &tmp1, &presig->a); + EFqDeserialize(&t, &ctx->credential.A); + EFqFromAffine(&tmp1, &t); + EFqAdd(&tmp2, &tmp2, &tmp1); + if (EFqToAffine(&presig->T, &tmp2) != 1) { + break; + } + + FpDeserialize((FpElem*)&t.x, &ctx->credential.x); + FpMul(&presig->b, &presig->a, (FpElem*)&t.x); + + if (!FpRandNonzero(&presig->rx, ctx->rnd_func, ctx->rnd_param)) { + break; + } + if (!FpRandNonzero(&presig->rf, ctx->rnd_func, ctx->rnd_param)) { + break; + } + if (!FpRandNonzero(&presig->ra, ctx->rnd_func, ctx->rnd_param)) { + break; + } + if (!FpRandNonzero(&presig->rb, ctx->rnd_func, ctx->rnd_param)) { + break; + } + VliSub(&t.x.limbs, &epid20_p.limbs, + &presig->rx.limbs); // FpNeg(&t.x, rx), but this is fast. + FpMul((FpElem*)&t.y, &presig->a, &presig->rx); + FpSub((FpElem*)&t.y, &presig->rb, (FpElem*)&t.y); + + // R2 = ea2^&t.x * e12^rf * e22 ^ &t.y * e2w ^ ra + Fq12MultiExp(&presig->R2, &ctx->precomp.ea2, &t.x.limbs, &ctx->precomp.e12, + &presig->rf.limbs, &ctx->precomp.e22, &t.y.limbs, + &ctx->precomp.e2w, &presig->ra.limbs); + sts = kEpidNoErr; + } while (0); + + // Zero sensitive stack variables + FpClear((FpElem*)&t.x); + FpClear((FpElem*)&t.y); + EFqFromAffine(&tmp1, &epid20_g1); + EFqFromAffine(&tmp2, &epid20_g1); + return sts; +} diff --git a/external/epid-sdk/epid/member/tiny/src/presig_compute.h b/external/epid-sdk/epid/member/tiny/src/presig_compute.h new file mode 100644 index 00000000..3c983012 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/presig_compute.h @@ -0,0 +1,51 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Precomputed signature computation. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_SRC_PRESIG_COMPUTE_H_ +#define EPID_MEMBER_TINY_SRC_PRESIG_COMPUTE_H_ + +#include "epid/common/errors.h" +#include "epid/member/tiny/math/mathtypes.h" + +/// \cond +typedef struct MembershipCredentialData MembershipCredentialData; +typedef struct MemberPairPrecomp MemberPairPrecomp; +typedef struct MemberCtx MemberCtx; +/// \endcond + +/*! Tiny pre-computed signature. +B and K values are not included into signeture pre-computation, +as compared with Intel(R) EPID 2.0 spec, to favor small size. +*/ +typedef struct PreComputedSignatureData { + EccPointFq T; ///< an element in G1 + EccPointFq R1; ///< an element in G1 + Fq12Elem R2; ///< an element in G1 + FpElem a; ///< an integer between [0, p-1] + FpElem b; ///< an integer between [0, p-1] + FpElem rx; ///< an integer between [0, p-1] + FpElem rf; ///< an integer between [0, p-1] + FpElem ra; ///< an integer between [0, p-1] + FpElem rb; ///< an integer between [0, p-1] +} PreComputedSignatureData; + +/// Performs signature pre-computation +EpidStatus EpidMemberComputePreSig(MemberCtx const* ctx, + PreComputedSignatureData* presig); + +#endif // EPID_MEMBER_TINY_SRC_PRESIG_COMPUTE_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/provisioncompressed.c b/external/epid-sdk/epid/member/tiny/src/provisioncompressed.c new file mode 100644 index 00000000..8aa0eece --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/provisioncompressed.c @@ -0,0 +1,31 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member ProvisionCompressed implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +EpidStatus EPID_API +EpidProvisionCompressed(MemberCtx* ctx, GroupPubKey const* pub_key, + CompressedPrivKey const* compressed_privkey, + MemberPrecomp const* precomp_str) { + (void)ctx; + (void)pub_key; + (void)compressed_privkey; + (void)precomp_str; + return kEpidNotImpl; +} diff --git a/external/epid-sdk/epid/member/tiny/src/provisioncredential.c b/external/epid-sdk/epid/member/tiny/src/provisioncredential.c new file mode 100644 index 00000000..a1c68fca --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/provisioncredential.c @@ -0,0 +1,81 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member ProvisionCredentialal implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include "epid/member/api.h" +#include "epid/member/software_member.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/validate.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static EccPointFq2 const epid20_g2 = { + {{{{0xBF282394, 0xF6021343, 0x3D32470E, 0xD25D5268, 0x743CCF22, 0x21670413, + 0x4AA3DA05, 0xE20171C5}}}, + {{{0xBAA189BE, 0x7DF7B212, 0x289653E2, 0x43433BF6, 0x4FBB5656, 0x46CCDC25, + 0x53A85A80, 0x592D1EF6}}}}, + {{{{0xDD2335AE, 0x414DB822, 0x4D916838, 0x55E8B59A, 0x312826BD, 0xC621E703, + 0x51FFD350, 0xAE60A4E7}}}, + {{{0x51B92421, 0x2C90FE89, 0x9093D613, 0x2CDC6181, 0x7645E253, 0xF80274F8, + 0x89AFE5AD, 0x1AB442F9}}}}}; + +EpidStatus EPID_API EpidProvisionCredential( + MemberCtx* ctx, GroupPubKey const* pub_key, + MembershipCredential const* credential, MemberPrecomp const* precomp_str) { + NativeGroupPubKey native_pub_key; + NativeMembershipCredential native_cred; + if (!pub_key || !credential || !ctx) { + return kEpidBadArgErr; + } + if (0 != memcmp(&pub_key->gid, &credential->gid, sizeof(GroupId))) { + return kEpidBadArgErr; + } + GroupPubKeyDeserialize(&native_pub_key, pub_key); + MembershipCredentialDeserialize(&native_cred, credential); + if (!GroupPubKeyIsInRange(&native_pub_key) || + !MembershipCredentialIsInRange(&native_cred) || !ctx->f_is_set || + !MembershipCredentialIsInGroup(&native_cred, &ctx->f, &native_pub_key, + &ctx->pairing_state)) { + return kEpidBadArgErr; + } + + ctx->credential = *credential; + ctx->pub_key = *pub_key; + ctx->is_provisioned = 1; + + if (precomp_str) { + PreCompDeserialize(&ctx->precomp, precomp_str); + } else { + PairingCompute(&ctx->precomp.ea2, &native_cred.A, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e12, &native_pub_key.h1, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e22, &native_pub_key.h2, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e2w, &native_pub_key.h2, &native_pub_key.w, + &ctx->pairing_state); + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/provisionkey.c b/external/epid-sdk/epid/member/tiny/src/provisionkey.c new file mode 100644 index 00000000..74971b2e --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/provisionkey.c @@ -0,0 +1,90 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member ProvisionKey implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include "epid/member/api.h" +#include "epid/member/software_member.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/validate.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static EccPointFq2 const epid20_g2 = { + {{{{0xBF282394, 0xF6021343, 0x3D32470E, 0xD25D5268, 0x743CCF22, 0x21670413, + 0x4AA3DA05, 0xE20171C5}}}, + {{{0xBAA189BE, 0x7DF7B212, 0x289653E2, 0x43433BF6, 0x4FBB5656, 0x46CCDC25, + 0x53A85A80, 0x592D1EF6}}}}, + {{{{0xDD2335AE, 0x414DB822, 0x4D916838, 0x55E8B59A, 0x312826BD, 0xC621E703, + 0x51FFD350, 0xAE60A4E7}}}, + {{{0x51B92421, 0x2C90FE89, 0x9093D613, 0x2CDC6181, 0x7645E253, 0xF80274F8, + 0x89AFE5AD, 0x1AB442F9}}}}}; + +EpidStatus EPID_API EpidProvisionKey(MemberCtx* ctx, GroupPubKey const* pub_key, + PrivKey const* priv_key, + MemberPrecomp const* precomp_str) { + NativeGroupPubKey native_pub_key; + NativePrivKey native_priv_key; + if (!pub_key || !priv_key || !ctx) { + return kEpidBadArgErr; + } + if (0 != memcmp(&pub_key->gid, &priv_key->gid, sizeof(GroupId))) { + return kEpidBadArgErr; + } + GroupPubKeyDeserialize(&native_pub_key, pub_key); + if (!GroupPubKeyIsInRange(&native_pub_key)) { + return kEpidBadArgErr; + } + + PrivKeyDeserialize(&native_priv_key, priv_key); + if (!PrivKeyIsInRange(&native_priv_key) || + !PrivKeyIsInGroup(&native_priv_key, &native_pub_key, + &ctx->pairing_state)) { + memset(&native_priv_key.f, 0, sizeof(native_priv_key.f)); + return kEpidBadArgErr; + } + ctx->f = native_priv_key.f; + memset(&native_priv_key.f, 0, sizeof(native_priv_key.f)); + ctx->f_is_set = 1; + + ctx->credential.gid = priv_key->gid; + ctx->credential.A = priv_key->A; + ctx->credential.x = priv_key->x; + ctx->pub_key = *pub_key; + ctx->is_provisioned = 1; + + if (precomp_str) { + PreCompDeserialize(&ctx->precomp, precomp_str); + } else { + PairingCompute(&ctx->precomp.ea2, &native_priv_key.cred.A, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e12, &native_pub_key.h1, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e22, &native_pub_key.h2, &epid20_g2, + &ctx->pairing_state); + PairingCompute(&ctx->precomp.e2w, &native_pub_key.h2, &native_pub_key.w, + &ctx->pairing_state); + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/registerbasename.c b/external/epid-sdk/epid/member/tiny/src/registerbasename.c new file mode 100644 index 00000000..f253650b --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/registerbasename.c @@ -0,0 +1,47 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member RegisterBaseName implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include "epid/member/api.h" +#include "epid/member/tiny/src/allowed_basenames.h" +#include "epid/member/tiny/src/context.h" + +EpidStatus EPID_API EpidRegisterBasename(MemberCtx* ctx, void const* basename, + size_t basename_len) { + if (basename_len == 0) { + return kEpidBadArgErr; + } + if (!ctx || !basename) { + return kEpidBadArgErr; + } + + if (IsBasenameAllowed(ctx->allowed_basenames, basename, basename_len)) { + return kEpidDuplicateErr; + } + return AllowBasename(ctx->allowed_basenames, basename, basename_len) + ? kEpidNoErr + : kEpidNoMemErr; +} + +EpidStatus EPID_API EpidClearRegisteredBasenames(MemberCtx* ctx) { + if (!ctx) { + return kEpidBadArgErr; + } + InitBasenames(ctx->allowed_basenames, MAX_ALLOWED_BASENAMES); + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/serialize.c b/external/epid-sdk/epid/member/tiny/src/serialize.c new file mode 100644 index 00000000..54b21db0 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/serialize.c @@ -0,0 +1,141 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny portable implementations of standard library functions +/*! \file */ + +#include "epid/member/tiny/src/serialize.h" +#include + +#include "epid/common/types.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/signbasic.h" + +void* BasicSignatureSerialize(BasicSignature* dest, + NativeBasicSignature const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqSerialize(&dest->B, &src->B); + EFqSerialize(&dest->K, &src->K); + EFqSerialize(&dest->T, &src->T); + FpSerialize(&dest->c, &src->c); + FpSerialize(&dest->sx, &src->sx); + FpSerialize(&dest->sf, &src->sf); + FpSerialize(&dest->sa, &src->sa); + FpSerialize(&dest->sb, &src->sb); + return dest + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* BasicSignatureDeserialize(NativeBasicSignature* dest, + BasicSignature const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqDeserialize(&dest->B, &src->B); + EFqDeserialize(&dest->K, &src->K); + EFqDeserialize(&dest->T, &src->T); + FpDeserialize(&dest->c, &src->c); + FpDeserialize(&dest->sx, &src->sx); + FpDeserialize(&dest->sf, &src->sf); + FpDeserialize(&dest->sa, &src->sa); + FpDeserialize(&dest->sb, &src->sb); + return src + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void* GroupPubKeySerialize(GroupPubKey* dest, NativeGroupPubKey const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqSerialize(&dest->h1, &src->h1); + EFqSerialize(&dest->h2, &src->h2); + EFq2Serialize(&dest->w, &src->w); + dest->gid = src->gid; + return dest + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + dest->gid = src->gid; + SwapNativeAndPortableLayout( + (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid), + (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid)); + return dest + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* GroupPubKeyDeserialize(NativeGroupPubKey* dest, + GroupPubKey const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqDeserialize(&dest->h1, &src->h1); + EFqDeserialize(&dest->h2, &src->h2); + EFq2Deserialize(&dest->w, &src->w); + dest->gid = src->gid; + return src + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + dest->gid = src->gid; + SwapNativeAndPortableLayout( + (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid), + (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* PrivKeyDeserialize(NativePrivKey* dest, PrivKey const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqDeserialize(&dest->cred.A, &src->A); + FpDeserialize(&dest->cred.x, &src->x); + FpDeserialize(&dest->f, &src->f); + dest->cred.gid = src->gid; + return src + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + dest->cred.gid = src->gid; + SwapNativeAndPortableLayout((uint8_t*)dest + sizeof(dest->cred.gid), + sizeof(*dest) - sizeof(dest->cred.gid), + (uint8_t*)src + sizeof(src->gid), + sizeof(*src) - sizeof(src->gid)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* PreCompDeserialize(NativeMemberPrecomp* dest, + MemberPrecomp const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + Fq12Deserialize(&dest->ea2, (Fq12ElemStr*)&src->ea2); + Fq12Deserialize(&dest->e12, (Fq12ElemStr*)&src->e12); + Fq12Deserialize(&dest->e22, (Fq12ElemStr*)&src->e22); + Fq12Deserialize(&dest->e2w, (Fq12ElemStr*)&src->e2w); + return src + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + SwapNativeAndPortableLayout(dest, sizeof(*dest), src, sizeof(*src)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} + +void const* MembershipCredentialDeserialize(NativeMembershipCredential* dest, + MembershipCredential const* src) { +#if defined(UNOPTIMIZED_SERIALIZATION) + EFqDeserialize(&dest->A, &src->A); + FpDeserialize(&dest->x, &src->x); + dest->gid = src->gid; + return src + 1; +#else // defined(UNOPTIMIZED_SERIALIZATION) + dest->gid = src->gid; + SwapNativeAndPortableLayout( + (uint8_t*)dest + sizeof(dest->gid), sizeof(*dest) - sizeof(dest->gid), + (uint8_t*)src + sizeof(src->gid), sizeof(*src) - sizeof(src->gid)); + return src + 1; +#endif // defined(UNOPTIMIZED_SERIALIZATION) +} diff --git a/external/epid-sdk/epid/member/tiny/src/serialize.h b/external/epid-sdk/epid/member/tiny/src/serialize.h new file mode 100644 index 00000000..caed32f7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/serialize.h @@ -0,0 +1,98 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Definition of de/serialize functionality. + +#ifndef EPID_MEMBER_TINY_SRC_SERIALIZE_H_ +#define EPID_MEMBER_TINY_SRC_SERIALIZE_H_ + +/// \cond +typedef struct BasicSignature BasicSignature; +typedef struct NativeBasicSignature NativeBasicSignature; + +typedef struct GroupPubKey GroupPubKey; +typedef struct NativeGroupPubKey NativeGroupPubKey; + +typedef struct PrivKey PrivKey; +typedef struct NativePrivKey NativePrivKey; + +typedef struct MembershipCredential MembershipCredential; +typedef struct NativeMembershipCredential NativeMembershipCredential; + +typedef struct MemberPrecomp MemberPrecomp; +typedef struct NativeMemberPrecomp NativeMemberPrecomp; +/// \endcond + +/// Write a basic signature to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data written to dest +*/ +void* BasicSignatureSerialize(BasicSignature* dest, + NativeBasicSignature const* src); + +/// Read a basic signature from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data read from to src +*/ +void const* BasicSignatureDeserialize(NativeBasicSignature* dest, + BasicSignature const* src); + +/// Write a group public key to a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data written to dest +*/ +void* GroupPubKeySerialize(GroupPubKey* dest, NativeGroupPubKey const* src); + +/// Read a group public key from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data read from to src +*/ +void const* GroupPubKeyDeserialize(NativeGroupPubKey* dest, + GroupPubKey const* src); + +/// Read a member private key from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data read from to src +*/ +void const* PrivKeyDeserialize(NativePrivKey* dest, PrivKey const* src); + +/// Read pairing pre-computation data from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data read from to src +*/ +void const* PreCompDeserialize(NativeMemberPrecomp* dest, + MemberPrecomp const* src); + +/// Read a membership credential from a portable buffer +/*! +\param[out] dest target buffer +\param [in] src source data +\result pointer to next byte after final data read from to src +*/ +void const* MembershipCredentialDeserialize(NativeMembershipCredential* dest, + MembershipCredential const* src); +#endif // EPID_MEMBER_TINY_SRC_SERIALIZE_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/sethashalg.c b/external/epid-sdk/epid/member/tiny/src/sethashalg.c new file mode 100644 index 00000000..105eba26 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/sethashalg.c @@ -0,0 +1,33 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member SetHashAlg implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +#include "epid/member/tiny/src/context.h" + +EpidStatus EPID_API EpidMemberSetHashAlg(MemberCtx* ctx, HashAlg hash_alg) { + if (!ctx) { + return kEpidBadArgErr; + } + if ((kSha512 != hash_alg) && (kSha256 != hash_alg)) { + return kEpidBadArgErr; + } + ctx->hash_alg = hash_alg; + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/setsigrl.c b/external/epid-sdk/epid/member/tiny/src/setsigrl.c new file mode 100644 index 00000000..8378a9a8 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/setsigrl.c @@ -0,0 +1,79 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member SetSigRl implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/stdlib/endian.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +EpidStatus EPID_API EpidMemberSetSigRl(MemberCtx* ctx, SigRl const* sig_rl, + size_t sig_rl_size) { + uint32_t n2_in = 0; + size_t calculated_sig_rl_size = 0; + uint32_t i = 0; + if (!ctx || !sig_rl) { + return kEpidBadArgErr; + } + + if (!ctx->is_provisioned) { + return kEpidOutOfSequenceError; + } + + n2_in = be32toh(sig_rl->n2); + + // sanity check SigRl size + if (n2_in > MAX_SIGRL_ENTRIES) { + return kEpidBadArgErr; + } + calculated_sig_rl_size = MIN_SIGRL_SIZE + n2_in * sizeof(sig_rl->bk[0]); + if (calculated_sig_rl_size != sig_rl_size) { + return kEpidBadArgErr; + } + // verify that gid given and gid in SigRl match + if (0 != memcmp(&ctx->pub_key.gid, &sig_rl->gid, sizeof(sig_rl->gid))) { + return kEpidBadArgErr; + } + + // ensure version is not being reverted + if (ctx->sig_rl) { + uint32_t current_ver = be32toh(ctx->sig_rl->version); + uint32_t incoming_ver = be32toh(sig_rl->version); + if (current_ver >= incoming_ver) { + return kEpidBadArgErr; + } + } + +#ifdef USE_SIGRL_BY_REFERENCE + ctx->sig_rl = (SigRl*)sig_rl; + (void)i; +#else + if (!ctx->sig_rl) { + ctx->sig_rl = (SigRl*)ctx->heap; + } + ctx->sig_rl->version = sig_rl->version; + ctx->sig_rl->n2 = sig_rl->n2; + memset(ctx->sig_rl->bk, 0, MAX_SIGRL_ENTRIES * sizeof(*ctx->sig_rl->bk)); + + for (i = 0; i < n2_in; i++) { + ctx->sig_rl->bk[i] = sig_rl->bk[i]; + } +#endif + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/sign.c b/external/epid-sdk/epid/member/tiny/src/sign.c new file mode 100644 index 00000000..c6836b3f --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/sign.c @@ -0,0 +1,117 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member sign implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/nrprove.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/signbasic.h" +#include "epid/member/tiny/stdlib/endian.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +// SIZE_MAX is not guaranteed in C89/90 +#define SIZE_T_MAX ((size_t)(-1)) + +size_t EPID_API EpidGetSigSize(SigRl const* sig_rl) { + const size_t kMinSigSize = sizeof(EpidSignature) - sizeof(NrProof); + if (!sig_rl) { + return kMinSigSize; + } else { + uint32_t n2 = be32toh(sig_rl->n2); + if (n2 > (SIZE_T_MAX - kMinSigSize) / sizeof(NrProof)) { + return kMinSigSize; + } else { + return kMinSigSize + n2 * sizeof(NrProof); + } + } +} + +EpidStatus EPID_API EpidSign(MemberCtx const* ctx, void const* msg, + size_t msg_len, void const* basename, + size_t basename_len, EpidSignature* sig, + size_t sig_len) { + EpidStatus sts = kEpidErr; + OctStr32 octstr32_0 = {{0x00, 0x00, 0x00, 0x00}}; + NativeBasicSignature sigma0; + if (!ctx || !sig) { + return kEpidBadArgErr; + } + if (!msg && (0 != msg_len)) { + // if message is non-empty it must have both length and content + return kEpidBadArgErr; + } + if (!ctx->is_provisioned) { + return kEpidOutOfSequenceError; + } + if (!basename && (0 != basename_len)) { + // if basename is non-empty it must have both length and content + return kEpidBadArgErr; + } + if (EpidGetSigSize(ctx->sig_rl) > sig_len) { + return kEpidBadArgErr; + } + + // 11. The member sets sigma0 = (B, K, T, c, sx, sf, sa, sb). + sts = EpidSignBasic(ctx, msg, msg_len, basename, basename_len, &sigma0); + if (kEpidNoErr != sts) { + return sts; + } + BasicSignatureSerialize(&sig->sigma0, &sigma0); + if (ctx->sig_rl) { + uint32_t i = 0; + uint32_t num_sig_rl = 0; + EpidStatus nr_prove_status = kEpidNoErr; + // 13. If SigRL is provided as input, the member proceeds with + // the following steps: + // a. The member verifies that gid in public key and in SigRL + // match. + // This was done under EpidMemberSetSigRl function. + // b. The member copies RLver and n2 values in SigRL to the + // signature. + sig->rl_ver = ctx->sig_rl->version; + sig->n2 = ctx->sig_rl->n2; + // c. For i = 0, ..., n2-1, the member computes sigma[i] = + // nrProve(f, B, K, B[i], K[i]). The details of nrProve() + // will be given in the next subsection. + num_sig_rl = be32toh(ctx->sig_rl->n2); + for (i = 0; i < num_sig_rl; i++) { + sts = EpidNrProve(ctx, msg, msg_len, &sigma0, &ctx->sig_rl->bk[i], + &sig->sigma[i]); + if (kEpidNoErr != sts) { + nr_prove_status = sts; + } + } + if (kEpidNoErr != nr_prove_status) { + memset(&sig->sigma[0], 0, num_sig_rl * sizeof(sig->sigma[0])); + return nr_prove_status; + } + } else { + // 12. If SigRL is not provided as input, + // a. The member sets RLver = 0 and n2 = 0. + // b. The member outputs (sigma0, RLver, n2) and returns "succeeded". + sig->rl_ver = octstr32_0; + sig->n2 = octstr32_0; + } + // d. The member outputs (sigma0, RLver, n2, sigma[0], ..., + // sigma[n2-1]). + // e. If any of the nrProve() functions outputs "failed", the + // member returns "revoked", otherwise returns "succeeded". + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/signbasic.c b/external/epid-sdk/epid/member/tiny/src/signbasic.c new file mode 100644 index 00000000..bc374ccd --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/signbasic.c @@ -0,0 +1,159 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Basic signature computation. +/*! \file */ + +#include "epid/member/tiny/src/signbasic.h" + +#include "epid/common/types.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/hashwrap.h" +#include "epid/member/tiny/math/serialize.h" +#include "epid/member/tiny/src/context.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/presig_compute.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static const FpElemStr epid20_p_str = { + {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, + 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, + 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}}; + +static const G2ElemStr epid20_g2_str = { + {{{{0xE2, 0x01, 0x71, 0xC5, 0x4A, 0xA3, 0xDA, 0x05, 0x21, 0x67, 0x04, + 0x13, 0x74, 0x3C, 0xCF, 0x22, 0xD2, 0x5D, 0x52, 0x68, 0x3D, 0x32, + 0x47, 0x0E, 0xF6, 0x02, 0x13, 0x43, 0xBF, 0x28, 0x23, 0x94}}}, + {{{0x59, 0x2D, 0x1E, 0xF6, 0x53, 0xA8, 0x5A, 0x80, 0x46, 0xCC, 0xDC, + 0x25, 0x4F, 0xBB, 0x56, 0x56, 0x43, 0x43, 0x3B, 0xF6, 0x28, 0x96, + 0x53, 0xE2, 0x7D, 0xF7, 0xB2, 0x12, 0xBA, 0xA1, 0x89, 0xBE}}}}, + {{{{0xAE, 0x60, 0xA4, 0xE7, 0x51, 0xFF, 0xD3, 0x50, 0xC6, 0x21, 0xE7, + 0x03, 0x31, 0x28, 0x26, 0xBD, 0x55, 0xE8, 0xB5, 0x9A, 0x4D, 0x91, + 0x68, 0x38, 0x41, 0x4D, 0xB8, 0x22, 0xDD, 0x23, 0x35, 0xAE}}}, + {{{0x1A, 0xB4, 0x42, 0xF9, 0x89, 0xAF, 0xE5, 0xAD, 0xF8, 0x02, 0x74, + 0xF8, 0x76, 0x45, 0xE2, 0x53, 0x2C, 0xDC, 0x61, 0x81, 0x90, 0x93, + 0xD6, 0x13, 0x2C, 0x90, 0xFE, 0x89, 0x51, 0xB9, 0x24, 0x21}}}}}; + +static const G1ElemStr epid20_g1_str = { + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + +EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + NativeBasicSignature* sig) { + EpidStatus sts = kEpidErr; + PreComputedSignatureData presig; + tiny_sha sha_state; + sha_digest digest; + G1ElemStr g1_str; + Fq12ElemStr fq12_str; + FpElemStr fp_str; + FpElem x; + + FpDeserialize(&x, &ctx->credential.x); + do { + sts = EpidMemberComputePreSig(ctx, &presig); + if (kEpidNoErr != sts) { + break; + } + // B <- random + if (basename) { + if (!IsBasenameAllowed(ctx->allowed_basenames, basename, basename_len)) { + sts = kEpidBadArgErr; + break; + } + /* Basename, K is linked to fixed B */ + if (!EFqHash(&sig->B, (const unsigned char*)basename, basename_len, + ctx->hash_alg)) { + break; + } + } else { + /* No basename, B is random */ + if (!EFqRand(&sig->B, ctx->rnd_func, ctx->rnd_param)) { + break; + } + } + // K <- B^f + // guaranteed not to fail, based on f nonzero, B not identity + EFqAffineExp(&sig->K, &sig->B, &ctx->f); + EFqCp(&sig->T, &presig.T); + + // R1 = B^rf + // guaranteed not to fail, if rf != p or 0, but bad inputs could cause it to + // fail + if (!EFqAffineExp(&presig.R1, &sig->B, &presig.rf)) { + break; + } + + // 5. The member computes + // t3 = Fp.hash(p || g1 || g2 || h1 || h2 || w || B || K || T || R1 || R2). + tinysha_init(ctx->hash_alg, &sha_state); + + tinysha_update(&sha_state, (void const*)&epid20_p_str, + sizeof(epid20_p_str)); + tinysha_update(&sha_state, (void const*)&epid20_g1_str, + sizeof(epid20_g1_str)); + tinysha_update(&sha_state, (void const*)&epid20_g2_str, + sizeof(epid20_g2_str)); + tinysha_update(&sha_state, (void const*)&ctx->pub_key.h1, + sizeof(ctx->pub_key.h1)); + tinysha_update(&sha_state, (void const*)&ctx->pub_key.h2, + sizeof(ctx->pub_key.h2)); + tinysha_update(&sha_state, (void const*)&ctx->pub_key.w, + sizeof(ctx->pub_key.w)); + EFqSerialize(&g1_str, &sig->B); + tinysha_update(&sha_state, (void const*)&g1_str, sizeof(g1_str)); + EFqSerialize(&g1_str, &sig->K); + tinysha_update(&sha_state, (void const*)&g1_str, sizeof(g1_str)); + EFqSerialize(&g1_str, &sig->T); + tinysha_update(&sha_state, (void const*)&g1_str, sizeof(g1_str)); + EFqSerialize(&g1_str, &presig.R1); + tinysha_update(&sha_state, (void const*)&g1_str, sizeof(g1_str)); + Fq12Serialize(&fq12_str, &presig.R2); + tinysha_update(&sha_state, (void const*)&fq12_str, sizeof(fq12_str)); + tinysha_final(digest.digest, &sha_state); + FpFromHash(&sig->c, digest.digest, tinysha_digest_size(&sha_state)); + + // 6. The member computes c = Fp.hash(t3 || m). + tinysha_init(ctx->hash_alg, &sha_state); + FpSerialize(&fp_str, &sig->c); + tinysha_update(&sha_state, (void const*)&fp_str, sizeof(fp_str)); + tinysha_update(&sha_state, msg, msg_len); + tinysha_final(digest.digest, &sha_state); + + FpFromHash(&sig->c, digest.digest, tinysha_digest_size(&sha_state)); + // The variables sx, sf, sa, sb are computed from x, f, a, b with random + // elements + // This randomness allows verification but means that the s variables reveal + // no secret information + FpMul(&sig->sx, &sig->c, &x); + FpMul(&sig->sf, &sig->c, &ctx->f); + FpMul(&sig->sa, &sig->c, &presig.a); + FpMul(&sig->sb, &sig->c, &presig.b); + FpAdd(&sig->sx, &sig->sx, &presig.rx); + FpAdd(&sig->sf, &sig->sf, &presig.rf); + FpAdd(&sig->sa, &sig->sa, &presig.ra); + FpAdd(&sig->sb, &sig->sb, &presig.rb); + sts = kEpidNoErr; + } while (0); + // clearing stack-allocated variables before function return + (void)memset(&presig, 0, sizeof(presig)); + return sts; +} diff --git a/external/epid-sdk/epid/member/tiny/src/signbasic.h b/external/epid-sdk/epid/member/tiny/src/signbasic.h new file mode 100644 index 00000000..092501a5 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/signbasic.h @@ -0,0 +1,37 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Basic signature computation +/*! \file */ + +#ifndef EPID_MEMBER_TINY_SRC_SIGNBASIC_H_ +#define EPID_MEMBER_TINY_SRC_SIGNBASIC_H_ + +#include + +#include "epid/common/errors.h" +#include "epid/member/tiny/math/mathtypes.h" + +/// \cond +typedef struct MemberCtx MemberCtx; +typedef struct NativeBasicSignature NativeBasicSignature; +/// \endcond + +/// Compute Intel(R) EPID Basic Signature. +EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, + void const* basename, size_t basename_len, + NativeBasicSignature* sig); + +#endif // EPID_MEMBER_TINY_SRC_SIGNBASIC_H_ diff --git a/external/epid-sdk/epid/member/tiny/src/startup.c b/external/epid-sdk/epid/member/tiny/src/startup.c new file mode 100644 index 00000000..ce8f4ec5 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/startup.c @@ -0,0 +1,27 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny member Startup implementation. +/*! \file */ + +#define EXPORT_EPID_APIS +#include + +EpidStatus EPID_API EpidMemberStartup(MemberCtx* ctx) { + if (!ctx) { + return kEpidBadArgErr; + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tiny/src/validate.c b/external/epid-sdk/epid/member/tiny/src/validate.c new file mode 100644 index 00000000..75903f12 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/validate.c @@ -0,0 +1,101 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Validate native types +/*! \file */ + +#include "epid/member/tiny/src/validate.h" +#include "epid/member/tiny/math/efq.h" +#include "epid/member/tiny/math/efq2.h" +#include "epid/member/tiny/math/fp.h" +#include "epid/member/tiny/math/fq12.h" +#include "epid/member/tiny/math/mathtypes.h" +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/stdlib/tiny_stdlib.h" + +static EccPointFq2 const epid20_g2 = { + {{{{0xBF282394, 0xF6021343, 0x3D32470E, 0xD25D5268, 0x743CCF22, 0x21670413, + 0x4AA3DA05, 0xE20171C5}}}, + {{{0xBAA189BE, 0x7DF7B212, 0x289653E2, 0x43433BF6, 0x4FBB5656, 0x46CCDC25, + 0x53A85A80, 0x592D1EF6}}}}, + {{{{0xDD2335AE, 0x414DB822, 0x4D916838, 0x55E8B59A, 0x312826BD, 0xC621E703, + 0x51FFD350, 0xAE60A4E7}}}, + {{{0x51B92421, 0x2C90FE89, 0x9093D613, 0x2CDC6181, 0x7645E253, 0xF80274F8, + 0x89AFE5AD, 0x1AB442F9}}}}}; + +static EccPointFq const epid20_g1 = { + {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}, + {{0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000}}}; + +int GroupPubKeyIsInRange(NativeGroupPubKey const* input) { + return EFqOnCurve(&input->h1) && EFqOnCurve(&input->h2) && + EFq2OnCurve(&input->w); +} + +int MembershipCredentialIsInRange(NativeMembershipCredential const* input) { + return EFqOnCurve(&input->A) && FpInField(&input->x); +} + +int MembershipCredentialIsInGroup(NativeMembershipCredential const* input, + FpElem const* f, + NativeGroupPubKey const* pubkey, + PairingState const* pairing_state) { + EccPointJacobiFq g1; + EccPointJacobiFq t2; + EccPointFq t2_affine; + Fq12Elem t3; + Fq12Elem t4; + // to save stack space, reuse t4 and parts of t3 + EccPointFq2* t1_affine = (EccPointFq2*)&t4; + // the following casts rely on EccPointJacobiFq2 and Fq6Elem having same size + EccPointJacobiFq2* w = (EccPointJacobiFq2*)&t3.z0; + EccPointJacobiFq2* t1 = (EccPointJacobiFq2*)&t3.z1; + int result = 0; + if (0 != memcmp(&input->gid, &pubkey->gid, sizeof(pubkey->gid))) { + return 0; + } + EFqFromAffine(&g1, &epid20_g1); + EFq2FromAffine(t1, &epid20_g2); + EFq2FromAffine(w, &pubkey->w); + EFq2MulSSCM(t1, t1, &input->x); + EFq2Add(t1, t1, w); + EFq2ToAffine(t1_affine, t1); + PairingCompute(&t3, &input->A, t1_affine, pairing_state); + EFqFromAffine(&t2, &pubkey->h1); + EFqMulSSCM(&t2, &t2, f); + EFqAdd(&t2, &t2, &g1); + EFqToAffine(&t2_affine, &t2); + PairingCompute(&t4, &t2_affine, &epid20_g2, pairing_state); + result = Fq12Eq(&t3, &t4); + memset(&t2, 0, sizeof(t2)); + memset(&t2_affine, 0, sizeof(t2_affine)); + memset(&t4, 0, sizeof(t4)); + return result; +} + +int PrivKeyIsInRange(NativePrivKey const* input) { + return EFqOnCurve(&input->cred.A) && FpInField(&input->f) && + FpInField(&input->cred.x); +} + +int PrivKeyIsInGroup(NativePrivKey const* input, + NativeGroupPubKey const* pubkey, + PairingState const* pairing_state) { + return MembershipCredentialIsInGroup(&input->cred, &input->f, pubkey, + pairing_state); +} diff --git a/external/epid-sdk/epid/member/tiny/src/validate.h b/external/epid-sdk/epid/member/tiny/src/validate.h new file mode 100644 index 00000000..933ba05d --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/src/validate.h @@ -0,0 +1,86 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Validate native types +/*! \file */ +#ifndef EPID_MEMBER_TINY_SRC_VALIDATE_H_ +#define EPID_MEMBER_TINY_SRC_VALIDATE_H_ + +/// \cond +typedef struct FpElem FpElem; + +typedef struct GroupPubKey GroupPubKey; +typedef struct NativeGroupPubKey NativeGroupPubKey; + +typedef struct PrivKey PrivKey; +typedef struct NativePrivKey NativePrivKey; + +typedef struct MembershipCredential MembershipCredential; +typedef struct NativeMembershipCredential NativeMembershipCredential; + +typedef struct PairingState PairingState; +/// \endcond + +/// Test if the elements of a Group Public Key are in appropriate ranges. +/*! +\param[in] input the value to test. +\returns A value different from zero (i.e., true) if indeed + all elements are in range. Zero (i.e., false) otherwise. +*/ +int GroupPubKeyIsInRange(NativeGroupPubKey const* input); + +/// Test if the elements of a Membership Credential are in appropriate ranges. +/*! +\param[in] input the value to test. +\returns A value different from zero (i.e., true) if indeed + all elements are in range. Zero (i.e., false) otherwise. +*/ +int MembershipCredentialIsInRange(NativeMembershipCredential const* input); + +/// Test if a Membership Credential is in fact in the specified group. +/*! +\param[in] input the value to test. +\param[in] f the f value. +\param[in] pubkey the group key. +\param[in] pairing_state previously computed pairing state. +\returns A value different from zero (i.e., true) if indeed + it is in the group. Zero (i.e., false) otherwise. +*/ +int MembershipCredentialIsInGroup(NativeMembershipCredential const* input, + FpElem const* f, + NativeGroupPubKey const* pubkey, + PairingState const* pairing_state); + +/// Test if the elements of a Private Key are in appropriate ranges. +/*! +\param[in] input the value to test. +\returns A value different from zero (i.e., true) if indeed + all elements are in range. Zero (i.e., false) otherwise. +*/ +int PrivKeyIsInRange(NativePrivKey const* input); + +/// Test if a Private Key is in fact in the specified group. +/*! +\param[in] input the value to test. +\param[in] pubkey the group key. +\param[in] pairing_state previously computed pairing state. +\returns A value different from zero (i.e., true) if indeed + it is in the group. Zero (i.e., false) otherwise. +*/ +int PrivKeyIsInGroup(NativePrivKey const* input, + NativeGroupPubKey const* pubkey, + PairingState const* pairing_state); + +#endif // EPID_MEMBER_TINY_SRC_VALIDATE_H_ diff --git a/external/epid-sdk/epid/member/tiny/stdlib/endian.h b/external/epid-sdk/epid/member/tiny/stdlib/endian.h new file mode 100644 index 00000000..1f606cf1 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/stdlib/endian.h @@ -0,0 +1,38 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Convert values between host and big-/little-endian byte order. +/*! \file */ + +#ifndef EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ +#define EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ + +#include + +/// Transform big endian uint32_t to host uint32_t +#define be32toh(big_endian_32bits) \ + ((uint32_t)(((((unsigned char*)&(big_endian_32bits))[0]) << 24) + \ + ((((unsigned char*)&(big_endian_32bits))[1]) << 16) + \ + ((((unsigned char*)&(big_endian_32bits))[2]) << 8) + \ + (((unsigned char*)&(big_endian_32bits))[3]))) + +/// Transform host uint32_t to big endian uint32_t +#define htobe32(host_32bits) \ + (uint32_t)(((((uint32_t)(host_32bits)) & 0xFF) << 24) | \ + ((((uint32_t)(host_32bits)) & 0xFF00) << 8) | \ + ((((uint32_t)(host_32bits)) & 0xFF0000) >> 8) | \ + ((((uint32_t)(host_32bits)) & 0xFF000000) >> 24)) + +#endif // EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ diff --git a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresource.h b/external/epid-sdk/epid/member/tiny/stdlib/src/tiny_stdlib.c similarity index 51% rename from external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresource.h rename to external/epid-sdk/epid/member/tiny/stdlib/src/tiny_stdlib.c index 6e46c950..a3faca64 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/sources/ippcp/src/pcpbnresource.h +++ b/external/epid-sdk/epid/member/tiny/stdlib/src/tiny_stdlib.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,36 +13,34 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ +/// Tiny portable implementations of standard library functions +/*! \file */ -/* -// -// Purpose: -// Cryptography Primitive. -// Internal BN Resource Definitions & Function Prototypes -// -// Created: Sun 29-Jun-2003 12:16 -// Author(s): Sergey Kirillov -// -// -*/ +#include "epid/member/tiny/stdlib/tiny_stdlib.h" -#if !defined(_PCP_BNRESOURCE_H) -#define _PCP_BNRESOURCE_H +#ifdef SHARED +void* memset(void* ptr, int value, size_t num) { + unsigned char* p = ptr; + size_t i = num; + while (i != 0) { + i -= 1; + p[i] = (unsigned char)value; + } + return ptr; +} -typedef struct { - void* pNext; - IppsBigNumState* pBN; -} BigNumNode; +int memcmp(const void* ptr1, const void* ptr2, size_t num) { + const unsigned char* p1 = (const unsigned char*)ptr1; + const unsigned char* p2 = (const unsigned char*)ptr2; + int d = 0; + while (num != 0 && d == 0) { + d = (*p1 == *p2) ? 0 : ((*p1 < *p2) ? -1 : 1); + p1 += 1; + p2 += 1; + num -= 1; + } + return d; +} - -/* size (byte) of BN resource */ -int cpBigNumListGetSize(int feBitSize, int nodes); - -/* init BN resource */ -void cpBigNumListInit(int feBitSize, int nodes, BigNumNode* pList); - -/* get BN from resource */ -IppsBigNumState* cpBigNumListGet(BigNumNode** pList); - -#endif /* _PCP_BNRESOURCE_H */ +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.h b/external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.h new file mode 100644 index 00000000..906a250a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.h @@ -0,0 +1,64 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny portable implementations of standard library functions +/*! \file */ + +#ifndef EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_ +#define EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_ + +#include + +/// Fill block of memory +/*! + * Sets the first num bytes of the block of memory pointed by ptr + * to the specified value (interpreted as an unsigned char) + * + * \param ptr Pointer to the block of memory to fill. + * \param value Value to be set. The value is passed as an int, + * but the function fills the block of memory using the + * unsigned char conversion of this value. + * \param num Number of bytes to be set to the value. size_t is + * an unsigned integral type. + * \result ptr is returned. + */ +void* memset(void* ptr, int value, size_t num); + +/// Compare two blocks of memory +/*! + * Compares the first num bytes of the block of memory pointed by + * ptr1 to the first num bytes pointed by ptr2, returning zero if + * they all match or a value different from zero representing which + * is greater if they do not. + * + * Notice that, unlike strcmp, the function does not stop comparing + * after finding a null character. + * + * \param ptr1 Pointer to block of memory. + * \param ptr2 Pointer to block of memory. + * \param num Number of bytes to compare. + * \result an integral value indicating the relationship between the + * content of the memory blocks: + * \retval <0 the first byte that does not match in both memory + * blocks has a lower value in ptr1 than in ptr2 (if + * evaluated as unsigned char values) + * \retval 0 the contents of both memory blocks are equal + * \retval >0 the first byte that does not match in both memory blocks + * has a greater value in ptr1 than in ptr2 (if evaluated + * as unsigned char values) + */ +int memcmp(const void* ptr1, const void* ptr2, size_t num); + +#endif // EPID_MEMBER_TINY_STDLIB_TINY_STDLIB_H_ diff --git a/external/epid-sdk-3.0.0/parts-site/configurations/debug/__init__.py b/external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.parts similarity index 51% rename from external/epid-sdk-3.0.0/parts-site/configurations/debug/__init__.py rename to external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.parts index 624392fd..0ddc8bc7 100644 --- a/external/epid-sdk-3.0.0/parts-site/configurations/debug/__init__.py +++ b/external/epid-sdk/epid/member/tiny/stdlib/tiny_stdlib.parts @@ -1,5 +1,6 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 ############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################ -# pylint: disable=locally-disabled, missing-docstring +"""Build configuration for tiny standard library. +""" +Import('*') +env.PartName('tiny_stdlib') -from parts.config import DefineConfiguration +include_files = Pattern(src_dir='.', includes=['*.h'], recursive=False).files() -DefineConfiguration("debug", dependsOn='default') +src_files = Pattern(src_dir='src', includes=['*.c'], recursive=True).files() + +env.Append(CPPPATH='#') + +if 'shared' in env['MODE']: + env.Append(CPPDEFINES=['SHARED']) + +outputs = env.Library('${PART_SHORT_NAME}', src_files) + +sdk_outs = env.Sdk(outputs) +env.SdkInclude(include_files, sub_dir='${PART_SHORT_NAME}') + +if 'install_lib' in env['MODE'] and 'shared' not in env['MODE']: + env.InstallLib(outputs) diff --git a/external/epid-sdk/epid/member/tiny/unittests/allowed_basenames-test.cc b/external/epid-sdk/epid/member/tiny/unittests/allowed_basenames-test.cc new file mode 100644 index 00000000..dc4e93c8 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/allowed_basenames-test.cc @@ -0,0 +1,117 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief Basename management unit tests. + */ +#ifndef SHARED +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tiny/src/allowed_basenames.h" +} + +namespace { + +TEST(AllowedBasenames, GetBasenamesSizeSucceeds) { + size_t bsn_count = 10; + size_t expected_bsn_size = + sizeof(size_t) // current_bsn_number + + sizeof(size_t) // max_bsn_number + + sizeof(sha_digest) * bsn_count; // digest * max_bsn_number + size_t bsn_size = BasenamesGetSize(bsn_count); + EXPECT_EQ(expected_bsn_size, bsn_size); +} + +TEST(AllowedBasenames, ReportsRegisteredBasename) { + const std::vector bsn0 = {'b', 's', 'n', '0'}; + const std::vector bsn1 = {'b', 's', 'n', '1'}; + + AllowedBasenames* base_names = nullptr; + std::vector base_names_buf; + size_t bsn_size = BasenamesGetSize(2); + base_names_buf.resize(bsn_size); + memset(base_names_buf.data(), 1, bsn_size); + base_names = (AllowedBasenames*)&base_names_buf[0]; + InitBasenames(base_names, 2); + + EXPECT_TRUE(AllowBasename(base_names, bsn0.data(), bsn0.size())); + EXPECT_TRUE(AllowBasename(base_names, bsn1.data(), bsn1.size())); + EXPECT_TRUE(IsBasenameAllowed(base_names, bsn0.data(), bsn0.size())); +} + +TEST(AllowedBasenames, ReportsUnregisteredBasename) { + const std::vector bsn0 = {'b', 's', 'n', '0'}; + const std::vector bsn1 = {'b', 's', 'n', '1'}; + + AllowedBasenames* base_names = nullptr; + std::vector base_names_buf; + size_t bsn_size = BasenamesGetSize(1); + base_names_buf.resize(bsn_size); + base_names = (AllowedBasenames*)&base_names_buf[0]; + InitBasenames(base_names, 1); + + EXPECT_TRUE(AllowBasename(base_names, bsn0.data(), bsn0.size())); + EXPECT_FALSE(IsBasenameAllowed(base_names, bsn1.data(), bsn1.size())); +} + +TEST(AllowedBasenames, IsBasenameAllowedReturnsFalseWhenNoBasenamesRegistered) { + const std::vector bsn0 = {'b', 's', 'n', '0'}; + + AllowedBasenames* base_names = nullptr; + std::vector base_names_buf; + size_t bsn_size = BasenamesGetSize(1); + base_names_buf.resize(bsn_size); + base_names = (AllowedBasenames*)&base_names_buf[0]; + InitBasenames(base_names, 1); + + EXPECT_FALSE(IsBasenameAllowed(base_names, bsn0.data(), bsn0.size())); +} + +TEST(AllowedBasenames, AllowBasenameReturnsFalseForMoreThanMaxBasenames) { + const std::vector bsn0 = {'b', 's', 'n', '0'}; + + AllowedBasenames* base_names = nullptr; + std::vector base_names_buf; + size_t bsn_size = BasenamesGetSize(5); + base_names_buf.resize(bsn_size); + base_names = (AllowedBasenames*)&base_names_buf[0]; + InitBasenames(base_names, 5); + + for (int n = 0; n < 5; n++) { + EXPECT_TRUE(AllowBasename(base_names, &n, sizeof(n))); + } + // One more basename should not fit into storage + EXPECT_FALSE(AllowBasename(base_names, bsn0.data(), bsn0.size())); +} + +TEST(AllowedBasenames, AllowBasenameCanReturnTrue) { + const std::vector bsn0 = {'b', 's', 'n', '0'}; + + AllowedBasenames* base_names = nullptr; + std::vector base_names_buf; + size_t bsn_size = BasenamesGetSize(1); + base_names_buf.resize(bsn_size); + base_names = (AllowedBasenames*)&base_names_buf[0]; + InitBasenames(base_names, 1); + + EXPECT_TRUE(AllowBasename(base_names, bsn0.data(), bsn0.size())); +} + +} // namespace +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/context-test.cc b/external/epid-sdk/epid/member/tiny/unittests/context-test.cc new file mode 100644 index 00000000..dafa4cf7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/context-test.cc @@ -0,0 +1,484 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +} +bool operator==(MemberPrecomp const& lhs, MemberPrecomp const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} +/// compares GroupPubKey values +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs); + +/// compares MembershipCredential values +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs); +namespace { +////////////////////////////////////////////////////////////////////////// +// EpidMemberDeinit Tests +TEST_F(EpidMemberTest, DeinitWorksGivenNullMemberCtx) { + EpidMemberDeinit(nullptr); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberGetSize Tests +TEST_F(EpidMemberTest, GetSizeFailsGivenNullParams) { + size_t ctx_size = 0; + MemberParams params = {0}; + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(¶ms, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(nullptr, &ctx_size)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(nullptr, nullptr)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberGetSize Tests +TEST_F(EpidMemberTest, GetSizeWorksGivenValidParams) { + size_t ctx_size = 0; + Prng my_prng; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberInit Tests +TEST_F(EpidMemberTest, InitFailsGivenNullParameters) { + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(nullptr, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(¶ms, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(nullptr, ctx)); +} + +TEST_F(EpidMemberTest, InitFailsGivenInvalidParameters) { + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, &f, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(¶ms, ctx)); +} + +TEST_F(EpidMemberTest, InitSucceedsGivenValidParameters) { + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, &f, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidNoErr, EpidMemberInit(¶ms, ctx)); + EpidMemberDeinit(ctx); +} + +TEST_F(EpidMemberTest, InitSucceedsGivenValidParametersWithNoF) { + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidNoErr, EpidMemberInit(¶ms, ctx)); + EpidMemberDeinit(ctx); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberCreate Tests +TEST_F(EpidMemberTest, CreateIsNotImplemented) { + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNotImpl, EpidMemberCreate(¶ms, &ctx)); + EpidMemberDelete(&ctx); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberStartup +TEST_F(EpidMemberTest, StartupFailsGivenNullParameters) { + EXPECT_EQ(kEpidBadArgErr, EpidMemberStartup(nullptr)); +} + +TEST_F(EpidMemberTest, StartupSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); + + EXPECT_EQ(kEpidNoErr, EpidMemberStartup(member)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberSetHashAlg +TEST_F(EpidMemberTest, SetHashAlgFailsGivenNullPtr) { + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(nullptr, kSha256)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA256) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha256)); +} +TEST_F(EpidMemberTest, DISABLED_CanSetHashAlgoToSHA384) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha384)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA512) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha512)); +} +TEST_F(EpidMemberTest, DISABLED_CanSetHashAlgoToSHA512256) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha512_256)); +} +TEST_F(EpidMemberTest, SetHashAlgFailsForNonSupportedAlgorithm) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_256)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_384)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_512)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, (HashAlg)-1)); +} + +TEST_F(EpidMemberTest, SetHashAlgRejectsSHA384) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha384)); +} + +TEST_F(EpidMemberTest, SetHashAlgRejectsSHA512256) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha512_256)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberSetSigRl +TEST_F(EpidMemberTest, SetSigRlFailsGivenNullPointer) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(nullptr, &srl, sizeof(SigRl))); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, nullptr, sizeof(SigRl))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenZeroSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(member_ctx, &srl, 0)); +} +// Size parameter must be at least big enough for n2 == 0 case +TEST_F(EpidMemberTest, SetSigRlFailsGivenTooSmallSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ( + kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1)); + srl.n2 = this->kOctStr32_1; + EXPECT_EQ( + kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1)); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenN2TooBigForSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.n2 = this->kOctStr32_1; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenN2TooSmallForSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenBadGroupId) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.gid.data[0] = ~srl.gid.data[0]; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenEmptySigRlFromDifferentGroup) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenOldVersion) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.version = this->kOctStr32_1; + EXPECT_EQ(kEpidNoErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); + OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00}; + srl.version = octstr32_0; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlPreservesOldRlOnFailure) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXSigrevokedMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); + // wrong sigrl contains revoked member0 and has lower version + SigRl const* wrong_sig_rl = + reinterpret_cast(this->kGrpXSigRlSingleEntry.data()); + size_t wrong_sig_rl_size = this->kGrpXSigRlSingleEntry.size(); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, wrong_sig_rl, wrong_sig_rl_size)); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(sig_rl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + // Check that sigrevoked member is still in SigRl + EXPECT_EQ(kEpidSigRevokedInSigRl, EpidSign(member_ctx, msg.data(), msg.size(), + nullptr, 0, sig, sig_len)); +} +TEST_F(EpidMemberTest, SetSigRlFailsIfNotProvisioned) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + SigRl const* sig_rl = &srl; + size_t sig_rl_size = sizeof(srl) - sizeof(srl.bk); + EXPECT_EQ(kEpidOutOfSequenceError, + EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenValidSigRl) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenEmptySigRl) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + uint8_t sig_rl_data_n2_zero[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x00, + // not bk's + }; + SigRl* sig_rl = reinterpret_cast(sig_rl_data_n2_zero); + size_t sig_rl_size = sizeof(sig_rl_data_n2_zero); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenSigRlWithOneEntry) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = + reinterpret_cast(this->kGrpXSigRlSingleEntry.data()); + size_t sig_rl_size = this->kGrpXSigRlSingleEntry.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +////////////////////////////////////////////////////////////////////////// +// EpidRegisterBasename +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenNullPtr) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'_', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(member, nullptr, basename.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(nullptr, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenDuplicateBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'d', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename.data(), basename.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenInvalidBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {}; + std::vector basename2 = {'b', 's', 'n'}; + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(member, basename.data(), basename.size())); + EXPECT_EQ(kEpidBadArgErr, EpidRegisterBasename(member, basename2.data(), 0)); +} +TEST_F(EpidMemberTest, RegisterBaseNameSucceedsGivenUniqueBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'b', 's', 'n', '0', '1'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameSucceedsGivenMultipleUniqueBaseNames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename1 = {'b', 's', 'n', '0', '1'}; + std::vector basename2 = {'b', 's', 'n', '0', '2'}; + std::vector basename3 = {'b', 's', 'n', '0', '3'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename1.data(), basename1.size())); + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename2.data(), basename2.size())); + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename3.data(), basename3.size())); + // Verify that basenames registered succesfully + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename1.data(), basename1.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename2.data(), basename2.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename3.data(), basename3.size())); +} +TEST_F(EpidMemberTest, + RegisterBaseNameSucceedsGivenBsnContainingAllPossibleBytes) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidRegisterBasename(member, this->kData_0_255.data(), + this->kData_0_255.size())); +} +////////////////////////////////////////////////////////////////////////// +// EpidClearRegisteredBasenames +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesFailsGivenNullPtr) { + EXPECT_EQ(kEpidBadArgErr, EpidClearRegisteredBasenames(nullptr)); +} +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesClearsBasenames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidRegisterBasename(member, this->kData_0_255.data(), + this->kData_0_255.size())); + EXPECT_EQ(kEpidNoErr, EpidClearRegisteredBasenames(member)); + // check, that after clearing EpidRegisterBasename works correctly + THROW_ON_EPIDERR(EpidRegisterBasename(member, this->kData_0_255.data(), + this->kData_0_255.size())); +} +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesClearsAllBasenames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + for (int i = 0; i < 3; ++i) { + THROW_ON_EPIDERR(EpidRegisterBasename(member, &i, sizeof(i))); + } + EXPECT_EQ(kEpidNoErr, EpidClearRegisteredBasenames(member)); + for (int i = 0; i < 3; ++i) { + THROW_ON_EPIDERR(EpidRegisterBasename(member, &i, sizeof(i))); + } +} +TEST_F(EpidMemberTest, + EpidClearRegisteredBasenamesCausesSignWithBasenameAfterItToFail) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + THROW_ON_EPIDERR(EpidClearRegisteredBasenames(member)); + ASSERT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/decompress_privkey-test.cc b/external/epid-sdk/epid/member/tiny/unittests/decompress_privkey-test.cc new file mode 100644 index 00000000..25a65ef7 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/decompress_privkey-test.cc @@ -0,0 +1,99 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief DecompressPrivKey unit tests. + */ +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +#include "epid/member/tiny/unittests/member-testhelper.h" + +bool operator==(PrivKey const& lhs, PrivKey const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} +namespace { + +TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenNullParameters) { + auto const& pub_key = this->kGrpXKey; + auto const& compressed_privkey = this->kGrpXMember9CompressedKey; + PrivKey priv_key = {}; + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(nullptr, &compressed_privkey, &priv_key)); + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key, nullptr, &priv_key)); + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key, &compressed_privkey, nullptr)); +} + +TEST_F(EpidMemberTest, DISABLED_CanDecompressPrivKeyGivenValidCompressedKey) { + auto const& pub_key = this->kGrpXKey; + auto const& compressed_privkey = this->kGrpXMember9CompressedKey; + auto const& expected_decompressed_key = this->kGrpXMember9PrivKey; + PrivKey priv_key = {}; + EXPECT_EQ(kEpidNoErr, + EpidDecompressPrivKey(&pub_key, &compressed_privkey, &priv_key)); + EXPECT_EQ(expected_decompressed_key, priv_key); +} + +TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenKeysMissmatch) { + auto const& pub_key = this->kGrpYKey; + auto const& compressed_privkey = this->kGrpXMember9CompressedKey; + PrivKey priv_key = {}; + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key, &compressed_privkey, &priv_key)); +} + +TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenInvalidGroupKey) { + // Test for cases when h1 or w of group public key are invalid. + // Note h2 of group public key is not used for key decompression. + auto const& compressed_privkey = this->kGrpXMember9CompressedKey; + PrivKey priv_key = {}; + + auto pub_key_h1 = this->kGrpXKey; + pub_key_h1.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key_h1, &compressed_privkey, &priv_key)); + + auto pub_key_w = this->kGrpXKey; + pub_key_w.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key_w, &compressed_privkey, &priv_key)); +} + +TEST_F(EpidMemberTest, + DISABLED_DecompressPrivKeyFailsGivenInvalidCompressedKey) { + auto const& pub_key = this->kGrpXKey; + PrivKey priv_key = {}; + + auto compressed_privkey_ax = this->kGrpXMember9CompressedKey; + compressed_privkey_ax.ax.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + EpidDecompressPrivKey(&pub_key, &compressed_privkey_ax, &priv_key)); + + auto compressed_privkey_seed = this->kGrpXMember9CompressedKey; + compressed_privkey_seed.seed.data[0]++; + EXPECT_EQ(kEpidBadArgErr, EpidDecompressPrivKey( + &pub_key, &compressed_privkey_seed, &priv_key)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/get_sigsize-test.cc b/external/epid-sdk/epid/member/tiny/unittests/get_sigsize-test.cc new file mode 100644 index 00000000..52657afc --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/get_sigsize-test.cc @@ -0,0 +1,94 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// GetSigSize unit tests. +/*!\file */ + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +#include "epid/member/tiny/unittests/member-testhelper.h" + +namespace { + +TEST_F(EpidMemberTest, GetSigSizeReturnsSizeofBasicSigGivenNullPointer) { + size_t sig_size_without_sig_rl = sizeof(EpidSignature) - sizeof(NrProof); + EXPECT_EQ(sig_size_without_sig_rl, EpidGetSigSize(nullptr)); +} + +TEST_F(EpidMemberTest, GetSigSizeReturnsCorrectValueGivenValidSigRl) { + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00}; + OctStr32 octstr32_1 = {0x00, 0x00, 0x00, 0x01}; + OctStr32 octstr32_2 = {0x00, 0x00, 0x00, 0x02}; + OctStr32 octstr32_16 = {0x00, 0x00, 0x00, 0x10}; + OctStr32 octstr32_256 = {0x00, 0x00, 0x01, 0x00}; + OctStr32 octstr32_65536 = {0x00, 0x01, 0x00, 0x00}; + OctStr32 octstr32_4294967295 = {0xff, 0xff, 0xff, 0xff}; + + size_t one_entry_size = sizeof(NrProof); + size_t sig_size_0_entries = sizeof(EpidSignature) - one_entry_size; + size_t sig_size_1_entry = sig_size_0_entries + one_entry_size; + size_t sig_size_2_entries = sig_size_0_entries + 2 * one_entry_size; + size_t sig_size_16_entries = sig_size_0_entries + 16 * one_entry_size; + size_t sig_size_256_entries = sig_size_0_entries + 256 * one_entry_size; + size_t sig_size_65536_entries = sig_size_0_entries + 65536 * one_entry_size; + // no entries + srl.n2 = octstr32_0; + EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl)); + // 1 entry + srl.n2 = octstr32_1; + EXPECT_EQ(sig_size_1_entry, EpidGetSigSize(&srl)); + // 2 entries + srl.n2 = octstr32_2; + EXPECT_EQ(sig_size_2_entries, EpidGetSigSize(&srl)); + // 16 entries + srl.n2 = octstr32_16; + EXPECT_EQ(sig_size_16_entries, EpidGetSigSize(&srl)); + // 256 entries + srl.n2 = octstr32_256; + EXPECT_EQ(sig_size_256_entries, EpidGetSigSize(&srl)); + // 65536 entries + srl.n2 = octstr32_65536; + EXPECT_EQ(sig_size_65536_entries, EpidGetSigSize(&srl)); + // 4294967295 entries + srl.n2 = octstr32_4294967295; +#if (SIZE_MAX <= 0xFFFFFFFF) // When size_t value is 32 bit or lower + EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl)); +#else + size_t sig_size_4294967295_entries = + sig_size_0_entries + 4294967295 * one_entry_size; + EXPECT_EQ(sig_size_4294967295_entries, EpidGetSigSize(&srl)); +#endif +} + +TEST_F(EpidMemberTest, + GetSigSizeReturnsCorrectValueGivenValidSigRlUsingIKGFData) { + const std::vector sigrl_bin = { +#include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc" + }; + + SigRl const* sig_rl = reinterpret_cast(sigrl_bin.data()); + size_t sig_size_3_entries = + sizeof(EpidSignature) - sizeof(NrProof) + 3 * sizeof(NrProof); + // 3 entries + EXPECT_EQ(sig_size_3_entries, EpidGetSigSize(sig_rl)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/internal/nr_prove-test.cc b/external/epid-sdk/epid/member/tiny/unittests/internal/nr_prove-test.cc new file mode 100644 index 00000000..e95cf245 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/internal/nr_prove-test.cc @@ -0,0 +1,181 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Tiny NrProve unit tests. +/*! \file */ + +#ifndef SHARED +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/nrprove.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/signbasic.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +namespace { + +TEST_F(EpidMemberTest, NrProveFailsGivenInvalidSigRlEntry) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + NrProof proof; + // make sure that can generate NrProof using incorrupt sig_rl_enty + THROW_ON_EPIDERR(EpidNrProve(member, msg.data(), msg.size(), &this->kBasicSig, + &sig_rl->bk[0], &proof)); + SigRlEntry sig_rl_enty_invalid_k = sig_rl->bk[0]; + sig_rl_enty_invalid_k.k.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), &this->kBasicSig, + &sig_rl_enty_invalid_k, &proof)); + + SigRlEntry sig_rl_enty_invalid_b = sig_rl->bk[0]; + sig_rl_enty_invalid_b.b.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), &this->kBasicSig, + &sig_rl_enty_invalid_b, &proof)); +} + +TEST_F(EpidMemberTest, NrProveFailsGivenInvalidBasicSig) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + // make sure that can generate NrProof using incorrupt basic sig + THROW_ON_EPIDERR(EpidNrProve(member, msg.data(), msg.size(), &this->kBasicSig, + &sig_rl->bk[0], &proof)); + // invalid basic sig is only when K value is invalid!! + NativeBasicSignature basic_sig_invalid_K = this->kBasicSig; + basic_sig_invalid_K.K.x.limbs.word[0]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), &basic_sig_invalid_K, + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofForEmptyMessage) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + + EXPECT_EQ(kEpidNoErr, EpidNrProve(member, nullptr, 0, &this->kBasicSig, + &sig_rl->bk[0], &proof)); + + BasicSignatureSerialize(&basic_sig, &this->kBasicSig); + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidNoErr, + EpidNrVerify(ctx, &basic_sig, nullptr, 0, &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofForMsgContainingAllPossibleBytes) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kData_0_255; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), + &this->kBasicSig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + BasicSignatureSerialize(&basic_sig, &this->kBasicSig); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProof) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), + &this->kBasicSig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + BasicSignatureSerialize(&basic_sig, &this->kBasicSig); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha512) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + NrProof proof; + EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), + &this->kBasicSig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + BasicSignatureSerialize(&basic_sig, &this->kBasicSig); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha256) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + NrProof proof; + EXPECT_EQ(kEpidNoErr, EpidNrProve(member, msg.data(), msg.size(), + &this->kBasicSig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + BasicSignatureSerialize(&basic_sig, &this->kBasicSig); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} +} // namespace +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/internal/presig_compute-test.cc b/external/epid-sdk/epid/member/tiny/unittests/internal/presig_compute-test.cc new file mode 100644 index 00000000..bd608fe2 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/internal/presig_compute-test.cc @@ -0,0 +1,44 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief tiny EpidMemberComputePreSig unit tests. + */ + +#ifndef SHARED +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tiny/src/presig_compute.h" +} + +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +namespace { + +TEST_F(EpidMemberTest, SuccessfullyComputePresig) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + PreComputedSignatureData presig = {0}; + EXPECT_EQ(kEpidNoErr, EpidMemberComputePreSig(member, &presig)); +} + +} // namespace +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/internal/serialize-test.cc b/external/epid-sdk/epid/member/tiny/unittests/internal/serialize-test.cc new file mode 100644 index 00000000..bbd29f62 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/internal/serialize-test.cc @@ -0,0 +1,409 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief native type serialization unit tests. + * + * \warning to run the tests in this file you must build a non-shared mode. + */ + +#ifndef SHARED + +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/common/types.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/signbasic.h" +} + +/// compares BasicSignature values +bool operator==(BasicSignature const& lhs, BasicSignature const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(NativeBasicSignature const& lhs, + NativeBasicSignature const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(NativeGroupPubKey const& lhs, NativeGroupPubKey const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(NativePrivKey const& lhs, NativePrivKey const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(NativeMembershipCredential const& lhs, + NativeMembershipCredential const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +namespace { +//////////////////////////////////////////////////////////////////////// +// BasicSignatureSerialize + +TEST(TinySerializeTest, BasicSignatureSerializeWorks) { + const NativeBasicSignature serialized_BaseSig = { + // B + {{0xB315D67E, 0x1924AE56, 0xCF527861, 0xEBB789B6, 0x3F429D2A, 0xB193BF9A, + 0x6BD8502F, 0x5E73BE39}, + {0x0BD51968, 0x0F13472D, 0xC96B5096, 0xA9CD4491, 0x4AB668CF, 0x2123D56C, + 0xF30AF180, 0x0DB43C33}}, + // K + {{0x9C3524E3, 0x4E4CA66B, 0x58731363, 0xB57BC920, 0x1317EBFA, 0xBD71A2D6, + 0x046B29FE, 0x64B5A803}, + {0x86A7A14A, 0xDE584912, 0xFEFD476A, 0x8559EF80, 0x34D8E1D2, 0x81F6BF1D, + 0xE0C42E4B, 0x477FEC10}}, + // T + {{0x444DB42F, 0xB57CFAA0, 0x3FB8C069, 0x3593EC91, 0xB968BBAA, 0x02D2BFBB, + 0xCF2E5D4A, 0xE57236B5}, + {0x23C435BE, 0x92D96415, 0x6A552F32, 0x5E071AA9, 0xBBC76EDC, 0xC1C5D18A, + 0x654CA5AE, 0xB96FEBB0}}, + // c + {0xD03D247B, 0x8C2A93E5, 0xCBB14B7A, 0x85919691, 0xC7009CFC, 0xEFD5278B, + 0x82D2F470, 0xA2CDE297}, + // xs + {0xEB24D967, 0xDC578F59, 0x58C76405, 0x1958415E, 0xF08890BD, 0xDB47D06A, + 0x7257B3F5, 0x6346AA98}, + // sf + {0x11B85D46, 0xBEA435F3, 0x11E85329, 0xDD10B17B, 0xC41B1647, 0x268C5DDC, + 0x4E39F40C, 0x25421795}, + // sa + {0xCDA62A84, 0x3CC19531, 0xDCC526F5, 0x3A248BB8, 0xF973B761, 0x3E009735, + 0x6FC46BCC, 0x4EBDEDE8}, + // sb + {0x2E0B26CF, 0x6193CD96, 0xED6E97F8, 0xBB9D186E, 0xB37A5227, 0xF82B38E5, + 0x610CAF48, 0x92A3681B}}; + BasicSignature result = {0}; + const BasicSignature expected_BaseSig = { + // B + {{0x5E, 0x73, 0xBE, 0x39, 0x6B, 0xD8, 0x50, 0x2F, 0xB1, 0x93, 0xBF, + 0x9A, 0x3F, 0x42, 0x9D, 0x2A, 0xEB, 0xB7, 0x89, 0xB6, 0xCF, 0x52, + 0x78, 0x61, 0x19, 0x24, 0xAE, 0x56, 0xB3, 0x15, 0xD6, 0x7E}, + {0x0D, 0xB4, 0x3C, 0x33, 0xF3, 0x0A, 0xF1, 0x80, 0x21, 0x23, 0xD5, + 0x6C, 0x4A, 0xB6, 0x68, 0xCF, 0xA9, 0xCD, 0x44, 0x91, 0xC9, 0x6B, + 0x50, 0x96, 0x0F, 0x13, 0x47, 0x2D, 0x0B, 0xD5, 0x19, 0x68}}, + // K + {{0x64, 0xB5, 0xA8, 0x03, 0x04, 0x6B, 0x29, 0xFE, 0xBD, 0x71, 0xA2, + 0xD6, 0x13, 0x17, 0xEB, 0xFA, 0xB5, 0x7B, 0xC9, 0x20, 0x58, 0x73, + 0x13, 0x63, 0x4E, 0x4C, 0xA6, 0x6B, 0x9C, 0x35, 0x24, 0xE3}, + {0x47, 0x7F, 0xEC, 0x10, 0xE0, 0xC4, 0x2E, 0x4B, 0x81, 0xF6, 0xBF, + 0x1D, 0x34, 0xD8, 0xE1, 0xD2, 0x85, 0x59, 0xEF, 0x80, 0xFE, 0xFD, + 0x47, 0x6A, 0xDE, 0x58, 0x49, 0x12, 0x86, 0xA7, 0xA1, 0x4A}}, + // T + {{0xE5, 0x72, 0x36, 0xB5, 0xCF, 0x2E, 0x5D, 0x4A, 0x02, 0xD2, 0xBF, + 0xBB, 0xB9, 0x68, 0xBB, 0xAA, 0x35, 0x93, 0xEC, 0x91, 0x3F, 0xB8, + 0xC0, 0x69, 0xB5, 0x7C, 0xFA, 0xA0, 0x44, 0x4D, 0xB4, 0x2F}, + {0xB9, 0x6F, 0xEB, 0xB0, 0x65, 0x4C, 0xA5, 0xAE, 0xC1, 0xC5, 0xD1, + 0x8A, 0xBB, 0xC7, 0x6E, 0xDC, 0x5E, 0x07, 0x1A, 0xA9, 0x6A, 0x55, + 0x2F, 0x32, 0x92, 0xD9, 0x64, 0x15, 0x23, 0xC4, 0x35, 0xBE}}, + // c + {0xA2, 0xCD, 0xE2, 0x97, 0x82, 0xD2, 0xF4, 0x70, 0xEF, 0xD5, 0x27, + 0x8B, 0xC7, 0x00, 0x9C, 0xFC, 0x85, 0x91, 0x96, 0x91, 0xCB, 0xB1, + 0x4B, 0x7A, 0x8C, 0x2A, 0x93, 0xE5, 0xD0, 0x3D, 0x24, 0x7B}, + // sx + {0x63, 0x46, 0xAA, 0x98, 0x72, 0x57, 0xB3, 0xF5, 0xDB, 0x47, 0xD0, + 0x6A, 0xF0, 0x88, 0x90, 0xBD, 0x19, 0x58, 0x41, 0x5E, 0x58, 0xC7, + 0x64, 0x05, 0xDC, 0x57, 0x8F, 0x59, 0xEB, 0x24, 0xD9, 0x67}, + // sf + {0x25, 0x42, 0x17, 0x95, 0x4E, 0x39, 0xF4, 0x0C, 0x26, 0x8C, 0x5D, + 0xDC, 0xC4, 0x1B, 0x16, 0x47, 0xDD, 0x10, 0xB1, 0x7B, 0x11, 0xE8, + 0x53, 0x29, 0xBE, 0xA4, 0x35, 0xF3, 0x11, 0xB8, 0x5D, 0x46}, + // sa + {0x4E, 0xBD, 0xED, 0xE8, 0x6F, 0xC4, 0x6B, 0xCC, 0x3E, 0x00, 0x97, + 0x35, 0xF9, 0x73, 0xB7, 0x61, 0x3A, 0x24, 0x8B, 0xB8, 0xDC, 0xC5, + 0x26, 0xF5, 0x3C, 0xC1, 0x95, 0x31, 0xCD, 0xA6, 0x2A, 0x84}, + // sb + {0x92, 0xA3, 0x68, 0x1B, 0x61, 0x0C, 0xAF, 0x48, 0xF8, 0x2B, 0x38, + 0xE5, 0xB3, 0x7A, 0x52, 0x27, 0xBB, 0x9D, 0x18, 0x6E, 0xED, 0x6E, + 0x97, 0xF8, 0x61, 0x93, 0xCD, 0x96, 0x2E, 0x0B, 0x26, 0xCF}}; + BasicSignatureSerialize(&result, &serialized_BaseSig); + EXPECT_EQ(expected_BaseSig, result); +} + +//////////////////////////////////////////////////////////////////////// +// BasicSignatureDeserialize + +TEST(TinySerializeTest, BasicSignatureDeserializeWorks) { + const BasicSignature deserialized_BaseSig = { + // B + {{0x5E, 0x73, 0xBE, 0x39, 0x6B, 0xD8, 0x50, 0x2F, 0xB1, 0x93, 0xBF, + 0x9A, 0x3F, 0x42, 0x9D, 0x2A, 0xEB, 0xB7, 0x89, 0xB6, 0xCF, 0x52, + 0x78, 0x61, 0x19, 0x24, 0xAE, 0x56, 0xB3, 0x15, 0xD6, 0x7E}, + {0x0D, 0xB4, 0x3C, 0x33, 0xF3, 0x0A, 0xF1, 0x80, 0x21, 0x23, 0xD5, + 0x6C, 0x4A, 0xB6, 0x68, 0xCF, 0xA9, 0xCD, 0x44, 0x91, 0xC9, 0x6B, + 0x50, 0x96, 0x0F, 0x13, 0x47, 0x2D, 0x0B, 0xD5, 0x19, 0x68}}, + // K + {{0x64, 0xB5, 0xA8, 0x03, 0x04, 0x6B, 0x29, 0xFE, 0xBD, 0x71, 0xA2, + 0xD6, 0x13, 0x17, 0xEB, 0xFA, 0xB5, 0x7B, 0xC9, 0x20, 0x58, 0x73, + 0x13, 0x63, 0x4E, 0x4C, 0xA6, 0x6B, 0x9C, 0x35, 0x24, 0xE3}, + {0x47, 0x7F, 0xEC, 0x10, 0xE0, 0xC4, 0x2E, 0x4B, 0x81, 0xF6, 0xBF, + 0x1D, 0x34, 0xD8, 0xE1, 0xD2, 0x85, 0x59, 0xEF, 0x80, 0xFE, 0xFD, + 0x47, 0x6A, 0xDE, 0x58, 0x49, 0x12, 0x86, 0xA7, 0xA1, 0x4A}}, + // T + {{0xE5, 0x72, 0x36, 0xB5, 0xCF, 0x2E, 0x5D, 0x4A, 0x02, 0xD2, 0xBF, + 0xBB, 0xB9, 0x68, 0xBB, 0xAA, 0x35, 0x93, 0xEC, 0x91, 0x3F, 0xB8, + 0xC0, 0x69, 0xB5, 0x7C, 0xFA, 0xA0, 0x44, 0x4D, 0xB4, 0x2F}, + {0xB9, 0x6F, 0xEB, 0xB0, 0x65, 0x4C, 0xA5, 0xAE, 0xC1, 0xC5, 0xD1, + 0x8A, 0xBB, 0xC7, 0x6E, 0xDC, 0x5E, 0x07, 0x1A, 0xA9, 0x6A, 0x55, + 0x2F, 0x32, 0x92, 0xD9, 0x64, 0x15, 0x23, 0xC4, 0x35, 0xBE}}, + // c + {0xA2, 0xCD, 0xE2, 0x97, 0x82, 0xD2, 0xF4, 0x70, 0xEF, 0xD5, 0x27, + 0x8B, 0xC7, 0x00, 0x9C, 0xFC, 0x85, 0x91, 0x96, 0x91, 0xCB, 0xB1, + 0x4B, 0x7A, 0x8C, 0x2A, 0x93, 0xE5, 0xD0, 0x3D, 0x24, 0x7B}, + // sx + {0x63, 0x46, 0xAA, 0x98, 0x72, 0x57, 0xB3, 0xF5, 0xDB, 0x47, 0xD0, + 0x6A, 0xF0, 0x88, 0x90, 0xBD, 0x19, 0x58, 0x41, 0x5E, 0x58, 0xC7, + 0x64, 0x05, 0xDC, 0x57, 0x8F, 0x59, 0xEB, 0x24, 0xD9, 0x67}, + // sf + {0x25, 0x42, 0x17, 0x95, 0x4E, 0x39, 0xF4, 0x0C, 0x26, 0x8C, 0x5D, + 0xDC, 0xC4, 0x1B, 0x16, 0x47, 0xDD, 0x10, 0xB1, 0x7B, 0x11, 0xE8, + 0x53, 0x29, 0xBE, 0xA4, 0x35, 0xF3, 0x11, 0xB8, 0x5D, 0x46}, + // sa + {0x4E, 0xBD, 0xED, 0xE8, 0x6F, 0xC4, 0x6B, 0xCC, 0x3E, 0x00, 0x97, + 0x35, 0xF9, 0x73, 0xB7, 0x61, 0x3A, 0x24, 0x8B, 0xB8, 0xDC, 0xC5, + 0x26, 0xF5, 0x3C, 0xC1, 0x95, 0x31, 0xCD, 0xA6, 0x2A, 0x84}, + // sb + {0x92, 0xA3, 0x68, 0x1B, 0x61, 0x0C, 0xAF, 0x48, 0xF8, 0x2B, 0x38, + 0xE5, 0xB3, 0x7A, 0x52, 0x27, 0xBB, 0x9D, 0x18, 0x6E, 0xED, 0x6E, + 0x97, 0xF8, 0x61, 0x93, 0xCD, 0x96, 0x2E, 0x0B, 0x26, 0xCF}}; + const NativeBasicSignature expected_BaseSig = { + // B + {{0xB315D67E, 0x1924AE56, 0xCF527861, 0xEBB789B6, 0x3F429D2A, 0xB193BF9A, + 0x6BD8502F, 0x5E73BE39}, + {0x0BD51968, 0x0F13472D, 0xC96B5096, 0xA9CD4491, 0x4AB668CF, 0x2123D56C, + 0xF30AF180, 0x0DB43C33}}, + // K + {{0x9C3524E3, 0x4E4CA66B, 0x58731363, 0xB57BC920, 0x1317EBFA, 0xBD71A2D6, + 0x046B29FE, 0x64B5A803}, + {0x86A7A14A, 0xDE584912, 0xFEFD476A, 0x8559EF80, 0x34D8E1D2, 0x81F6BF1D, + 0xE0C42E4B, 0x477FEC10}}, + // T + {{0x444DB42F, 0xB57CFAA0, 0x3FB8C069, 0x3593EC91, 0xB968BBAA, 0x02D2BFBB, + 0xCF2E5D4A, 0xE57236B5}, + {0x23C435BE, 0x92D96415, 0x6A552F32, 0x5E071AA9, 0xBBC76EDC, 0xC1C5D18A, + 0x654CA5AE, 0xB96FEBB0}}, + // c + {0xD03D247B, 0x8C2A93E5, 0xCBB14B7A, 0x85919691, 0xC7009CFC, 0xEFD5278B, + 0x82D2F470, 0xA2CDE297}, + // xs + {0xEB24D967, 0xDC578F59, 0x58C76405, 0x1958415E, 0xF08890BD, 0xDB47D06A, + 0x7257B3F5, 0x6346AA98}, + // sf + {0x11B85D46, 0xBEA435F3, 0x11E85329, 0xDD10B17B, 0xC41B1647, 0x268C5DDC, + 0x4E39F40C, 0x25421795}, + // sa + {0xCDA62A84, 0x3CC19531, 0xDCC526F5, 0x3A248BB8, 0xF973B761, 0x3E009735, + 0x6FC46BCC, 0x4EBDEDE8}, + // sb + {0x2E0B26CF, 0x6193CD96, 0xED6E97F8, 0xBB9D186E, 0xB37A5227, 0xF82B38E5, + 0x610CAF48, 0x92A3681B}}; + NativeBasicSignature result = {0}; + BasicSignatureDeserialize(&result, &deserialized_BaseSig); + EXPECT_EQ(expected_BaseSig, result); +} + +////////////////////////////////////////////////////////////////////////// +// GroupPubKeySerialize Tests +TEST_F(EpidMemberTest, GroupPubKeySerializeWorks) { + NativeGroupPubKey const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + GroupPubKey const expected = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w + }; + GroupPubKey actual = {0}; + GroupPubKeySerialize(&actual, &input); + EXPECT_EQ(expected, actual); +} + +////////////////////////////////////////////////////////////////////////// +// GroupPubKeyDeserialize Tests +TEST_F(EpidMemberTest, GroupPubKeyDeserializeWorks) { + GroupPubKey const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w + }; + NativeGroupPubKey const expected = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + NativeGroupPubKey actual = {0}; + GroupPubKeyDeserialize(&actual, &input); + EXPECT_EQ(expected, actual); +} + +////////////////////////////////////////////////////////////////////////// +// PrivKeyDeserialize Tests +TEST_F(EpidMemberTest, PrivKeyDeserializeWorks) { + PrivKey const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, + 0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, + 0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, + {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, + 0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, + 0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, + 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, + 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7} // f + }; + NativePrivKey const expected = { + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, + 0x105eafd8, 0xa1e0d7df, 0x0a30ae43} // x + }, + {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356, + 0x6d47090b, 0x4840b56c} // f + }; + NativePrivKey actual = {0}; + PrivKeyDeserialize(&actual, &input); + EXPECT_EQ(expected, actual); +} + +////////////////////////////////////////////////////////////////////////// +// MembershipCredentialDeserialize Tests +TEST_F(EpidMemberTest, MembershipCredentialDeserializeWorks) { + MembershipCredential const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, + 0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, + 0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, + {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, + 0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, + 0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77} // x + }; + NativeMembershipCredential const expected = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8, + 0xa1e0d7df, 0x0a30ae43} // x + }; + NativeMembershipCredential actual = {0}; + MembershipCredentialDeserialize(&actual, &input); + EXPECT_EQ(expected, actual); +} + +} // namespace + +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/internal/signbasic-test.cc b/external/epid-sdk/epid/member/tiny/unittests/internal/signbasic-test.cc new file mode 100644 index 00000000..9c364ac0 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/internal/signbasic-test.cc @@ -0,0 +1,109 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief tiny SignBasic unit tests. + */ + +#ifndef SHARED +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/serialize.h" +#include "epid/member/tiny/src/signbasic.h" +#include "epid/verifier/api.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +namespace { + +///////////////////////////////////////////////////////////////////////// +// SignBasic + +TEST_F(EpidMemberTest, BasicSignaturesOfSameMessageAreDifferent) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + NativeBasicSignature basic_sig1 = {0}; + NativeBasicSignature basic_sig2 = {0}; + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig1)); + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig2)); + EXPECT_NE(0, memcmp(&basic_sig1, &basic_sig2, sizeof(NativeBasicSignature))); +} + +TEST_F(EpidMemberTest, SignBasicSucceedsUsingRandomBase) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + NativeBasicSignature native_basic_sig = {0}; + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &native_basic_sig)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + BasicSignature basic_sig = {0}; + BasicSignatureSerialize(&basic_sig, &native_basic_sig); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha512) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + NativeBasicSignature native_basic_sig = {0}; + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &native_basic_sig)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + BasicSignature basic_sig = {0}; + BasicSignatureSerialize(&basic_sig, &native_basic_sig); + EpidVerifierSetHashAlg(ctx, kSha512); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha256) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + NativeBasicSignature native_basic_sig = {0}; + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &native_basic_sig)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + BasicSignature basic_sig = {0}; + BasicSignatureSerialize(&basic_sig, &native_basic_sig); + EpidVerifierSetHashAlg(ctx, kSha256); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} + +} // namespace +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/internal/validate-test.cc b/external/epid-sdk/epid/member/tiny/unittests/internal/validate-test.cc new file mode 100644 index 00000000..b0909596 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/internal/validate-test.cc @@ -0,0 +1,317 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief native type validation unit tests. + * + * \warning to run the tests in this file you must build a non-shared mode. + */ + +#ifndef SHARED + +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/common/types.h" +#include "epid/member/tiny/math/pairing.h" +#include "epid/member/tiny/src/native_types.h" +#include "epid/member/tiny/src/validate.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// GroupPubKeyIsInRange Tests +TEST_F(EpidMemberTest, GroupPubKeyIsInRangePasses) { + NativeGroupPubKey const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_TRUE(GroupPubKeyIsInRange(&input)); +} + +TEST_F(EpidMemberTest, GroupPubKeyIsInRangeFails) { + NativeGroupPubKey const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}}, //< q + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_FALSE(GroupPubKeyIsInRange(&input)); +} + +////////////////////////////////////////////////////////////////////////// +// MembershipCredentialIsInRange Tests +TEST_F(EpidMemberTest, MembershipCredentialIsInRangePasses) { + NativeMembershipCredential const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8, + 0xa1e0d7df, 0x0a30ae43} // x + }; + EXPECT_TRUE(MembershipCredentialIsInRange(&input)); +} + +TEST_F(EpidMemberTest, MembershipCredentialIsInRangeFails) { + NativeMembershipCredential const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}}, //< q + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8, + 0xa1e0d7df, 0x0a30ae43} // x + }; + EXPECT_FALSE(MembershipCredentialIsInRange(&input)); +} + +////////////////////////////////////////////////////////////////////////// +// MembershipCredentialIsInGroup Tests +TEST_F(EpidMemberTest, MembershipCredentialIsInGroupPasses) { + PairingState pairing_state; + PairingInit(&pairing_state); + NativeMembershipCredential const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8, + 0xa1e0d7df, 0x0a30ae43} // x + }; + FpElem const f = {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, + 0xe07cc68e, 0x05d64356, 0x6d47090b, 0x4840b56c}; // f + NativeGroupPubKey const pubkey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_TRUE( + MembershipCredentialIsInGroup(&input, &f, &pubkey, &pairing_state)); +} + +TEST_F(EpidMemberTest, MembershipCredentialIsInGroupFails) { + PairingState pairing_state; + PairingInit(&pairing_state); + NativeMembershipCredential const input = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8, + 0xa1e0d7df, 0x0a30ae43} // x + }; + FpElem const f = {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, + 0xe07cc68e, 0x05d64356, 0x6d47090b, 0x4840b56c}; // f + NativeGroupPubKey const pubkey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_FALSE( + MembershipCredentialIsInGroup(&input, &f, &pubkey, &pairing_state)); +} + +////////////////////////////////////////////////////////////////////////// +// PrivKeyIsInRange Tests +TEST_F(EpidMemberTest, PrivKeyIsInRangePasses) { + NativePrivKey const input = { + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, + 0x105eafd8, 0xa1e0d7df, 0x0a30ae43} // x + }, + {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356, + 0x6d47090b, 0x4840b56c} // f + }; + EXPECT_TRUE(PrivKeyIsInRange(&input)); +} + +TEST_F(EpidMemberTest, PrivKeyIsInRangeRangeFails) { + NativePrivKey const input = { + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xAED33013, 0xD3292DDB, 0x12980A82, 0x0CDC65FB, 0xEE71A49F, + 0x46E5F25E, 0xFFFCF0CD, 0xFFFFFFFF}}}, //< q + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, + 0x105eafd8, 0xa1e0d7df, 0x0a30ae43} // x + }, + {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356, + 0x6d47090b, 0x4840b56c} // f + }; + EXPECT_FALSE(PrivKeyIsInRange(&input)); +} + +////////////////////////////////////////////////////////////////////////// +// PrivKeyIsInGroup Tests +TEST_F(EpidMemberTest, PrivKeyIsInGroupPasses) { + PairingState pairing_state; + PairingInit(&pairing_state); + NativePrivKey const input = { + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, + 0x105eafd8, 0xa1e0d7df, 0x0a30ae43} // x + }, + {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356, + 0x6d47090b, 0x4840b56c} // f + }; + NativeGroupPubKey const pubkey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_TRUE(PrivKeyIsInGroup(&input, &pubkey, &pairing_state)); +} + +TEST_F(EpidMemberTest, PrivKeyIsInGroupFails) { + PairingState pairing_state; + PairingInit(&pairing_state); + NativePrivKey const input = { + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02}, // group id + {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a, + 0xacbfdd77, 0xf468e15f, 0x46c969ee}}}, + {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f, + 0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}}, // A + {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, + 0x105eafd8, 0xa1e0d7df, 0x0a30ae43} // x + }, + {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356, + 0x6d47090b, 0x4840b56c} // f + }; + NativeGroupPubKey const pubkey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb, + 0x3d753d61, 0xe21b17eb, 0xb36fff81}}}, + {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c, + 0xfdb5b79d, 0xe08859a4, 0x3a075680}}}}, // h1 + {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b, + 0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}}, + {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b, + 0x48120aa6, 0xe314ac72, 0x765dc06e}}}}, // h2 + {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6, + 0x50719451, 0xe20fca1c, 0xbd195a95}}}, + {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8, + 0xa6657a68, 0xb86ae7e5, 0xca78115b}}}}, + {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a, + 0xbc077230, 0xe8b3c725, 0x9021a7e0}}}, + {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2, + 0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}}; + EXPECT_FALSE(PrivKeyIsInGroup(&input, &pubkey, &pairing_state)); +} + +} // namespace + +#endif // SHARED diff --git a/external/epid-sdk/epid/member/tiny/unittests/join_request-test.cc b/external/epid-sdk/epid/member/tiny/unittests/join_request-test.cc new file mode 100644 index 00000000..9d45d8d6 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/join_request-test.cc @@ -0,0 +1,369 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Join Request related unit tests. + */ + +#include +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/member/api.h" +} + +#include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" +#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +/// compares FpElemStr values +bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// compares JoinRequest values +bool operator==(JoinRequest const& lhs, JoinRequest const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// compares JoinRequest values for inequality +bool operator!=(JoinRequest const& lhs, JoinRequest const& rhs) { + return 0 != std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +namespace { + +// local constant for Join Request tests. This can be hoisted later if needed +// avoids cpplint warning about multiple includes. +const GroupPubKey kPubKey = { +#include "epid/common-testhelper/testdata/grp01/gpubkey.inc" +}; + +const FpElemStr kFEps1 = {0x56, 0x57, 0xda, 0x39, 0x9f, 0x69, 0x17, 0x84, + 0xac, 0xf9, 0xf6, 0xdf, 0xfe, 0xd2, 0x41, 0xe8, + 0x02, 0x30, 0xf8, 0xd8, 0x72, 0x35, 0xd3, 0x0e, + 0x76, 0x2e, 0xda, 0x4b, 0xf4, 0xc5, 0x31, 0x0f}; +/// Validates join request. +void ValidateJoinRequest(JoinRequest const& request, HashAlg hash_alg, + GroupPubKey const& grp_public_key, FpElemStr const& f, + IssuerNonce const& ni) { + Epid2Params params_values = { +#include "epid/common/src/epid2params_ate.inc" + }; + + Epid20Params params; + + // h1^f ?= F + EcPointObj F_expected(¶ms.G1, grp_public_key.h1); + THROW_ON_EPIDERR(EcExp(params.G1, F_expected, (BigNumStr*)&f, F_expected)); + ASSERT_EQ(*(G1ElemStr*)(F_expected.data().data()), request.F); + + // H(p|g1|g2|h1|h2|w|F|R|ni) ?= c, where R = h1^s * F^(-c) + FfElementObj nc(¶ms.fp, request.c); + THROW_ON_EPIDERR(FfNeg(params.fp, nc, nc)); + EcPointObj a(¶ms.G1, grp_public_key.h1); + EcPointObj b(¶ms.G1, request.F); + THROW_ON_EPIDERR(EcExp(params.G1, a, (BigNumStr*)&request.s, a)); + THROW_ON_EPIDERR(EcExp(params.G1, b, (BigNumStr*)nc.data().data(), b)); + THROW_ON_EPIDERR(EcMul(params.G1, a, b, a)); + +#pragma pack(1) + struct { + BigNumStr p; // Intel(R) EPID 2.0 parameter p + G1ElemStr g1; // Intel(R) EPID 2.0 parameter g1 + G2ElemStr g2; // Intel(R) EPID 2.0 parameter g2 + G1ElemStr h1; // Group public key value h1 + G1ElemStr h2; // Group public key value h2 + G2ElemStr w; // Group public key value w + G1ElemStr F; // Variable F computed in algorithm + G1ElemStr R; // Variable R computed in algorithm + IssuerNonce NI; // Issuer Nonce + } commitment_values = {params_values.p, + params_values.g1, + params_values.g2, + grp_public_key.h1, + grp_public_key.h2, + grp_public_key.w, + request.F, + *(G1ElemStr*)(a.data().data()), + ni}; +#pragma pack() + + FfElementObj commitment(¶ms.fp); + THROW_ON_EPIDERR(FfHash(params.fp, &commitment_values, + sizeof commitment_values, hash_alg, commitment)); + ASSERT_EQ(*(FpElemStr*)(commitment.data().data()), request.c); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenNullParameters) { + GroupPubKey pub_key = kPubKey; + IssuerNonce ni; + MemberParams params; + Prng prng; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj ctx(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(nullptr, &pub_key, &ni, &join_request)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(ctx, nullptr, &ni, &join_request)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(ctx, &pub_key, nullptr, &join_request)); + EXPECT_EQ(kEpidBadArgErr, EpidCreateJoinRequest(ctx, &pub_key, &ni, nullptr)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenNoF) { + GroupPubKey pub_key = kPubKey; + IssuerNonce ni; + MemberParams params; + Prng prng; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj ctx(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(ctx, &pub_key, &ni, &join_request)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenInvalidGroupKey) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + pub_key.h1.x.data.data[15] = 0xff; + Epid20Params epid_params; + EcPointObj pt(&epid_params.G1); + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + ASSERT_NE(kEpidNoErr, ReadEcPoint(epid_params.G1, (uint8_t*)&pub_key.h1, + sizeof(pub_key.h1), pt)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenInvalidFValue) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + EpidStatus sts; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + + std::unique_ptr member; + size_t context_size = 0; + sts = EpidMemberGetSize(¶ms, &context_size); + EXPECT_TRUE(kEpidNoErr == sts || kEpidBadArgErr == sts) + << "Actual value " << sts; + + if (kEpidNoErr == sts) { + member.reset(new uint8_t[context_size]()); + sts = EpidMemberInit(¶ms, (MemberCtx*)member.get()); + EXPECT_TRUE(kEpidNoErr == sts || kEpidBadArgErr == sts) + << "Actual value " << sts; + } + + if (kEpidNoErr == sts) { + sts = EpidCreateJoinRequest((MemberCtx*)member.get(), &pub_key, &ni, + &join_request); + EXPECT_EQ(kEpidBadArgErr, sts); + } + + EpidMemberDeinit((MemberCtx*)member.get()); +} + +TEST_F(EpidMemberTest, CreateJoinRequestWorksUsingSha512) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha512, pub_key, f, ni)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestWorksUsingSha256) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha256, pub_key, f, ni)); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestGeneratesDiffJoinRequestsOnMultipleCalls) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request1; + JoinRequest join_request2; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request1)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request1, kSha512, pub_key, f, ni)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request2)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request2, kSha512, pub_key, f, ni)); + EXPECT_NE(join_request1, join_request2); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestGeneratesDiffJoinRequestsGivenDiffHashAlgs) { + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request1; + JoinRequest join_request2; + // Ensure that two members created with equal seed and do not + // interfere each other. Member1 is deleted by the time member2 + // is created. + { + Prng prng; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member1(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member1, kSha256)); + prng.set_seed(0x1234); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member1, &pub_key, &ni, &join_request1)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request1, kSha256, pub_key, f, ni)); + } + { + Prng prng; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member2(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member2, kSha512)); + prng.set_seed(0x1234); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member2, &pub_key, &ni, &join_request2)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request2, kSha512, pub_key, f, ni)); + } + EXPECT_NE(join_request1, join_request2); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestWorksGivenValidParametersUsingIKGFData) { + Prng prng; + MemberParams params = {0}; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha512, *pub_key, f, ni)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/main-testhelper.cc b/external/epid-sdk/epid/member/tiny/unittests/main-testhelper.cc new file mode 100644 index 00000000..2ea1d21a --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/main-testhelper.cc @@ -0,0 +1,24 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Main entry point for tiny member unit tests +/*! \file */ + +#include + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.cc b/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.cc new file mode 100644 index 00000000..870b29c1 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.cc @@ -0,0 +1,468 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief EpidMemberTest test fixture implementation. + */ + +#include "epid/member/tiny/unittests/member-testhelper.h" + +#include +#include +#include + +extern "C" { +#include "epid/common/types.h" +#include "epid/member/tiny/src/native_types.h" +} + +#include "epid/common-testhelper/mem_params-testhelper.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// compares G1ElemStr values +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// Arbitrary test data were generated based on Intel(R) EPID 2.0 parameters +const GroupPubKey EpidMemberTest::kGroupPublicKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w +}; + +const PrivKey EpidMemberTest::kMemberPrivateKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, + 0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, + 0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, + {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, + 0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, + 0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, + 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, + 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7} // f +}; + +const MemberPrecomp EpidMemberTest::kMemberPrecomp = { + {0xd8, 0x14, 0xba, 0x4b, 0x44, 0x03, 0x55, 0x6c, 0xf6, 0x42, 0xe8, + 0xf0, 0x4c, 0xb5, 0xe7, 0xd4, 0xa2, 0xa3, 0x69, 0x47, 0xf5, 0xd4, + 0xc8, 0xe9, 0xc5, 0x5a, 0x39, 0xb5, 0x55, 0xa5, 0xd3, 0xfb, 0xf3, + 0x85, 0x5a, 0x0d, 0xd5, 0xee, 0xde, 0xf4, 0xa8, 0xb1, 0x8b, 0xcf, + 0xa9, 0x0d, 0x29, 0xbf, 0x86, 0x27, 0x9c, 0x1f, 0x96, 0xed, 0xd8, + 0x44, 0x01, 0x35, 0x1a, 0xce, 0xfd, 0x4e, 0x6f, 0xa1, 0x66, 0x0d, + 0x59, 0x08, 0x6d, 0xa2, 0xe4, 0x99, 0x83, 0xdc, 0x39, 0x28, 0xb7, + 0x1c, 0x1a, 0x33, 0xad, 0xca, 0x5c, 0x35, 0x26, 0x1f, 0xab, 0xba, + 0x0d, 0x53, 0xaf, 0xe0, 0x72, 0x14, 0xc5, 0xa7, 0x2e, 0x58, 0x26, + 0xc9, 0x8e, 0xfa, 0x6f, 0x62, 0xfc, 0xf0, 0x08, 0x3e, 0xa3, 0x11, + 0x3a, 0xf0, 0xb8, 0x3b, 0x2d, 0x3e, 0xec, 0xd5, 0xbc, 0xf2, 0x05, + 0x68, 0xf4, 0x40, 0xce, 0x2c, 0x8f, 0xdd, 0xa4, 0xe5, 0xe1, 0xb5, + 0xbe, 0xbd, 0x3e, 0xd4, 0xf6, 0x9a, 0xb3, 0x37, 0x24, 0x0d, 0xea, + 0x13, 0xd7, 0x1f, 0xa2, 0x75, 0x68, 0xa1, 0xbe, 0x2c, 0x01, 0x42, + 0x2a, 0xae, 0x6f, 0xae, 0x7a, 0x72, 0x3a, 0x11, 0x03, 0x58, 0x02, + 0x0d, 0xf0, 0xb0, 0xd9, 0x6f, 0xb1, 0xe4, 0xf2, 0x70, 0xb8, 0xff, + 0x22, 0x56, 0x7c, 0xb3, 0x80, 0xfd, 0xdf, 0xe5, 0xab, 0xcc, 0x18, + 0x7a, 0xfd, 0x91, 0xd0, 0xb0, 0x63, 0x40, 0xd4, 0x71, 0xfa, 0x03, + 0xf5, 0xf1, 0x26, 0xe1, 0xa5, 0x5a, 0xd9, 0x6d, 0xf5, 0x5a, 0x7b, + 0x2a, 0x3a, 0xfe, 0x94, 0x9e, 0x74, 0x41, 0x79, 0x49, 0x7e, 0x48, + 0x1d, 0x58, 0x5e, 0xf6, 0x98, 0xa3, 0x6e, 0x61, 0x8e, 0x9f, 0x1f, + 0xcd, 0x15, 0x01, 0x16, 0xa5, 0xe0, 0xab, 0xd6, 0xd6, 0x1f, 0x1c, + 0xf5, 0x81, 0x76, 0xc1, 0xec, 0x10, 0xc2, 0xcc, 0x68, 0x59, 0x4d, + 0x47, 0xef, 0x4b, 0x7f, 0xd8, 0x78, 0x9c, 0xfe, 0x9a, 0x86, 0x7e, + 0x0c, 0xfd, 0x3e, 0x0a, 0x7a, 0x72, 0x8b, 0x14, 0x5f, 0xe6, 0x5f, + 0x19, 0xa3, 0x0a, 0x1b, 0x71, 0xdc, 0xd2, 0xae, 0x35, 0xc3, 0x11, + 0xa5, 0xd3, 0xea, 0xe1, 0xa9, 0xe7, 0x70, 0x0c, 0x7a, 0x39, 0x56, + 0x3c, 0xe4, 0xe7, 0xf9, 0xb6, 0xf1, 0x15, 0x40, 0xab, 0xb6, 0xc4, + 0xad, 0xbd, 0xf4, 0xcc, 0x13, 0xb7, 0xa8, 0xb6, 0x92, 0x1e, 0x72, + 0x27, 0xa7, 0xff, 0xd9, 0xea, 0x2f, 0x91, 0x96, 0x22, 0xd2, 0xc4, + 0x4d, 0x80, 0xdc, 0x47, 0x66, 0x87, 0xcc, 0xcf, 0xc5, 0x64, 0xf7, + 0xb2, 0x34, 0xed, 0xd5, 0x44, 0x44, 0xcc, 0x57, 0x41, 0xc7, 0x92, + 0xb7, 0x5c, 0x12, 0xf7, 0x81, 0xf2, 0x92, 0x35, 0x3e, 0x4b, 0xdf, + 0xf8, 0xda, 0x68, 0xac, 0x30, 0xe3, 0xdd, 0x9e, 0x22, 0xaa, 0x6d, + 0x77, 0xdd, 0xac, 0xd9, 0x11, 0x6e, 0xfb, 0x1a, 0x88, 0xb3}, // e12 + { + 0x07, 0x3f, 0x9d, 0x47, 0x82, 0xb8, 0x3d, 0x6a, 0xe0, 0x36, 0xab, 0xa6, + 0xfa, 0xe6, 0xd2, 0x1c, 0xc8, 0xb2, 0xd0, 0x01, 0xd4, 0x96, 0xdc, 0x2e, + 0xf8, 0x19, 0xdc, 0x70, 0x1b, 0xf9, 0x73, 0x0c, 0x2b, 0xc2, 0xe2, 0x1d, + 0x85, 0x53, 0x81, 0x51, 0xfb, 0xca, 0x16, 0x86, 0xd4, 0x4e, 0xfd, 0x1a, + 0x59, 0xe3, 0x97, 0xc4, 0x7f, 0x99, 0xd8, 0x66, 0x08, 0xa1, 0xe4, 0x9f, + 0xbb, 0x3a, 0xce, 0xa5, 0x23, 0x9c, 0x83, 0x13, 0xc5, 0xc8, 0xf2, 0x16, + 0x1e, 0xe8, 0xe6, 0xc5, 0x36, 0x57, 0x2c, 0xdf, 0x73, 0xb4, 0xe2, 0xb2, + 0xcb, 0xeb, 0xbb, 0xf7, 0x45, 0xd1, 0x44, 0xbd, 0x6e, 0x92, 0x95, 0x00, + 0xe5, 0x89, 0xb5, 0x91, 0x78, 0xc7, 0x44, 0xb1, 0x2f, 0x37, 0xdf, 0xfb, + 0xe7, 0x8a, 0x44, 0x3f, 0x3d, 0x06, 0x5f, 0x5b, 0x1c, 0x5f, 0xce, 0x11, + 0x05, 0x35, 0x3c, 0xad, 0x92, 0x7e, 0x79, 0xb8, 0xff, 0x28, 0x05, 0xe4, + 0x04, 0x2c, 0xb6, 0x1d, 0x22, 0xab, 0x36, 0x00, 0x5f, 0x74, 0xf1, 0xe3, + 0xf6, 0xa6, 0x68, 0xe6, 0x7b, 0x25, 0xb8, 0xcf, 0x19, 0xb0, 0x1a, 0xdd, + 0x0f, 0xad, 0x63, 0x73, 0x62, 0x1b, 0xe7, 0x94, 0x5d, 0xbf, 0x3d, 0xf1, + 0xf9, 0x8e, 0xab, 0x59, 0xe5, 0xd1, 0x7c, 0x62, 0xdd, 0xbc, 0x40, 0x07, + 0x70, 0x5b, 0x13, 0xf6, 0x12, 0x09, 0xb4, 0x0d, 0x3e, 0xab, 0x8b, 0x70, + 0x60, 0x1d, 0xd4, 0x61, 0x37, 0x28, 0x98, 0x3e, 0x7e, 0xdc, 0xfd, 0xd2, + 0xc0, 0x2f, 0x4b, 0x71, 0x31, 0x34, 0xd7, 0x69, 0x41, 0x5e, 0xaa, 0x72, + 0xe4, 0xdf, 0xeb, 0xfe, 0x8d, 0xcd, 0x68, 0xfc, 0x68, 0x55, 0xbe, 0x32, + 0x7d, 0x24, 0xc5, 0x07, 0x0f, 0xa8, 0xbd, 0x5a, 0xfe, 0xe7, 0xec, 0xdb, + 0xfd, 0x19, 0xc8, 0xa9, 0x20, 0xa2, 0x7f, 0x6c, 0xa6, 0x62, 0xec, 0xed, + 0x9b, 0x79, 0xbf, 0x9c, 0x0e, 0x31, 0x0b, 0x25, 0x2f, 0xd3, 0xcc, 0xa0, + 0xdd, 0xb2, 0xf2, 0x69, 0x26, 0x85, 0x21, 0x06, 0x94, 0x56, 0x5f, 0x59, + 0x5c, 0xf5, 0xb7, 0x82, 0xce, 0x0f, 0xdd, 0x40, 0xdb, 0x83, 0xac, 0x3c, + 0x41, 0xa0, 0x1b, 0xb1, 0xaf, 0xda, 0x55, 0xbf, 0x6b, 0x1a, 0xef, 0xe6, + 0x90, 0xe7, 0xaa, 0x0f, 0x04, 0x3c, 0x9f, 0x5b, 0xb7, 0xcd, 0x98, 0xa8, + 0x9e, 0xff, 0x54, 0x26, 0xc8, 0xd5, 0x5c, 0x30, 0x5e, 0xa2, 0x99, 0x8e, + 0x34, 0xd5, 0x98, 0x9f, 0xcd, 0x57, 0xd1, 0x4d, 0x1d, 0xee, 0x01, 0x5d, + 0x5a, 0x6d, 0xb2, 0xf1, 0xcf, 0x4b, 0xc0, 0x21, 0x23, 0x96, 0x05, 0xf9, + 0xc9, 0x66, 0xe5, 0x25, 0x9d, 0xa3, 0x8e, 0x78, 0x43, 0x19, 0xc1, 0x7f, + 0x7b, 0xef, 0xf5, 0xed, 0x00, 0xb7, 0x45, 0x1f, 0x4e, 0xa9, 0xfa, 0xe3, + 0xff, 0x54, 0xf2, 0x21, 0x73, 0xf8, 0x6b, 0xa1, 0xc7, 0x31, 0x4d, 0x6a, + }, // e22 + { + 0x49, 0x0d, 0x0f, 0x2a, 0x5c, 0x6a, 0x3b, 0xad, 0x71, 0xc9, 0x22, 0x49, + 0xe8, 0x08, 0xdd, 0xba, 0x79, 0x57, 0xb7, 0xc7, 0x61, 0xe4, 0xdb, 0x84, + 0x68, 0x57, 0xb9, 0x30, 0x83, 0xa4, 0xdc, 0xef, 0x70, 0x93, 0x28, 0xe2, + 0x6f, 0xb9, 0xbc, 0x15, 0x28, 0x3a, 0x30, 0xbd, 0x96, 0x83, 0xdb, 0xf2, + 0x9d, 0x1e, 0xc7, 0x64, 0x6d, 0x2e, 0x7c, 0xa2, 0xf3, 0xaa, 0x2f, 0x4b, + 0x6d, 0x86, 0x9e, 0x48, 0x20, 0x29, 0x4b, 0x1f, 0x8d, 0xc2, 0x93, 0xc3, + 0x55, 0x25, 0x8e, 0xb0, 0x8a, 0x7e, 0x64, 0x45, 0x3f, 0xf4, 0x1d, 0x16, + 0x4c, 0x88, 0x2d, 0x54, 0xbe, 0xa8, 0x67, 0x70, 0x81, 0xc5, 0xb9, 0x5c, + 0x16, 0x00, 0xef, 0x78, 0xf6, 0x4d, 0x6a, 0xeb, 0xfd, 0xa2, 0x0d, 0x52, + 0x86, 0xf3, 0x04, 0x4b, 0xd8, 0xf0, 0x7d, 0x50, 0x8b, 0xad, 0xc0, 0x37, + 0xdb, 0x38, 0xf2, 0x7d, 0x1f, 0x8b, 0x13, 0x83, 0x7b, 0xcc, 0xe8, 0x25, + 0xfe, 0xfa, 0x0c, 0x02, 0x05, 0x2e, 0x75, 0x12, 0xa1, 0x0a, 0x89, 0xab, + 0xf1, 0xb2, 0x08, 0x47, 0x9a, 0xea, 0xef, 0x1d, 0xa4, 0x9f, 0xde, 0x89, + 0x47, 0x3e, 0x7c, 0x5e, 0x4a, 0x40, 0xdc, 0xec, 0xc5, 0x1b, 0x7e, 0x33, + 0x0a, 0x19, 0x69, 0x27, 0xa6, 0xcc, 0x25, 0xfc, 0xf9, 0xeb, 0xbd, 0xb7, + 0x8a, 0xdb, 0x45, 0x5f, 0x9d, 0x9e, 0x01, 0xde, 0x3d, 0x91, 0x10, 0x99, + 0x13, 0xbf, 0xc0, 0xfa, 0x9d, 0xd4, 0x0f, 0xb3, 0x09, 0xf3, 0xa1, 0xae, + 0x68, 0xe1, 0x1b, 0x48, 0x85, 0x9f, 0x81, 0x66, 0x91, 0xe2, 0xf0, 0x7b, + 0x29, 0xdb, 0x8f, 0x5d, 0x99, 0xa9, 0xd3, 0x39, 0x30, 0xd9, 0x1b, 0x94, + 0x2a, 0x1c, 0x5c, 0xe9, 0xc0, 0x3f, 0x6e, 0xb2, 0x27, 0xbe, 0x74, 0x7a, + 0xca, 0xe1, 0x0f, 0x6a, 0x43, 0x2e, 0x98, 0x65, 0xaf, 0x7f, 0x6e, 0x5a, + 0x55, 0x98, 0xc1, 0x58, 0x29, 0xb3, 0x86, 0x54, 0x0f, 0x57, 0x91, 0x89, + 0x29, 0xb1, 0x98, 0x79, 0xcc, 0x95, 0x39, 0xd0, 0xab, 0xe0, 0x9f, 0xf3, + 0xda, 0xf9, 0x5e, 0xd9, 0x34, 0xbb, 0x72, 0xda, 0xe5, 0x72, 0xd3, 0xf8, + 0x9b, 0xf9, 0x14, 0x84, 0x48, 0x81, 0x54, 0x4f, 0xe6, 0x2b, 0x80, 0xc8, + 0xc1, 0x79, 0xfe, 0x83, 0xff, 0x76, 0xa3, 0x6d, 0xfe, 0x37, 0x78, 0xc5, + 0x30, 0x7a, 0x50, 0xe2, 0x5d, 0x12, 0xdc, 0x72, 0xe9, 0x58, 0x7c, 0x07, + 0x4f, 0xff, 0x15, 0x8a, 0x97, 0x3b, 0xcb, 0x60, 0xfa, 0x4e, 0xde, 0x8c, + 0x80, 0x3a, 0x8b, 0x0b, 0xc6, 0x1d, 0xa3, 0xce, 0x6a, 0xb3, 0x50, 0x69, + 0x03, 0x96, 0xca, 0xc0, 0xb6, 0x94, 0x6f, 0x8f, 0xab, 0x6f, 0x5b, 0x00, + 0x2a, 0x1d, 0x90, 0xa7, 0x81, 0xc6, 0x15, 0x77, 0x79, 0xf3, 0x36, 0x23, + 0xd1, 0x46, 0x25, 0x58, 0x6f, 0x7b, 0x22, 0xac, 0x4c, 0x7a, 0xf3, 0x9f, + }, // e2w + { + 0x8d, 0x71, 0xe2, 0xb0, 0x73, 0x2f, 0x4a, 0xba, 0x64, 0xe8, 0x7a, 0x12, + 0xaf, 0xe4, 0x4f, 0xdb, 0x6b, 0x3e, 0x38, 0x07, 0x0c, 0x79, 0x22, 0x48, + 0x1b, 0x9d, 0x33, 0x53, 0x5c, 0x75, 0x3b, 0x40, 0x5e, 0x18, 0xd1, 0x92, + 0x4a, 0xd1, 0x82, 0x1c, 0xc7, 0x3a, 0xf7, 0x7e, 0x32, 0x19, 0x99, 0x5d, + 0x01, 0x0e, 0xb0, 0xf2, 0x8f, 0x80, 0xc6, 0xb9, 0xeb, 0x1f, 0x9e, 0xae, + 0x9e, 0xe0, 0x99, 0xfd, 0xe8, 0x93, 0x11, 0x61, 0x7d, 0xc2, 0x49, 0xdb, + 0xa8, 0x73, 0xa4, 0xa9, 0x33, 0xe2, 0x04, 0xd1, 0x7d, 0x8b, 0xe1, 0xd6, + 0x2b, 0x10, 0x6c, 0x79, 0x02, 0xbf, 0xfc, 0x53, 0x03, 0xa9, 0xbc, 0x30, + 0x4d, 0x4d, 0xf4, 0x32, 0xce, 0x9a, 0x4a, 0xfa, 0xd6, 0x7f, 0x26, 0x17, + 0xc5, 0xf6, 0xed, 0xe4, 0xcc, 0xb9, 0x79, 0xe2, 0xa8, 0x86, 0xbb, 0xd7, + 0xfb, 0x05, 0xd2, 0x81, 0xbe, 0x07, 0x1c, 0x47, 0x48, 0x4f, 0x6d, 0x6b, + 0x52, 0x42, 0xe4, 0xc6, 0x20, 0x46, 0xa3, 0xae, 0x5b, 0x55, 0x55, 0xfe, + 0x4a, 0xad, 0xf2, 0x32, 0x07, 0x0f, 0x91, 0xa9, 0xe5, 0xd3, 0x86, 0x08, + 0x73, 0x93, 0xc7, 0x1e, 0x6b, 0xcd, 0x69, 0xd0, 0xfb, 0xc1, 0x74, 0xc2, + 0xb8, 0x90, 0xc8, 0xf8, 0x93, 0xbf, 0x08, 0x0f, 0x15, 0x19, 0x26, 0x71, + 0x4a, 0x9e, 0xdf, 0xdf, 0xca, 0x6f, 0xca, 0xfd, 0x67, 0xec, 0x4d, 0x21, + 0x5b, 0x99, 0xbd, 0x4b, 0x79, 0x22, 0x2d, 0xe4, 0x24, 0x72, 0x88, 0x93, + 0xce, 0xe6, 0x7f, 0xef, 0x35, 0x83, 0x67, 0x39, 0xb9, 0x34, 0x80, 0x64, + 0x0a, 0xf4, 0xff, 0x42, 0x9d, 0xee, 0xda, 0xb8, 0xd3, 0xdc, 0x1d, 0x0d, + 0x9f, 0x45, 0xe9, 0xbe, 0xf4, 0x3e, 0xa6, 0x58, 0x8b, 0xf0, 0xfd, 0x01, + 0x73, 0x63, 0xd0, 0xc6, 0x9d, 0xb9, 0x32, 0xd1, 0x91, 0xfe, 0xb1, 0xf5, + 0x4b, 0x48, 0xb4, 0x46, 0xae, 0x61, 0xd7, 0x90, 0xfe, 0x86, 0x74, 0x68, + 0xee, 0x78, 0x86, 0x65, 0x99, 0x6d, 0x7b, 0xf0, 0x17, 0x1a, 0x4c, 0xb0, + 0x37, 0x73, 0xdc, 0x38, 0x41, 0xfa, 0x02, 0xd2, 0x13, 0x8f, 0x71, 0xb4, + 0x0a, 0x72, 0x70, 0x0f, 0xe1, 0x2c, 0x9a, 0xa9, 0x51, 0xfa, 0xb2, 0xbf, + 0x84, 0xf2, 0xa6, 0xfb, 0xc3, 0x83, 0x16, 0x7e, 0x27, 0xec, 0x06, 0x5d, + 0x64, 0x79, 0xe7, 0x42, 0x30, 0xf8, 0x2d, 0xbc, 0x0f, 0x07, 0x8b, 0xf2, + 0x99, 0xda, 0x91, 0x4c, 0x65, 0xcf, 0x7f, 0x57, 0x2d, 0x2f, 0x67, 0xe7, + 0xfb, 0x75, 0xe9, 0xb2, 0xa3, 0x72, 0x60, 0x88, 0x2b, 0x14, 0x31, 0x62, + 0xbc, 0x45, 0x59, 0x5c, 0x58, 0x39, 0xb3, 0x4a, 0xeb, 0xb9, 0x18, 0x24, + 0x05, 0xcb, 0xda, 0xd3, 0x5e, 0x54, 0xba, 0xda, 0xfd, 0xfc, 0xa0, 0x02, + 0xb3, 0xde, 0x52, 0x3e, 0xc0, 0xd0, 0xb8, 0x19, 0x85, 0x1b, 0x7b, 0xe3, + } // ea2 +}; +const NativeBasicSignature EpidMemberTest::kBasicSig = { + // B + {{0xD2E7034F, 0xDE132705, 0x532E403A, 0x9D6C5CAB, 0x6AA4231B, 0x16C48B8A, + 0x3784FC01, 0x1A4456B3}, + {0xD0BB1EEC, 0x417952E2, 0x71755350, 0xE39B1B6F, 0x10ABCD80, 0x89EAF58F, + 0xE68604BC, 0x1F308883}}, + // K + {{0x7BA80706, 0x3A0326CB, 0xBFB2C975, 0xF362D12D, 0xBD15EC31, 0x832BB024, + 0x583ED765, 0x6F6C3E01}, + {0xFBEDFF07, 0x4450A702, 0xB80EAC00, 0x6B2E31AE, 0xE49B1639, 0xC7E70FED, + 0x2FEC671D, 0x923A7258}}, + // T + {{0x931C950D, 0xEF075B6B, 0x126CB51A, 0x6278696A, 0xB5BEE13B, 0x2D682765, + 0xA9C2B37D, 0xCDECCBBA}, + {0xE8953E8D, 0x151E3984, 0x276EC430, 0x33327946, 0x7F32E500, 0x07C3D873, + 0x27E7E4D3, 0xFA0A9ED2}}, + // c + {0x2FDCAC88, 0x432C5EC5, 0x532F10A9, 0x5FE27AF0, 0xEE0657AB, 0x97884AF7, + 0x0897633B, 0xE5C33EEF}, + // sx + {0x86639266, 0x80D60A98, 0x80AB6BB6, 0x87066083, 0x9D029C65, 0xD7550AE6, + 0x94D81487, 0xD9FDF300}, + // sf + {0xCD23A7BC, 0x2C2F28D5, 0xDCC46E40, 0x951B6719, 0x988B676D, 0xD7DC015A, + 0xEBBEA941, 0xAAEFA83A}, + // sa + {0xB706055E, 0xA1280802, 0xE9EB52AF, 0x1D147522, 0x952A12B2, 0x7744D263, + 0x76E80259, 0x55422EA1}, + // sb + {0xF8EE5D60, 0xDB85B38E, 0xD57C2B9F, 0x3F0A58C0, 0x3A0AB12C, 0xB9971C02, + 0x69E22FF7, 0xBAAF3219}}; + +const std::vector EpidMemberTest::kGroupPublicKeyDataIkgf = { +#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" +}; +const std::vector EpidMemberTest::kMemberPrivateKeyDataIkgf = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" +}; + +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha256 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc" +}; +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha384 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc" +}; +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha512 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc" +}; +const std::vector EpidMemberTest::kTest1Msg = {'t', 'e', 's', 't', + '1'}; +std::vector EpidMemberTest::kSigRlData = { +#include "epid/common-testhelper/testdata/grp01/sigrl.inc" +}; +std::vector EpidMemberTest::kSigRl5EntryData = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x00, 0x00, 0x00, 0x05, + // bk's + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, 0x8, + 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, 0x2e, + 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, 0x67, + 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, 0x9d, 0xc7, + 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, 0x7d, 0xfe, + 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, 0x89, 0xb2, + 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, 0xcf, 0xd, 0x40, + 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, 0x4f, 0x7a, 0xb5, + 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, 0x33, 0xad, 0xf6, + 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, 0xce, 0xec, 0xd1, + 0xa8, 0xc, 0x8b, + + 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10, 0xfe, + 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60, 0x3e, 0xc0, + 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82, 0xc4, 0x49, + 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5, 0x77, 0x16, 0x4, + 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8, 0x40, 0xbd, 0x69, + 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9, 0xdd, 0x97, 0x6c, + 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2, 0xca, 0x5, 0x44, 0x9b, + 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa, 0xcf, 0xa4, 0x4, 0xe9, 0xf3, + 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3, 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, + 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60, 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, + 0x11, + + 0x6e, 0x22, 0xaa, 0x10, 0x84, 0x58, 0x8b, 0xff, 0xd8, 0x37, 0x8, 0xa9, 0xe9, + 0xdb, 0xf6, 0x1f, 0x69, 0x10, 0x95, 0x6c, 0xbf, 0xd, 0x11, 0x48, 0x6f, 0x1b, + 0x3c, 0x62, 0x46, 0x13, 0x89, 0x13, 0x5f, 0xa1, 0x3, 0x62, 0xed, 0x62, 0xdf, + 0x3d, 0xbf, 0xcd, 0xb7, 0x41, 0x48, 0x81, 0x3, 0x9f, 0x54, 0xa, 0xe, 0xb3, + 0x35, 0xf9, 0xde, 0x24, 0xba, 0x6d, 0x4c, 0x7f, 0xfc, 0xc1, 0xb4, 0xce, + 0x6d, 0xa1, 0x73, 0x7c, 0xaa, 0xb, 0xad, 0x2, 0xd6, 0x37, 0x85, 0xe, 0xbb, + 0x48, 0x11, 0x38, 0xc4, 0xaa, 0x1b, 0xf, 0xcf, 0xc1, 0x9c, 0x26, 0xcc, 0x95, + 0xc2, 0x5b, 0x49, 0x9, 0x3d, 0xe9, 0x7d, 0xce, 0xc7, 0xa6, 0x4, 0x3e, 0x7c, + 0x9e, 0x28, 0xde, 0x8, 0x11, 0xe, 0x61, 0x3b, 0xc0, 0x9c, 0x6b, 0x58, 0x23, + 0xe6, 0x40, 0x7b, 0xbd, 0xb8, 0x72, 0xf, 0xe0, 0xee, 0xcf, 0xba, 0xb4, + + 0xc4, 0xff, 0xaf, 0x48, 0x15, 0xda, 0x60, 0x40, 0xcc, 0xd7, 0xf2, 0x68, + 0xf7, 0xe2, 0x70, 0x12, 0x8d, 0x15, 0xa5, 0xb7, 0xe6, 0x4c, 0x23, 0xea, + 0x4d, 0x8a, 0x51, 0x6, 0x67, 0x3, 0x4c, 0x83, 0x6f, 0x28, 0x67, 0xcf, 0x63, + 0x46, 0x3e, 0x8a, 0x45, 0x9f, 0xed, 0x1a, 0xde, 0xa7, 0xad, 0xb2, 0x2b, 0xf, + 0x8b, 0xab, 0x7c, 0x70, 0xff, 0xc3, 0xa8, 0x6e, 0x8c, 0xaa, 0xb1, 0xf6, + 0x20, 0xe3, 0xb9, 0xf1, 0xc3, 0x3d, 0x5, 0x6a, 0x1e, 0x26, 0x2d, 0xf4, 0xd, + 0xe4, 0x53, 0x63, 0x67, 0x23, 0x48, 0xa8, 0x1, 0xa8, 0xee, 0xe1, 0x5f, 0x64, + 0xe3, 0x2c, 0x71, 0xe2, 0x10, 0x82, 0x0, 0x52, 0xd7, 0x74, 0x87, 0xff, 0x1c, + 0x0, 0x19, 0xe6, 0x4d, 0x15, 0x91, 0x6d, 0xf3, 0x38, 0x3b, 0xee, 0xf3, 0xd5, + 0xd1, 0xc7, 0x6d, 0xd9, 0x8e, 0x55, 0x70, 0x90, 0xb0, 0xb, 0x3c, 0x4a, 0x67, + 0x19, + + 0x4f, 0x98, 0x92, 0xf9, 0x18, 0x38, 0xf5, 0xb4, 0xf7, 0x2f, 0xa7, 0x21, + 0x71, 0x52, 0x27, 0xd0, 0x57, 0x4f, 0x9c, 0x30, 0xe, 0xb2, 0x27, 0xce, 0xd7, + 0xb2, 0x9f, 0xc0, 0xf6, 0xc3, 0xb0, 0x7c, 0x40, 0x18, 0x75, 0x4a, 0xde, + 0xb0, 0x9f, 0x46, 0x8a, 0x5a, 0xeb, 0x4f, 0xcb, 0x5e, 0x60, 0xf5, 0xca, + 0xf4, 0x98, 0xaf, 0x62, 0x9b, 0x7e, 0x10, 0xda, 0xba, 0x2f, 0x47, 0x64, + 0xf2, 0xc0, 0x84, 0x19, 0x75, 0xe0, 0xe4, 0xff, 0x20, 0xda, 0x7d, 0xe5, 0xd, + 0xc8, 0xf8, 0xe3, 0x83, 0x61, 0x19, 0x17, 0xf1, 0xa9, 0x1b, 0xff, 0x39, + 0x79, 0x88, 0x1, 0xfb, 0xe7, 0x23, 0xd2, 0xac, 0xe0, 0x49, 0x12, 0x2a, 0x38, + 0xb4, 0x7c, 0xc2, 0x1b, 0x88, 0x5f, 0x68, 0x32, 0x11, 0xd9, 0xfd, 0xdc, + 0x65, 0x2, 0xb3, 0x74, 0x2c, 0x13, 0xf2, 0xd8, 0xf1, 0x45, 0xc5, 0xd1, 0xf4, + 0xa3, 0x38, 0x81, 0x92}; +const std::vector EpidMemberTest::kMsg0 = {'m', 's', 'g', '0'}; +const std::vector EpidMemberTest::kBsn0 = {'b', 's', 'n', '0'}; +const std::vector EpidMemberTest::kMsg1 = {'m', 's', 'g', '1'}; +const std::vector EpidMemberTest::kBsn1 = {'b', 's', 'n', '1'}; +const std::vector EpidMemberTest::kData_0_255 = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0xff, +}; + +const GroupPubKey EpidMemberTest::kGrpXKey = { +#include "epid/common-testhelper/testdata/grp_x/pubkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXMember0PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXSigrevokedMember0PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc" +}; +const std::vector EpidMemberTest::kGrpXSigRl = { +#include "epid/common-testhelper/testdata/grp_x/sigrl.inc" +}; +const std::vector EpidMemberTest::kGrpXSigRlSingleEntry = { +#include "epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc" +}; + +const CompressedPrivKey EpidMemberTest::kGrpXMember9CompressedKey = { +#include "epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXMember9PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc" +}; + +const GroupPubKey EpidMemberTest::kGrpYKey = { +#include "epid/common-testhelper/testdata/grp_y/pubkey.inc" +}; + +const CompressedPrivKey EpidMemberTest::kGrpYMember9CompressedKey = { +#include "epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc" +}; + +const OctStr32 EpidMemberTest::kOctStr32_1 = {0x00, 0x00, 0x00, 0x01}; + +/// Arbitrary test data were generated based on Intel(R) EPID 2.0 parameters +const GroupPubKey EpidMemberTest::kEps0GroupPublicKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x07, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w +}; + +const PrivKey EpidMemberTest::kEps0MemberPrivateKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xae, 0x5a, 0x18, 0x8d, 0xc8, 0xa9, 0xe2, 0x5c, 0xdf, 0xef, 0x62, + 0x6b, 0x34, 0xdf, 0x0d, 0xf2, 0xf6, 0xcf, 0x6a, 0x4d, 0x68, 0x88, + 0xc8, 0x12, 0x08, 0xae, 0xb6, 0x30, 0x54, 0xdf, 0xa7, 0xdc}}}, + {{{0xec, 0x39, 0x86, 0x7b, 0x5c, 0x5e, 0x28, 0x17, 0x5b, 0xfe, 0x93, + 0xa1, 0x31, 0x8a, 0x82, 0x99, 0xb0, 0x84, 0x8c, 0x90, 0xc5, 0x54, + 0x2c, 0x6d, 0xff, 0x75, 0xcf, 0x05, 0x6e, 0x2b, 0x6c, 0xf3}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x7a, 0x57, 0x41, 0x5b, 0x85, 0x44, 0x0e, 0x2b, 0xb3, 0xcc, 0xa7, + 0x99, 0x6d, 0x19, 0x79, 0x45, 0x04, 0xb8, 0x94, 0x07, 0x47, 0x14, + 0xed, 0x8d, 0xf4, 0x1e, 0x7d, 0xa0, 0x17, 0xc5, 0xc4, 0x10} // f +}; diff --git a/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.h b/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.h new file mode 100644 index 00000000..b9c38c9b --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/member-testhelper.h @@ -0,0 +1,119 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief EpidMemberTest test fixture. + */ +#ifndef EPID_MEMBER_TINY_UNITTESTS_MEMBER_TESTHELPER_H_ +#define EPID_MEMBER_TINY_UNITTESTS_MEMBER_TESTHELPER_H_ + +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/common-testhelper/member_wrapper-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +typedef struct G1ElemStr G1ElemStr; +typedef struct NativeBasicSignature NativeBasicSignature; + +/// compares G1ElemStr values +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs); + +/// compares MembershipCredential values +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs); + +/// compares GroupPubKey values +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs); + +/// Test fixture class for EpidMember +class EpidMemberTest : public ::testing::Test { + public: + /// test data + static const GroupPubKey kGroupPublicKey; + /// test data + static const PrivKey kMemberPrivateKey; + /// test data + static const std::vector kGroupPublicKeyDataIkgf; + /// test data + static const std::vector kMemberPrivateKeyDataIkgf; + /// test data + static const MemberPrecomp kMemberPrecomp; + /// test data + static const std::vector kGrp01Member0SigTest1Sha256; + /// test data + static const NativeBasicSignature kBasicSig; + /// test data + static const std::vector kGrp01Member0SigTest1Sha384; + /// test data + static const std::vector kGrp01Member0SigTest1Sha512; + /// test data + static const std::vector kTest1Msg; + /// signature based revocation list with 50 entries + static std::vector kSigRlData; + /// signature based revocation list with 5 entries + static std::vector kSigRl5EntryData; + /// a message + static const std::vector kMsg0; + /// a message + static const std::vector kMsg1; + /// a basename + static const std::vector kBsn0; + /// a basename + static const std::vector kBsn1; + /// a data with bytes [0,255] + static const std::vector kData_0_255; + /// a group key in group X + static const GroupPubKey kGrpXKey; + /// a member 0 private key in group X + static const PrivKey kGrpXMember0PrivKey; + /// a member private key in group X revoked in SigRl + static const PrivKey kGrpXSigrevokedMember0PrivKey; + /// a SigRl of group X + static const std::vector kGrpXSigRl; + /// a SigRl with single entry of group X + static const std::vector kGrpXSigRlSingleEntry; + /// a compressed private key in group X + static const CompressedPrivKey kGrpXMember9CompressedKey; + /// a private key in group X + static const PrivKey kGrpXMember9PrivKey; + + /// a group key in group Y + static const GroupPubKey kGrpYKey; + /// a compressed private key in group Y + static const CompressedPrivKey kGrpYMember9CompressedKey; + + /// value "1" represented as an octstr constant + static const OctStr32 kOctStr32_1; + + /// EPS specific group public key + static const GroupPubKey kEps0GroupPublicKey; + /// EPS specific member private key + static const PrivKey kEps0MemberPrivateKey; + + /// setup called before each TEST_F starts + virtual void SetUp() {} + /// teardown called after each TEST_F finishes + virtual void TearDown() {} +}; + +#endif // EPID_MEMBER_TINY_UNITTESTS_MEMBER_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/member/tiny/unittests/presig-test.cc b/external/epid-sdk/epid/member/tiny/unittests/presig-test.cc new file mode 100644 index 00000000..4e1f5388 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/presig-test.cc @@ -0,0 +1,117 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief ComputePreSig unit tests. + */ +#include +#include +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +namespace { + +/////////////////////////////////////////////////////////////////////// +// EpidAddPreSigs +TEST_F(EpidMemberTest, DISABLED_AddPreSigsFailsGivenNullPointer) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + EXPECT_EQ(kEpidBadArgErr, EpidAddPreSigs(nullptr, 1)); +} + +TEST_F(EpidMemberTest, DISABLED_AddPreSigsFailsGivenHugeNumberOfPreSigs) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + // number_presigs = 0x80..01 of size equal to sizeof(size_t) + EXPECT_NE(kEpidNoErr, EpidAddPreSigs(member, (SIZE_MAX >> 1) + 2)); +} + +TEST_F(EpidMemberTest, + DISABLED_AddPreSigsComputesSpecifiedNumberOfPresigsIfInputPresigsNull) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 2)); + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 1)); + // request to generate 0 pre-computed signatures do nothing + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0)); + EXPECT_EQ((size_t)3, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, + DISABLED_AddPreSigsAddsCorrectNumberOfPresigsGivenValidInput) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + const size_t presigs1_added = 2; + const size_t presigs2_added = 3; + + // add + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs1_added)); + // extend + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs2_added)); + // add empty pre-computed signatures array does not affect internal pool + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0)); + EXPECT_EQ(presigs1_added + presigs2_added, EpidGetNumPreSigs(member)); +} + +/////////////////////////////////////////////////////////////////////// +// EpidGetNumPreSigs +TEST_F(EpidMemberTest, DISABLED_GetNumPreSigsReturnsZeroGivenNullptr) { + EXPECT_EQ((size_t)0, EpidGetNumPreSigs(nullptr)); +} + +TEST_F(EpidMemberTest, DISABLED_NumPreSigsForNewleyCreatedContextIsZero) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + EXPECT_EQ((size_t)0, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, DISABLED_GetNumPreSigsReturnsNumberOfAddedPresigs) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + const size_t presigs_added = 5; + + THROW_ON_EPIDERR(EpidAddPreSigs(member, presigs_added)); + EXPECT_EQ(presigs_added, EpidGetNumPreSigs(member)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/provision_compressed-test.cc b/external/epid-sdk/epid/member/tiny/unittests/provision_compressed-test.cc new file mode 100644 index 00000000..7df36ec2 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/provision_compressed-test.cc @@ -0,0 +1,176 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Provision compressed unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +} + +namespace { + +EpidStatus ProvisionCompressedAndStart( + MemberCtx* ctx, GroupPubKey const* pub_key, + CompressedPrivKey const* compressed_privkey, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionCompressed(ctx, pub_key, compressed_privkey, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(nullptr, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, nullptr, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(nullptr, &pub_key, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, nullptr, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, + DISABLED_ProvisionCompressedSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + EpidProvisionCompressed(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, + EpidProvisionCompressed(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsForInvalidGroupPubKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGrpXKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, DISABLED_ProvisionCompressedFailsForInvalidPrivateKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kGrpXMember9CompressedKey; + priv_key.ax.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + priv_key = this->kGrpXMember9CompressedKey; + priv_key.seed.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/provision_credential-test.cc b/external/epid-sdk/epid/member/tiny/unittests/provision_credential-test.cc new file mode 100644 index 00000000..67167aa9 --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/provision_credential-test.cc @@ -0,0 +1,317 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief Provision credential unit tests. + */ +#include +#include + +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +namespace { + +EpidStatus ProvisionCredentialAndStart(MemberCtx* ctx, + GroupPubKey const* pub_key, + MembershipCredential const* credential, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionCredential(ctx, pub_key, credential, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, ProvisionCredentialFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(nullptr, &pub_key, &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, nullptr, &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(nullptr, &pub_key, &credential, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, nullptr, &credential, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidCredential) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + MembershipCredential base_credential; + base_credential.A = this->kGrpXMember9PrivKey.A; + base_credential.gid = this->kGrpXMember9PrivKey.gid; + base_credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + credential = base_credential; + credential.A.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + credential = base_credential; + credential.A.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + credential = base_credential; + credential.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidGroupKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGroupPublicKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsCredentialNotInGroup) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + MembershipCredential base_credential; + base_credential.A = this->kGrpXMember9PrivKey.A; + base_credential.gid = this->kGrpXMember9PrivKey.gid; + base_credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + credential = base_credential; + credential.gid.data[0] = ~credential.gid.data[0]; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialPrecomp) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialNoPrecomp) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +// test that create succeeds with valid IKGF given parameters +TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialPrecomp) { + Prng prng; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + const PrivKey* priv_key = + reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + FpElemStr f = priv_key->f; + MembershipCredential credential; + credential.A = priv_key->A; + credential.gid = priv_key->gid; + credential.x = priv_key->x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, pub_key, + &credential, &precomp)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialNoPrecomp) { + Prng prng; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + const PrivKey* priv_key = + reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + FpElemStr f = priv_key->f; + MembershipCredential credential; + credential.A = priv_key->A; + credential.gid = priv_key->gid; + credential.x = priv_key->x; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + ProvisionCredentialAndStart(member, pub_key, &credential, nullptr)); +} + +TEST_F(EpidMemberTest, + DISABLED_ProvisionCredentialCanStoreMembershipCredentialNoPrecomp) { + Prng prng; + MembershipCredential const orig_credential = + *(MembershipCredential*)&this->kGrpXMember9PrivKey; + + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &orig_credential, nullptr)); + + FAIL() << "todo(developer): implement verification that credentials are " + "provisioned"; + // MembershipCredential credential; + // uint32_t nv_index = 0x01c10100; + // EXPECT_EQ(kEpidNoErr, EpidNvReadMembershipCredential( + // member->tpm2_ctx, nv_index, &pub_key, + // &credential)); + // EXPECT_EQ(orig_credential, credential); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/provision_key-test.cc b/external/epid-sdk/epid/member/tiny/unittests/provision_key-test.cc new file mode 100644 index 00000000..c8a692ba --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/provision_key-test.cc @@ -0,0 +1,243 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Provision key unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +} + +namespace { + +EpidStatus ProvisionBulkAndStart(MemberCtx* ctx, GroupPubKey const* pub_key, + PrivKey const* priv_key, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionKey(ctx, pub_key, priv_key, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(nullptr, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, nullptr, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(nullptr, &pub_key, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, nullptr, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); +} + +// test that create succeeds with valid IKGF given parameters +TEST_F(EpidMemberTest, ProvisionBulkSucceedsGivenValidParametersUsingIKGFData) { + Prng prng; + const GroupPubKey pub_key = { +#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" + }; + const PrivKey priv_key = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" + }; + + const MemberPrecomp precomp = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc" + }; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidGroupPubKey) { + Prng prng; + + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGroupPublicKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidF) { + Prng prng; + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kMemberPrivateKey; + priv_key.f = f; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidPrivateKey) { + Prng prng; + + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kMemberPrivateKey; + priv_key.A.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + priv_key = this->kMemberPrivateKey; + priv_key.A.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, DISABLED_ProvisionBulkCanStoreMembershipCredential) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &priv_key.f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + FAIL() << "todo(developer): implement verification that credentials are " + "provisioned"; + // uint32_t nv_index = 0x01c10100; + // MembershipCredential credential; + // MembershipCredential const orig_credential{ priv_key.gid, priv_key.A, + // priv_key.x }; + // EXPECT_EQ(kEpidNoErr, EpidNvReadMembershipCredential( + // member->tpm2_ctx, nv_index, &pub_key, + // &credential)); + // EXPECT_EQ(orig_credential, credential); +} + +} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/sign-test.cc b/external/epid-sdk/epid/member/tiny/unittests/sign-test.cc similarity index 77% rename from external/epid-sdk-3.0.0/epid/member/unittests/sign-test.cc rename to external/epid-sdk/epid/member/tiny/unittests/sign-test.cc index ce24b8a9..542a80d7 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/sign-test.cc +++ b/external/epid-sdk/epid/member/tiny/unittests/sign-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,18 +19,19 @@ * \brief Sign unit tests. */ #include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/member/api.h" -#include "epid/member/src/context.h" #include "epid/verifier/api.h" } #include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/prng-testhelper.h" -#include "epid/member/unittests/member-testhelper.h" #include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/member/tiny/unittests/member-testhelper.h" namespace { /// Count of elements in array @@ -48,20 +49,52 @@ TEST_F(EpidMemberTest, SignFailsGivenNullParameters) { SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; srl.gid = this->kGroupPublicKey.gid; std::vector sig(EpidGetSigSize(&srl)); - EXPECT_EQ(kEpidBadArgErr, EpidSign(nullptr, msg.data(), msg.size(), - bsn.data(), bsn.size(), &srl, sizeof(srl), - (EpidSignature*)sig.data(), sig.size())); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); EXPECT_EQ(kEpidBadArgErr, - EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), - &srl, sizeof(srl), nullptr, sig.size())); + EpidSign(nullptr, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig.data(), sig.size())); + EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), nullptr, sig.size())); EXPECT_EQ(kEpidBadArgErr, - EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(), &srl, - sizeof(srl), (EpidSignature*)sig.data(), sig.size())); + EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig.data(), sig.size())); EXPECT_EQ(kEpidBadArgErr, - EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(), &srl, - sizeof(srl), (EpidSignature*)sig.data(), sig.size())); + EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(), + (EpidSignature*)sig.data(), sig.size())); } +TEST_F(EpidMemberTest, SignFailsGivenNonZeroMessageLenWithNullMessage) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + std::vector sig(EpidGetSigSize(&srl)); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig.data(), sig.size())); +} + +TEST_F(EpidMemberTest, SignFailsGivenNonZeroBasenameLenWithNullBasename) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + std::vector sig(EpidGetSigSize(&srl)); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(), + (EpidSignature*)sig.data(), sig.size())); +} TEST_F(EpidMemberTest, SignFailsGivenWrongSigLen) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, @@ -70,37 +103,20 @@ TEST_F(EpidMemberTest, SignFailsGivenWrongSigLen) { auto& bsn = this->kBsn0; SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; srl.gid = this->kGroupPublicKey.gid; + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); // signature buffer one byte less than needed std::vector sig_small(EpidGetSigSize(&srl) - 1); EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), - &srl, sizeof(srl), (EpidSignature*)sig_small.data(), - sig_small.size())); + (EpidSignature*)sig_small.data(), sig_small.size())); // signature buffer is one byte - a less than allowed for EpidSignature std::vector sig_one(1); - EXPECT_EQ( - kEpidBadArgErr, - EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), &srl, - sizeof(srl), (EpidSignature*)sig_one.data(), sig_one.size())); -} - -TEST_F(EpidMemberTest, SignFailsGivenWrongSigRlLen) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - auto& msg = this->kMsg0; - auto& bsn = this->kBsn0; - SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; - srl.gid = this->kGroupPublicKey.gid; - - std::vector sig(EpidGetSigSize(&srl)); - std::vector srl_reduced(1); EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), - (SigRl*)srl_reduced.data(), srl_reduced.size(), - (EpidSignature*)sig.data(), sig.size())); + (EpidSignature*)sig_one.data(), sig_one.size())); } TEST_F(EpidMemberTest, SignFailsGivenUnregisteredBasename) { @@ -113,13 +129,23 @@ TEST_F(EpidMemberTest, SignFailsGivenUnregisteredBasename) { SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; srl.gid = this->kGroupPublicKey.gid; std::vector sig(EpidGetSigSize(&srl)); - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - EXPECT_EQ( - kEpidBadArgErr, - EpidSign(member, msg.data(), msg.size(), bsn1.data(), bsn1.size(), &srl, - sizeof(srl), (EpidSignature*)sig.data(), sig.size())); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), bsn1.data(), bsn1.size(), + (EpidSignature*)sig.data(), sig.size())); +} +TEST_F(EpidMemberTest, SignsFailsIfNotProvisioned) { + Prng my_prng; + MemberCtxObj member(&Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidOutOfSequenceError, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); } - ///////////////////////////////////////////////////////////////////////// // Anonymity @@ -131,12 +157,10 @@ TEST_F(EpidMemberTest, SignaturesOfSameMessageAreDifferent) { std::vector sig1(EpidGetSigSize(nullptr)); std::vector sig2(EpidGetSigSize(nullptr)); // without signature based revocation list - EXPECT_EQ(kEpidNoErr, - EpidSign(member, msg.data(), msg.size(), nullptr, 0, nullptr, 0, - (EpidSignature*)sig1.data(), sig1.size())); - EXPECT_EQ(kEpidNoErr, - EpidSign(member, msg.data(), msg.size(), nullptr, 0, nullptr, 0, - (EpidSignature*)sig2.data(), sig2.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig1.data(), sig1.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig2.data(), sig2.size())); EXPECT_TRUE(sig1.size() == sig2.size() && 0 != memcmp(sig1.data(), sig2.data(), sig1.size())); // with signature based revocation list @@ -164,12 +188,11 @@ TEST_F(EpidMemberTest, SignaturesOfSameMessageAreDifferent) { size_t srl1_size = sizeof(sig_rl_data_n2_one); std::vector sig3(EpidGetSigSize(srl1)); std::vector sig4(EpidGetSigSize(srl1)); - EXPECT_EQ(kEpidNoErr, - EpidSign(member, msg.data(), msg.size(), nullptr, 0, srl1, - srl1_size, (EpidSignature*)sig3.data(), sig3.size())); - EXPECT_EQ(kEpidNoErr, - EpidSign(member, msg.data(), msg.size(), nullptr, 0, srl1, - srl1_size, (EpidSignature*)sig4.data(), sig4.size())); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig3.data(), sig3.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig4.data(), sig4.size())); EXPECT_TRUE(sig3.size() == sig4.size() && 0 != memcmp(sig3.data(), sig4.data(), sig3.size())); } @@ -182,13 +205,13 @@ TEST_F(EpidMemberTest, SignaturesOfSameMessageWithSameBasenameAreDifferent) { std::vector sig1(EpidGetSigSize(nullptr)); std::vector sig2(EpidGetSigSize(nullptr)); // without signature based revocation list - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), - nullptr, 0, (EpidSignature*)sig1.data(), sig1.size())); + (EpidSignature*)sig1.data(), sig1.size())); EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), - nullptr, 0, (EpidSignature*)sig2.data(), sig2.size())); + (EpidSignature*)sig2.data(), sig2.size())); EXPECT_TRUE(sig1.size() == sig2.size() && 0 != memcmp(sig1.data(), sig2.data(), sig1.size())); @@ -217,12 +240,13 @@ TEST_F(EpidMemberTest, SignaturesOfSameMessageWithSameBasenameAreDifferent) { size_t srl1_size = sizeof(sig_rl_data_n2_one); std::vector sig3(EpidGetSigSize(srl1)); std::vector sig4(EpidGetSigSize(srl1)); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), - bsn.size(), srl1, srl1_size, - (EpidSignature*)sig3.data(), sig3.size())); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), - bsn.size(), srl1, srl1_size, - (EpidSignature*)sig4.data(), sig4.size())); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig3.data(), sig3.size())); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig4.data(), sig4.size())); EXPECT_TRUE(sig3.size() == sig4.size() && 0 != memcmp(sig3.data(), sig4.data(), sig3.size())); } @@ -235,13 +259,11 @@ TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseNoSigRl) { MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; - auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); @@ -257,8 +279,9 @@ TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseWithSigRl) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -271,12 +294,12 @@ TEST_F(EpidMemberTest, SignsMessageUsingBasenameNoSigRl) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), - bsn.size(), nullptr, 0, sig, sig_len)); + bsn.size(), sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); @@ -290,15 +313,16 @@ TEST_F(EpidMemberTest, SignsMessageUsingBasenameWithSigRl) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); SigRl const* srl = reinterpret_cast(this->kSigRl5EntryData.data()); size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), - bsn.size(), srl, srl_size, sig, sig_len)); + bsn.size(), sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); @@ -312,12 +336,12 @@ TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesNoSigRl) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); @@ -328,15 +352,16 @@ TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesWithSigRl) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); SigRl const* srl = reinterpret_cast(this->kSigRl5EntryData.data()); size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -351,8 +376,8 @@ TEST_F(EpidMemberTest, SignsUsingRandomBaseWithoutRegisteredBasenamesNoSigRl) { std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); @@ -369,83 +394,82 @@ TEST_F(EpidMemberTest, std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } +#ifndef TPM_TSS +TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector bsn(1024 * 1024); // exactly 1 MB + uint8_t c = 0; + for (size_t i = 0; i < bsn.size(); ++i) { + bsn[i] = c++; + } + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGrpXKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector bsn(1024 * 1024); // exactly 1 MB + uint8_t c = 0; + for (size_t i = 0; i < bsn.size(); ++i) { + bsn[i] = c++; + } + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + SigRl const* srl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t srl_size = this->kGrpXSigRl.size() * sizeof(this->kGrpXSigRl[0]); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + VerifierCtxObj ctx(this->kGrpXKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); +} -///////////////////////////////////////////////////////////////////////// -// Variable sigRL - -TEST_F(EpidMemberTest, SignFailsGivenInvalidSigRl) { +TEST_F(EpidMemberTest, SignsMsgUsingBsnContainingAllPossibleBytesNoSigRl) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; - - // sign fail with mismatch gid - uint8_t sig_rl_data_n2_one[] = { - // gid - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x02, - // version - 0x00, 0x00, 0x00, 0x00, - // n2 - 0x0, 0x00, 0x00, 0x01, - // one bk - 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, - 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, - 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, - 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, - 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, - 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, - 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, - 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, - 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, - 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, - 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b}; - SigRl* srl = reinterpret_cast(sig_rl_data_n2_one); - size_t srl_size = sizeof(sig_rl_data_n2_one); - size_t sig_len = EpidGetSigSize(srl); - std::vector newsig(sig_len); - EpidSignature* sig = (EpidSignature*)newsig.data(); - - EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); - - // sign fail given invalid sigrl size - uint8_t sig_rl_data_n_one[] = { - // gid - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - // version - 0x00, 0x00, 0x00, 0x00, - // n2 - 0x0, 0x00, 0x00, 0x00, - // one bk - 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, - 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, - 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, - 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, - 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, - 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, - 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, - 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, - 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, - 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, - 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b}; - SigRl* srl1 = reinterpret_cast(sig_rl_data_n_one); - size_t srl1_size = sizeof(sig_rl_data_n_one); - size_t sig_len1 = EpidGetSigSize(srl1); - std::vector newsig1(sig_len1); - EpidSignature* sig1 = (EpidSignature*)newsig1.data(); - - EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl1, srl1_size, sig1, sig_len1)); + auto& bsn = this->kData_0_255; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } +#endif + +///////////////////////////////////////////////////////////////////////// +// Variable sigRL TEST_F(EpidMemberTest, SignsMessageGivenNoSigRl) { Prng my_prng; @@ -457,8 +481,8 @@ TEST_F(EpidMemberTest, SignsMessageGivenNoSigRl) { std::vector newsig(sig_len); EpidSignature* sig = (EpidSignature*)newsig.data(); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, @@ -478,8 +502,8 @@ TEST_F(EpidMemberTest, SignsMessageGivenNoSigRlUsingIKGFData) { MemberCtxObj member(grp_public_key, mbr_private_key, &Prng::Generate, &my_prng); EpidSignature* sig = (EpidSignature*)newsig.data(); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(grp_public_key); EXPECT_EQ(kEpidSigValid, @@ -507,8 +531,9 @@ TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntries) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -534,8 +559,9 @@ TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntriesUsingIkgfData) { EpidSignature* sig_ikgf = reinterpret_cast(sig_data_ikgf.data()); size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size)); EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr, - 0, srl_ikgf, srl_size, sig_ikgf, sig_len)); + 0, sig_ikgf, sig_len)); VerifierCtxObj ctx_ikgf(grp_public_key); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -584,8 +610,9 @@ TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntries) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -640,8 +667,9 @@ TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntriesUsingIKGFData) { EpidSignature* sig_ikgf = reinterpret_cast(sig_data_ikgf.data()); size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size)); EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr, - 0, srl_ikgf, srl_size, sig_ikgf, sig_len)); + 0, sig_ikgf, sig_len)); VerifierCtxObj ctx_ikgf(grp_public_key); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size)); EXPECT_EQ(kEpidSigValid, @@ -650,36 +678,29 @@ TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntriesUsingIKGFData) { TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevoked) { // note: a complete sig + nr proof should still be returned!! - const GroupPubKey pub_key = { -#include "epid/common-testhelper/testdata/grp_x/pubkey.inc" - }; - const PrivKey priv_key = { -#include "epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc" - }; - Prng my_prng; - MemberCtxObj member(pub_key, priv_key, this->kMemberPrecomp, &Prng::Generate, - &my_prng); + auto& pub_key = this->kGrpXKey; + auto& priv_key = this->kGrpXMember0PrivKey; auto& msg = this->kMsg0; - auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - const std::vector kGrpXSigRlMember0Sha256Bsn0Msg0FirstEntry = { -#include "epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha256_bsn0_msg0_revoked_middle_entry.inc" + Prng my_prng; + MemberCtxObj member(pub_key, priv_key, &Prng::Generate, &my_prng); + const std::vector kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry = { +#include "epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc" }; auto srl = reinterpret_cast( - kGrpXSigRlMember0Sha256Bsn0Msg0FirstEntry.data()); - size_t srl_size = kGrpXSigRlMember0Sha256Bsn0Msg0FirstEntry.size(); + kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.data()); + size_t srl_size = kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.size(); std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(pub_key); - THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); - EXPECT_EQ(kEpidSigInvalid, + EXPECT_EQ(kEpidSigRevokedInSigRl, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } @@ -694,8 +715,6 @@ TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevokedUsingIKGFData) { MemberCtxObj member(grp_public_key, member_private_key_revoked_by_sig, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; - auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); const std::vector sig_Rl = { #include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc" }; @@ -705,31 +724,30 @@ TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevokedUsingIKGFData) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); EXPECT_EQ(kEpidSigRevokedInSigRl, - EpidSign(member, msg.data(), msg.size(), nullptr, 0, srl, srl_size, - sig, sig_len)); + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); VerifierCtxObj ctx(grp_public_key); - THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); - EXPECT_EQ(kEpidSigInvalid, + EXPECT_EQ(kEpidSigRevokedInSigRl, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } + ///////////////////////////////////////////////////////////////////////// // Variable hash alg TEST_F(EpidMemberTest, SignsMessageUsingSha256HashAlg) { Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); @@ -737,17 +755,16 @@ TEST_F(EpidMemberTest, SignsMessageUsingSha256HashAlg) { EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } -TEST_F(EpidMemberTest, SignsMessageUsingSha384HashAlg) { +TEST_F(EpidMemberTest, DISABLED_SignsMessageUsingSha384HashAlg) { Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha384, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha384)); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); @@ -757,15 +774,14 @@ TEST_F(EpidMemberTest, SignsMessageUsingSha384HashAlg) { TEST_F(EpidMemberTest, SignsMessageUsingSha512HashAlg) { Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha512, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); @@ -776,14 +792,14 @@ TEST_F(EpidMemberTest, SignsMessageUsingSha512HashAlg) { TEST_F(EpidMemberTest, DISABLED_SignsMessageUsingSha512256HashAlg) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); + kSha512_256, this->kMemberPrecomp, &Prng::Generate, + &my_prng); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512_256)); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256)); @@ -794,25 +810,25 @@ TEST_F(EpidMemberTest, DISABLED_SignsMessageUsingSha512256HashAlg) { ///////////////////////////////////////////////////////////////////////// // Variable precomputed signatures -TEST_F(EpidMemberTest, SignConsumesPrecomputedSignaturesNoSigRl) { +TEST_F(EpidMemberTest, DISABLED_SignConsumesPrecomputedSignaturesNoSigRl) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 3, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 3)); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member)); } -TEST_F(EpidMemberTest, SignConsumesPrecomputedSignaturesWithSigRl) { +TEST_F(EpidMemberTest, DISABLED_SignConsumesPrecomputedSignaturesWithSigRl) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 3, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 3)); auto& msg = this->kMsg0; SigRl const* srl = reinterpret_cast(this->kSigRl5EntryData.data()); @@ -820,33 +836,35 @@ TEST_F(EpidMemberTest, SignConsumesPrecomputedSignaturesWithSigRl) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member)); } -TEST_F(EpidMemberTest, SignsMessageWithPrecomputedSignaturesNoSigRl) { +TEST_F(EpidMemberTest, DISABLED_SignsMessageWithPrecomputedSignaturesNoSigRl) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); auto& msg = this->kMsg0; std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } -TEST_F(EpidMemberTest, SignsMessageWithPrecomputedSignaturesWithSigRl) { +TEST_F(EpidMemberTest, + DISABLED_SignsMessageWithPrecomputedSignaturesWithSigRl) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); auto& msg = this->kMsg0; SigRl const* srl = reinterpret_cast(this->kSigRl5EntryData.data()); @@ -854,8 +872,9 @@ TEST_F(EpidMemberTest, SignsMessageWithPrecomputedSignaturesWithSigRl) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); @@ -872,8 +891,8 @@ TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesNoSigRl) { EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); // test sign without precomputed signatures - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, @@ -891,9 +910,10 @@ TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesWithSigRl) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); // test sign without precomputed signatures - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); @@ -901,41 +921,6 @@ TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesWithSigRl) { EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); } -TEST_F(EpidMemberTest, SignFailsOnBadPrecomputedSignaturesNoSigRl) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - PreComputedSignature precompsig; - precompsig = this->kPrecomputedSignatures[0]; - precompsig.B.x.data.data[0]++; - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, &precompsig)); - auto& msg = this->kMsg0; - std::vector sig_data(EpidGetSigSize(nullptr)); - EpidSignature* sig = reinterpret_cast(sig_data.data()); - size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)); -} - -TEST_F(EpidMemberTest, SignFailsOnBadPrecomputedSignaturesWithSigRl) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - PreComputedSignature precompsig; - precompsig = this->kPrecomputedSignatures[0]; - precompsig.B.x.data.data[0]++; - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, &precompsig)); - auto& msg = this->kMsg0; - SigRl const* srl = - reinterpret_cast(this->kSigRl5EntryData.data()); - size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); - std::vector sig_data(EpidGetSigSize(srl)); - EpidSignature* sig = reinterpret_cast(sig_data.data()); - size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)); -} - ///////////////////////////////////////////////////////////////////////// // Variable messages @@ -948,9 +933,9 @@ TEST_F(EpidMemberTest, SignsEmptyMessageNoSigRl) { std::vector sig_data(EpidGetSigSize(nullptr)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), 0, bsn.data(), bsn.size(), - nullptr, 0, sig, sig_len)); + sig, sig_len)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), 0)); @@ -967,8 +952,9 @@ TEST_F(EpidMemberTest, SignsEmptyMessageWithSigRl) { std::vector sig_data(EpidGetSigSize(srl)); EpidSignature* sig = reinterpret_cast(sig_data.data()); size_t sig_len = sig_data.size() * sizeof(uint8_t); - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), 0, nullptr, 0, srl, - srl_size, sig, sig_len)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), 0, nullptr, 0, sig, sig_len)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); @@ -993,8 +979,8 @@ TEST_F(EpidMemberTest, SignsShortMessageNoSigRl) { msg[n] = (uint8_t)n; } for (auto length : lengths) { - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), length, nullptr, 0, - nullptr, 0, sig, sig_len)) + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len)) << "EpidSign for message_len: " << length << " failed"; EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length)) << "EpidVerify for message_len: " << length << " failed"; @@ -1023,9 +1009,10 @@ TEST_F(EpidMemberTest, SignsShortMessageWithSigRl) { for (size_t n = 0; n < msg.size(); n++) { msg.at(n) = (uint8_t)n; } + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); for (auto length : lengths) { - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), length, nullptr, 0, srl, - srl_size, sig, sig_len)) + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len)) << "EpidSign for message_len: " << message_len << " failed"; EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length)) << "EpidVerify for message_len: " << message_len << " failed"; @@ -1044,8 +1031,8 @@ TEST_F(EpidMemberTest, SignsLongMessageNoSigRl) { for (size_t n = 0; n < msg.size(); n++) { msg.at(n) = (uint8_t)n; } - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - nullptr, 0, sig, sig_len)) + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)) << "EpidSign for message_len: " << 1000000 << " failed"; EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())) @@ -1068,12 +1055,28 @@ TEST_F(EpidMemberTest, SignsLongMessageWithSigRl) { for (size_t n = 0; n < msg.size(); n++) { msg.at(n) = (uint8_t)n; } - EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, - srl, srl_size, sig, sig_len)) + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)) << "EpidSign for message_len: " << 1000000 << " failed"; EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())) << "EpidVerify for message_len: " << 1000000 << " failed"; } +TEST_F(EpidMemberTest, SignsMsgContainingAllPossibleBytesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + VerifierCtxObj ctx(this->kGroupPublicKey); + std::vector msg = this->kData_0_255; + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + } // namespace diff --git a/external/epid-sdk/epid/member/tiny/unittests/utest.parts b/external/epid-sdk/epid/member/tiny/unittests/utest.parts new file mode 100644 index 00000000..aee3023e --- /dev/null +++ b/external/epid-sdk/epid/member/tiny/unittests/utest.parts @@ -0,0 +1,64 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +"""Build configuration for unit test of minimal library. +""" +Import('*') +env.PartName('utest') + +env.DependsOn([Component(env.subst('${PART_PARENT_NAME}'), + requires=REQ.EXISTS|REQ.DEFAULT), + Component('gtest'), + Component('common-testhelper'), + Component('verifier')]) + +utest_files = Pattern(src_dir='.', + includes=['*-test.cc', + '*-testhelper.cc'], + recursive=True).files() + +env.Append(CPPPATH='#') + +env['UNIT_TEST_TARGET_NAME'] = "${PART_PARENT_NAME}-${UNIT_TEST_TARGET}" + +shlib = [] + +if 'shared' in env['MODE']: + if env['TARGET_OS'] == 'win32': + dependent_shlib = env.subst("${{DEPENDS.{0}.SDKBIN}}" + .format(env.subst("${PART_PARENT_NAME}"))) + shlib = env.CCopy("${INSTALL_TEST_BIN}", dependent_shlib) + else: + dependent_shlib = env.subst("${{DEPENDS.{0}.SDKLIB}}" + .format(env.subst("${PART_PARENT_NAME}"))) + shlib = env.CCopy("${INSTALL_LIB}", dependent_shlib) + + +utest = env.UnitTest('${PART_SHORT_NAME}', + utest_files, + command_args=[ + '--gtest_filter=**', + '--gtest_color=yes', + '--gtest_print_time=1', + '--gtest_output=xml', + #'--gtest_break_on_failure', + #'--gtest_catch_exceptions=0', + ], + data_src=[], + make_pdb=(env.isConfigBasedOn('debug')), + INSTALL_BIN='${INSTALL_TEST_BIN}' + ) +Depends(utest, shlib) diff --git a/external/epid-sdk/epid/member/tinymember.parts b/external/epid-sdk/epid/member/tinymember.parts new file mode 100644 index 00000000..9f79f676 --- /dev/null +++ b/external/epid-sdk/epid/member/tinymember.parts @@ -0,0 +1,98 @@ +# pylint:disable=I0011,W0401,W0614,C0103,E0602 +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +"""Build configuration for tiny member library. +""" +Import('*') +env.PartName('member') + +default_build_mode = 'static' + +include_files = Pattern(src_dir='.', includes=['*.h'], recursive=False).files() + +src_files = Pattern( + src_dir='tiny/src', includes=['*.c'], recursive=False).files() + +install_files = Pattern( + src_dir='tiny', + includes=[ + '*.h', '*.c', '*-test.cc', '*-testhelper.cc', '*-testhelper.h', + '*.parts', 'Makefile' + ], + excludes=['*/platform_specific*/'], + recursive=True) + +if 'install_package' in env['MODE']: + env.InstallTopLevel(install_files, sub_dir='epid/member/tiny') + +else: + env.Part(parts_file='tiny/stdlib/tiny_stdlib.parts') + env.Part(parts_file='tiny/math/math.parts') + env.DependsOn([ + Component('tinycommon', requires=REQ.HEADERS), + Component('member.tiny_stdlib'), Component('member.math') + ]) + + env.Append(CPPPATH='#') + + if 'use-sigrl-by-reference' in env['MODE']: + env.Append(CPPDEFINES=['USE_SIGRL_BY_REFERENCE']) + else: + max_sigrl_entries = ARGUMENTS.get('MAX_SIGRL_ENTRIES', 0) + n2_max = int(max_sigrl_entries) + if n2_max: + env.Append(CPPDEFINES=['MAX_SIGRL_ENTRIES={0}'.format(n2_max)]) + + if 'static' in env['MODE'] and 'shared' in env['MODE']: + PrintError("both shared and static build mode specified for '{}'. " + .format(env.subst('$PART_SHORT_NAME'))) + if 'static' not in env['MODE'] and 'shared' not in env['MODE']: + PrintMessage( + "build mode not specified for '{}'. Defaulting to '{}'" + .format(env.subst('$PART_SHORT_NAME'), default_build_mode)) + env['MODE'].append(default_build_mode) + + if 'shared' in env['MODE']: + env.Append(CPPDEFINES=['SHARED']) + env.ExportCPPDEFINES(['SHARED']) + outputs = env.SharedLibrary('${PART_SHORT_NAME}', src_files) + elif 'static' in env['MODE']: + outputs = env.Library('${PART_SHORT_NAME}', src_files) + else: + print env.subst('$PART_SHORT_NAME') + PrintError("build mode not specified for '{}'. {}".format( + env.subst('$PART_SHORT_NAME'), + "Specify either 'shared' or 'static'.")) + + sdk_outs = env.Sdk(outputs) + env.SdkInclude(include_files, sub_dir='epid/${PART_SHORT_NAME}') + + if 'shared' in env['MODE']: + env.InstallTarget(outputs) + + if 'install_lib' in env['MODE']: + env.InstallInclude(include_files, sub_dir='epid/${PART_SHORT_NAME}') + if 'static' in env['MODE']: + env.InstallLib(outputs) + + is_utest_build = False + for i in BUILD_TARGETS: + if "utest::" in str(i): + is_utest_build = True + if is_utest_build: + env.Part( + parts_file='tiny/unittests/utest.parts', + CONFIG=DefaultEnvironment().subst('$CONFIG')) diff --git a/external/epid-sdk/epid/member/tpm2/commit.h b/external/epid-sdk/epid/member/tpm2/commit.h new file mode 100644 index 00000000..145e50f0 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/commit.h @@ -0,0 +1,72 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// SDK TPM Commit API. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_COMMIT_H_ +#define EPID_MEMBER_TPM2_COMMIT_H_ + +#include + +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct FfElement FfElement; +typedef struct EcPoint EcPoint; +/// \endcond + +/*! +\addtogroup Tpm2Module tpm2 +\ingroup EpidMemberModule +@{ +*/ + +/// Performs TPM2_Commit TPM operation. +/*! +Generates random r and compute K, L and E points. + +\param[in] ctx +The TPM context. +\param[in] p1 +A point P1 on G1 curve. +\param[in] s2 +Octet array used to derive x-coordinate of a point P2. +\param[in] s2_len +Length of s2 buffer. +\param[in] y2 +y coordinate of the point associated with s2. +\param[out] k +Result of G1.exp(P2, private key f). +\param[out] l +Result of G1.exp(P2, random r). +\param[out] e +Result of G1.exp(P1, random r). +\param[out] counter +A value associated with the random r. Should be initialized with zero. + +\returns ::EpidStatus + +\see Tpm2CreateContext +*/ +EpidStatus Tpm2Commit(Tpm2Ctx* ctx, EcPoint const* p1, void const* s2, + size_t s2_len, FfElement const* y2, EcPoint* k, + EcPoint* l, EcPoint* e, uint16_t* counter); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_COMMIT_H_ diff --git a/external/epid-sdk/epid/member/tpm2/context.h b/external/epid-sdk/epid/member/tpm2/context.h new file mode 100644 index 00000000..83e9f928 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/context.h @@ -0,0 +1,123 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// SDK TPM API. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_CONTEXT_H_ +#define EPID_MEMBER_TPM2_CONTEXT_H_ + +#include "epid/common/bitsupplier.h" +#include "epid/common/errors.h" +#include "epid/common/types.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct FpElemStr FpElemStr; +typedef struct Epid2Params_ Epid2Params_; +typedef struct MemberParams MemberParams; +/// \endcond + +/*! + \addtogroup Tpm2Module tpm2 + \ingroup EpidMemberModule + @{ +*/ + +/// Creates a new Tpm context +/*! + + Must be called to create the TPM context that is used by other TPM + APIs. + + You need to use a cryptographically secure random number generator + to create a TPM context. The ::BitSupplier is provided as a function + prototype for your own implementation of the random number generator. + + ::Tpm2DeleteContext must be called to safely release the TPM context. + + \param[in] params + member parameters to initialize rnd_func, rnd_param, ff_elem, ctx. + + \param[in] epid2_params + The field and group parameters. + + \param[out] rnd_func + random function if exists in MemberParms + + \param[out] rnd_param + random parameters if exists in MemberParms + + \param[out] f + seed f if exists in MemberParams + + \param[out] ctx + Newly constructed TPM context. + + \returns ::EpidStatus + + \see Tpm2DeleteContext +*/ +EpidStatus Tpm2CreateContext(MemberParams const* params, + Epid2Params_ const* epid2_params, + BitSupplier* rnd_func, void** rnd_param, + const FpElemStr** f, Tpm2Ctx** ctx); + +/// Deletes an existing Tpm context. +/*! + + Must be called to safely release a TPM context created using + ::Tpm2CreateContext. + + De-initializes the context, frees memory used by the context, and + sets the context pointer to NULL. + + \param[in,out] ctx + The TPM context. Can be NULL. + + \see Tpm2CreateContext +*/ +void Tpm2DeleteContext(Tpm2Ctx** ctx); + +/// Sets the hash algorithm to be used by a TPM2. +/*! + + \param[in] ctx + The TPM2 context. + \param[in] hash_alg + The hash algorithm to use. + + \returns ::EpidStatus +*/ +EpidStatus Tpm2SetHashAlg(Tpm2Ctx* ctx, HashAlg hash_alg); + +/// Reset an existing Tpm context. +/*! + +Must be called to reset a TPM context created using +::Tpm2CreateContext. + +Re-initializes the context, reset memory used for primary key. + +\param[in,out] ctx +The TPM context. Can be NULL. + +\see Tpm2CreateContext +*/ +void Tpm2ResetContext(Tpm2Ctx** ctx); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_CONTEXT_H_ diff --git a/external/epid-sdk-3.0.0/parts-site/configurations/__init__.py b/external/epid-sdk/epid/member/tpm2/createprimary.h similarity index 50% rename from external/epid-sdk-3.0.0/parts-site/configurations/__init__.py rename to external/epid-sdk/epid/member/tpm2/createprimary.h index 8e82fa75..16bd582d 100644 --- a/external/epid-sdk-3.0.0/parts-site/configurations/__init__.py +++ b/external/epid-sdk/epid/member/tpm2/createprimary.h @@ -1,5 +1,5 @@ -############################################################################ -# Copyright 2016 Intel Corporation +/*############################################################################ +# Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,15 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ -# pylint: disable=locally-disabled, missing-docstring, no-member, unused-variable +/// TPM2_CreatePrimary command interface. +/*! \file */ +#ifndef EPID_MEMBER_TPM2_CREATEPRIMARY_H_ +#define EPID_MEMBER_TPM2_CREATEPRIMARY_H_ -import parts.load_module as load_module -import parts.reporter as reporter +#include "epid/common/errors.h" -def configuration(type_name): - """define configurations""" - try: - mod = load_module.load_module( - load_module.get_site_directories('configurations'), type_name, 'configtype') - except ImportError: - reporter.report_error('configuration "%s" was not found.'%type_name, show_stack=False) +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct G1ElemStr G1ElemStr; +/// \endcond + +/// Creates Primary key +/*! + +\param[in,out] ctx +TPM context. +\param[out] p_str +Primary key: g1^f +\returns ::EpidStatus +*/ +EpidStatus Tpm2CreatePrimary(Tpm2Ctx* ctx, G1ElemStr* p_str); + +#endif // EPID_MEMBER_TPM2_CREATEPRIMARY_H_ diff --git a/external/epid-sdk/epid/member/tpm2/getrandom.h b/external/epid-sdk/epid/member/tpm2/getrandom.h new file mode 100644 index 00000000..b7f79809 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/getrandom.h @@ -0,0 +1,57 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +#ifndef EPID_MEMBER_TPM2_GETRANDOM_H_ +#define EPID_MEMBER_TPM2_GETRANDOM_H_ + +/*! + * \file + * \brief SDK TPM API. + */ + +#include "epid/common/errors.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +/// \endcond + +/*! +\addtogroup Tpm2Module tpm2 +\ingroup EpidMemberModule +@{ +*/ + +/// Get random data +/*! +This command returns the next num_bits from the random number generator (RNG). + +\param[in,out] ctx +TPM context. + +\param[in] num_bits +Number of bits to return. + +\param[out] random_data +Output random bits. + +\returns ::EpidStatus + +\see Tpm2CreateContext +*/ +EpidStatus Tpm2GetRandom(Tpm2Ctx* ctx, int const num_bits, void* random_data); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_GETRANDOM_H_ diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/commit.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/commit.c new file mode 100644 index 00000000..6e00cdd7 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/commit.c @@ -0,0 +1,147 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Commit implementation. +/*! \file */ + +#include "epid/member/tpm2/commit.h" +#include +#include +#include "epid/common/math/ecgroup.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/ibm_tss/conversion.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Bit 7 binary mask +#define BIT7 0x080 +/// Binary 00011111 +#define BITS0500 0x3f + +EpidStatus Tpm2Commit(Tpm2Ctx* ctx, EcPoint const* p1, void const* s2, + size_t s2_len, FfElement const* y2, EcPoint* k, + EcPoint* l, EcPoint* e, uint16_t* counter) { + EpidStatus sts = kEpidErr; + TPM_RC rc = TPM_RC_SUCCESS; + + if (!ctx || !ctx->epid2_params || !ctx->key_handle) { + return kEpidBadArgErr; + } + + if (s2 && s2_len <= 0) { + return kEpidBadArgErr; + } + + if ((!s2 && y2) || (s2 && !y2)) { + return kEpidBadArgErr; + } + + if (s2 && (!k || !l)) { + return kEpidBadArgErr; + } + + if (!e || !counter) { + return kEpidBadArgErr; + } + + if (s2_len > UINT16_MAX) { + return kEpidBadArgErr; + } + + do { + FiniteField* Fq = ctx->epid2_params->Fq; + EcGroup* G1 = ctx->epid2_params->G1; + Commit_In in = {0}; + Commit_Out out; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + unsigned int sessionAttributes0 = 0; + + in.signHandle = ctx->key_handle; + if (p1) { + G1ElemStr p1_str = {0}; + sts = WriteEcPoint(G1, p1, &p1_str, sizeof(p1_str)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadTpm2EcPoint(&p1_str, &in.P1); + BREAK_ON_EPID_ERROR(sts); + } + if (s2) { + FqElemStr y2_str = {0}; + sts = WriteFfElement(Fq, y2, &y2_str, sizeof(y2_str)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadTpm2FfElement(&y2_str.data, &in.y2); + BREAK_ON_EPID_ERROR(sts); + in.s2.t.size = (UINT16)s2_len; + if (0 != memcpy_S(&in.s2.t.buffer, sizeof(in.s2.t.buffer), s2, s2_len)) { + sts = kEpidBadArgErr; + break; + } + } + rc = TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_Commit, + sessionHandle0, NULL, sessionAttributes0, TPM_RH_NULL, + NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_Commit", rc); + // workaround based on Table 2:15 to filter response code format defining + // handle, session, or parameter number modifier if bit 7 is 1 error is + // RC_FMT1 + if ((rc & BIT7) != 0) { + rc = rc & (BITS0500 | RC_FMT1); + if (TPM_RC_ATTRIBUTES == rc || TPM_RC_ECC_POINT == rc || + TPM_RC_HASH == rc || TPM_RC_KEY == rc || TPM_RC_SCHEME == rc || + TPM_RC_SIZE == rc) + sts = kEpidBadArgErr; + else + sts = kEpidErr; + } else { + if (TPM_RC_NO_RESULT == rc) + sts = kEpidBadArgErr; + else + sts = kEpidErr; + } + break; + } + if (out.E.size > 0) { + G1ElemStr e_str = {0}; + sts = WriteTpm2EcPoint(&out.E, &e_str); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &e_str, sizeof(e_str), e); + BREAK_ON_EPID_ERROR(sts); + } + if (out.K.size > 0 && k) { + G1ElemStr k_str = {0}; + sts = WriteTpm2EcPoint(&out.K, &k_str); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &k_str, sizeof(k_str), k); + BREAK_ON_EPID_ERROR(sts); + } + if (out.L.size > 0 && l) { + G1ElemStr l_str = {0}; + sts = WriteTpm2EcPoint(&out.L, &l_str); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &l_str, sizeof(l_str), l); + BREAK_ON_EPID_ERROR(sts); + } + *counter = out.counter; + } while (0); + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/context.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/context.c new file mode 100644 index 00000000..b0d6421a --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/context.c @@ -0,0 +1,150 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM context implementation. +/*! \file */ + +#include "epid/member/tpm2/context.h" + +#include +#include + +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/getrandom.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" +#include "epid/member/tpm_member.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Deletes key from TPM +/*! +\param[in,out] ctx +TPM context. + +\returns ::EpidStatus +*/ +void Tpm2FlushKey(Tpm2Ctx* ctx); + +/// Flag that indicates that context was already created +bool is_context_already_created = false; + +/// Internal Random function as a BitSupplier +static int __STDCALL tpm2_rnd_func(unsigned int* rand_data, int num_bits, + void* user_data) { + return Tpm2GetRandom((Tpm2Ctx*)user_data, num_bits, rand_data); +} + +EpidStatus Tpm2CreateContext(MemberParams const* params, + Epid2Params_ const* epid2_params, + BitSupplier* rnd_func, void** rnd_param, + const FpElemStr** f, Tpm2Ctx** ctx) { + EpidStatus sts = kEpidNoErr; + TPM_RC rc = TPM_RC_FAILURE; + Tpm2Ctx* tpm_ctx = NULL; + FfElement* ff_elem = NULL; + if (!params || !epid2_params || !rnd_func || !rnd_param || !f || !ctx) { + return kEpidBadArgErr; + } + + if (is_context_already_created) { + return kEpidBadArgErr; + } + is_context_already_created = true; + + tpm_ctx = SAFE_ALLOC(sizeof(Tpm2Ctx)); + if (!tpm_ctx) { + return kEpidMemAllocErr; + } + + do { + if (params->f) { + FiniteField* Fp = epid2_params->Fp; + // Validate f + sts = NewFfElement(Fp, &ff_elem); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, params->f, sizeof(*params->f), ff_elem); + BREAK_ON_EPID_ERROR(sts); + } + + tpm_ctx->epid2_params = epid2_params; + tpm_ctx->key_handle = 0; + tpm_ctx->hash_alg = kInvalidHashAlg; + + rc = TSS_Create(&tpm_ctx->tss); + if (rc != TPM_RC_SUCCESS) { + sts = kEpidErr; + break; + } + + *ctx = tpm_ctx; + *rnd_func = tpm2_rnd_func; + *rnd_param = *ctx; + *f = params->f; + sts = kEpidNoErr; + } while (0); + DeleteFfElement(&ff_elem); + if (kEpidNoErr != sts) { + Tpm2DeleteContext(&tpm_ctx); + *ctx = NULL; + } + return sts; +} + +void Tpm2DeleteContext(Tpm2Ctx** ctx) { + is_context_already_created = false; + if (ctx && *ctx) { + Tpm2FlushKey(*ctx); + TSS_Delete((*ctx)->tss); + SAFE_FREE(*ctx); + } +} + +EpidStatus Tpm2SetHashAlg(Tpm2Ctx* ctx, HashAlg hash_alg) { + if (!ctx) return kEpidBadArgErr; + if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg && + kSha512_256 != hash_alg) + return kEpidHashAlgorithmNotSupported; + // can not change hash alg of existing TPM2 key object + if (ctx->key_handle) return kEpidOutOfSequenceError; + ctx->hash_alg = hash_alg; + return kEpidNoErr; +} + +void Tpm2ResetContext(Tpm2Ctx** ctx) { + if (ctx && *ctx) { + Tpm2FlushKey(*ctx); + } +} + +void Tpm2FlushKey(Tpm2Ctx* ctx) { + if (ctx->key_handle) { + TPM_RC rc; + FlushContext_In in; + in.flushHandle = ctx->key_handle; + rc = TSS_Execute(ctx->tss, NULL, (COMMAND_PARAMETERS*)&in, NULL, + TPM_CC_FlushContext, TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_FlushContext", rc); + } + ctx->key_handle = 0; + } +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.c new file mode 100644 index 00000000..e4531077 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.c @@ -0,0 +1,134 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM-SDK data conversion implementation. +/*! \file */ + +#include "epid/member/tpm2/ibm_tss/conversion.h" +#include +#include +#include "epid/common/math/ecgroup.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" + +TPMI_ALG_HASH EpidtoTpm2HashAlg(HashAlg hash_alg) { + switch (hash_alg) { + case kSha256: + return TPM_ALG_SHA256; + case kSha384: + return TPM_ALG_SHA384; + case kSha512: + return TPM_ALG_SHA512; + default: + return TPM_ALG_NULL; + } +} + +HashAlg Tpm2toEpidHashAlg(TPMI_ALG_HASH tpm_hash_alg) { + switch (tpm_hash_alg) { + case TPM_ALG_SHA256: + return kSha256; + case TPM_ALG_SHA384: + return kSha384; + case TPM_ALG_SHA512: + return kSha512; + default: + return kInvalidHashAlg; + } +} + +EpidStatus ReadTpm2FfElement(OctStr256 const* str, + TPM2B_ECC_PARAMETER* tpm_data) { + if (!str || !tpm_data) { + return kEpidBadArgErr; + } + if (0 != + memcpy_S(tpm_data->b.buffer, MAX_ECC_KEY_BYTES, str, sizeof(OctStr256))) { + return kEpidBadArgErr; + } + tpm_data->b.size = (UINT16)sizeof(OctStr256); + return kEpidNoErr; +} + +EpidStatus WriteTpm2FfElement(TPM2B_ECC_PARAMETER const* tpm_data, + OctStr256* str) { + if (!tpm_data || !str || tpm_data->b.size > (UINT16)sizeof(OctStr256)) { + return kEpidBadArgErr; + } + uint8_t* buf = (uint8_t*)str; + size_t real_size = sizeof(OctStr256); + if (tpm_data->b.size < real_size) { + memset(buf, 0x00, real_size - tpm_data->b.size); + buf += real_size - tpm_data->b.size; + real_size = tpm_data->b.size; + } + if (0 != memcpy_S(buf, real_size, tpm_data->b.buffer, tpm_data->b.size)) { + return kEpidBadArgErr; + } + return kEpidNoErr; +} + +EpidStatus ReadTpm2EcPoint(G1ElemStr const* p_str, TPM2B_ECC_POINT* tpm_point) { + if (!p_str || !tpm_point) { + return kEpidBadArgErr; + } + + // copy X + if (0 != memcpy_S(tpm_point->point.x.t.buffer, MAX_ECC_KEY_BYTES, &p_str->x, + sizeof(G1ElemStr) / 2)) { + return kEpidErr; + } + tpm_point->point.x.t.size = sizeof(G1ElemStr) / 2; + + // copy Y + if (0 != memcpy_S(tpm_point->point.y.t.buffer, MAX_ECC_KEY_BYTES, &p_str->y, + sizeof(G1ElemStr) / 2)) { + return kEpidErr; + } + tpm_point->point.y.t.size = sizeof(G1ElemStr) / 2; + + tpm_point->size = sizeof(tpm_point->point); + return kEpidNoErr; +} + +EpidStatus WriteTpm2EcPoint(TPM2B_ECC_POINT const* tpm_point, + G1ElemStr* p_str) { + if (!p_str || !tpm_point) { + return kEpidBadArgErr; + } + + if (tpm_point->point.x.t.size > sizeof(G1ElemStr) / 2 || + tpm_point->point.y.t.size > sizeof(G1ElemStr) / 2) { + return kEpidBadArgErr; + } + + memset(p_str, '\0', sizeof(G1ElemStr)); + + // copy X + if (0 != + memcpy_S(&p_str->x + (sizeof(G1ElemStr) / 2 - tpm_point->point.x.t.size), + tpm_point->point.x.t.size, tpm_point->point.x.t.buffer, + tpm_point->point.x.t.size)) { + return kEpidErr; + } + // copy Y + if (0 != + memcpy_S(&p_str->y + (sizeof(G1ElemStr) / 2 - tpm_point->point.y.t.size), + tpm_point->point.y.t.size, tpm_point->point.y.t.buffer, + tpm_point->point.y.t.size)) { + return kEpidErr; + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.h b/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.h new file mode 100644 index 00000000..8e6ba2ee --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/conversion.h @@ -0,0 +1,117 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM-SDK data conversion interface. +/*! \file */ +#ifndef EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_ +#define EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_ + +#include +#include "epid/common/errors.h" +#include "epid/common/types.h" + +#ifndef TPM_ALG_SHA256 +/// TPM code of SHA 256 algorithm +#define TPM_ALG_SHA256 (TPM_ALG_ID)(0x000B) +#endif +#ifndef TPM_ALG_SHA384 +/// TPM code of SHA 384 algorithm +#define TPM_ALG_SHA384 (TPM_ALG_ID)(0x000C) +#endif +#ifndef TPM_ALG_SHA512 +/// TPM code of SHA 512 algorithm +#define TPM_ALG_SHA512 (TPM_ALG_ID)(0x000D) +#endif +#ifndef TPM_ALG_NULL +/// TPM code of Null algorithm +#define TPM_ALG_NULL (TPM_ALG_ID)(0x0010) +#endif + +/// \cond +typedef struct G1ElemStr G1ElemStr; +/// \endcond + +/// Maps HashAlg to TPM type +/*! +Maps Intel(R) EPID SDK HashAlg into TPMI_ALG_HASH. + +\param[in] hash_alg +Code of the hash algorithm +\returns TPMI_ALG_HASH +*/ +TPMI_ALG_HASH EpidtoTpm2HashAlg(HashAlg hash_alg); + +/// Maps TPMI_ALG_HASH to HashAlg +/*! +Maps TPM hash code TPMI_ALG_HASH into HashAlg. + +\param[in] tpm_hash_alg +Code of the hash algorithm in TPM + +\returns HashAlg +*/ +HashAlg Tpm2toEpidHashAlg(TPMI_ALG_HASH tpm_hash_alg); + +/// Converts serialized FfElement into TPM type +/*! + +\param[in] str +Serialized Intel(R) EPID SDK FfElement +\param[out] tpm_data +tpm type data. +\returns ::EpidStatus +*/ +EpidStatus ReadTpm2FfElement(OctStr256 const* str, + TPM2B_ECC_PARAMETER* tpm_data); + +/// Converts TPM finite field element types into serialized FfElement +/*! + +\param[in] tpm_data +The TPM finite field data, typically TPM2B_DIGEST or +TPM2B_ECC_PARAMETER. +\param[out] str +The target buffer. + +\returns ::EpidStatus +*/ +EpidStatus WriteTpm2FfElement(TPM2B_ECC_PARAMETER const* tpm_data, + OctStr256* str); + +/// Converts ECPoint string to TMP ECPoint structure. +/*! + + \param[in] p_str + The serialized EcPoint to convert. + \param[out] tpm_point + The TPM EC point representation. + + \returns ::EpidStatus +*/ +EpidStatus ReadTpm2EcPoint(G1ElemStr const* p_str, TPM2B_ECC_POINT* tpm_point); + +/// Serializes TMP ECPoint to ECPoint string. +/*! + + \param[in] tpm_point + The TPM EC point to convert. + \param[in] p_str + The target string. + +\returns ::EpidStatus +*/ +EpidStatus WriteTpm2EcPoint(TPM2B_ECC_POINT const* tpm_point, G1ElemStr* p_str); + +#endif // EPID_MEMBER_TPM2_IBM_TSS_CONVERSION_H_ diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/createprimary.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/createprimary.c new file mode 100644 index 00000000..dc52b1f0 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/createprimary.c @@ -0,0 +1,100 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \brief TPM2_CreatePrimary command implementation. + * \file + */ +#include "epid/member/tpm2/createprimary.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/ibm_tss/conversion.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" +#include "tss2/TPM_Types.h" +#include "tss2/tss.h" + +EpidStatus Tpm2CreatePrimary(Tpm2Ctx* ctx, G1ElemStr* p_str) { + if (!ctx || !ctx->epid2_params || !p_str) { + return kEpidBadArgErr; + } + CreatePrimary_In in = {0}; + CreatePrimary_Out out; + TPM_RC rc = TPM_RC_SUCCESS; + TPMI_ALG_PUBLIC algPublic = TPM_ALG_ECC; + TPMI_ECC_CURVE curveID = TPM_ECC_BN_P256; + TPMI_ALG_HASH halg = TPM_ALG_NULL; + TPMI_ALG_HASH nalg = TPM_ALG_NULL; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + TPM2B_ECC_POINT public_area; + unsigned int sessionAttributes0 = 0; + const char* parentPasswordPtr = NULL; + + in.primaryHandle = TPM_RH_ENDORSEMENT; + halg = EpidtoTpm2HashAlg(ctx->hash_alg); + if (halg == TPM_ALG_NULL) { + return kEpidHashAlgorithmNotSupported; + } + nalg = halg; + /* Table 185 - TPM2B_PUBLIC inPublic */ + /* Table 184 - TPMT_PUBLIC in.inPublic.publicArea */ + in.inPublic.publicArea.type = algPublic; + in.inPublic.publicArea.nameAlg = nalg; + + /* Table 32 - TPMA_OBJECT objectAttributes */ + in.inPublic.publicArea.objectAttributes.val |= TPMA_OBJECT_NODA; + in.inPublic.publicArea.objectAttributes.val |= TPMA_OBJECT_FIXEDTPM; + in.inPublic.publicArea.objectAttributes.val |= TPMA_OBJECT_FIXEDPARENT; + in.inPublic.publicArea.objectAttributes.val |= + TPMA_OBJECT_SENSITIVEDATAORIGIN; + in.inPublic.publicArea.parameters.eccDetail.symmetric.algorithm = + TPM_ALG_NULL; + in.inPublic.publicArea.parameters.eccDetail.scheme.scheme = TPM_ALG_ECDAA; + in.inPublic.publicArea.parameters.eccDetail.scheme.details.ecdaa.hashAlg = + halg; + in.inPublic.publicArea.parameters.eccDetail.scheme.details.ecdaa.count = 1; + in.inPublic.publicArea.parameters.eccDetail.curveID = curveID; + in.inPublic.publicArea.parameters.eccDetail.kdf.scheme = TPM_ALG_NULL; + in.inSensitive.sensitive.userAuth.t.size = 0; + in.inSensitive.sensitive.data.t.size = 0; + in.inPublic.publicArea.objectAttributes.val |= + TPMA_OBJECT_SENSITIVEDATAORIGIN; + in.inPublic.publicArea.objectAttributes.val |= TPMA_OBJECT_USERWITHAUTH; + in.inPublic.publicArea.objectAttributes.val &= ~TPMA_OBJECT_ADMINWITHPOLICY; + in.inPublic.publicArea.objectAttributes.val |= TPMA_OBJECT_SIGN; + in.inPublic.publicArea.objectAttributes.val &= ~TPMA_OBJECT_DECRYPT; + in.inPublic.publicArea.objectAttributes.val &= ~TPMA_OBJECT_RESTRICTED; + in.inPublic.publicArea.unique.ecc.y.t.size = 0; + in.inPublic.publicArea.unique.ecc.x.t.size = 0; + in.inPublic.publicArea.authPolicy.t.size = 0; + in.inPublic.publicArea.unique.rsa.t.size = 0; + in.outsideInfo.t.size = 0; + in.creationPCR.count = 0; + rc = TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_CreatePrimary, + sessionHandle0, parentPasswordPtr, sessionAttributes0, + TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_CreatePrimary", rc); + if (TPM_RC_ATTRIBUTES == rc || TPM_RC_KDF == rc || TPM_RC_SYMMETRIC == rc || + TPM_RC_TYPE == rc || TPM_RC_SCHEME == rc || TPM_RC_SIZE == rc || + TPM_RC_KEY == rc) + return kEpidBadArgErr; + return kEpidErr; + } + ctx->key_handle = out.objectHandle; + public_area.point = out.outPublic.publicArea.unique.ecc; + return WriteTpm2EcPoint(&public_area, p_str); +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/getrandom.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/getrandom.c new file mode 100644 index 00000000..14877507 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/getrandom.c @@ -0,0 +1,78 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TPM2_GetRandom command implementation. + */ +#include + +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/getrandom.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" + +#include "tss2/TPM_Types.h" +#include "tss2/tss.h" + +EpidStatus Tpm2GetRandom(Tpm2Ctx* ctx, int const num_bits, void* random_data) { + EpidStatus sts = kEpidNoErr; + TPM_RC rc = TPM_RC_FAILURE; + int num_bytes = (num_bits + CHAR_BIT - 1) / CHAR_BIT; + BYTE* buf = (BYTE*)random_data; + + if (!ctx || !random_data) { + return kEpidBadArgErr; + } + + if (num_bits <= 0) { + return kEpidBadArgErr; + } + + do { + GetRandom_In in; + GetRandom_Out out; + size_t max_digest_size = sizeof(((TPM2B_DIGEST*)0)->t.buffer); + UINT16 bytes_to_reqest = ((size_t)num_bytes > max_digest_size) + ? (UINT16)max_digest_size + : (UINT16)num_bytes; + in.bytesRequested = bytes_to_reqest; + + rc = TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_GetRandom, + TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_GetRandom", rc); + sts = kEpidErr; + break; + } + if (!out.randomBytes.t.size || out.randomBytes.t.size > bytes_to_reqest) { + sts = kEpidErr; + break; + } + + if (0 != memcpy_S(buf, (size_t)num_bytes, out.randomBytes.t.buffer, + out.randomBytes.t.size)) { + sts = kEpidErr; + break; + } + + num_bytes -= out.randomBytes.t.size; + buf += out.randomBytes.t.size; + } while (num_bytes > 0); + + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/load_external.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/load_external.c new file mode 100644 index 00000000..dd0c67ab --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/load_external.c @@ -0,0 +1,137 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TPM2_LoadExternal command implementation. + */ + +#include "epid/member/tpm2/load_external.h" + +#include "epid/common/math/ecgroup.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/ibm_tss/conversion.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" +#include "tss2/TPM_Types.h" +#include "tss2/tss.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus Tpm2LoadExternal(Tpm2Ctx* ctx, FpElemStr const* f_str) { + EpidStatus sts = kEpidErr; + TPM_RC rc = TPM_RC_SUCCESS; + EcPoint* pub = NULL; + FfElement* f = NULL; + TPMI_ALG_HASH tpm_hash_alg = TPM_ALG_NULL; + + if (!ctx || !ctx->epid2_params || !f_str) { + return kEpidBadArgErr; + } + + do { + LoadExternal_In in = {0}; + LoadExternal_Out out; + G1ElemStr pub_str = {0}; + TPMS_ECC_PARMS* ecc_details = &in.inPublic.publicArea.parameters.eccDetail; + EcGroup* G1 = ctx->epid2_params->G1; + EcPoint* g1 = ctx->epid2_params->g1; + + sts = NewFfElement(ctx->epid2_params->Fp, &f); + BREAK_ON_EPID_ERROR(sts); + // verify that f is valid + sts = ReadFfElement(ctx->epid2_params->Fp, f_str, sizeof(*f_str), f); + BREAK_ON_EPID_ERROR(sts); + if (ctx->key_handle) { + FlushContext_In in_fc; + in_fc.flushHandle = ctx->key_handle; + TSS_Execute(ctx->tss, NULL, (COMMAND_PARAMETERS*)&in_fc, NULL, + TPM_CC_FlushContext, TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_FlushContext", rc); + } + ctx->key_handle = 0; + } + + sts = NewEcPoint(G1, &pub); + BREAK_ON_EPID_ERROR(sts); + + sts = EcExp(G1, g1, (BigNumStr const*)f_str, pub); + BREAK_ON_EPID_ERROR(sts); + + sts = WriteEcPoint(G1, pub, &pub_str, sizeof(pub_str)); + BREAK_ON_EPID_ERROR(sts); + + tpm_hash_alg = EpidtoTpm2HashAlg(ctx->hash_alg); + if (tpm_hash_alg == TPM_ALG_NULL) { + sts = kEpidHashAlgorithmNotSupported; + break; + } + + in.hierarchy = TPM_RH_NULL; + in.inPublic.size = sizeof(TPM2B_PUBLIC); + in.inPublic.publicArea.type = TPM_ALG_ECC; + in.inPublic.publicArea.nameAlg = tpm_hash_alg; + in.inPublic.publicArea.objectAttributes.val = + TPMA_OBJECT_NODA | TPMA_OBJECT_USERWITHAUTH | TPMA_OBJECT_SIGN; + in.inPublic.publicArea.authPolicy.t.size = 0; + + ecc_details->symmetric.algorithm = TPM_ALG_NULL; + ecc_details->scheme.scheme = TPM_ALG_ECDAA; + ecc_details->scheme.details.ecdaa.hashAlg = tpm_hash_alg; + ecc_details->scheme.details.ecdaa.count = 0; + ecc_details->curveID = TPM_ECC_BN_P256; + ecc_details->kdf.scheme = TPM_ALG_NULL; + + sts = ReadTpm2FfElement(&pub_str.x.data, + &in.inPublic.publicArea.unique.ecc.x); + BREAK_ON_EPID_ERROR(sts); + sts = ReadTpm2FfElement(&pub_str.y.data, + &in.inPublic.publicArea.unique.ecc.y); + BREAK_ON_EPID_ERROR(sts); + + in.inPrivate.t.size = sizeof(in.inPrivate.t.sensitiveArea); + in.inPrivate.t.sensitiveArea.sensitiveType = TPM_ALG_ECC; + sts = ReadTpm2FfElement(&f_str->data, + &in.inPrivate.t.sensitiveArea.sensitive.ecc); + BREAK_ON_EPID_ERROR(sts); + + rc = TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_LoadExternal, + TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_LoadExternal", rc); + if (TPM_RC_BINDING == rc || TPM_RC_ECC_POINT == rc || + TPM_RC_KEY_SIZE == rc) + sts = kEpidBadArgErr; + else + sts = kEpidErr; + break; + } + + ctx->key_handle = out.objectHandle; + } while (0); + + DeleteEcPoint(&pub); + DeleteFfElement(&f); + + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/nv.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/nv.c new file mode 100644 index 00000000..15a92548 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/nv.c @@ -0,0 +1,166 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TSS NV API implementation. + */ + +#include "epid/member/tpm2/nv.h" +#include +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" + +EpidStatus Tpm2NvUndefineSpace(Tpm2Ctx* ctx, uint32_t nv_index) { + TPM_RC rc = 0; + NV_UndefineSpace_In in; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + if (!ctx) { + return kEpidBadArgErr; + } + if ((nv_index >> 24) != TPM_HT_NV_INDEX) { + return kEpidBadArgErr; + } + + in.authHandle = TPM_RH_OWNER; + // the NV Index to remove from NV space + in.nvIndex = nv_index; + rc = TSS_Execute(ctx->tss, NULL, (COMMAND_PARAMETERS*)&in, NULL, + TPM_CC_NV_UndefineSpace, sessionHandle0, NULL, 0, + TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_NV_UndefineSpace", rc); + return kEpidBadArgErr; + } + return kEpidNoErr; +} + +EpidStatus Tpm2NvDefineSpace(Tpm2Ctx* ctx, uint32_t nv_index, size_t size) { + TPM_RC rc = 0; + NV_DefineSpace_In in = {0}; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + if (!ctx || size == 0 || size > MAX_NV_BUFFER_SIZE) { + return kEpidBadArgErr; + } + if ((nv_index >> 24) != TPM_HT_NV_INDEX) { + return kEpidBadArgErr; + } + + in.authHandle = TPM_RH_OWNER; + // the handle of the data area + in.publicInfo.nvPublic.nvIndex = nv_index; + // hash algorithm used to compute the name of the Index and used for the + // authPolicy + in.publicInfo.nvPublic.nameAlg = TPM_ALG_SHA256; + in.publicInfo.nvPublic.attributes.val = TPMA_NVA_NO_DA | TPMA_NVA_AUTHWRITE | + TPMA_NVA_AUTHREAD | TPMA_NVA_ORDINARY; + // the size of the data area + in.publicInfo.nvPublic.dataSize = (uint16_t)size; + rc = TSS_Execute(ctx->tss, NULL, (COMMAND_PARAMETERS*)&in, NULL, + TPM_CC_NV_DefineSpace, sessionHandle0, NULL, 0, TPM_RH_NULL, + NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_NV_DefineSpace", rc); + if (rc == TPM_RC_NV_DEFINED) { + return kEpidDuplicateErr; + } + return kEpidBadArgErr; + } + return kEpidNoErr; +} + +EpidStatus Tpm2NvRead(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void* data) { + TPM_RC rc = 0; + NV_Read_In in; + NV_Read_Out out; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + int done = FALSE; + // bytes read so far + uint16_t bytes_read_so_far = 0; + + if (!ctx || !data || size == 0 || size > MAX_NV_BUFFER_SIZE) { + return kEpidBadArgErr; + } + if ((nv_index >> 24) != TPM_HT_NV_INDEX) { + return kEpidBadArgErr; + } + + if ((nv_index >> 24) != TPM_HT_NV_INDEX) { + return kEpidBadArgErr; + } + // Authorization handle + in.authHandle = nv_index; + in.nvIndex = nv_index; + in.offset = offset; + while ((rc == TPM_RC_SUCCESS) && !done) { + in.offset = offset + bytes_read_so_far; + if ((uint32_t)(size - bytes_read_so_far) < MAX_NV_BUFFER_SIZE) { + // last chunk + in.size = (uint16_t)size - bytes_read_so_far; + } else { + // next chunk + in.size = MAX_NV_BUFFER_SIZE; + } + rc = TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_NV_Read, + sessionHandle0, NULL, 0, TPM_RH_NULL, NULL, 0); + if (rc == TPM_RC_SUCCESS) { + // copy the results to the read buffer + memcpy_S((uint8_t*)data + bytes_read_so_far, size - bytes_read_so_far, + out.data.b.buffer, out.data.b.size); + bytes_read_so_far += out.data.b.size; + if (bytes_read_so_far == size) { + done = TRUE; + } + } else { + print_tpm2_response_code("TPM2_NV_Read", rc); + } + } + if (rc != TPM_RC_SUCCESS) { + return kEpidBadArgErr; + } + return kEpidNoErr; +} + +EpidStatus Tpm2NvWrite(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void const* data) { + TPM_RC rc = TPM_RC_SUCCESS; + NV_Write_In in = {0}; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + if (!ctx || !data || size == 0 || size > MAX_NV_BUFFER_SIZE) { + return kEpidBadArgErr; + } + if ((nv_index >> 24) != TPM_HT_NV_INDEX) { + return kEpidBadArgErr; + } + + in.authHandle = nv_index; + in.data.b.size = (uint16_t)size; + memcpy(in.data.b.buffer, data, size); + in.nvIndex = nv_index; + // beginning offset + in.offset = offset; + rc = TSS_Execute(ctx->tss, NULL, (COMMAND_PARAMETERS*)&in, NULL, + TPM_CC_NV_Write, sessionHandle0, NULL, 0, TPM_RH_NULL, NULL, + 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_NV_Write", rc); + return kEpidBadArgErr; + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.c new file mode 100644 index 00000000..90ae9af3 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.c @@ -0,0 +1,37 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM context implementation. +/*! \file */ +#ifndef EPID_ENABLE_DEBUG_PRINT +#define EPID_ENABLE_DEBUG_PRINT +#endif + +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include +#include +#include + +void print_tpm2_response_code(char const* operation, TPM_RC rc) { + const char* msg; + const char* submsg; + const char* num; + TSS_ResponseCode_toString(&msg, &submsg, &num, rc); + printf("%s: %s%s%s\n", operation, msg, submsg, num); +} + +#ifdef EPID_ENABLE_DEBUG_PRINT +#undef EPID_ENABLE_DEBUG_PRINT +#endif diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.h b/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.h new file mode 100644 index 00000000..83269a23 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/printtss.h @@ -0,0 +1,36 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM log error prints +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_IBM_TSS_PRINTTSS_H_ +#define EPID_MEMBER_TPM2_IBM_TSS_PRINTTSS_H_ + +#if !defined(EPID_ENABLE_DEBUG_PRINT) +/// Do not print tpm2 response error if EPID_ENABLE_DEBUG_PRINT is undefined +#define print_tpm2_response_code(...) +#else +#include +#include +/// Print TPM 2.0 response code as human readable message +/*! + * \param[in] operation The operation that returned the code + * \param[in] rc The response code + */ +void print_tpm2_response_code(char const* operation, TPM_RC rc); +#endif + +#endif // EPID_MEMBER_TPM2_IBM_TSS_PRINTTSS_H_ diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/sign.c b/external/epid-sdk/epid/member/tpm2/ibm_tss/sign.c new file mode 100644 index 00000000..fb6eb39b --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/sign.c @@ -0,0 +1,155 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Sign implementation. +/*! \file */ + +#include "epid/member/tpm2/sign.h" +#include +#include +#include +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/tpm2/getrandom.h" +#include "epid/member/tpm2/ibm_tss/conversion.h" +#include "epid/member/tpm2/ibm_tss/printtss.h" +#include "epid/member/tpm2/ibm_tss/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// Bit 7 binary mask +#define BIT7 0x080 +/// Binary 00011111 +#define BITS0500 0x3f + +EpidStatus Tpm2Sign(Tpm2Ctx* ctx, void const* digest, size_t digest_len, + uint16_t counter, FfElement* k, FfElement* s) { + EpidStatus sts = kEpidErr; + TPM_RC rc = TPM_RC_SUCCESS; + + if (!ctx || !ctx->epid2_params || !digest || !s) { + return kEpidBadArgErr; + } + if (0 == digest_len || EpidGetHashSize(ctx->hash_alg) != digest_len) { + return kEpidBadArgErr; + } + if (ctx->key_handle == 0) { + return kEpidBadArgErr; + } + + do { + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + unsigned int sessionAttributes0 = 0; + Sign_In in = {0}; + Sign_Out out; + FiniteField* Fp = ctx->epid2_params->Fp; + FpElemStr k_str; + FpElemStr s_str; + in.keyHandle = ctx->key_handle; + if (0 != memcpy_S(in.digest.t.buffer, sizeof(in.digest.t.buffer), digest, + digest_len)) { + sts = kEpidErr; + break; + } + in.digest.t.size = (uint16_t)digest_len; + in.inScheme.scheme = TPM_ALG_ECDAA; + in.inScheme.details.ecdaa.hashAlg = EpidtoTpm2HashAlg(ctx->hash_alg); + in.inScheme.details.ecdaa.count = counter; + /* proof that digest was created by the TPM (NULL ticket) */ + /* Table 91 - Definition of TPMT_TK_HASHCHECK Structure */ + in.validation.tag = TPM_ST_HASHCHECK; + in.validation.hierarchy = TPM_RH_NULL; + in.validation.digest.t.size = 0; + rc = + TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_Sign, sessionHandle0, + NULL, sessionAttributes0, TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS) { + print_tpm2_response_code("TPM2_Sign", rc); + // workaround based on Table 2:15 to filter response code format defining + // handle, session, or parameter number modifier if bit 7 is 1 error is + // RC_FMT1 + if ((rc & BIT7) != 0) { + rc = rc & (BITS0500 | RC_FMT1); + if (TPM_RC_VALUE == rc) { + sts = kEpidBadArgErr; + } + } else { + sts = kEpidErr; + } + break; + } + + if (k) { + sts = WriteTpm2FfElement(&out.signature.signature.ecdaa.signatureR, + (OctStr256*)&k_str); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &k_str, sizeof(k_str), k); + BREAK_ON_EPID_ERROR(sts); + } + + sts = WriteTpm2FfElement(&out.signature.signature.ecdaa.signatureS, + (OctStr256*)&s_str); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &s_str, sizeof(s_str), s); + BREAK_ON_EPID_ERROR(sts); + } while (0); + return sts; +} + +EpidStatus Tpm2ReleaseCounter(Tpm2Ctx* ctx, uint16_t counter) { + EpidStatus sts = kEpidErr; + + if (!ctx) { + return kEpidBadArgErr; + } + + do { + TPM_RC rc = TPM_RC_SUCCESS; + TPMI_SH_AUTH_SESSION sessionHandle0 = TPM_RS_PW; + unsigned int sessionAttributes0 = 0; + Sign_In in = {0}; + Sign_Out out; + in.keyHandle = ctx->key_handle; + + in.digest.t.size = (uint16_t)EpidGetHashSize(ctx->hash_alg); + memset(in.digest.t.buffer, 0x1, (size_t)in.digest.t.size); + in.inScheme.scheme = TPM_ALG_ECDAA; + in.inScheme.details.ecdaa.hashAlg = EpidtoTpm2HashAlg(ctx->hash_alg); + in.inScheme.details.ecdaa.count = counter; + in.validation.tag = TPM_ST_HASHCHECK; + in.validation.hierarchy = TPM_RH_NULL; + in.validation.digest.t.size = 0; + rc = + TSS_Execute(ctx->tss, (RESPONSE_PARAMETERS*)&out, + (COMMAND_PARAMETERS*)&in, NULL, TPM_CC_Sign, sessionHandle0, + NULL, sessionAttributes0, TPM_RH_NULL, NULL, 0); + if (rc != TPM_RC_SUCCESS && (rc & (BITS0500 | RC_FMT1)) != TPM_RC_VALUE) { + print_tpm2_response_code("Tpm2ReleaseCounter: TPM2_Sign", rc); + sts = kEpidErr; + break; + } + sts = kEpidNoErr; + } while (0); + + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/ibm_tss/state.h b/external/epid-sdk/epid/member/tpm2/ibm_tss/state.h new file mode 100644 index 00000000..5f570bb2 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/ibm_tss/state.h @@ -0,0 +1,39 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM internal state. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_IBM_TSS_STATE_H_ +#define EPID_MEMBER_TPM2_IBM_TSS_STATE_H_ + +#include "epid/common/types.h" +#include "tss2/TPM_Types.h" + +/// \cond +typedef struct Epid2Params_ Epid2Params_; +typedef struct FfElement FfElement; +typedef struct TSS_CONTEXT TSS_CONTEXT; +/// \endcond + +/// TPM TSS context definition +typedef struct Tpm2Ctx { + TSS_CONTEXT* tss; ///< TSS context + Epid2Params_ const* epid2_params; ///< Intel(R) EPID 2.0 params + TPM_HANDLE key_handle; ///< Handle to f value of private key + HashAlg hash_alg; ///< Hash algorithm to use +} Tpm2Ctx; + +#endif // EPID_MEMBER_TPM2_IBM_TSS_STATE_H_ diff --git a/external/epid-sdk/epid/member/tpm2/load_external.h b/external/epid-sdk/epid/member/tpm2/load_external.h new file mode 100644 index 00000000..64e8199f --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/load_external.h @@ -0,0 +1,54 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// SDK TPM API. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_LOAD_EXTERNAL_H_ +#define EPID_MEMBER_TPM2_LOAD_EXTERNAL_H_ + +#include "epid/common/errors.h" +#include "epid/common/types.h" // HashAlg + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct FpElemStr FpElemStr; +/// \endcond + +/*! + \addtogroup Tpm2Module tpm2 + \ingroup EpidMemberModule + @{ +*/ + +/// Invokes TPM2_LoadExternal command +/*! + This command is used to load an object that is not a Protected Object into the + TPM. The command allows loading of a public area or both a public and sensitive + area. + + \param[in,out] ctx + TPM context. + + \param[in] f_str + The f value of the member private key. + + \returns ::EpidStatus +*/ +EpidStatus Tpm2LoadExternal(Tpm2Ctx* ctx, FpElemStr const* f_str); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_LOAD_EXTERNAL_H_ diff --git a/external/epid-sdk/epid/member/tpm2/nv.h b/external/epid-sdk/epid/member/tpm2/nv.h new file mode 100644 index 00000000..4b70fdbd --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/nv.h @@ -0,0 +1,110 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// SDK TPM non volatile memory API. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_NV_H_ +#define EPID_MEMBER_TPM2_NV_H_ + +#include + +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +/// \endcond + +/*! + \addtogroup Tpm2Module tpm2 + \ingroup EpidMemberModule + @{ +*/ + +/// Performs TPM2_NV_DefineSpace TPM command. +/*! + \param[in] ctx + The TPM context. + \param[in] nv_index + Handle of the data area. + \param[in] size + Size of the data area. + + \returns ::EpidStatus + + \see Tpm2NvRead + \see Tpm2NvWrite +*/ +EpidStatus Tpm2NvDefineSpace(Tpm2Ctx* ctx, uint32_t nv_index, size_t size); + +/// Performs TPM2_NV_UndefineSpace TPM command. +/*! + \param[in] ctx + The TPM context. + \param[in] nv_index + Handle of the data area to undefine. + + \returns ::EpidStatus + + \see Tpm2NvDefineSpace +*/ +EpidStatus Tpm2NvUndefineSpace(Tpm2Ctx* ctx, uint32_t nv_index); + +/// Performs TPM2_NV_Write TPM command. +/*! + An area in NV memory must be defined prior writing. + + \param[in] ctx + The TPM context. + \param[in] nv_index + NV Index to be write. + \param[in] size + Number of bytes to write. + \param[in] offset + Offset into the area. + \param[in] data + Data to write. + + \returns ::EpidStatus + + \see Tpm2NvDefineSpace +*/ +EpidStatus Tpm2NvWrite(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void const* data); + +/// Performs TPM2_NV_Read TPM command. +/*! + \param[in] ctx + The TPM context. + \param[in] nv_index + NV Index to be read. + \param[in] size + Number of bytes to read. + \param[in] offset + Offset into the area. + \param[out] data + Data read. + + \returns ::EpidStatus + + \see Tpm2NvWrite +*/ +EpidStatus Tpm2NvRead(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void* data); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_NV_H_ diff --git a/external/epid-sdk/epid/member/tpm2/sign.h b/external/epid-sdk/epid/member/tpm2/sign.h new file mode 100644 index 00000000..ddbc2ce6 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/sign.h @@ -0,0 +1,85 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// SDK TPM Sign API. +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_SIGN_H_ +#define EPID_MEMBER_TPM2_SIGN_H_ + +#include + +#include "epid/common/errors.h" +#include "epid/common/stdtypes.h" + +/// \cond +typedef struct Tpm2Ctx Tpm2Ctx; +typedef struct FfElement FfElement; +/// \endcond + +/*! +\addtogroup Tpm2Module tpm2 +\ingroup EpidMemberModule +@{ +*/ + +/// Performs TPM2_Sign TPM command. +/*! +Calculate a pair (k, s) an ECDAA signature. + +Private key f must exist in the TPM context. + +\param[in] ctx +The TPM context. +\param[in] digest +Digest to be signed. +\param[in] digest_len +The size of digest in bytes. +\param[in] counter +A value associated with the random r generated during TPM2_Commit. +\param[out] k +The ECDAA signature k value. Nonce produced by the TPM during signing. +\param[out] s +The ECDAA signature s value. + +\returns ::EpidStatus + +\see Tpm2CreateContext +\see Tpm2Commit +*/ +EpidStatus Tpm2Sign(Tpm2Ctx* ctx, void const* digest, size_t digest_len, + uint16_t counter, FfElement* k, FfElement* s); + +/// Erases random r value assosiated with counter. +/*! + +\param[in] ctx +The TPM context. +\param[in] counter +To be released value associated with the random r generated during TPM2_Commit. + +\note +This function should be used if Tpm2Sign wasn't called after Tpm2Commit +which created counter. + +\returns ::EpidStatus + +\see Tpm2Commit +*/ +EpidStatus Tpm2ReleaseCounter(Tpm2Ctx* ctx, uint16_t counter); + +/*! @} */ + +#endif // EPID_MEMBER_TPM2_SIGN_H_ diff --git a/external/epid-sdk/epid/member/tpm2/src/commit.c b/external/epid-sdk/epid/member/tpm2/src/commit.c new file mode 100644 index 00000000..57150825 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/commit.c @@ -0,0 +1,188 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Commit implementation. +/*! \file */ + +#include "epid/member/tpm2/commit.h" +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/src/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +static EpidStatus InsertR(Tpm2Ctx* ctx, FfElement* r, uint16_t* counter) { + uint16_t index = 0; + if (!ctx || !r || !counter) { + return kEpidBadArgErr; + } + for (index = 0; index < MAX_COMMIT_COUNT; ++index) { + if (!ctx->commit_data[index]) { + ctx->commit_data[index] = r; + break; + } + } + if (index == MAX_COMMIT_COUNT) { + return kEpidMemAllocErr; + } + *counter = index + 1; // counter == 0 should be invalid + return kEpidNoErr; +} + +static void DeleteR(Tpm2Ctx* ctx, uint16_t* counter) { + if (counter && *counter != 0 && *counter <= MAX_COMMIT_COUNT) { + DeleteFfElement(&ctx->commit_data[*counter - 1]); + *counter = 0; + } +} + +EpidStatus Tpm2Commit(Tpm2Ctx* ctx, EcPoint const* p1, void const* s2, + size_t s2_len, FfElement const* y2, EcPoint* k, + EcPoint* l, EcPoint* e, uint16_t* counter) { + EpidStatus sts = kEpidErr; + FiniteField* Fp = NULL; + FiniteField* Fq = NULL; + EcGroup* G1 = NULL; + FfElement* x2 = NULL; + FfElement* r = NULL; + EcPoint* point = NULL; + EcPoint* infinity = NULL; + uint16_t ctr = 0; + + if (!ctx || !ctx->epid2_params || !ctx->f) { + return kEpidBadArgErr; + } + + if (s2 && s2_len <= 0) { + return kEpidBadArgErr; + } + + if ((!s2 && y2) || (s2 && !y2)) { + return kEpidBadArgErr; + } + + if (s2 && (!k || !l)) { + return kEpidBadArgErr; + } + + if (!e || !counter) { + return kEpidBadArgErr; + } + + do { + G1ElemStr point_str = {0}; + BigNumStr r_str = {0}; + const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + bool is_equal = false; + Fp = ctx->epid2_params->Fp; + Fq = ctx->epid2_params->Fq; + G1 = ctx->epid2_params->G1; + + sts = NewEcPoint(G1, &infinity); + BREAK_ON_EPID_ERROR(sts); + // step b + if (s2) { + // step c: compute x2 := HnameAlg(s2) mod p + sts = NewFfElement(Fq, &x2); + BREAK_ON_EPID_ERROR(sts); + sts = FfHash(Fq, s2, s2_len, ctx->hash_alg, x2); + BREAK_ON_EPID_ERROR(sts); + + // step d: if (x2, y2) is not a point on the curve of signHandle, return + // TPM_RC_ECC_POINT + sts = NewEcPoint(G1, &point); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fq, x2, &point_str.x, sizeof(point_str.x)); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fq, y2, &point_str.y, sizeof(point_str.y)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadEcPoint(G1, &point_str, sizeof(point_str), point); + BREAK_ON_EPID_ERROR(sts); + } + + // step e: if p1 is not an Empty Point and p1 is not a point on the curve of + // signHandle, return TPM_RC_ECC_POINT + // This step is guranteed by ReadEcPoint SDK function + + // step g: generate or derive r (see C.2.2) + // step h: set r = r mod n + sts = NewFfElement(Fp, &r); + BREAK_ON_EPID_ERROR(sts); + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, r); + BREAK_ON_EPID_ERROR(sts); + sts = InsertR(ctx, r, &ctr); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, r, &r_str, sizeof(r_str)); + BREAK_ON_EPID_ERROR(sts); + // step i: if s2 is not an Empty Buffer, set K = [ds](x2, y2) and L = + // [r](x2, y2) + if (s2) { + BigNumStr f_str = {0}; + do { + sts = WriteFfElement(Fp, ctx->f, &f_str, sizeof(f_str)); + BREAK_ON_EPID_ERROR(sts); + sts = EcExp(G1, point, &f_str, k); + BREAK_ON_EPID_ERROR(sts); + } while (0); + EpidZeroMemory(&f_str, sizeof(f_str)); + BREAK_ON_EPID_ERROR(sts); + sts = EcExp(G1, point, &r_str, l); + BREAK_ON_EPID_ERROR(sts); + sts = EcIsEqual(G1, k, infinity, &is_equal); + BREAK_ON_EPID_ERROR(sts); + if (is_equal) { + sts = kEpidBadArgErr; + break; + } + sts = EcIsEqual(G1, l, infinity, &is_equal); + BREAK_ON_EPID_ERROR(sts); + if (is_equal) { + sts = kEpidBadArgErr; + break; + } + } + // step j: if p1 is not an Empty Point, set E = [r](p1 ) + if (p1) { + sts = EcExp(G1, p1, &r_str, e); + BREAK_ON_EPID_ERROR(sts); + } else { + // step k: if p1 is an Empty Point and s2 is an Empty Buffer, set E = [r]G + sts = EcExp(G1, ctx->epid2_params->g1, &r_str, e); + BREAK_ON_EPID_ERROR(sts); + } + sts = EcIsEqual(G1, e, infinity, &is_equal); + BREAK_ON_EPID_ERROR(sts); + if (is_equal) { + sts = kEpidBadArgErr; + break; + } + *counter = ctr; + } while (0); + + if (sts != kEpidNoErr) { + DeleteR(ctx, &ctr); + } + DeleteEcPoint(&infinity); + DeleteEcPoint(&point); + DeleteFfElement(&x2); + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/context.c b/external/epid-sdk/epid/member/tpm2/src/context.c new file mode 100644 index 00000000..e6121a04 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/context.c @@ -0,0 +1,119 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM context implementation. +/*! \file */ + +#include + +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" +#include "epid/member/software_member.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/src/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus Tpm2CreateContext(MemberParams const* params, + Epid2Params_ const* epid2_params, + BitSupplier* rnd_func, void** rnd_param, + const FpElemStr** f, Tpm2Ctx** ctx) { + Tpm2Ctx* tpm_ctx = NULL; + EpidStatus sts = kEpidNoErr; + FfElement* ff_elem = NULL; + + if (!params || !epid2_params || !rnd_func || !rnd_param || !f || !ctx) { + return kEpidBadArgErr; + } + + tpm_ctx = SAFE_ALLOC(sizeof(Tpm2Ctx)); + if (!tpm_ctx) { + return kEpidMemAllocErr; + } + + do { + int i; + + if (params->f) { + FiniteField* Fp = epid2_params->Fp; + // Validate f + sts = NewFfElement(Fp, &ff_elem); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, params->f, sizeof(*params->f), ff_elem); + BREAK_ON_EPID_ERROR(sts); + } + tpm_ctx->epid2_params = epid2_params; + tpm_ctx->rnd_func = params->rnd_func; + tpm_ctx->rnd_param = params->rnd_param; + tpm_ctx->f = NULL; + *rnd_func = params->rnd_func; + *rnd_param = params->rnd_param; + *f = params->f; + + for (i = 0; i < MAX_NV_NUMBER; ++i) { + tpm_ctx->nv->nv_index = 0; + tpm_ctx->nv->data = NULL; + tpm_ctx->nv->data_size = 0; + } + + memset(tpm_ctx->commit_data, 0, sizeof(tpm_ctx->commit_data)); + + *ctx = tpm_ctx; + sts = kEpidNoErr; + } while (0); + DeleteFfElement(&ff_elem); + if (kEpidNoErr != sts) { + Tpm2DeleteContext(&tpm_ctx); + *ctx = NULL; + } + return sts; +} + +void Tpm2DeleteContext(Tpm2Ctx** ctx) { + if (ctx && *ctx) { + int i; + (*ctx)->rnd_param = NULL; + DeleteFfElement(&(*ctx)->f); + for (i = 0; i < MAX_COMMIT_COUNT; ++i) { + DeleteFfElement(&(*ctx)->commit_data[i]); + } + for (i = 0; i < MAX_NV_NUMBER; ++i) { + (*ctx)->nv->nv_index = 0; + SAFE_FREE((*ctx)->nv->data); + (*ctx)->nv->data_size = 0; + } + SAFE_FREE(*ctx); + } +} + +EpidStatus Tpm2SetHashAlg(Tpm2Ctx* ctx, HashAlg hash_alg) { + if (!ctx) return kEpidBadArgErr; + if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg && + kSha512_256 != hash_alg) + return kEpidHashAlgorithmNotSupported; + ctx->hash_alg = hash_alg; + return kEpidNoErr; +} + +void Tpm2ResetContext(Tpm2Ctx** ctx) { + if (ctx && *ctx) { + DeleteFfElement(&(*ctx)->f); + } +} diff --git a/external/epid-sdk/epid/member/tpm2/src/createprimary.c b/external/epid-sdk/epid/member/tpm2/src/createprimary.c new file mode 100644 index 00000000..6a893cbb --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/createprimary.c @@ -0,0 +1,58 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \brief TPM2_CreatePrimary command implementation. + * \file + */ +#include "epid/member/tpm2/createprimary.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/member/software_member.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/src/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus Tpm2CreatePrimary(Tpm2Ctx* ctx, G1ElemStr* p_str) { + EpidStatus sts = kEpidErr; + FfElement* ff_elem; + FpElemStr ff_elem_str; + if (!ctx || !ctx->epid2_params) { + return kEpidBadArgErr; + } + (void)p_str; + do { + const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + FiniteField* Fp = ctx->epid2_params->Fp; + sts = NewFfElement(Fp, &ff_elem); + BREAK_ON_EPID_ERROR(sts); + sts = FfGetRandom(Fp, &kOne, ctx->rnd_func, ctx->rnd_param, ff_elem); + BREAK_ON_EPID_ERROR(sts); + sts = WriteFfElement(Fp, ff_elem, &ff_elem_str, sizeof(ff_elem_str)); + BREAK_ON_EPID_ERROR(sts); + } while (0); + DeleteFfElement(&ff_elem); + if (kEpidNoErr == sts) { + sts = Tpm2LoadExternal(ctx, &ff_elem_str); + } + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/getrandom.c b/external/epid-sdk/epid/member/tpm2/src/getrandom.c new file mode 100644 index 00000000..1ded2cfe --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/getrandom.c @@ -0,0 +1,43 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TPM2_GetRandom command implementation. + */ + +#include "epid/member/tpm2/getrandom.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/src/state.h" + +EpidStatus Tpm2GetRandom(Tpm2Ctx* ctx, int const num_bits, void* random_data) { + int rand_ret = -1; + + if (!ctx || !random_data) { + return kEpidBadArgErr; + } + + if (num_bits <= 0) { + return kEpidBadArgErr; + } + + rand_ret = ctx->rnd_func(random_data, num_bits, ctx->rnd_param); + if (rand_ret != 0) { + return kEpidErr; + } + + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/load_external.c b/external/epid-sdk/epid/member/tpm2/src/load_external.c new file mode 100644 index 00000000..e294eaec --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/load_external.c @@ -0,0 +1,54 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TPM2_LoadExternal command implementation. + */ + +#include "epid/member/tpm2/load_external.h" + +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/member/tpm2/src/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +EpidStatus Tpm2LoadExternal(Tpm2Ctx* ctx, FpElemStr const* f_str) { + EpidStatus sts = kEpidErr; + if (!ctx || !ctx->epid2_params || !f_str) { + return kEpidBadArgErr; + } + + do { + FiniteField* Fp = ctx->epid2_params->Fp; + + if (ctx->f) { + DeleteFfElement(&ctx->f); + } + + sts = NewFfElement(Fp, &ctx->f); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, f_str, sizeof(*f_str), ctx->f); + BREAK_ON_EPID_ERROR(sts); + } while (0); + + return sts; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/nv.c b/external/epid-sdk/epid/member/tpm2/src/nv.c new file mode 100644 index 00000000..4d1e122f --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/nv.c @@ -0,0 +1,134 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief TPM NV API implementation. + */ + +#include "epid/member/tpm2/nv.h" + +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/src/state.h" + +/// Find nv_index in nv array +int EpidFindNvIndex(Tpm2Ctx* ctx, uint32_t nv_index) { + int i; + for (i = 0; i < MAX_NV_NUMBER; ++i) { + if (ctx->nv[i].nv_index == nv_index) return i; + } + return -1; +} + +/// Find empty node in nv array +int EpidFindFirstEmptyNvIndex(Tpm2Ctx* ctx) { + int i; + for (i = 0; i < MAX_NV_NUMBER; ++i) { + if (!ctx->nv[i].data_size) return i; + } + return -1; +} + +EpidStatus Tpm2NvDefineSpace(Tpm2Ctx* ctx, uint32_t nv_index, size_t size) { + int index = 0; + if (!ctx || size <= 0) { + return kEpidBadArgErr; + } + if (nv_index < MIN_NV_INDEX) { + return kEpidBadArgErr; + } + if (EpidFindNvIndex(ctx, nv_index) != -1) { + return kEpidDuplicateErr; + } + index = EpidFindFirstEmptyNvIndex(ctx); + if (index == -1) { + return kEpidBadArgErr; + } + ctx->nv[index].nv_index = nv_index; + // memory will be allocated on first NvWrite call + ctx->nv[index].data_size = size; + return kEpidNoErr; +} + +EpidStatus Tpm2NvUndefineSpace(Tpm2Ctx* ctx, uint32_t nv_index) { + int index = 0; + if (!ctx) { + return kEpidBadArgErr; + } + if (nv_index < MIN_NV_INDEX) { + return kEpidBadArgErr; + } + index = EpidFindNvIndex(ctx, nv_index); + if (index == -1) { + return kEpidBadArgErr; + } + ctx->nv[index].nv_index = 0; + SAFE_FREE(ctx->nv[index].data); + ctx->nv[index].data_size = 0; + return kEpidNoErr; +} + +EpidStatus Tpm2NvRead(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void* data) { + uint8_t* buf = NULL; + int index = 0; + if (!ctx || !data || size <= 0) { + return kEpidBadArgErr; + } + if (nv_index < MIN_NV_INDEX) { + return kEpidBadArgErr; + } + index = EpidFindNvIndex(ctx, nv_index); + if (index == -1 || !ctx->nv[index].data) { + return kEpidBadArgErr; + } + if (offset + size > ctx->nv[index].data_size) { + return kEpidBadArgErr; + } + buf = (uint8_t*)ctx->nv[index].data + offset; + if (0 != memcpy_S(data, size, buf, size)) { + return kEpidErr; + } + return kEpidNoErr; +} + +EpidStatus Tpm2NvWrite(Tpm2Ctx* ctx, uint32_t nv_index, size_t size, + uint16_t offset, void const* data) { + uint8_t* buf = NULL; + int index = 0; + if (!ctx || !data || size <= 0) { + return kEpidBadArgErr; + } + if (nv_index < MIN_NV_INDEX) { + return kEpidBadArgErr; + } + index = EpidFindNvIndex(ctx, nv_index); + if (index == -1) { + return kEpidBadArgErr; + } + if (offset + size > ctx->nv[index].data_size) { + return kEpidBadArgErr; + } + if (!ctx->nv[index].data) { + ctx->nv[index].data = SAFE_ALLOC(ctx->nv[index].data_size); + if (!ctx->nv[index].data) return kEpidMemAllocErr; + } + buf = (uint8_t*)ctx->nv[index].data + offset; + if (0 != memcpy_S(buf, size, data, size)) { + return kEpidErr; + } + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/sign.c b/external/epid-sdk/epid/member/tpm2/src/sign.c new file mode 100644 index 00000000..9d2ad6b5 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/sign.c @@ -0,0 +1,127 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Sign implementation. +/*! \file */ + +#include "epid/member/tpm2/sign.h" + +#include + +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/common/types.h" +#include "epid/member/tpm2/src/state.h" + +/// Handle Intel(R) EPID Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +static EpidStatus GetCommitNonce(Tpm2Ctx* ctx, uint16_t counter, + FfElement** r) { + if (!ctx || counter == 0 || !r) { + return kEpidBadArgErr; + } + if (counter >= MAX_COMMIT_COUNT) { + return kEpidBadArgErr; + } + *r = ctx->commit_data[counter - 1]; + return kEpidNoErr; +} + +static void ClearCommitNonce(Tpm2Ctx* ctx, uint16_t counter) { + if (ctx && counter > 0 && counter < MAX_COMMIT_COUNT) { + DeleteFfElement(&ctx->commit_data[counter - 1]); + } +} + +EpidStatus Tpm2Sign(Tpm2Ctx* ctx, void const* digest, size_t digest_len, + uint16_t counter, FfElement* k, FfElement* s) { + EpidStatus sts = kEpidErr; + FfElement* t = NULL; + BigNum* digest_bn = NULL; + FfElement* commit_nonce = NULL; + + if (!ctx || !digest || !s || !ctx->epid2_params) { + return kEpidBadArgErr; + } + if (0 == digest_len || EpidGetHashSize(ctx->hash_alg) != digest_len) { + return kEpidBadArgErr; + } + if (!ctx->f) { + return kEpidBadArgErr; + } + + do { + FpElemStr tmp_str; + FiniteField* Fp = ctx->epid2_params->Fp; + const FpElemStr zero = {0}; + + sts = GetCommitNonce(ctx, counter, &commit_nonce); + BREAK_ON_EPID_ERROR(sts); + + sts = NewBigNum(digest_len, &digest_bn); + BREAK_ON_EPID_ERROR(sts); + sts = NewFfElement(Fp, &t); + BREAK_ON_EPID_ERROR(sts); + + // a. set T = digest (mod p) + sts = ReadBigNum(digest, digest_len, digest_bn); + BREAK_ON_EPID_ERROR(sts); + sts = InitFfElementFromBn(Fp, digest_bn, t); + BREAK_ON_EPID_ERROR(sts); + // b. compute integer s = (r + T*f)(mod p) + sts = FfMul(Fp, ctx->f, t, s); + BREAK_ON_EPID_ERROR(sts); + sts = FfAdd(Fp, commit_nonce, s, s); + BREAK_ON_EPID_ERROR(sts); + + // d. if s = 0, output failure (negligible probability) + sts = WriteFfElement(Fp, s, &tmp_str, sizeof(tmp_str)); + BREAK_ON_EPID_ERROR(sts); + if (0 == memcmp(&zero, &tmp_str, sizeof(tmp_str))) { + sts = kEpidBadArgErr; + break; + } + + if (k) { + // k = T + sts = WriteFfElement(Fp, t, &tmp_str, sizeof(tmp_str)); + BREAK_ON_EPID_ERROR(sts); + sts = ReadFfElement(Fp, &tmp_str, sizeof(tmp_str), k); + BREAK_ON_EPID_ERROR(sts); + } + ClearCommitNonce(ctx, counter); + sts = kEpidNoErr; + } while (0); + + DeleteFfElement(&t); + DeleteBigNum(&digest_bn); + + return sts; +} + +EpidStatus Tpm2ReleaseCounter(Tpm2Ctx* ctx, uint16_t counter) { + if (!ctx) { + return kEpidBadArgErr; + } + + ClearCommitNonce(ctx, counter); + return kEpidNoErr; +} diff --git a/external/epid-sdk/epid/member/tpm2/src/state.h b/external/epid-sdk/epid/member/tpm2/src/state.h new file mode 100644 index 00000000..660019ad --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/src/state.h @@ -0,0 +1,63 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM internal state +/*! \file */ + +#ifndef EPID_MEMBER_TPM2_SRC_STATE_H_ +#define EPID_MEMBER_TPM2_SRC_STATE_H_ + +#include +#include "epid/common/bitsupplier.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" // HashAlg + +/// \cond +typedef struct Epid2Params_ Epid2Params_; +typedef struct FfElement FfElement; +/// \endcond + +/// Maximum NV index +#define MAX_NV_NUMBER 10 +/// Minimal possible NV index in TPM +#define MIN_NV_INDEX 0x01000000 +/// Maximum number of Tpm2Commit random values that can exist in memory +/// simultaneously +#define MAX_COMMIT_COUNT 100 + +#if (MAX_COMMIT_COUNT >= UINT16_MAX) +#error "MAX_COMMIT_COUNT maximum commit count is restricted by uint16_t" +#endif + +/// One NV entry +typedef struct NvEntry { + uint32_t nv_index; + void* data; + size_t data_size; +} NvEntry; + +/// TPM State +typedef struct Tpm2Ctx { + Epid2Params_ const* epid2_params; ///< Intel(R) EPID 2.0 params + FfElement* f; ///< Member private key f value + BitSupplier rnd_func; ///< Pseudo random number generation function + void* rnd_param; ///< Pointer to user context for rnd_func + HashAlg hash_alg; ///< Hash algorithm to use + FfElement* commit_data[MAX_COMMIT_COUNT]; ///< Tpm2Commit random value + ///< corresponding to counter + NvEntry nv[MAX_NV_NUMBER]; ///< NV memory +} Tpm2Ctx; + +#endif // EPID_MEMBER_TPM2_SRC_STATE_H_ diff --git a/external/epid-sdk/epid/member/tpm2/tpm2.parts b/external/epid-sdk/epid/member/tpm2/tpm2.parts new file mode 100644 index 00000000..b6adb3a6 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/tpm2.parts @@ -0,0 +1,123 @@ +############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ +import os + +Import('*') + +env.PartName('tpm2') + +include_files = Pattern(src_dir='.', + includes=['*.h'], + recursive=False).files() + +install_files = Pattern(src_dir='.', + includes=[ + '*.h', + '*.c', + '*-test.cc', + '*-testhelper.cc', + '*.parts'], + recursive=True) + +if 'install_package' in env['MODE']: + env.InstallTopLevel(install_files, + sub_dir='epid/member/${PART_SHORT_NAME}') +else: + env.DependsOn([ + Component('common'), + ]) + + env.Append(CPPPATH='#') + + if 'use_tss' in env['MODE']: + src_files = Pattern(src_dir='ibm_tss', + includes=['*.c'], + recursive=False).files() + utest_files = Pattern(src_dir='unittests', + includes=['*-test.cc', + '*-testhelper.cc'], + excludes=['*-simulator-test.cc'], + recursive=False).files() + if env['TARGET_ARCH'] == 'x86_64' and env['TARGET_PLATFORM']['OS'] == 'win32': + PrintError("--use-tss is not compatiable with x86_64 target. " + "Try an x86 build.") + try: + TSSROOT = os.environ['TSSROOT'] + except KeyError, e: + env.PrintError("Necessary environment variable not set: ", + e, show_stack=False) + env.Append(CPPPATH=TSSROOT) + env.Append(LIBPATH=TSSROOT) + if 'cl' in env['CC']: + env.Append(CCFLAGS=['/wd4201', # allow nameless struct + '/wd4200', # allow zero-sized array in struct + ]) + env.Append(CPPDEFINES=['TPM_TSS']) + + else: + src_files = Pattern(src_dir='src', + includes=['*.c'], + recursive=False).files() + + utest_files = Pattern(src_dir='unittests', + includes=['*-test.cc', + '*-testhelper.cc'], + excludes=['*-tss-test.cc'], + recursive=False).files() + + testenv = env.Clone() + + outputs = env.Library('${PART_NAME}', src_files) + env.Sdk(outputs) + env.SdkInclude(include_files, + sub_dir='epid/member/${PART_SHORT_NAME}') + + #unit tests + testenv['UNIT_TEST_TARGET_NAME'] = "${PART_NAME}-${UNIT_TEST_TARGET}" + + utest = testenv.UnitTest("utest", + utest_files, + command_args=[ + '--gtest_color=yes', + '--gtest_print_time=1', + '--gtest_output=xml', + '--gtest_filter=**', + ], + make_pdb=(env.isConfigBasedOn('debug') or + env.isConfigBasedOn('static_crt_debug')), + depends=[Component('gtest'), + Component('common-testhelper'), + Component('member.tpm2')], + INSTALL_BIN='${INSTALL_TEST_BIN}') + + if 'use_tss' in env['MODE']: + if env['TARGET_PLATFORM']['OS'] == 'win32': + libpost = env['LIBSUFFIX'] + shlibpost = env['SHLIBSUFFIX'] + else: + libpost = env['SHLIBSUFFIX'] + shlibpost = libpost + + tss_libname = env['LIBPREFIX'] + 'tss' + libpost + env.SdkLib(os.path.join(TSSROOT, tss_libname)) + + if env['TARGET_PLATFORM']['OS'] != 'win32': + env.ExportLIBS(['crypto']) + + tss_shlibname = env['SHLIBPREFIX'] + 'tss' + shlibpost + runtime_lib = testenv.CCopy("${INSTALL_TEST_BIN}", + os.path.join(TSSROOT, tss_shlibname)) + Depends(utest, runtime_lib) diff --git a/external/epid-sdk/epid/member/tpm2/unittests/commit-simulator-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/commit-simulator-test.cc new file mode 100644 index 00000000..c5764279 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/commit-simulator-test.cc @@ -0,0 +1,292 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Commit unit tests. +/*! \file */ + +#include + +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/common/src/epid2params.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/sign.h" +#include "epid/member/tpm2/src/state.h" +} + +namespace { + +TEST_F(EpidTpm2Test, CommitComputeKLESha256) { + // Testing step i and j of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + EcPointObj p1_exp_r(¶ms.G1), p2_exp_r(¶ms.G1); + G1ElemStr p1_exp_r_str, p2_exp_r_str; + EcPointObj p2(¶ms.G1, this->kP2Sha256Str); + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p1, (BigNumStr const*)&r_str, p1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p1_exp_r, &p1_exp_r_str, sizeof(p1_exp_r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p2, (BigNumStr const*)&r_str, p2_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p2_exp_r, &p2_exp_r_str, sizeof(p2_exp_r_str))); + + G1ElemStr k_str, l_str, e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, k, &k_str, sizeof(k_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, l, &l_str, sizeof(l_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(this->kP2Sha256ExpF, k_str); + EXPECT_EQ(p2_exp_r_str, l_str); + EXPECT_EQ(p1_exp_r_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitComputeKLESha384) { + // Testing step i and j of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha384Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha384)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p1, this->kS2Sha384.data(), this->kS2Sha384.size(), + y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + EcPointObj p1_exp_r(¶ms.G1), p2_exp_r(¶ms.G1); + G1ElemStr p1_exp_r_str, p2_exp_r_str; + EcPointObj p2(¶ms.G1, this->kP2Sha384Str); + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p1, (BigNumStr const*)&r_str, p1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p1_exp_r, &p1_exp_r_str, sizeof(p1_exp_r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p2, (BigNumStr const*)&r_str, p2_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p2_exp_r, &p2_exp_r_str, sizeof(p2_exp_r_str))); + + G1ElemStr k_str, l_str, e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, k, &k_str, sizeof(k_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, l, &l_str, sizeof(l_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(this->kP2Sha384ExpF, k_str); + EXPECT_EQ(p2_exp_r_str, l_str); + EXPECT_EQ(p1_exp_r_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitComputeKLESha512) { + // Testing step i and j of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha512Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha512)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p1, this->kS2Sha512.data(), this->kS2Sha512.size(), + y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + EcPointObj p1_exp_r(¶ms.G1), p2_exp_r(¶ms.G1); + G1ElemStr p1_exp_r_str, p2_exp_r_str; + EcPointObj p2(¶ms.G1, this->kP2Sha512Str); + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p1, (BigNumStr const*)&r_str, p1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p1_exp_r, &p1_exp_r_str, sizeof(p1_exp_r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p2, (BigNumStr const*)&r_str, p2_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p2_exp_r, &p2_exp_r_str, sizeof(p2_exp_r_str))); + + G1ElemStr k_str, l_str, e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, k, &k_str, sizeof(k_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, l, &l_str, sizeof(l_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(this->kP2Sha512ExpF, k_str); + EXPECT_EQ(p2_exp_r_str, l_str); + EXPECT_EQ(p1_exp_r_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitComputeKLESha512256) { + // Testing step i and j of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha512256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha512_256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p1, this->kS2Sha512256.data(), + this->kS2Sha512256.size(), y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + EcPointObj p1_exp_r(¶ms.G1), p2_exp_r(¶ms.G1); + G1ElemStr p1_exp_r_str, p2_exp_r_str; + EcPointObj p2(¶ms.G1, this->kP2Sha512256Str); + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p1, (BigNumStr const*)&r_str, p1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p1_exp_r, &p1_exp_r_str, sizeof(p1_exp_r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p2, (BigNumStr const*)&r_str, p2_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p2_exp_r, &p2_exp_r_str, sizeof(p2_exp_r_str))); + + G1ElemStr k_str, l_str, e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, k, &k_str, sizeof(k_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, l, &l_str, sizeof(l_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(this->kP2Sha512256ExpF, k_str); + EXPECT_EQ(p2_exp_r_str, l_str); + EXPECT_EQ(p1_exp_r_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitComputeEOnly) { + // Testing step j excuding i of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha512Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha512)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p1, nullptr, 0, nullptr, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + EcPointObj p1_exp_r(¶ms.G1); + G1ElemStr p1_exp_r_str; + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, p1, (BigNumStr const*)&r_str, p1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, p1_exp_r, &p1_exp_r_str, sizeof(p1_exp_r_str))); + + G1ElemStr e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(p1_exp_r_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitComputeEOnlyWithDefaultP1) { + // Testing step k excuding i of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha512Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha512)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, nullptr, + nullptr, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + EcPointObj g1(¶ms.G1, this->kg1Str); + EcPointObj g1_exp_r(¶ms.G1); + G1ElemStr g1_exp_r_str; + Prng the_same_prng; + FfElementObj r(¶ms.fp); + BigNumStr zero = {0}; + FpElemStr r_str = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r)); + THROW_ON_EPIDERR(WriteFfElement(params.fp, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(EcExp(params.G1, g1, (BigNumStr const*)&r_str, g1_exp_r)); + THROW_ON_EPIDERR( + WriteEcPoint(params.G1, g1_exp_r, &g1_exp_r_str, sizeof(g1_exp_r_str))); + + G1ElemStr e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(g1_exp_r_str, e_str); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/commit-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/commit-test.cc new file mode 100644 index 00000000..dca23f38 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/commit-test.cc @@ -0,0 +1,321 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Commit unit tests. +/*! \file */ + +#include "gtest/gtest.h" + +#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/common/src/endian_convert.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/sign.h" +} + +namespace { + +TEST_F(EpidTpm2Test, CommitFailsGivenNullParameters) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(nullptr, p1, this->kS2Sha256.data(), + this->kS2Sha256.size(), y2, k, l, e, &counter)); + EXPECT_EQ(kEpidBadArgErr, Tpm2Commit(tpm, p1, nullptr, this->kS2Sha256.size(), + y2, k, l, e, &counter)); + // Testing step a of the "C.2.3 Tpm2Commit()" + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + nullptr, k, l, e, &counter)); + // Testing step a of the "C.2.3 Tpm2Commit()" + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, nullptr, l, e, &counter)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, nullptr, e, &counter)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, nullptr, &counter)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, nullptr)); +} + +TEST_F(EpidTpm2Test, CommitFailsGivenInvalidLength) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidBadArgErr, Tpm2Commit(tpm, p1, this->kS2Sha256.data(), 0, y2, + k, l, e, &counter)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), sizeof(uint16_t) - 1, + y2, k, l, e, &counter)); +} + +TEST_F(EpidTpm2Test, CommitFailsGivenPrivateKeyDoesNotExists) { + // Testing step d of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, NULL, epid2params); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, &counter)); +} + +TEST_F(EpidTpm2Test, CommitFailsGivenS2y2NotOnCurve) { + // Testing step d of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + EcPointObj p1(¶ms.G1, this->kP1Str); + FqElemStr invalid_kY2Sha256Str = this->kY2Sha256Str; + invalid_kY2Sha256Str.data.data[31]++; // make point not belong to the group + FfElementObj invalid_y2(¶ms.fq, invalid_kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, p1, this->kS2Sha256.data(), this->kS2Sha256.size(), + invalid_y2, k, l, e, &counter)); +} + +TEST_F(EpidTpm2Test, CommitFailsIfResultIsAtInfinity) { + // Testing step l of the "C.2.3 Tpm2Commit()" + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + G1ElemStr infinity_str = {0}; + EcPointObj infinity(¶ms.G1, infinity_str); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Commit(tpm, infinity, this->kS2Sha256.data(), + this->kS2Sha256.size(), y2, k, l, e, &counter)); +} + +TEST_F(EpidTpm2Test, CommitCanUseKeyLoadedByLoadExternal) { + Prng prng; + Epid2ParamsObj epid2params; + Epid20Params params; + FpElemStr f_str = this->kMemberFValue; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + uint16_t counter = 0; + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, nullptr, this->kS2Sha256.data(), + this->kS2Sha256.size(), y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + // k = (x2, y2) ^ f, where x2 = Hash(s2) + G1ElemStr k_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, k, &k_str, sizeof(k_str))); + EXPECT_EQ(this->kP2Sha256ExpF, k_str); +} + +TEST_F(EpidTpm2Test, CommitReturnsSameLEForSameP1P2) { + Prng prng; + Epid2ParamsObj epid2params; + Epid20Params params; + FpElemStr f_str = this->kMemberFValue; + // create TPM context + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + // load f value + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + // commit(P1=p2, P2=p2) => k = p2^f, l = p2^r, e = p2^r + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + EcPointObj p2(¶ms.G1, kP2Sha256Str); + EcPointObj p2_exp_f(¶ms.G1, kP2Sha256ExpF); + + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + uint16_t counter = 0; + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p2, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, &counter)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); + + G1ElemStr l_str, e_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, l, &l_str, sizeof(l_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, e, &e_str, sizeof(e_str))); + EXPECT_EQ(l_str, e_str); +} + +TEST_F(EpidTpm2Test, CommitCanBeUsedTwice) { + Prng prng; + Epid2ParamsObj epid2params; + Epid20Params params; + FpElemStr f_str = this->kMemberFValue; + // create TPM context + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + // load f value + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + EcPointObj p1(¶ms.G1, this->kP1Str); + EcPointObj e(¶ms.G1); + uint16_t ctr1 = 0, ctr2 = 0; + + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, p1, nullptr, 0, nullptr, nullptr, + nullptr, e, &ctr1)); + + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, p1, nullptr, 0, nullptr, nullptr, + nullptr, e, &ctr2)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, ctr1)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, ctr2)); +} +TEST_F(EpidTpm2Test, CommitCanUseHashFromEcHashSha256) { + HashAlg halg = kSha256; + Prng prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + Epid20Params params; + EcPointObj R(¶ms.G1), k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj y(¶ms.fq); + uint32_t i = 0; + uint16_t counter = 0; + G1ElemStr R_str = {0}; + std::vector bsn = {'b', 's', 'n', '0'}; + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, halg)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + EXPECT_EQ(kEpidNoErr, + EcHash(epid2params.G1(), bsn.data(), bsn.size(), halg, R, &i)); + i = ntohl(i); + THROW_ON_EPIDERR(WriteEcPoint(epid2params.G1(), R, &R_str, sizeof(R_str))); + THROW_ON_EPIDERR( + ReadFfElement(params.fq.get(), &R_str.y, sizeof(R_str.y), y)); + + std::vector digest((uint8_t*)&i, (uint8_t*)&i + sizeof(i)); + digest.reserve(digest.size() + bsn.size()); + digest.insert(digest.end(), bsn.begin(), bsn.end()); + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, nullptr, digest.data(), digest.size(), + y, k, l, e, &counter)); + Tpm2ReleaseCounter(tpm, counter); +} +#ifndef TPM_TSS +TEST_F(EpidTpm2Test, CommitCanUseHashFromEcHashSha384) { + HashAlg halg = kSha384; + Prng prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + Epid20Params params; + EcPointObj R(¶ms.G1), k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj y(¶ms.fq); + uint32_t i = 0; + uint16_t counter = 0; + G1ElemStr R_str = {0}; + std::vector bsn = {'b', 's', 'n', '0'}; + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, halg)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + EXPECT_EQ(kEpidNoErr, + EcHash(epid2params.G1(), bsn.data(), bsn.size(), halg, R, &i)); + i = ntohl(i); + THROW_ON_EPIDERR(WriteEcPoint(epid2params.G1(), R, &R_str, sizeof(R_str))); + THROW_ON_EPIDERR( + ReadFfElement(params.fq.get(), &R_str.y, sizeof(R_str.y), y)); + + std::vector digest((uint8_t*)&i, (uint8_t*)&i + sizeof(i)); + digest.reserve(digest.size() + bsn.size()); + digest.insert(digest.end(), bsn.begin(), bsn.end()); + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, nullptr, digest.data(), digest.size(), + y, k, l, e, &counter)); + Tpm2ReleaseCounter(tpm, counter); +} +TEST_F(EpidTpm2Test, CommitCanUseHashFromEcHashSha512) { + HashAlg halg = kSha512; + Prng prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &prng, &f_str, epid2params); + Epid20Params params; + EcPointObj R(¶ms.G1), k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj y(¶ms.fq); + uint32_t i = 0; + uint16_t counter = 0; + G1ElemStr R_str = {0}; + std::vector bsn = {'b', 's', 'n', '0'}; + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, halg)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f_str)); + + EXPECT_EQ(kEpidNoErr, + EcHash(epid2params.G1(), bsn.data(), bsn.size(), halg, R, &i)); + i = ntohl(i); + THROW_ON_EPIDERR(WriteEcPoint(epid2params.G1(), R, &R_str, sizeof(R_str))); + THROW_ON_EPIDERR( + ReadFfElement(params.fq.get(), &R_str.y, sizeof(R_str.y), y)); + + std::vector digest((uint8_t*)&i, (uint8_t*)&i + sizeof(i)); + digest.reserve(digest.size() + bsn.size()); + digest.insert(digest.end(), bsn.begin(), bsn.end()); + EXPECT_EQ(kEpidNoErr, Tpm2Commit(tpm, nullptr, digest.data(), digest.size(), + y, k, l, e, &counter)); + Tpm2ReleaseCounter(tpm, counter); +} +#endif // TPM_TSS +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/context-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/context-test.cc new file mode 100644 index 00000000..3b7d98ad --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/context-test.cc @@ -0,0 +1,105 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM Context unit tests. +/*! \file */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/common/src/epid2params.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/load_external.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2CreateContext Tests +TEST_F(EpidTpm2Test, CreateFailsGivenNullParameters) { + Tpm2Ctx* ctx = nullptr; + Prng my_prng; + BitSupplier rnd_func = NULL; + void* rnd_param = NULL; + const FpElemStr* f = NULL; + MemberParams mem_params = {0}; + Epid2ParamsObj epid_params; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params); + + EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(nullptr, epid_params, &rnd_func, + &rnd_param, &f, &ctx)); + EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, nullptr, &rnd_func, + &rnd_param, &f, &ctx)); + EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, epid_params, nullptr, + &rnd_param, &f, &ctx)); + EXPECT_EQ(kEpidBadArgErr, Tpm2CreateContext(&mem_params, epid_params, + &rnd_func, nullptr, &f, &ctx)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param, + nullptr, &ctx)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param, + &f, nullptr)); +} + +TEST_F(EpidTpm2Test, CreateSucceedsGivenValidParameters) { + Tpm2Ctx* ctx = nullptr; + Prng my_prng; + BitSupplier rnd_func = NULL; + void* rnd_param = NULL; + const FpElemStr* f = NULL; + MemberParams mem_params = {0}; + Epid2ParamsObj epid_params; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params); + + EXPECT_EQ(kEpidNoErr, Tpm2CreateContext(&mem_params, epid_params, &rnd_func, + &rnd_param, &f, &ctx)); + Tpm2DeleteContext(&ctx); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2DeleteContext Tests +TEST_F(EpidTpm2Test, DeleteWorksGivenNullTpm2Ctx) { + Tpm2DeleteContext(nullptr); + Tpm2Ctx* ctx = nullptr; + Tpm2DeleteContext(&ctx); +} + +TEST_F(EpidTpm2Test, DeleteNullsTpm2Ctx) { + Tpm2Ctx* ctx = nullptr; + Prng my_prng; + BitSupplier rnd_func = NULL; + void* rnd_param = NULL; + const FpElemStr* f = NULL; + MemberParams mem_params = {0}; + Epid2ParamsObj epid_params; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, &mem_params); + Tpm2CreateContext(&mem_params, epid_params, &rnd_func, &rnd_param, &f, &ctx); + Tpm2DeleteContext(&ctx); + EXPECT_EQ(nullptr, ctx); +} + +TEST_F(EpidTpm2Test, PROTECTED_SampleTest) { SUCCEED(); } + +TEST_F(EpidTpm2Test, PROTECTED_EPS1_SampleTest) { SUCCEED(); } + +TEST_F(EpidTpm2Test, PROTECTED_EPSOther_SampleTest) { SUCCEED(); } + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/conversion-tss-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/conversion-tss-test.cc new file mode 100644 index 00000000..5279058b --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/conversion-tss-test.cc @@ -0,0 +1,160 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM mapper unit tests. +/*! \file */ + +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" +#include "gtest/gtest.h" +extern "C" { +#include "epid/member/tpm2/ibm_tss/conversion.h" +} + +bool operator==(OctStr256 const& lhs, OctStr256 const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(OctStr256)); +} + +bool operator==(G1ElemStr const& epid_point, TPM2B_ECC_POINT const& tpm_point) { + if (std::memcmp(&epid_point.x, tpm_point.point.x.t.buffer, + sizeof(G1ElemStr) / 2) != 0) + return false; + + return 0 == std::memcmp(&epid_point.y, tpm_point.point.y.t.buffer, + sizeof(G1ElemStr) / 2); +} + +//////////////////////////////////////////////// +// EpidtoTpm2HashAlg +TEST_F(EpidTpm2Test, EpidtoTpm2HashAlgWorksCorrectly) { + EXPECT_EQ(TPM_ALG_SHA256, EpidtoTpm2HashAlg(kSha256)); + EXPECT_EQ(TPM_ALG_SHA384, EpidtoTpm2HashAlg(kSha384)); + EXPECT_EQ(TPM_ALG_SHA512, EpidtoTpm2HashAlg(kSha512)); + EXPECT_EQ(TPM_ALG_NULL, EpidtoTpm2HashAlg(kSha512_256)); + EXPECT_EQ(TPM_ALG_NULL, EpidtoTpm2HashAlg(kInvalidHashAlg)); + EXPECT_EQ(TPM_ALG_NULL, EpidtoTpm2HashAlg((HashAlg)10)); +} +//////////////////////////////////////////////// +// Tpm2toEpidHashAlg +TEST_F(EpidTpm2Test, Tpm2toEpidHashAlgWorksCorrectly) { + EXPECT_EQ(kSha256, Tpm2toEpidHashAlg(TPM_ALG_SHA256)); + EXPECT_EQ(kSha384, Tpm2toEpidHashAlg(TPM_ALG_SHA384)); + EXPECT_EQ(kSha512, Tpm2toEpidHashAlg(TPM_ALG_SHA512)); + EXPECT_EQ(kInvalidHashAlg, Tpm2toEpidHashAlg(TPM_ALG_NULL)); + EXPECT_EQ(kInvalidHashAlg, Tpm2toEpidHashAlg((TPMI_ALG_HASH)0x0020)); +} +//////////////////////////////////////////////// +// ReadTpm2FfElement +TEST_F(EpidTpm2Test, ReadTpm2FfElementFailsGivenNullPointer) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + OctStr256 stub = {0}; + EXPECT_EQ(kEpidBadArgErr, ReadTpm2FfElement(nullptr, &ecc_parameter)); + EXPECT_EQ(kEpidBadArgErr, ReadTpm2FfElement(&stub, nullptr)); +} + +TEST_F(EpidTpm2Test, ReadTpm2FfElementMapsGivenValidArguments) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + EXPECT_EQ(kEpidNoErr, + ReadTpm2FfElement((OctStr256*)this->kTpmFfElemStrData.data(), + &ecc_parameter)); + EXPECT_EQ((uint16_t)this->kTpmFfElemStrData.size(), ecc_parameter.b.size); + EXPECT_EQ(*(OctStr256*)this->kTpmFfElemStrData.data(), + *(OctStr256*)ecc_parameter.b.buffer); +} + +//////////////////////////////////////////////// +// WriteTpm2FfElement + +TEST_F(EpidTpm2Test, WriteTpm2FfElementFailsGivenNullPointer) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + OctStr256 result = {0}; + EXPECT_EQ(kEpidBadArgErr, WriteTpm2FfElement(nullptr, &result)); + EXPECT_EQ(kEpidBadArgErr, WriteTpm2FfElement(&ecc_parameter, nullptr)); +} + +TEST_F(EpidTpm2Test, WriteTpm2FfElementfailsGivenSmallBufSize) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + OctStr256 result = {0}; + THROW_ON_EPIDERR(ReadTpm2FfElement((OctStr256*)this->kTpmFfElemStrData.data(), + &ecc_parameter)); + + ecc_parameter.b.size++; + EXPECT_EQ(kEpidBadArgErr, WriteTpm2FfElement(&ecc_parameter, &result)); +} + +TEST_F(EpidTpm2Test, WriteTpm2FfElementWorksGivenLargerBufSize) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + OctStr256 result = {0}; + THROW_ON_EPIDERR(ReadTpm2FfElement((OctStr256*)this->kTpmFfElemStrData.data(), + &ecc_parameter)); + + std::vector expected(ecc_parameter.b.size); + for (size_t i = 1; i < expected.size(); ++i) { + expected[i] = this->kTpmFfElemStrData[i - 1]; + } + ecc_parameter.b.size--; + expected[0] = 0x00; + EXPECT_EQ(kEpidNoErr, WriteTpm2FfElement(&ecc_parameter, &result)); + + EXPECT_EQ(*(OctStr256*)expected.data(), result); +} + +TEST_F(EpidTpm2Test, WriteTpm2FfElementWorksGivenValidArguments) { + TPM2B_ECC_PARAMETER ecc_parameter = {0}; + OctStr256 result = {0}; + THROW_ON_EPIDERR(ReadTpm2FfElement((OctStr256*)this->kTpmFfElemStrData.data(), + &ecc_parameter)); + + EXPECT_EQ(kEpidNoErr, WriteTpm2FfElement(&ecc_parameter, &result)); + EXPECT_EQ(*(OctStr256*)this->kTpmFfElemStrData.data(), result); +} + +//////////////////////////////////////////////// +// ReadTpmFromEcPoint +TEST_F(EpidTpm2Test, ReadTpm2EcPointFailsGivenNullPointer) { + TPM2B_ECC_POINT tpm_point; + + EXPECT_EQ(kEpidBadArgErr, ReadTpm2EcPoint(nullptr, &tpm_point)); + EXPECT_EQ(kEpidBadArgErr, ReadTpm2EcPoint(&this->kEpidPointStr, nullptr)); +} + +TEST_F(EpidTpm2Test, ReadTpm2EcPointWorksGivenValidArguments) { + TPM2B_ECC_POINT tpm_point; + + EXPECT_EQ(kEpidNoErr, ReadTpm2EcPoint(&this->kEpidPointStr, &tpm_point)); + + EXPECT_EQ(this->kEpidPointStr, tpm_point); +} + +//////////////////////////////////////////////// +// WriteTpm2EcPoint +TEST_F(EpidTpm2Test, WriteTpm2EcPointFailsGivenNullPointer) { + TPM2B_ECC_POINT tpm_point; + G1ElemStr str = {0}; + EXPECT_EQ(kEpidBadArgErr, WriteTpm2EcPoint(nullptr, &str)); + EXPECT_EQ(kEpidBadArgErr, WriteTpm2EcPoint(&tpm_point, nullptr)); +} + +TEST_F(EpidTpm2Test, WriteTpm2EcPointWorksGivenValidArguments) { + TPM2B_ECC_POINT tpm_point; + G1ElemStr str = {0}; + EXPECT_EQ(kEpidNoErr, ReadTpm2EcPoint(&this->kEpidPointStr, &tpm_point)); + + EXPECT_EQ(kEpidNoErr, WriteTpm2EcPoint(&tpm_point, &str)); + + EXPECT_EQ(str, tpm_point); +} diff --git a/external/epid-sdk/epid/member/tpm2/unittests/createprimary-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/createprimary-test.cc new file mode 100644 index 00000000..c1e4f418 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/createprimary-test.cc @@ -0,0 +1,48 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM2_CreatePrimary unit tests. +/*! \file */ + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/member/tpm2/createprimary.h" +} +namespace { + +TEST_F(EpidTpm2Test, CreatePrimaryFailsGivenNullParameters) { + Epid2ParamsObj epid2params; + Tpm2CtxObj tss(nullptr, nullptr, nullptr, epid2params); + G1ElemStr res = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2CreatePrimary(tss, nullptr)); + EXPECT_EQ(kEpidBadArgErr, Tpm2CreatePrimary(nullptr, &res)); +} +TEST_F(EpidTpm2Test, CreatePrimaryWorksGivenValidParameter) { + Prng prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tss(Prng::Generate, &prng, nullptr, epid2params); + G1ElemStr res = {0}; + THROW_ON_EPIDERR(Tpm2SetHashAlg(tss, kSha256)); + EXPECT_EQ(kEpidNoErr, Tpm2CreatePrimary(tss, &res)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/getrandom-simulator-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-simulator-test.cc new file mode 100644 index 00000000..da6c2746 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-simulator-test.cc @@ -0,0 +1,53 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM GetRandom unit tests. +/*! \file */ +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/getrandom.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2GetRandom Tests + +// Test if GetRandom can get deterministic data for known seed +TEST_F(EpidTpm2Test, GetRandomGetsExpectedDataForGivenSeed) { + std::vector expected_digest = { + 0x76, 0x90, 0x2c, 0x3b, 0xa5, 0x25, 0xd7, 0x1e, 0x66, 0x67, 0xaa, 0xb9, + 0x80, 0x50, 0x9c, 0x17, 0x65, 0x19, 0x06, 0x2a, 0x53, 0x49, 0x7d, 0x1b, + 0xe5, 0xf4, 0xec, 0xf3, 0xf0, 0x69, 0x81, 0xdc, 0x0f, 0x5a, 0x6f, 0x1c, + 0xb3, 0x78, 0xa8, 0xea, 0x6b, 0xab, 0x1d, 0xc7, 0xd6, 0x1a, 0x10, 0x1a}; + std::vector output(48); + Prng my_prng; + my_prng.set_seed(0x1234); + Epid2ParamsObj epid2params; + int num_bits = (int)expected_digest.size() * 8; + Tpm2CtxObj tpm2(&Prng::Generate, &my_prng, NULL, epid2params); + my_prng.set_seed(0x1234); + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tpm2, num_bits, output.data())); + EXPECT_EQ(expected_digest, output); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/getrandom-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-test.cc new file mode 100644 index 00000000..3bde88bd --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-test.cc @@ -0,0 +1,67 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM GetRandom unit tests. +/*! \file */ +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/getrandom.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2GetRandom Tests +TEST_F(EpidTpm2Test, GetRandomFailsGivenNullParameters) { + uint8_t output[48] = {0}; + Prng my_prng; + my_prng.set_seed(0x1234); + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + EXPECT_EQ(kEpidBadArgErr, Tpm2GetRandom(nullptr, 48 * 8, output)); + EXPECT_EQ(kEpidBadArgErr, Tpm2GetRandom(tpm, 48 * 8, nullptr)); +} + +TEST_F(EpidTpm2Test, GetRandomReturnsDifferentBufs) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + int length = 10; + std::vector buf1(length, (uint8_t)0); + std::vector buf2(length, (uint8_t)0); + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tpm, length * CHAR_BIT, buf1.data())); + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tpm, length * CHAR_BIT, buf2.data())); + EXPECT_NE(buf1, buf2); +} + +TEST_F(EpidTpm2Test, GetRandomCanGenerateLongStream) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + int length = 1000; + std::vector zeros(length, (uint8_t)0); + std::vector buf = zeros; + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tpm, length * CHAR_BIT, buf.data())); + EXPECT_NE(buf, zeros); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/getrandom-tss-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-tss-test.cc new file mode 100644 index 00000000..021fce44 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/getrandom-tss-test.cc @@ -0,0 +1,44 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM Context unit tests. +/*! \file */ + +#include +#include +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/getrandom.h" +} + +namespace { + +TEST_F(EpidTpm2Test, GetRandomOnTssReturnsDifferentBufs) { + Epid2ParamsObj epid2params; + Tpm2CtxObj tss(nullptr, nullptr, nullptr, epid2params); + size_t length = 10; + std::vector buf1(length, (uint8_t)0); + std::vector buf2(length, (uint8_t)0); + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf1.data())); + EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf2.data())); + EXPECT_NE(buf1, buf2); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/load_external-simulator-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/load_external-simulator-test.cc new file mode 100644 index 00000000..ec580803 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/load_external-simulator-test.cc @@ -0,0 +1,58 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2LoadExternal unit tests. +/*! \file */ + +#include + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tpm2/load_external.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2LoadExternal Tests +TEST_F(EpidTpm2Test, LoadExternalCanLoadFValueSha384) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha384)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(ctx, &f_str)); +} +TEST_F(EpidTpm2Test, LoadExternalCanLoadFValueSha512) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(ctx, &f_str)); +} +TEST_F(EpidTpm2Test, LoadExternalCanLoadFValueSha512_256) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha512_256)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(ctx, &f_str)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/load_external-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/load_external-test.cc new file mode 100644 index 00000000..8405e270 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/load_external-test.cc @@ -0,0 +1,60 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2LoadExternal unit tests. +/*! \file */ + +#include + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/tpm2/load_external.h" +} + +namespace { +TEST_F(EpidTpm2Test, SetHashAlgFailsIfHashAlgNotSupported) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_256)); + EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_384)); + EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_512)); +} +////////////////////////////////////////////////////////////////////////// +// Tpm2LoadExternal Tests +TEST_F(EpidTpm2Test, LoadExternalFailsGivenNullParameters) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidBadArgErr, Tpm2LoadExternal(nullptr, &f_str)); + EXPECT_EQ(kEpidBadArgErr, Tpm2LoadExternal(ctx, nullptr)); +} +TEST_F(EpidTpm2Test, LoadExternalCanLoadFValueSha256) { + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f_str = this->kMemberFValue; + Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(ctx, &f_str)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/main-testhelper.cc b/external/epid-sdk/epid/member/tpm2/unittests/main-testhelper.cc new file mode 100644 index 00000000..1d491658 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/main-testhelper.cc @@ -0,0 +1,64 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// Main entry point for unit tests. +/*! \file */ + +#include "epid/common-testhelper/testapp-testhelper.h" +#include "gtest/gtest.h" + +int main(int argc, char** argv) { + std::vector positive; + std::vector negative; + std::vector argv_new; + argv_new.push_back(argv[0]); + bool include_protected = false; + bool print_help = false; + for (int i = 1; i < argc; i++) { + std::string arg(argv[i]); + if (arg == std::string("--also_run_protected_tests")) { + include_protected = true; + } else if (arg == std::string("--help")) { + print_help = true; + argv_new.push_back(argv[i]); + } else if (arg.compare(0, 15, "--gtest_filter=") == 0) { + split_filter(&positive, &negative, arg.substr(15)); + } else { + argv_new.push_back(argv[i]); + } + } + if (!include_protected) { + negative.push_back("*.*_PROTECTED_*"); + negative.push_back("*.PROTECTED_*"); + } + std::string filter = join_filter(positive, negative); + if (filter != "") { + argv_new.push_back(&filter[0]); + } + int argc_new = (int)argv_new.size(); + argv_new.push_back(nullptr); + testing::InitGoogleTest(&argc_new, argv_new.data()); + if (print_help) { + printf("\n"); + printf("Custom Options:\n"); + printf(" --also_run_protected_tests\n"); + printf(" similar to --gtest_also_run_disabled_tests, but for\n"); + printf(" protected tests (PROTECTED_ instead of DISABLED_)\n"); + printf("\n"); + printf("Protected tests are tests where some data is protected\n"); + printf("(i.e. hidden) from the code and can only be used indirectly.\n"); + } + return RUN_ALL_TESTS(); +} diff --git a/external/epid-sdk/epid/member/tpm2/unittests/nv-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/nv-test.cc new file mode 100644 index 00000000..5c30abf0 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/nv-test.cc @@ -0,0 +1,326 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM non volatile memory API unit tests. +/*! \file */ +#include +#include +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/member/tpm2/nv.h" +} + +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +namespace { + +TEST(NvTest, CanStoreMembershipCredential) { + // Demonstrate NV API usage + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + + MembershipCredential const credential = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, + 0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, + 0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, + {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, + 0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, + 0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A + {{{0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}}} // x + }; + MembershipCredential data = {0}; + + // probe is nv_index is defined + if (kEpidNoErr != Tpm2NvRead(tpm, nv_index, sizeof(data), 0, &data)) { + EXPECT_EQ(kEpidNoErr, + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + } + // write + EXPECT_EQ(kEpidNoErr, + Tpm2NvWrite(tpm, nv_index, sizeof(credential), 0, &credential)); + + // read + EXPECT_EQ(kEpidNoErr, Tpm2NvRead(tpm, nv_index, sizeof(data), 0, &data)); + EXPECT_EQ(credential, data); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, CanUseOffset) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + + std::array const data1_src = {1, 2, 3}; + std::array const data2_src = {4, 5, 6, 7, 8}; + std::array data1_dst = {0}; + std::array data2_dst = {0}; + + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, data1_src.size() + data2_src.size())); + + EXPECT_EQ(kEpidNoErr, + Tpm2NvWrite(tpm, nv_index, data1_src.size(), 0, data1_src.data())); + EXPECT_EQ(kEpidNoErr, + Tpm2NvWrite(tpm, nv_index, data2_src.size(), + (uint16_t)data1_src.size(), data2_src.data())); + + EXPECT_EQ(kEpidNoErr, + Tpm2NvRead(tpm, nv_index, data1_dst.size(), 0, data1_dst.data())); + EXPECT_EQ(data1_src, data1_dst); + + EXPECT_EQ(kEpidNoErr, + Tpm2NvRead(tpm, nv_index, data2_dst.size(), + (uint16_t)data1_dst.size(), data2_dst.data())); + EXPECT_EQ(data2_src, data2_dst); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2NvDefineSpace Tests +TEST(NvTest, NvDefineSpaceFailsGivenNullParameters) { + uint32_t nv_index = 0x01000000; + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvDefineSpace(nullptr, nv_index, sizeof(MembershipCredential))); +} + +TEST(NvTest, NvDefineSpaceCanAllocateSpace) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + EXPECT_EQ(kEpidNoErr, + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvDefineSpaceCatchReDefinition) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000002; + EXPECT_EQ(kEpidNoErr, + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + EXPECT_EQ(kEpidDuplicateErr, + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2NvUndefineSpace Tests +TEST(NvTest, NvUndefineSpaceFailsGivenNullParameters) { + uint32_t nv_index = 0x01000000; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvUndefineSpace(nullptr, nv_index)); +} + +TEST(NvTest, NvUndefineSpaceCanDeallocateSpace) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + MembershipCredential data = {0}; + THROW_ON_EPIDERR(Tpm2NvDefineSpace(tpm, nv_index, sizeof(data))); + EXPECT_EQ(kEpidNoErr, Tpm2NvUndefineSpace(tpm, nv_index)); + EXPECT_EQ(kEpidBadArgErr, Tpm2NvRead(tpm, nv_index, sizeof(data), 0, &data)); +} + +TEST(NvTest, NvUndefineSpaceCatchReDefinition) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidNoErr, Tpm2NvDefineSpace(tpm, nv_index, sizeof(data))); + EXPECT_EQ(kEpidNoErr, Tpm2NvUndefineSpace(tpm, nv_index)); + EXPECT_EQ(kEpidBadArgErr, Tpm2NvUndefineSpace(tpm, nv_index)); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2NvWrite Tests +TEST(NvTest, NvWriteFailsGivenNullParameters) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvWrite(nullptr, nv_index, sizeof(data), 0, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvWrite(tpm, nv_index, sizeof(data), 0, nullptr)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvWriteCanWrite) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidNoErr, Tpm2NvWrite(tpm, nv_index, sizeof(data), 0, &data)); + EXPECT_EQ(kEpidNoErr, Tpm2NvWrite(tpm, nv_index, sizeof(data) - 1, 1, &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvWriteFailsGivenOverflow) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvWrite(tpm, nv_index, sizeof(data), 1, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvWrite(tpm, nv_index, sizeof(data) + 1, 1, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvWrite(tpm, nv_index, 1, sizeof(MembershipCredential), &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvWriteFailsGivenInvalidLength) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvWrite(tpm, nv_index, 0, 0, &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvWriteFailsGivenIndexUndefined) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000003; + + MembershipCredential const data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvWrite(tpm, nv_index, 1, 0, &data)); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2NvRead Tests +TEST(NvTest, NvReadFailsGivenNullParameters) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential data = {0}; + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvRead(nullptr, nv_index, sizeof(data), 0, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvRead(tpm, nv_index, sizeof(data), 0, nullptr)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvReadCanRead) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + std::vector const data_src = {1, 2, 3, 4, 5, 6, 7, 8}; + std::vector data_dst(data_src.size()); + THROW_ON_EPIDERR(Tpm2NvDefineSpace(tpm, nv_index, data_src.size())); + THROW_ON_EPIDERR( + Tpm2NvWrite(tpm, nv_index, data_src.size(), 0, data_src.data())); + + EXPECT_EQ(kEpidNoErr, Tpm2NvRead(tpm, nv_index, 3, 0, data_dst.data())); + EXPECT_EQ(kEpidNoErr, Tpm2NvRead(tpm, nv_index, data_src.size() - 3, 3, + data_dst.data() + 3)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); + EXPECT_EQ(data_src, data_dst); +} + +TEST(NvTest, NvReadFailIfWriteWasNotCalled) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvRead(tpm, nv_index, sizeof(data), 0, &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvReadFailsGivenOverflow) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvRead(tpm, nv_index, sizeof(data), 1, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvRead(tpm, nv_index, sizeof(data) + 1, 0, &data)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2NvRead(tpm, nv_index, 1, sizeof(MembershipCredential), &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvReadFailsGivenInvalidLength) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000000; + THROW_ON_EPIDERR( + Tpm2NvDefineSpace(tpm, nv_index, sizeof(MembershipCredential))); + + MembershipCredential data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvRead(tpm, nv_index, 0, 0, &data)); + THROW_ON_EPIDERR(Tpm2NvUndefineSpace(tpm, nv_index)); +} + +TEST(NvTest, NvReadFailsGivenIndexUndefined) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + uint32_t nv_index = 0x01000003; + + MembershipCredential data = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2NvRead(tpm, nv_index, 1, 0, &data)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/sign-simulator-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/sign-simulator-test.cc new file mode 100644 index 00000000..d5876d1e --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/sign-simulator-test.cc @@ -0,0 +1,75 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM Sign unit tests. +/*! \file */ +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/sign.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2Sign Tests + +TEST_F(EpidTpm2Test, SignProducesKnownSignature) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + THROW_ON_EPIDERR( + Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, k, l, e, &counter)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); + + Prng the_same_prng; + FfElementObj f(¶ms.fp, this->kMemberFValue); + FfElementObj t(¶ms.fp); + FfElementObj r1(¶ms.fp), s_expected(¶ms.fp); + BigNumStr zero = {0}; + THROW_ON_EPIDERR( + FfGetRandom(params.fp, &zero, &Prng::Generate, &the_same_prng, r1)); + THROW_ON_EPIDERR(ReadFfElement(params.fp, this->kDigestSha256, + sizeof(this->kDigestSha256), t)); + THROW_ON_EPIDERR(FfMul(params.fp, f, t, s_expected)); + THROW_ON_EPIDERR(FfAdd(params.fp, r1, s_expected, s_expected)); + FpElemStr s_expected_str = {0}; + THROW_ON_EPIDERR(WriteFfElement(params.fp, s_expected, &s_expected_str, + sizeof(s_expected_str))); + + FpElemStr s_str = {0}; + THROW_ON_EPIDERR(WriteFfElement(params.fp, sig_s, &s_str, sizeof(s_str))); + EXPECT_EQ(s_expected_str, s_str); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/sign-test.cc b/external/epid-sdk/epid/member/tpm2/unittests/sign-test.cc new file mode 100644 index 00000000..a04a4446 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/sign-test.cc @@ -0,0 +1,320 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// TPM Sign unit tests. +/*! \file */ +#include + +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +extern "C" { +#include "epid/common/src/hashsize.h" +#include "epid/common/src/memory.h" +#include "epid/member/tpm2/commit.h" +#include "epid/member/tpm2/load_external.h" +#include "epid/member/tpm2/sign.h" +} + +namespace { +////////////////////////////////////////////////////////////////////////// +// Tpm2Sign Tests +// Verify signature computed by TPM ECDAA scheme: +// sign_k ?= digest mod p +// point^sign_s ?= random_exp * private_exp^sign_k +bool IsSignatureValid(void const* digest, size_t digest_len, + FfElement const* sign_k, FfElement const* sign_s, + EcPoint const* point, EcPoint const* private_exp, + EcPoint const* random_exp, HashAlg hash_alg) { + (void)hash_alg; + + Epid20Params params; + + BigNumObj digest_bn(digest_len); + THROW_ON_EPIDERR(ReadBigNum(digest, digest_len, digest_bn)); + FfElementObj t(¶ms.fp); + THROW_ON_EPIDERR(InitFfElementFromBn(params.fp, digest_bn, t)); + FpElemStr t_str, sign_k_str; + THROW_ON_EPIDERR(WriteFfElement(params.fp, t, &t_str, sizeof(t_str))); + THROW_ON_EPIDERR( + WriteFfElement(params.fp, sign_k, &sign_k_str, sizeof(sign_k_str))); + if (!(t_str == sign_k_str)) return false; + + BigNumStr exp; + // v1 = p2^s + EcPointObj v1(¶ms.G1); + THROW_ON_EPIDERR(WriteFfElement(params.fp, sign_s, &exp, sizeof(exp))); + THROW_ON_EPIDERR(EcExp(params.G1, point, &exp, v1)); + // v2 = k^sign_k + EcPointObj v2(¶ms.G1); + THROW_ON_EPIDERR(WriteFfElement(params.fp, sign_k, &exp, sizeof(exp))); + THROW_ON_EPIDERR(EcExp(params.G1, private_exp, &exp, v2)); + // v2 = l * k^digest + THROW_ON_EPIDERR(EcMul(params.G1, random_exp, v2, v2)); + // v1 ?= v2 + G1ElemStr v1_str, v2_str; + THROW_ON_EPIDERR(WriteEcPoint(params.G1, v1, &v1_str, sizeof(v1_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, v2, &v2_str, sizeof(v2_str))); + return v1_str == v2_str; +} + +TEST_F(EpidTpm2Test, SignProducesValidSignature) { + Epid20Params params; + + // create TPM context + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &f, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + // load f value + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f)); + + // commit(P1=p2, P2=p2) => k = p2^f, l = p2^r, e = p2^r + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + EcPointObj p2(¶ms.G1, kP2Sha256Str); + EcPointObj p2_exp_f(¶ms.G1, kP2Sha256ExpF); + + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + uint16_t counter = 0; + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p2, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, &counter)); + + // sign(digest) => sign_k = sign_k, sign_s = r + c * f, + // where c = H(sign_k||digest) + FfElementObj sign_k(¶ms.fp), sign_s(¶ms.fp); + EXPECT_EQ(kEpidNoErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sign_k, sign_s)); + + EXPECT_TRUE(IsSignatureValid(this->kDigestSha256, sizeof(this->kDigestSha256), + sign_k, sign_s, p2, k, l, kSha256)); +} + +TEST_F(EpidTpm2Test, SignProducesValidSignatureTwoTimes) { + Epid20Params params; + + // create TPM context + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &f, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + // load f value + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f)); + + // commit(P1=p2, P2=p2) => k = p2^f, l = p2^r, e = p2^r + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + EcPointObj p2(¶ms.G1, kP2Sha256Str); + EcPointObj p2_exp_f(¶ms.G1, kP2Sha256ExpF); + + EcPointObj k1(¶ms.G1), l1(¶ms.G1), e1(¶ms.G1); + EcPointObj k2(¶ms.G1), l2(¶ms.G1), e2(¶ms.G1); + uint16_t ctr1 = 0, ctr2 = 0; + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p2, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k1, l1, e1, &ctr1)); + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p2, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k2, l2, e2, &ctr2)); + + // sign(digest) => sign_k = sign_k, sign_s = r + c * f, + // where c = H(sign_k||digest) + FfElementObj sign_k1(¶ms.fp), sign_s1(¶ms.fp); + FfElementObj sign_k2(¶ms.fp), sign_s2(¶ms.fp); + EXPECT_EQ(kEpidNoErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + ctr1, sign_k1, sign_s1)); + EXPECT_EQ(kEpidNoErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + ctr2, sign_k2, sign_s2)); + + EXPECT_TRUE(IsSignatureValid(this->kDigestSha256, sizeof(this->kDigestSha256), + sign_k1, sign_s1, p2, k1, l1, kSha256)); + EXPECT_TRUE(IsSignatureValid(this->kDigestSha256, sizeof(this->kDigestSha256), + sign_k2, sign_s2, p2, k2, l2, kSha256)); +} + +TEST_F(EpidTpm2Test, SignFailsGivenNullParameters) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + THROW_ON_EPIDERR( + Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, k, l, e, &counter)); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(nullptr, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, Tpm2Sign(tpm, nullptr, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, nullptr)); +} + +TEST_F(EpidTpm2Test, SignFailsGivenInvalidDigestLen) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + THROW_ON_EPIDERR( + Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, k, l, e, &counter)); + + uint8_t digest[EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT + 1] = {0}; + EXPECT_EQ(kEpidBadArgErr, Tpm2Sign(tpm, digest, 0, counter, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, digest, EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT + 1, + counter, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, digest, EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT - 1, + counter, sig_k, sig_s)); +} + +TEST_F(EpidTpm2Test, SignFailsGivenUnrecognizedCounter) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + uint16_t zero = 0; + uint16_t one = 1; + uint16_t minus_one = (uint16_t)-1; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + zero, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), one, + sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + minus_one, sig_k, sig_s)); + + THROW_ON_EPIDERR( + Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, k, l, e, &counter)); + + uint16_t counter_plus_1 = counter + 1; + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter_plus_1, sig_k, sig_s)); + THROW_ON_EPIDERR(Tpm2ReleaseCounter(tpm, counter)); +} + +TEST_F(EpidTpm2Test, SignFailsGivenPreviouslyUsedCounter) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &this->kMemberFValue, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + THROW_ON_EPIDERR(Tpm2LoadExternal(tpm, &this->kMemberFValue)); + THROW_ON_EPIDERR( + Tpm2Commit(tpm, nullptr, nullptr, 0, nullptr, k, l, e, &counter)); + + EXPECT_EQ(kEpidNoErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); +} + +TEST_F(EpidTpm2Test, SignFailsIfKeyNotSet) { + Epid20Params params; + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + FfElementObj sig_k(¶ms.fp), sig_s(¶ms.fp); + uint16_t counter = 0; + + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sig_k, sig_s)); +} + +////////////////////////////////////////////////////////////////////////// +// Tpm2ReleaseCounter Tests +TEST_F(EpidTpm2Test, ReleaseCounterFailsGivenNullPtr) { + // create TPM context + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &f, epid2params); + uint16_t ctr = 0; + + EXPECT_EQ(kEpidBadArgErr, Tpm2ReleaseCounter(nullptr, ctr)); +} +TEST_F(EpidTpm2Test, ReleaseCounterSuccessfullyReleasesCounter) { + Epid20Params params; + + // create TPM context + Prng my_prng; + Epid2ParamsObj epid2params; + FpElemStr f = this->kMemberFValue; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, &f, epid2params); + THROW_ON_EPIDERR(Tpm2SetHashAlg(tpm, kSha256)); + // load f value + EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(tpm, &f)); + + // commit(P1=p2, P2=p2) => k = p2^f, l = p2^r, e = p2^r + FfElementObj y2(¶ms.fq, this->kY2Sha256Str); + EcPointObj p2(¶ms.G1, kP2Sha256Str); + EcPointObj p2_exp_f(¶ms.G1, kP2Sha256ExpF); + + EcPointObj k(¶ms.G1), l(¶ms.G1), e(¶ms.G1); + uint16_t counter = 0; + EXPECT_EQ(kEpidNoErr, + Tpm2Commit(tpm, p2, this->kS2Sha256.data(), this->kS2Sha256.size(), + y2, k, l, e, &counter)); + EXPECT_EQ(kEpidNoErr, Tpm2ReleaseCounter(tpm, counter)); + + // sign(digest) => sign_k = sign_k, sign_s = r + c * f, + // where c = H(sign_k||digest) + FfElementObj sign_k(¶ms.fp), sign_s(¶ms.fp); + EXPECT_EQ(kEpidBadArgErr, + Tpm2Sign(tpm, this->kDigestSha256, sizeof(this->kDigestSha256), + counter, sign_k, sign_s)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.cc b/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.cc new file mode 100644 index 00000000..11909365 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.cc @@ -0,0 +1,157 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM fixture class implementation. +/*! \file */ +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" + +#include +#include + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" + +extern "C" { +#include "epid/common/types.h" +} + +bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +const std::vector EpidTpm2Test::kTpmFfElemStrData = { + 0x98, 0x34, 0x87, 0x6d, 0xcf, 0xb0, 0x5c, 0xb1, 0x67, 0xa5, 0xc2, + 0x49, 0x53, 0xeb, 0xa5, 0x8c, 0x4a, 0xc8, 0x9b, 0x1a, 0xdf, 0x57, + 0xf2, 0x8f, 0x2f, 0x9d, 0x09, 0xaf, 0x10, 0x7e, 0xe8, 0xf0}; + +const G1ElemStr EpidTpm2Test::kEpidPointStr = { + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + +const uint8_t + EpidTpm2Test::kDigestSha256[EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT] = { + 0x11, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, + 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, + 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0x22}; + +const FpElemStr EpidTpm2Test::kMemberFValue = { + 0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, + 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, + 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7}; +const G1ElemStr EpidTpm2Test::kP1Str = { + {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D, + 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A, + 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}}, + {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F, + 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96, + 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}}; +const G1ElemStr EpidTpm2Test::kg1Str = { + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}}; + +const std::vector EpidTpm2Test::kS2Sha256 = {0, 0, 0, 4, + 'a', 'b', 'c'}; +const FqElemStr EpidTpm2Test::kY2Sha256Str = { + {{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38, + 0xB1, 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E, + 0x2C, 0x1F, 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}}; +const G1ElemStr EpidTpm2Test::kP2Sha256Str = { + {{{0x2E, 0xBB, 0x50, 0x4D, 0x88, 0xFF, 0x25, 0x62, 0xF3, 0x71, 0x65, + 0x81, 0xAD, 0xBE, 0x83, 0x6E, 0x54, 0xF5, 0xA6, 0x2A, 0x70, 0xE6, + 0x18, 0x6B, 0xD5, 0x4A, 0x10, 0x3C, 0x80, 0x08, 0x95, 0x3D}}}, + {{{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38, + 0xB1, 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E, + 0x2C, 0x1F, 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}}}; +const G1ElemStr EpidTpm2Test::kP2Sha256ExpF = { + {{{0xd0, 0xf3, 0xd9, 0xea, 0x45, 0x24, 0x96, 0xb8, 0x3e, 0x2f, 0xf2, + 0x18, 0x12, 0xad, 0xa7, 0xab, 0xe3, 0x1e, 0xff, 0xe7, 0xf7, 0x61, + 0x28, 0xae, 0x0a, 0x7c, 0x0f, 0xd9, 0x74, 0x0f, 0x4a, 0x94}}}, + {{{0xb7, 0xda, 0xd5, 0x97, 0x33, 0xab, 0xb6, 0x3c, 0xf7, 0x3b, 0xec, + 0xa4, 0x7f, 0xe6, 0x23, 0xd4, 0xf6, 0xe2, 0x9b, 0xdb, 0xa6, 0xbb, + 0xdf, 0xee, 0x62, 0x33, 0xcd, 0x88, 0x25, 0x52, 0xba, 0x99}}}}; + +const std::vector EpidTpm2Test::kS2Sha384 = {0, 0, 0, 0, + 'a', 'b', 'c'}; +const FqElemStr EpidTpm2Test::kY2Sha384Str = { + {{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80, + 0x92, 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3, + 0x48, 0xA9, 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}}; +const G1ElemStr EpidTpm2Test::kP2Sha384Str = { + {{{0xE1, 0xC8, 0x28, 0xB1, 0x9A, 0xDF, 0x5D, 0x4B, 0xC4, 0x25, 0x90, + 0xFB, 0x38, 0x20, 0xD4, 0x8B, 0x30, 0x8F, 0x95, 0x76, 0xC3, 0x7F, + 0x9D, 0xAD, 0x94, 0xC4, 0x31, 0x80, 0xD7, 0xDF, 0xD5, 0xFE}}}, + {{{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80, + 0x92, 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3, + 0x48, 0xA9, 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}}}; +const G1ElemStr EpidTpm2Test::kP2Sha384ExpF = { + {{{0x97, 0x90, 0xaf, 0xe1, 0xc3, 0x7d, 0x6f, 0xf3, 0x71, 0x88, 0x6c, + 0x8b, 0x20, 0xc8, 0x50, 0x0d, 0x74, 0x31, 0x2a, 0x7e, 0x7c, 0x8c, + 0xba, 0xf1, 0xd9, 0xac, 0x2f, 0xb9, 0x7a, 0xbc, 0xbb, 0x58}}}, + {{{0xad, 0x2b, 0xcf, 0x14, 0x2f, 0x60, 0xbb, 0xc8, 0xea, 0x9d, 0x8a, + 0x54, 0xa6, 0x3b, 0x3b, 0x46, 0x84, 0xdf, 0x72, 0xe2, 0xa9, 0x91, + 0x2b, 0x06, 0xe5, 0x7f, 0x63, 0x0e, 0x99, 0x7a, 0xe7, 0xd2}}}}; + +const std::vector EpidTpm2Test::kS2Sha512 = {0, 0, 0, 1, + 'a', 'b', 'c'}; +const FqElemStr EpidTpm2Test::kY2Sha512Str = { + {{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54, + 0x24, 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2, + 0xF2, 0x7B, 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}}; +const G1ElemStr EpidTpm2Test::kP2Sha512Str = { + {{{0x8C, 0x62, 0xA0, 0x2D, 0x55, 0x55, 0x55, 0x86, 0xBC, 0x82, 0xA6, + 0xA2, 0x21, 0x97, 0x9B, 0x9B, 0xB4, 0x03, 0x3D, 0x83, 0xF3, 0xBA, + 0xDA, 0x9C, 0x42, 0xF7, 0xB3, 0x94, 0x99, 0x2A, 0x96, 0xE4}}}, + {{{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54, + 0x24, 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2, + 0xF2, 0x7B, 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}}}; +const G1ElemStr EpidTpm2Test::kP2Sha512ExpF = { + {{{0xb4, 0xbc, 0x3d, 0x8c, 0x7b, 0xc3, 0x08, 0x89, 0xa3, 0x0e, 0x66, + 0x7f, 0x6d, 0x89, 0xab, 0x9b, 0xc4, 0xda, 0x14, 0x93, 0x62, 0x32, + 0x0d, 0xe2, 0x95, 0xb5, 0x71, 0x2d, 0x75, 0xbe, 0x63, 0xd4}}}, + {{{0xf6, 0x20, 0x85, 0x93, 0x3f, 0xfb, 0xf3, 0xad, 0xa9, 0x7e, 0xd3, + 0x93, 0x29, 0x22, 0x1b, 0x88, 0x56, 0xf0, 0xbd, 0x62, 0xbd, 0x63, + 0x8b, 0xcf, 0xe1, 0x62, 0x83, 0xb6, 0x1c, 0x56, 0x29, 0xc3}}}}; + +const std::vector EpidTpm2Test::kS2Sha512256 = {0, 0, 0, 0, + 'a', 'b', 'c'}; +const FqElemStr EpidTpm2Test::kY2Sha512256Str = { + {{0x30, 0xbe, 0x3f, 0x12, 0x00, 0x74, 0x48, 0xaa, 0x91, 0x90, 0x84, + 0x12, 0x4d, 0x58, 0x54, 0xe7, 0x04, 0x65, 0x37, 0x97, 0x88, 0xcf, + 0x67, 0xa0, 0x8c, 0x56, 0x93, 0xa7, 0x7f, 0xe8, 0x74, 0xfc}}}; +const G1ElemStr EpidTpm2Test::kP2Sha512256Str = { + {{{0x63, 0x28, 0x40, 0x14, 0x73, 0xd5, 0x91, 0xc4, 0xa2, 0xa4, 0xb6, + 0xd8, 0xa8, 0x75, 0x21, 0xd1, 0x26, 0x4e, 0x42, 0x13, 0x1f, 0xfa, + 0xed, 0x90, 0x8d, 0x56, 0x34, 0x57, 0x8a, 0x3a, 0x47, 0xa0}}}, + {{{0x30, 0xbe, 0x3f, 0x12, 0x00, 0x74, 0x48, 0xaa, 0x91, 0x90, 0x84, + 0x12, 0x4d, 0x58, 0x54, 0xe7, 0x04, 0x65, 0x37, 0x97, 0x88, 0xcf, + 0x67, 0xa0, 0x8c, 0x56, 0x93, 0xa7, 0x7f, 0xe8, 0x74, 0xfc}}}}; +const G1ElemStr EpidTpm2Test::kP2Sha512256ExpF = { + {{{0xa7, 0xef, 0x09, 0x07, 0x5e, 0xf1, 0xce, 0x85, 0xe8, 0x85, 0x03, + 0xbe, 0xdd, 0x2e, 0x32, 0x25, 0xab, 0x58, 0x90, 0xc4, 0x59, 0x60, + 0x1c, 0x17, 0x3b, 0x8c, 0x62, 0x35, 0xd3, 0x9f, 0x77, 0x8f}}}, + {{{0x38, 0xce, 0x8b, 0x36, 0xc1, 0xb1, 0xae, 0xc5, 0x61, 0x60, 0x12, + 0xf0, 0x5b, 0xc1, 0xb8, 0x5e, 0xf3, 0xb9, 0xa6, 0x26, 0x7f, 0x27, + 0x5b, 0x78, 0x61, 0x27, 0xe6, 0x0b, 0x38, 0x37, 0x89, 0x56}}}}; diff --git a/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.h b/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.h new file mode 100644 index 00000000..208a3431 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/tpm2-testhelper.h @@ -0,0 +1,78 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// TPM fixture class. +/*! \file */ +#ifndef EPID_MEMBER_TPM2_UNITTESTS_TPM2_TESTHELPER_H_ +#define EPID_MEMBER_TPM2_UNITTESTS_TPM2_TESTHELPER_H_ + +#include +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/common/bitsupplier.h" +#include "epid/common/src/hashsize.h" +#include "epid/member/tpm2/context.h" +} + +typedef struct FqElemStr FqElemStr; +typedef struct FpElemStr FpElemStr; +typedef struct G1ElemStr G1ElemStr; + +/// Test fixture class for Tpm +class EpidTpm2Test : public ::testing::Test { + public: + // tpm digest + static const std::vector kTpmFfElemStrData; + static const G1ElemStr kEpidPointStr; + static const uint8_t kDigestSha256[EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT]; + + static const FpElemStr kMemberFValue; + static const G1ElemStr kP1Str; + static const G1ElemStr kg1Str; + static const std::vector kS2Sha256; + static const FqElemStr kY2Sha256Str; + static const G1ElemStr kP2Sha256Str; + static const G1ElemStr kP2Sha256ExpF; + static const std::vector kS2Sha384; + static const FqElemStr kY2Sha384Str; + static const G1ElemStr kP2Sha384Str; + static const G1ElemStr kP2Sha384ExpF; + static const std::vector kS2Sha512; + static const FqElemStr kY2Sha512Str; + static const G1ElemStr kP2Sha512Str; + static const G1ElemStr kP2Sha512ExpF; + static const std::vector kS2Sha512256; + static const FqElemStr kY2Sha512256Str; + static const G1ElemStr kP2Sha512256Str; + static const G1ElemStr kP2Sha512256ExpF; + /// setup called before each TEST_F starts + virtual void SetUp() {} + /// teardown called after each TEST_F finishes + virtual void TearDown() {} +}; + +/// compares FpElemStr values +bool operator==(FpElemStr const& lhs, FpElemStr const& rhs); + +/// compares G1ElemStr values +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs); + +#endif // EPID_MEMBER_TPM2_UNITTESTS_TPM2_TESTHELPER_H_ diff --git a/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.cc b/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.cc new file mode 100644 index 00000000..6090c479 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.cc @@ -0,0 +1,61 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Ctx wrapper class implementation. +/*! \file */ +#include "epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h" + +#include +#include + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" + +extern "C" { +#include "epid/common/src/epid2params.h" +#include "epid/common/src/hashsize.h" +#include "epid/common/stdtypes.h" +#include "epid/common/types.h" +#include "epid/member/tpm2/context.h" +#include "epid/member/tpm2/sign.h" +} + +Tpm2CtxObj::Tpm2CtxObj(BitSupplier rnd_func, void* rnd_param, + const FpElemStr* f, Epid2ParamsObj const& params) + : ctx_(nullptr) { + EpidStatus sts = kEpidNoErr; + BitSupplier rnd_func_ = NULL; + void* rnd_param_ = NULL; + const FpElemStr* f_ = NULL; + MemberParams mem_params = {0}; + SetMemberParams(rnd_func, rnd_param, f, &mem_params); + + sts = Tpm2CreateContext(&mem_params, params, &rnd_func_, &rnd_param_, &f_, + &ctx_); + if (kEpidNoErr != sts) { + printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:"); + throw std::logic_error(std::string("Failed to call: ") + + "Tpm2CreateContext()"); + } +} + +Tpm2CtxObj::~Tpm2CtxObj() { Tpm2DeleteContext(&ctx_); } + +Tpm2Ctx* Tpm2CtxObj::ctx() const { return ctx_; } + +Tpm2CtxObj::operator Tpm2Ctx*() const { return ctx_; } + +Tpm2CtxObj::operator const Tpm2Ctx*() const { return ctx_; } diff --git a/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h b/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h new file mode 100644 index 00000000..0e9904f3 --- /dev/null +++ b/external/epid-sdk/epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h @@ -0,0 +1,58 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// Tpm2Ctx wrapper class. +/*! \file */ +#ifndef EPID_MEMBER_TPM2_UNITTESTS_TPM2_WRAPPER_TESTHELPER_H_ +#define EPID_MEMBER_TPM2_UNITTESTS_TPM2_WRAPPER_TESTHELPER_H_ + +#include +#include + +extern "C" { +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" +} + +typedef struct Tpm2Ctx Tpm2Ctx; +class Epid2ParamsObj; + +/// C++ Wrapper to manage memory for Tpm2Ctx via RAII +class Tpm2CtxObj { + public: + /// Create a Tpm2Ctx + Tpm2CtxObj(BitSupplier rnd_func, void* rnd_param, const FpElemStr* f, + class Epid2ParamsObj const& params); + + // This class instances are not meant to be copied. + // Explicitly delete copy constructor and assignment operator. + Tpm2CtxObj(const Tpm2CtxObj&) = delete; + Tpm2CtxObj& operator=(const Tpm2CtxObj&) = delete; + + /// Destroy the Tpm2Ctx + ~Tpm2CtxObj(); + /// get a pointer to the stored Tpm2Ctx + Tpm2Ctx* ctx() const; + /// cast operator to get the pointer to the stored Tpm2Ctx + operator Tpm2Ctx*() const; + /// const cast operator to get the pointer to the stored Tpm2Ctx + operator const Tpm2Ctx*() const; + + private: + /// The stored Tpm2Ctx + Tpm2Ctx* ctx_; +}; + +#endif // EPID_MEMBER_TPM2_UNITTESTS_TPM2_WRAPPER_TESTHELPER_H_ diff --git a/external/epid-sdk-3.0.0/example/util/stdtypes.h b/external/epid-sdk/epid/member/tpm_member.h similarity index 55% rename from external/epid-sdk-3.0.0/example/util/stdtypes.h rename to external/epid-sdk/epid/member/tpm_member.h index 72cead86..372377d3 100644 --- a/external/epid-sdk-3.0.0/example/util/stdtypes.h +++ b/external/epid-sdk/epid/member/tpm_member.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,27 +13,36 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ -#ifndef EXAMPLE_UTIL_STDTYPES_H_ -#define EXAMPLE_UTIL_STDTYPES_H_ - +/// Member creation parameters for TPM implementation. /*! * \file - * \brief C99 standard data types. + */ +#ifndef EPID_MEMBER_TPM_MEMBER_H_ +#define EPID_MEMBER_TPM_MEMBER_H_ +/*! +* \cond +*/ + +#include "epid/common/bitsupplier.h" +#include "epid/common/types.h" + +/*! +\addtogroup EpidMemberModule member +@{ +*/ + +/// TPM specific member parameters +/*! + \class TPMMemberParams +*/ +typedef struct MemberParams { + FpElemStr const* f; ///< Secret part of the private key. If NULL an + /// EPS based primary will be used. +} MemberParams; + +/*! + * @} + * \endcond */ -#include // Fixed-width integer types - -#ifndef __cplusplus -#ifndef _Bool -/// C99 standard name for bool -#define _Bool char -/// Boolean type -typedef char bool; -/// integer constant 1 -#define true 1 -/// integer constant 0 -#define false 0 -#endif // -#endif // ifndef __cplusplus - -#endif // EXAMPLE_UTIL_STDTYPES_H_ +#endif // EPID_MEMBER_TPM_MEMBER_H_ diff --git a/external/epid-sdk/epid/member/unittests/context-test.cc b/external/epid-sdk/epid/member/unittests/context-test.cc new file mode 100644 index 00000000..14540b39 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/context-test.cc @@ -0,0 +1,620 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +#include "epid/member/src/context.h" +#include "epid/member/src/storage.h" +#include "epid/member/src/write_precomp.h" +#include "epid/member/tpm2/nv.h" +} +bool operator==(MemberPrecomp const& lhs, MemberPrecomp const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} +/// compares GroupPubKey values +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs); + +/// compares MembershipCredential values +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs); +namespace { +////////////////////////////////////////////////////////////////////////// +// EpidMemberDeinit Tests +TEST_F(EpidMemberTest, DeinitWorksGivenNullMemberCtx) { + EpidMemberDeinit(nullptr); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberGetSize Tests +TEST_F(EpidMemberTest, GetSizeFailsGivenNullParams) { + size_t ctx_size = 0; + MemberParams params = {0}; + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(¶ms, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(nullptr, &ctx_size)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberGetSize(nullptr, nullptr)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberGetSize Tests +TEST_F(EpidMemberTest, GetSizeWorksGivenValidParams) { + size_t ctx_size = 0; + Prng my_prng; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberInit Tests +TEST_F(EpidMemberTest, InitFailsGivenNullParameters) { + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(nullptr, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(¶ms, nullptr)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(nullptr, ctx)); +} + +TEST_F(EpidMemberTest, InitFailsGivenInvalidParameters) { + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, &f, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidBadArgErr, EpidMemberInit(¶ms, ctx)); +} + +TEST_F(EpidMemberTest, InitSucceedsGivenValidParameters) { + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, &f, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidNoErr, EpidMemberInit(¶ms, ctx)); + EpidMemberDeinit(ctx); +} + +TEST_F(EpidMemberTest, InitSucceedsGivenValidParametersWithNoF) { + size_t ctx_size = 0; + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + std::vector ctx_buf; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberGetSize(¶ms, &ctx_size)); + ctx_buf.resize(ctx_size); + ctx = (MemberCtx*)&ctx_buf[0]; + + EXPECT_EQ(kEpidNoErr, EpidMemberInit(¶ms, ctx)); + EpidMemberDeinit(ctx); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberDelete Tests +TEST_F(EpidMemberTest, DeleteWorksGivenNullMemberCtx) { + EpidMemberDelete(nullptr); + MemberCtx* member_ctx = nullptr; + EpidMemberDelete(&member_ctx); +} +TEST_F(EpidMemberTest, DeleteNullsMemberCtx) { + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + THROW_ON_EPIDERR(EpidMemberCreate(¶ms, &ctx)); + EpidMemberDelete(&ctx); + EXPECT_EQ(nullptr, ctx); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberCreate Tests +// test that create fails if any mandatory parameters are NULL +TEST_F(EpidMemberTest, CreateFailsGivenNullParameters) { + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + EXPECT_EQ(kEpidBadArgErr, EpidMemberCreate(nullptr, &ctx)); + + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidBadArgErr, EpidMemberCreate(¶ms, nullptr)); + + SetMemberParams(nullptr, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidBadArgErr, EpidMemberCreate(¶ms, nullptr)); +} + +TEST_F(EpidMemberTest, CreateFailsGivenInvalidParameters) { + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + SetMemberParams(&Prng::Generate, &my_prng, &f, ¶ms); + EXPECT_EQ(kEpidBadArgErr, EpidMemberCreate(¶ms, &ctx)); + EpidMemberDelete(&ctx); +} + +TEST_F(EpidMemberTest, CreateSucceedsGivenValidParameters) { + MemberCtx* ctx = nullptr; + Prng my_prng; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &my_prng, nullptr, ¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberCreate(¶ms, &ctx)); + EpidMemberDelete(&ctx); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberStartup +TEST_F(EpidMemberTest, StartupFailsGivenNullParameters) { + EXPECT_EQ(kEpidBadArgErr, EpidMemberStartup(nullptr)); +} + +TEST_F(EpidMemberTest, StartupSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); + MembershipCredential credential_expected = ((MemberCtx*)member)->credential; + // reset member credential to test if startup reads them from NV memory + // correctly + ((MemberCtx*)member)->pub_key = {0}; + ((MemberCtx*)member)->credential = {0}; + EXPECT_EQ(kEpidNoErr, EpidMemberStartup(member)); + EXPECT_EQ(pub_key, ((MemberCtx*)member)->pub_key); + EXPECT_EQ(credential_expected, ((MemberCtx*)member)->credential); +} + +////////////////////////////////////////////////////////////////////////// +// EpidMemberSetHashAlg +TEST_F(EpidMemberTest, SetHashAlgFailsGivenNullPtr) { + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(nullptr, kSha256)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA256) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha256)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA384) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha384)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA512) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha512)); +} +TEST_F(EpidMemberTest, CanSetHashAlgoToSHA512256) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidMemberSetHashAlg(member_ctx, kSha512_256)); +} +TEST_F(EpidMemberTest, SetHashAlgFailsForNonSupportedAlgorithm) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_256)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_384)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, kSha3_512)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetHashAlg(member_ctx, (HashAlg)-1)); +} +////////////////////////////////////////////////////////////////////////// +// EpidMemberSetSigRl +TEST_F(EpidMemberTest, SetSigRlFailsGivenNullPointer) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(nullptr, &srl, sizeof(SigRl))); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, nullptr, sizeof(SigRl))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenZeroSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(member_ctx, &srl, 0)); +} +// Size parameter must be at least big enough for n2 == 0 case +TEST_F(EpidMemberTest, SetSigRlFailsGivenTooSmallSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ( + kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1)); + srl.n2 = this->kOctStr32_1; + EXPECT_EQ( + kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1)); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenN2TooBigForSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.n2 = this->kOctStr32_1; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenN2TooSmallForSize) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + EXPECT_EQ(kEpidBadArgErr, EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenBadGroupId) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.gid.data[0] = ~srl.gid.data[0]; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenEmptySigRlFromDifferentGroup) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlFailsGivenOldVersion) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + srl.version = this->kOctStr32_1; + EXPECT_EQ(kEpidNoErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); + OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00}; + srl.version = octstr32_0; + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, &srl, sizeof(srl) - sizeof(srl.bk))); +} +TEST_F(EpidMemberTest, SetSigRlPreservesOldRlOnFailure) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXSigrevokedMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); + // wrong sigrl contains revoked member0 and has lower version + SigRl const* wrong_sig_rl = + reinterpret_cast(this->kGrpXSigRlSingleEntry.data()); + size_t wrong_sig_rl_size = this->kGrpXSigRlSingleEntry.size(); + EXPECT_EQ(kEpidBadArgErr, + EpidMemberSetSigRl(member_ctx, wrong_sig_rl, wrong_sig_rl_size)); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(sig_rl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + // Check that sigrevoked member is still in SigRl + EXPECT_EQ(kEpidSigRevokedInSigRl, EpidSign(member_ctx, msg.data(), msg.size(), + nullptr, 0, sig, sig_len)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenValidSigRl) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t sig_rl_size = this->kGrpXSigRl.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenEmptySigRl) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + uint8_t sig_rl_data_n2_zero[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x00, + // not bk's + }; + SigRl* sig_rl = reinterpret_cast(sig_rl_data_n2_zero); + size_t sig_rl_size = sizeof(sig_rl_data_n2_zero); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlWorksGivenSigRlWithOneEntry) { + Prng my_prng; + MemberCtxObj member_ctx(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + SigRl const* sig_rl = + reinterpret_cast(this->kGrpXSigRlSingleEntry.data()); + size_t sig_rl_size = this->kGrpXSigRlSingleEntry.size(); + EXPECT_EQ(kEpidNoErr, EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +TEST_F(EpidMemberTest, SetSigRlFailsIfNotProvisioned) { + Prng my_prng; + MemberCtxObj member_ctx(&Prng::Generate, &my_prng); + uint8_t sig_rl_data[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x00, + // not bk's + }; + SigRl* sig_rl = reinterpret_cast(sig_rl_data); + size_t sig_rl_size = sizeof(sig_rl_data); + EXPECT_EQ(kEpidOutOfSequenceError, + EpidMemberSetSigRl(member_ctx, sig_rl, sig_rl_size)); +} +////////////////////////////////////////////////////////////////////////// +// EpidRegisterBasename +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenNullPtr) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'_', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(member, nullptr, basename.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(nullptr, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenDuplicateBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'d', 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename.data(), basename.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameFailsGivenInvalidBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {}; + std::vector basename2 = {'b', 's', 'n'}; + EXPECT_EQ(kEpidBadArgErr, + EpidRegisterBasename(member, basename.data(), basename.size())); + EXPECT_EQ(kEpidBadArgErr, EpidRegisterBasename(member, basename2.data(), 0)); +} +TEST_F(EpidMemberTest, RegisterBaseNameSucceedsGivenUniqueBaseName) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename = {'b', 's', 'n', '0', '1'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename.data(), basename.size())); +} +TEST_F(EpidMemberTest, RegisterBaseNameSucceedsGivenMultipleUniqueBaseNames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector basename1 = {'b', 's', 'n', '0', '1'}; + std::vector basename2 = {'b', 's', 'n', '0', '2'}; + std::vector basename3 = {'b', 's', 'n', '0', '3'}; + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename1.data(), basename1.size())); + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename2.data(), basename2.size())); + EXPECT_EQ(kEpidNoErr, + EpidRegisterBasename(member, basename3.data(), basename3.size())); + // Verify that basenames registered succesfully + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename1.data(), basename1.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename2.data(), basename2.size())); + EXPECT_EQ(kEpidDuplicateErr, + EpidRegisterBasename(member, basename3.data(), basename3.size())); +} +TEST_F(EpidMemberTest, + RegisterBaseNameSucceedsGivenBsnContainingAllPossibleBytes) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + EXPECT_EQ(kEpidNoErr, EpidRegisterBasename(member, this->kData_0_255.data(), + this->kData_0_255.size())); +} +////////////////////////////////////////////////////////////////////////// +// EpidClearRegisteredBasenames +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesFailsGivenNullPtr) { + EXPECT_EQ(kEpidBadArgErr, EpidClearRegisteredBasenames(nullptr)); +} +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesClearsBasenames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR( + EpidRegisterBasename(member, this->kBsn0.data(), this->kBsn0.size())); + EXPECT_EQ(kEpidNoErr, EpidClearRegisteredBasenames(member)); + // check, that after clearing EpidRegisterBasename works correctly + THROW_ON_EPIDERR( + EpidRegisterBasename(member, this->kBsn0.data(), this->kBsn0.size())); +} +TEST_F(EpidMemberTest, EpidClearRegisteredBasenamesClearsAllBasenames) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + for (int i = 0; i < 3; ++i) { + THROW_ON_EPIDERR(EpidRegisterBasename(member, &i, sizeof(i))); + } + EXPECT_EQ(kEpidNoErr, EpidClearRegisteredBasenames(member)); + for (int i = 0; i < 3; ++i) { + THROW_ON_EPIDERR(EpidRegisterBasename(member, &i, sizeof(i))); + } +} +TEST_F(EpidMemberTest, + EpidClearRegisteredBasenamesCausesSignWithBasenameAfterItToFail) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + THROW_ON_EPIDERR(EpidClearRegisteredBasenames(member)); + ASSERT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); +} +////////////////////////////////////////////////////////////////////////// +// EpidMemberWritePrecomp +TEST_F(EpidMemberTest, MemberWritePrecompFailsGivenNullPointer) { + MemberPrecomp precomp; + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + MemberCtx* ctx = member; + EXPECT_EQ(kEpidBadArgErr, EpidMemberWritePrecomp(nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, EpidMemberWritePrecomp(ctx, nullptr)); +} +TEST_F(EpidMemberTest, + MemberWritePrecompSucceedGivenValidArgumentWithLoadedPrecomp) { + MemberPrecomp precomp; + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + MemberCtx* ctx = member; + EXPECT_EQ(kEpidNoErr, EpidMemberWritePrecomp(ctx, &precomp)); + MemberPrecomp expected_precomp = this->kMemberPrecomp; + EXPECT_EQ(expected_precomp, precomp); +} +TEST_F(EpidMemberTest, + MemberWritePrecompSucceedGivenValidArgumentWithCalcPrecomp) { + MemberPrecomp precomp; + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + &Prng::Generate, &my_prng); + MemberCtx* ctx = member; + EXPECT_EQ(kEpidNoErr, EpidMemberWritePrecomp(ctx, &precomp)); + MemberPrecomp expected_precomp = this->kMemberPrecomp; + EXPECT_EQ(expected_precomp, precomp); +} +TEST_F(EpidMemberTest, DefaultHashAlgIsSha512) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + MemberCtx* ctx = member; + EXPECT_EQ(kSha512, ctx->hash_alg); +} +#ifdef TPM_TSS +////////////////////////////////////////////////////////////////////////// +// MemberCanLoadMembershipCredentialFromTpm +TEST_F(EpidMemberTest, + MemberCanLoadPreviouslyProvisionedMembershipCredentialFromTpm) { + // Not clear that this test is valid or in the right place. + Prng prng; + Epid2ParamsObj epid2params; + + uint32_t const nv_index = 0x01c10100; + GroupPubKey pub_key_expected = this->kGrpXKey; + GroupPubKey pub_key; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential_expected = {this->kGrpXMember9PrivKey.gid, + this->kGrpXMember9PrivKey.A, + this->kGrpXMember9PrivKey.x}; + MembershipCredential credential; + // Tpm2CtxObj calls Tpm2CreateContext() and sets + // is_context_already_created=true. To call this function in + // EpidMemberInit() successfully Tpm2DeleteContext() must be called. + // Putting creation of Tpm2CtxObj object in a block solves it + { + // write credentials + Tpm2CtxObj tpm(&Prng::Generate, &prng, nullptr, epid2params); + THROW_ON_EPIDERR(EpidNvWriteMembershipCredential( + tpm, &pub_key_expected, &credential_expected, nv_index)); + + // read credentials to confirm that credential has been really inserted + EXPECT_EQ(kEpidNoErr, EpidNvReadMembershipCredential( + tpm, nv_index, &pub_key, &credential)); + EXPECT_EQ(pub_key_expected, pub_key); + EXPECT_EQ(credential_expected, credential); + } + + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, EpidMemberStartup(member)); + EXPECT_EQ(pub_key_expected, ((MemberCtx*)member)->pub_key); + EXPECT_EQ(credential_expected, ((MemberCtx*)member)->credential); + + Tpm2NvUndefineSpace(((MemberCtx*)member)->tpm2_ctx, nv_index); +} +#endif +} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/decompress_privkey-test.cc b/external/epid-sdk/epid/member/unittests/decompress_privkey-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/member/unittests/decompress_privkey-test.cc rename to external/epid-sdk/epid/member/unittests/decompress_privkey-test.cc index 380e1ddc..1ba24536 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/decompress_privkey-test.cc +++ b/external/epid-sdk/epid/member/unittests/decompress_privkey-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * \brief DecompressPrivKey unit tests. */ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/get_sigsize-test.cc b/external/epid-sdk/epid/member/unittests/get_sigsize-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/member/unittests/get_sigsize-test.cc rename to external/epid-sdk/epid/member/unittests/get_sigsize-test.cc index b5202da3..50858b9b 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/get_sigsize-test.cc +++ b/external/epid-sdk/epid/member/unittests/get_sigsize-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * \brief GetSigSize unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { diff --git a/external/epid-sdk/epid/member/unittests/iskeyvalid-test.cc b/external/epid-sdk/epid/member/unittests/iskeyvalid-test.cc new file mode 100644 index 00000000..87c88370 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/iskeyvalid-test.cc @@ -0,0 +1,198 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// IsKeyValid unit tests. +/*! \file */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/src/validatekey.h" +} + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +namespace { + +//////////////////////////////////////////////// +// EpidMemberIsKeyValid +TEST_F(EpidMemberTest, EpidMemberIsKeyValidFailsGivenNullPointer) { + // create + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + + // provision + HashAlg hash_alg = kSha256; + const GroupPubKey pub_key = this->kGroupPublicKey; + const PrivKey priv_key = this->kMemberPrivateKey; + + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, hash_alg)); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, &this->kMemberPrecomp)); + + EXPECT_FALSE(EpidMemberIsKeyValid(nullptr, &priv_key.A, &priv_key.x, + &pub_key.h1, &pub_key.w)); + EXPECT_FALSE(EpidMemberIsKeyValid(member, nullptr, &priv_key.x, &pub_key.h1, + &pub_key.w)); + EXPECT_FALSE(EpidMemberIsKeyValid(member, &priv_key.A, nullptr, &pub_key.h1, + &pub_key.w)); + EXPECT_FALSE(EpidMemberIsKeyValid(member, &priv_key.A, &priv_key.x, nullptr, + &pub_key.w)); + EXPECT_FALSE(EpidMemberIsKeyValid(member, &priv_key.A, &priv_key.x, + &pub_key.h1, nullptr)); +} + +TEST_F(EpidMemberTest, EpidMemberIsKeyValidSucceedsForSha256) { + // create + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + + // provision + HashAlg hash_alg = kSha256; + const GroupPubKey pub_key = this->kGroupPublicKey; + const PrivKey priv_key = this->kMemberPrivateKey; + + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, hash_alg)); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, &this->kMemberPrecomp)); + EXPECT_TRUE(EpidMemberIsKeyValid(member, &priv_key.A, &priv_key.x, + &pub_key.h1, &pub_key.w)); +} + +TEST_F(EpidMemberTest, EpidMemberIsKeyValidFailsGivenIncorrectKeys) { + // create + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + + // provision + HashAlg hash_alg = kSha256; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, hash_alg)); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, &this->kMemberPrecomp)); + + // check the key is valid + EXPECT_TRUE(EpidMemberIsKeyValid(member, &priv_key.A, &priv_key.x, + &pub_key.h1, &pub_key.w)); + + // check key is invalid with incorrect data + PrivKey tmp_priv_key = priv_key; + tmp_priv_key.A.x.data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &priv_key.x, + &pub_key.h1, &pub_key.w)); + + tmp_priv_key = priv_key; + tmp_priv_key.A.y.data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &tmp_priv_key.x, + &pub_key.h1, &pub_key.w)); + + tmp_priv_key = priv_key; + tmp_priv_key.x.data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &tmp_priv_key.x, + &pub_key.h1, &pub_key.w)); + + GroupPubKey tmp_pub_key = pub_key; + tmp_pub_key.h1.x.data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &priv_key.x, + &tmp_pub_key.h1, &tmp_pub_key.w)); + + tmp_pub_key = pub_key; + tmp_pub_key.h1.y.data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &priv_key.x, + &tmp_pub_key.h1, &tmp_pub_key.w)); + + tmp_pub_key = pub_key; + tmp_pub_key.w.x->data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &priv_key.x, + &tmp_pub_key.h1, &tmp_pub_key.w)); + + tmp_pub_key = pub_key; + tmp_pub_key.w.y->data.data[31] -= 1; + EXPECT_FALSE(EpidMemberIsKeyValid(member, &tmp_priv_key.A, &priv_key.x, + &tmp_pub_key.h1, &tmp_pub_key.w)); +} + +TEST_F(EpidMemberTest, + PROTECTED_EpidMemberIsKeyValidSucceedsByCredentialForSha256_EPS0) { + // create + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + + // provision + HashAlg hash_alg = kSha256; + const GroupPubKey eps0_pub_key = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x07, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w + }; + + const PrivKey eps0_priv_key = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xae, 0x5a, 0x18, 0x8d, 0xc8, 0xa9, 0xe2, 0x5c, 0xdf, 0xef, 0x62, + 0x6b, 0x34, 0xdf, 0x0d, 0xf2, 0xf6, 0xcf, 0x6a, 0x4d, 0x68, 0x88, + 0xc8, 0x12, 0x08, 0xae, 0xb6, 0x30, 0x54, 0xdf, 0xa7, 0xdc}}}, + {{{0xec, 0x39, 0x86, 0x7b, 0x5c, 0x5e, 0x28, 0x17, 0x5b, 0xfe, 0x93, + 0xa1, 0x31, 0x8a, 0x82, 0x99, 0xb0, 0x84, 0x8c, 0x90, 0xc5, 0x54, + 0x2c, 0x6d, 0xff, 0x75, 0xcf, 0x05, 0x6e, 0x2b, 0x6c, 0xf3}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x7a, 0x57, 0x41, 0x5b, 0x85, 0x44, 0x0e, 0x2b, 0xb3, 0xcc, 0xa7, + 0x99, 0x6d, 0x19, 0x79, 0x45, 0x04, 0xb8, 0x94, 0x07, 0x47, 0x14, + 0xed, 0x8d, 0xf4, 0x1e, 0x7d, 0xa0, 0x17, 0xc5, 0xc4, 0x10} // f + }; + + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, hash_alg)); + EXPECT_TRUE(EpidMemberIsKeyValid(member, &eps0_priv_key.A, &eps0_priv_key.x, + &eps0_pub_key.h1, &eps0_pub_key.w)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/join_request-test.cc b/external/epid-sdk/epid/member/unittests/join_request-test.cc new file mode 100644 index 00000000..d61347a3 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/join_request-test.cc @@ -0,0 +1,380 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Join Request related unit tests. + */ + +#include +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/common/math/ecgroup.h" +#include "epid/common/math/finitefield.h" +#include "epid/common/src/epid2params.h" +#include "epid/member/api.h" +} + +#include "epid/common-testhelper/ecgroup_wrapper-testhelper.h" +#include "epid/common-testhelper/ecpoint_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/ffelement_wrapper-testhelper.h" +#include "epid/common-testhelper/finite_field_wrapper-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/src/context.h" +#include "epid/member/unittests/member-testhelper.h" + +/// compares FpElemStr values +bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// compares JoinRequest values +bool operator==(JoinRequest const& lhs, JoinRequest const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// compares JoinRequest values for inequality +bool operator!=(JoinRequest const& lhs, JoinRequest const& rhs) { + return 0 != std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +namespace { + +// local constant for Join Request tests. This can be hoisted later if needed +// avoids cpplint warning about multiple includes. +const GroupPubKey kPubKey = { +#include "epid/common-testhelper/testdata/grp01/gpubkey.inc" +}; + +const FpElemStr kFEps1 = {0x56, 0x57, 0xda, 0x39, 0x9f, 0x69, 0x17, 0x84, + 0xac, 0xf9, 0xf6, 0xdf, 0xfe, 0xd2, 0x41, 0xe8, + 0x02, 0x30, 0xf8, 0xd8, 0x72, 0x35, 0xd3, 0x0e, + 0x76, 0x2e, 0xda, 0x4b, 0xf4, 0xc5, 0x31, 0x0f}; +/// Validates join request. +void ValidateJoinRequest(JoinRequest const& request, HashAlg hash_alg, + GroupPubKey const& grp_public_key, FpElemStr const& f, + IssuerNonce const& ni) { + Epid2Params params_values = { +#include "epid/common/src/epid2params_ate.inc" + }; + + Epid20Params params; + + // h1^f ?= F + EcPointObj F_expected(¶ms.G1, grp_public_key.h1); + THROW_ON_EPIDERR(EcExp(params.G1, F_expected, (BigNumStr*)&f, F_expected)); + ASSERT_EQ(*(G1ElemStr*)(F_expected.data().data()), request.F); + + // H(p|g1|g2|h1|h2|w|F|R|ni) ?= c, where R = h1^s * F^(-c) + FfElementObj nc(¶ms.fp, request.c); + THROW_ON_EPIDERR(FfNeg(params.fp, nc, nc)); + EcPointObj a(¶ms.G1, grp_public_key.h1); + EcPointObj b(¶ms.G1, request.F); + THROW_ON_EPIDERR(EcExp(params.G1, a, (BigNumStr*)&request.s, a)); + THROW_ON_EPIDERR(EcExp(params.G1, b, (BigNumStr*)nc.data().data(), b)); + THROW_ON_EPIDERR(EcMul(params.G1, a, b, a)); + +#pragma pack(1) + struct { + BigNumStr p; // Intel(R) EPID 2.0 parameter p + G1ElemStr g1; // Intel(R) EPID 2.0 parameter g1 + G2ElemStr g2; // Intel(R) EPID 2.0 parameter g2 + G1ElemStr h1; // Group public key value h1 + G1ElemStr h2; // Group public key value h2 + G2ElemStr w; // Group public key value w + G1ElemStr F; // Variable F computed in algorithm + G1ElemStr R; // Variable R computed in algorithm + IssuerNonce NI; // Issuer Nonce + } commitment_values = {params_values.p, + params_values.g1, + params_values.g2, + grp_public_key.h1, + grp_public_key.h2, + grp_public_key.w, + request.F, + *(G1ElemStr*)(a.data().data()), + ni}; +#pragma pack() + + FfElementObj commitment(¶ms.fp); + THROW_ON_EPIDERR(FfHash(params.fp, &commitment_values, + sizeof commitment_values, hash_alg, commitment)); + ASSERT_EQ(*(FpElemStr*)(commitment.data().data()), request.c); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenNullParameters) { + GroupPubKey pub_key = kPubKey; + IssuerNonce ni; + MemberParams params; + Prng prng; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj ctx(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(nullptr, &pub_key, &ni, &join_request)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(ctx, nullptr, &ni, &join_request)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(ctx, &pub_key, nullptr, &join_request)); + EXPECT_EQ(kEpidBadArgErr, EpidCreateJoinRequest(ctx, &pub_key, &ni, nullptr)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenInvalidGroupKey) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + pub_key.h1.x.data.data[15] = 0xff; + Epid20Params epid_params; + EcPointObj pt(&epid_params.G1); + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + ASSERT_NE(kEpidNoErr, ReadEcPoint(epid_params.G1, (uint8_t*)&pub_key.h1, + sizeof(pub_key.h1), pt)); + EXPECT_EQ(kEpidBadArgErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); +} + +TEST_F(EpidMemberTest, CreateJoinRequestFailsGivenInvalidFValue) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + EpidStatus sts; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + + std::unique_ptr member; + size_t context_size = 0; + sts = EpidMemberGetSize(¶ms, &context_size); + EXPECT_TRUE(kEpidNoErr == sts || kEpidBadArgErr == sts) + << "Actual value " << sts; + + if (kEpidNoErr == sts) { + member.reset(new uint8_t[context_size]()); + sts = EpidMemberInit(¶ms, (MemberCtx*)member.get()); + EXPECT_TRUE(kEpidNoErr == sts || kEpidBadArgErr == sts) + << "Actual value " << sts; + } + + if (kEpidNoErr == sts) { + sts = EpidCreateJoinRequest((MemberCtx*)member.get(), &pub_key, &ni, + &join_request); + EXPECT_EQ(kEpidBadArgErr, sts); + } + + EpidMemberDeinit((MemberCtx*)member.get()); +} + +TEST_F(EpidMemberTest, CreateJoinRequestWorksGivenValidParameters) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha256, pub_key, f, ni)); +} + +TEST_F(EpidMemberTest, + PROTECTED_EPS1_CreateJoinRequestUsingWorksGivenValidParameters) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha256, pub_key, kFEps1, ni)); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestGeneratesDiffJoinRequestsOnMultipleCalls) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request1; + JoinRequest join_request2; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request1)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request1, kSha256, pub_key, f, ni)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request2)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request2, kSha256, pub_key, f, ni)); + EXPECT_NE(join_request1, join_request2); +} + +TEST_F( + EpidMemberTest, + PROTECTED_EPS1_CreateJoinRequestGeneratesDiffJoinRequestsOnMultipleCalls) { + Prng prng; + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request1; + JoinRequest join_request2; + SetMemberParams(Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request1)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request1, kSha256, pub_key, kFEps1, ni)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, &pub_key, &ni, &join_request2)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request2, kSha256, pub_key, kFEps1, ni)); + EXPECT_NE(join_request1, join_request2); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestGeneratesDiffJoinRequestsGivenDiffHashAlgs) { + MemberParams params = {0}; + GroupPubKey pub_key = kPubKey; + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request1; + JoinRequest join_request2; + // Ensure that two members created with equal seed and do not + // interfere each other. Member1 is deleted by the time member2 + // is created. + { + Prng prng; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member1(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member1, kSha256)); + prng.set_seed(0x1234); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member1, &pub_key, &ni, &join_request1)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request1, kSha256, pub_key, f, ni)); + } + { + Prng prng; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member2(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member2, kSha384)); + prng.set_seed(0x1234); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member2, &pub_key, &ni, &join_request2)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request2, kSha384, pub_key, f, ni)); + } + EXPECT_NE(join_request1, join_request2); +} + +TEST_F(EpidMemberTest, + CreateJoinRequestWorksGivenValidParametersUsingIKGFData) { + Prng prng; + MemberParams params = {0}; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + FpElemStr f = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + }; + IssuerNonce ni = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + }; + JoinRequest join_request; + SetMemberParams(Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidCreateJoinRequest(member, pub_key, &ni, &join_request)); + EXPECT_NO_FATAL_FAILURE( + ValidateJoinRequest(join_request, kSha256, *pub_key, f, ni)); +} +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/main-test.cc b/external/epid-sdk/epid/member/unittests/main-test.cc new file mode 100644 index 00000000..eb29e336 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/main-test.cc @@ -0,0 +1,66 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/*! + * \file + * \brief Main entry point for unit tests. + */ + +#include "epid/common-testhelper/testapp-testhelper.h" +#include "gtest/gtest.h" + +int main(int argc, char** argv) { + std::vector positive; + std::vector negative; + std::vector argv_new; + argv_new.push_back(argv[0]); + bool include_protected = false; + bool print_help = false; + for (int i = 1; i < argc; i++) { + std::string arg(argv[i]); + if (arg == std::string("--also_run_protected_tests")) { + include_protected = true; + } else if (arg == std::string("--help")) { + print_help = true; + argv_new.push_back(argv[i]); + } else if (arg.compare(0, 15, "--gtest_filter=") == 0) { + split_filter(&positive, &negative, arg.substr(15)); + } else { + argv_new.push_back(argv[i]); + } + } + if (!include_protected) { + negative.push_back("*.*_PROTECTED_*"); + negative.push_back("*.PROTECTED_*"); + } + std::string filter = join_filter(positive, negative); + if (filter != "") { + argv_new.push_back(&filter[0]); + } + int argc_new = (int)argv_new.size(); + argv_new.push_back(nullptr); + testing::InitGoogleTest(&argc_new, argv_new.data()); + if (print_help) { + printf("\n"); + printf("Custom Options:\n"); + printf(" --also_run_protected_tests\n"); + printf(" similar to --gtest_also_run_disabled_tests, but for\n"); + printf(" protected tests (PROTECTED_ instead of DISABLED_)\n"); + printf("\n"); + printf("Protected tests are tests where some data is protected\n"); + printf("(i.e. hidden) from the code and can only be used indirectly.\n"); + } + return RUN_ALL_TESTS(); +} diff --git a/external/epid-sdk/epid/member/unittests/member-testhelper.cc b/external/epid-sdk/epid/member/unittests/member-testhelper.cc new file mode 100644 index 00000000..3503f1f4 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/member-testhelper.cc @@ -0,0 +1,436 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Member C++ wrapper implementation. + */ + +#include "epid/member/unittests/member-testhelper.h" + +#include +#include +#include + +extern "C" { +#include "epid/common/types.h" +} + +#include "epid/common-testhelper/mem_params-testhelper.h" + +/// Handle SDK Error with Break +#define BREAK_ON_EPID_ERROR(ret) \ + if (kEpidNoErr != (ret)) { \ + break; \ + } + +/// compares G1ElemStr values +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} + +/// Arbitrary test data were generated based on Intel(R) EPID 2.0 parameters +const GroupPubKey EpidMemberTest::kGroupPublicKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w +}; + +const PrivKey EpidMemberTest::kMemberPrivateKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd, + 0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2, + 0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}}, + {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a, + 0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6, + 0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43, + 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07, + 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7} // f +}; + +const MemberPrecomp EpidMemberTest::kMemberPrecomp = { + {0xd8, 0x14, 0xba, 0x4b, 0x44, 0x03, 0x55, 0x6c, 0xf6, 0x42, 0xe8, + 0xf0, 0x4c, 0xb5, 0xe7, 0xd4, 0xa2, 0xa3, 0x69, 0x47, 0xf5, 0xd4, + 0xc8, 0xe9, 0xc5, 0x5a, 0x39, 0xb5, 0x55, 0xa5, 0xd3, 0xfb, 0xf3, + 0x85, 0x5a, 0x0d, 0xd5, 0xee, 0xde, 0xf4, 0xa8, 0xb1, 0x8b, 0xcf, + 0xa9, 0x0d, 0x29, 0xbf, 0x86, 0x27, 0x9c, 0x1f, 0x96, 0xed, 0xd8, + 0x44, 0x01, 0x35, 0x1a, 0xce, 0xfd, 0x4e, 0x6f, 0xa1, 0x66, 0x0d, + 0x59, 0x08, 0x6d, 0xa2, 0xe4, 0x99, 0x83, 0xdc, 0x39, 0x28, 0xb7, + 0x1c, 0x1a, 0x33, 0xad, 0xca, 0x5c, 0x35, 0x26, 0x1f, 0xab, 0xba, + 0x0d, 0x53, 0xaf, 0xe0, 0x72, 0x14, 0xc5, 0xa7, 0x2e, 0x58, 0x26, + 0xc9, 0x8e, 0xfa, 0x6f, 0x62, 0xfc, 0xf0, 0x08, 0x3e, 0xa3, 0x11, + 0x3a, 0xf0, 0xb8, 0x3b, 0x2d, 0x3e, 0xec, 0xd5, 0xbc, 0xf2, 0x05, + 0x68, 0xf4, 0x40, 0xce, 0x2c, 0x8f, 0xdd, 0xa4, 0xe5, 0xe1, 0xb5, + 0xbe, 0xbd, 0x3e, 0xd4, 0xf6, 0x9a, 0xb3, 0x37, 0x24, 0x0d, 0xea, + 0x13, 0xd7, 0x1f, 0xa2, 0x75, 0x68, 0xa1, 0xbe, 0x2c, 0x01, 0x42, + 0x2a, 0xae, 0x6f, 0xae, 0x7a, 0x72, 0x3a, 0x11, 0x03, 0x58, 0x02, + 0x0d, 0xf0, 0xb0, 0xd9, 0x6f, 0xb1, 0xe4, 0xf2, 0x70, 0xb8, 0xff, + 0x22, 0x56, 0x7c, 0xb3, 0x80, 0xfd, 0xdf, 0xe5, 0xab, 0xcc, 0x18, + 0x7a, 0xfd, 0x91, 0xd0, 0xb0, 0x63, 0x40, 0xd4, 0x71, 0xfa, 0x03, + 0xf5, 0xf1, 0x26, 0xe1, 0xa5, 0x5a, 0xd9, 0x6d, 0xf5, 0x5a, 0x7b, + 0x2a, 0x3a, 0xfe, 0x94, 0x9e, 0x74, 0x41, 0x79, 0x49, 0x7e, 0x48, + 0x1d, 0x58, 0x5e, 0xf6, 0x98, 0xa3, 0x6e, 0x61, 0x8e, 0x9f, 0x1f, + 0xcd, 0x15, 0x01, 0x16, 0xa5, 0xe0, 0xab, 0xd6, 0xd6, 0x1f, 0x1c, + 0xf5, 0x81, 0x76, 0xc1, 0xec, 0x10, 0xc2, 0xcc, 0x68, 0x59, 0x4d, + 0x47, 0xef, 0x4b, 0x7f, 0xd8, 0x78, 0x9c, 0xfe, 0x9a, 0x86, 0x7e, + 0x0c, 0xfd, 0x3e, 0x0a, 0x7a, 0x72, 0x8b, 0x14, 0x5f, 0xe6, 0x5f, + 0x19, 0xa3, 0x0a, 0x1b, 0x71, 0xdc, 0xd2, 0xae, 0x35, 0xc3, 0x11, + 0xa5, 0xd3, 0xea, 0xe1, 0xa9, 0xe7, 0x70, 0x0c, 0x7a, 0x39, 0x56, + 0x3c, 0xe4, 0xe7, 0xf9, 0xb6, 0xf1, 0x15, 0x40, 0xab, 0xb6, 0xc4, + 0xad, 0xbd, 0xf4, 0xcc, 0x13, 0xb7, 0xa8, 0xb6, 0x92, 0x1e, 0x72, + 0x27, 0xa7, 0xff, 0xd9, 0xea, 0x2f, 0x91, 0x96, 0x22, 0xd2, 0xc4, + 0x4d, 0x80, 0xdc, 0x47, 0x66, 0x87, 0xcc, 0xcf, 0xc5, 0x64, 0xf7, + 0xb2, 0x34, 0xed, 0xd5, 0x44, 0x44, 0xcc, 0x57, 0x41, 0xc7, 0x92, + 0xb7, 0x5c, 0x12, 0xf7, 0x81, 0xf2, 0x92, 0x35, 0x3e, 0x4b, 0xdf, + 0xf8, 0xda, 0x68, 0xac, 0x30, 0xe3, 0xdd, 0x9e, 0x22, 0xaa, 0x6d, + 0x77, 0xdd, 0xac, 0xd9, 0x11, 0x6e, 0xfb, 0x1a, 0x88, 0xb3}, // e12 + { + 0x07, 0x3f, 0x9d, 0x47, 0x82, 0xb8, 0x3d, 0x6a, 0xe0, 0x36, 0xab, 0xa6, + 0xfa, 0xe6, 0xd2, 0x1c, 0xc8, 0xb2, 0xd0, 0x01, 0xd4, 0x96, 0xdc, 0x2e, + 0xf8, 0x19, 0xdc, 0x70, 0x1b, 0xf9, 0x73, 0x0c, 0x2b, 0xc2, 0xe2, 0x1d, + 0x85, 0x53, 0x81, 0x51, 0xfb, 0xca, 0x16, 0x86, 0xd4, 0x4e, 0xfd, 0x1a, + 0x59, 0xe3, 0x97, 0xc4, 0x7f, 0x99, 0xd8, 0x66, 0x08, 0xa1, 0xe4, 0x9f, + 0xbb, 0x3a, 0xce, 0xa5, 0x23, 0x9c, 0x83, 0x13, 0xc5, 0xc8, 0xf2, 0x16, + 0x1e, 0xe8, 0xe6, 0xc5, 0x36, 0x57, 0x2c, 0xdf, 0x73, 0xb4, 0xe2, 0xb2, + 0xcb, 0xeb, 0xbb, 0xf7, 0x45, 0xd1, 0x44, 0xbd, 0x6e, 0x92, 0x95, 0x00, + 0xe5, 0x89, 0xb5, 0x91, 0x78, 0xc7, 0x44, 0xb1, 0x2f, 0x37, 0xdf, 0xfb, + 0xe7, 0x8a, 0x44, 0x3f, 0x3d, 0x06, 0x5f, 0x5b, 0x1c, 0x5f, 0xce, 0x11, + 0x05, 0x35, 0x3c, 0xad, 0x92, 0x7e, 0x79, 0xb8, 0xff, 0x28, 0x05, 0xe4, + 0x04, 0x2c, 0xb6, 0x1d, 0x22, 0xab, 0x36, 0x00, 0x5f, 0x74, 0xf1, 0xe3, + 0xf6, 0xa6, 0x68, 0xe6, 0x7b, 0x25, 0xb8, 0xcf, 0x19, 0xb0, 0x1a, 0xdd, + 0x0f, 0xad, 0x63, 0x73, 0x62, 0x1b, 0xe7, 0x94, 0x5d, 0xbf, 0x3d, 0xf1, + 0xf9, 0x8e, 0xab, 0x59, 0xe5, 0xd1, 0x7c, 0x62, 0xdd, 0xbc, 0x40, 0x07, + 0x70, 0x5b, 0x13, 0xf6, 0x12, 0x09, 0xb4, 0x0d, 0x3e, 0xab, 0x8b, 0x70, + 0x60, 0x1d, 0xd4, 0x61, 0x37, 0x28, 0x98, 0x3e, 0x7e, 0xdc, 0xfd, 0xd2, + 0xc0, 0x2f, 0x4b, 0x71, 0x31, 0x34, 0xd7, 0x69, 0x41, 0x5e, 0xaa, 0x72, + 0xe4, 0xdf, 0xeb, 0xfe, 0x8d, 0xcd, 0x68, 0xfc, 0x68, 0x55, 0xbe, 0x32, + 0x7d, 0x24, 0xc5, 0x07, 0x0f, 0xa8, 0xbd, 0x5a, 0xfe, 0xe7, 0xec, 0xdb, + 0xfd, 0x19, 0xc8, 0xa9, 0x20, 0xa2, 0x7f, 0x6c, 0xa6, 0x62, 0xec, 0xed, + 0x9b, 0x79, 0xbf, 0x9c, 0x0e, 0x31, 0x0b, 0x25, 0x2f, 0xd3, 0xcc, 0xa0, + 0xdd, 0xb2, 0xf2, 0x69, 0x26, 0x85, 0x21, 0x06, 0x94, 0x56, 0x5f, 0x59, + 0x5c, 0xf5, 0xb7, 0x82, 0xce, 0x0f, 0xdd, 0x40, 0xdb, 0x83, 0xac, 0x3c, + 0x41, 0xa0, 0x1b, 0xb1, 0xaf, 0xda, 0x55, 0xbf, 0x6b, 0x1a, 0xef, 0xe6, + 0x90, 0xe7, 0xaa, 0x0f, 0x04, 0x3c, 0x9f, 0x5b, 0xb7, 0xcd, 0x98, 0xa8, + 0x9e, 0xff, 0x54, 0x26, 0xc8, 0xd5, 0x5c, 0x30, 0x5e, 0xa2, 0x99, 0x8e, + 0x34, 0xd5, 0x98, 0x9f, 0xcd, 0x57, 0xd1, 0x4d, 0x1d, 0xee, 0x01, 0x5d, + 0x5a, 0x6d, 0xb2, 0xf1, 0xcf, 0x4b, 0xc0, 0x21, 0x23, 0x96, 0x05, 0xf9, + 0xc9, 0x66, 0xe5, 0x25, 0x9d, 0xa3, 0x8e, 0x78, 0x43, 0x19, 0xc1, 0x7f, + 0x7b, 0xef, 0xf5, 0xed, 0x00, 0xb7, 0x45, 0x1f, 0x4e, 0xa9, 0xfa, 0xe3, + 0xff, 0x54, 0xf2, 0x21, 0x73, 0xf8, 0x6b, 0xa1, 0xc7, 0x31, 0x4d, 0x6a, + }, // e22 + { + 0x49, 0x0d, 0x0f, 0x2a, 0x5c, 0x6a, 0x3b, 0xad, 0x71, 0xc9, 0x22, 0x49, + 0xe8, 0x08, 0xdd, 0xba, 0x79, 0x57, 0xb7, 0xc7, 0x61, 0xe4, 0xdb, 0x84, + 0x68, 0x57, 0xb9, 0x30, 0x83, 0xa4, 0xdc, 0xef, 0x70, 0x93, 0x28, 0xe2, + 0x6f, 0xb9, 0xbc, 0x15, 0x28, 0x3a, 0x30, 0xbd, 0x96, 0x83, 0xdb, 0xf2, + 0x9d, 0x1e, 0xc7, 0x64, 0x6d, 0x2e, 0x7c, 0xa2, 0xf3, 0xaa, 0x2f, 0x4b, + 0x6d, 0x86, 0x9e, 0x48, 0x20, 0x29, 0x4b, 0x1f, 0x8d, 0xc2, 0x93, 0xc3, + 0x55, 0x25, 0x8e, 0xb0, 0x8a, 0x7e, 0x64, 0x45, 0x3f, 0xf4, 0x1d, 0x16, + 0x4c, 0x88, 0x2d, 0x54, 0xbe, 0xa8, 0x67, 0x70, 0x81, 0xc5, 0xb9, 0x5c, + 0x16, 0x00, 0xef, 0x78, 0xf6, 0x4d, 0x6a, 0xeb, 0xfd, 0xa2, 0x0d, 0x52, + 0x86, 0xf3, 0x04, 0x4b, 0xd8, 0xf0, 0x7d, 0x50, 0x8b, 0xad, 0xc0, 0x37, + 0xdb, 0x38, 0xf2, 0x7d, 0x1f, 0x8b, 0x13, 0x83, 0x7b, 0xcc, 0xe8, 0x25, + 0xfe, 0xfa, 0x0c, 0x02, 0x05, 0x2e, 0x75, 0x12, 0xa1, 0x0a, 0x89, 0xab, + 0xf1, 0xb2, 0x08, 0x47, 0x9a, 0xea, 0xef, 0x1d, 0xa4, 0x9f, 0xde, 0x89, + 0x47, 0x3e, 0x7c, 0x5e, 0x4a, 0x40, 0xdc, 0xec, 0xc5, 0x1b, 0x7e, 0x33, + 0x0a, 0x19, 0x69, 0x27, 0xa6, 0xcc, 0x25, 0xfc, 0xf9, 0xeb, 0xbd, 0xb7, + 0x8a, 0xdb, 0x45, 0x5f, 0x9d, 0x9e, 0x01, 0xde, 0x3d, 0x91, 0x10, 0x99, + 0x13, 0xbf, 0xc0, 0xfa, 0x9d, 0xd4, 0x0f, 0xb3, 0x09, 0xf3, 0xa1, 0xae, + 0x68, 0xe1, 0x1b, 0x48, 0x85, 0x9f, 0x81, 0x66, 0x91, 0xe2, 0xf0, 0x7b, + 0x29, 0xdb, 0x8f, 0x5d, 0x99, 0xa9, 0xd3, 0x39, 0x30, 0xd9, 0x1b, 0x94, + 0x2a, 0x1c, 0x5c, 0xe9, 0xc0, 0x3f, 0x6e, 0xb2, 0x27, 0xbe, 0x74, 0x7a, + 0xca, 0xe1, 0x0f, 0x6a, 0x43, 0x2e, 0x98, 0x65, 0xaf, 0x7f, 0x6e, 0x5a, + 0x55, 0x98, 0xc1, 0x58, 0x29, 0xb3, 0x86, 0x54, 0x0f, 0x57, 0x91, 0x89, + 0x29, 0xb1, 0x98, 0x79, 0xcc, 0x95, 0x39, 0xd0, 0xab, 0xe0, 0x9f, 0xf3, + 0xda, 0xf9, 0x5e, 0xd9, 0x34, 0xbb, 0x72, 0xda, 0xe5, 0x72, 0xd3, 0xf8, + 0x9b, 0xf9, 0x14, 0x84, 0x48, 0x81, 0x54, 0x4f, 0xe6, 0x2b, 0x80, 0xc8, + 0xc1, 0x79, 0xfe, 0x83, 0xff, 0x76, 0xa3, 0x6d, 0xfe, 0x37, 0x78, 0xc5, + 0x30, 0x7a, 0x50, 0xe2, 0x5d, 0x12, 0xdc, 0x72, 0xe9, 0x58, 0x7c, 0x07, + 0x4f, 0xff, 0x15, 0x8a, 0x97, 0x3b, 0xcb, 0x60, 0xfa, 0x4e, 0xde, 0x8c, + 0x80, 0x3a, 0x8b, 0x0b, 0xc6, 0x1d, 0xa3, 0xce, 0x6a, 0xb3, 0x50, 0x69, + 0x03, 0x96, 0xca, 0xc0, 0xb6, 0x94, 0x6f, 0x8f, 0xab, 0x6f, 0x5b, 0x00, + 0x2a, 0x1d, 0x90, 0xa7, 0x81, 0xc6, 0x15, 0x77, 0x79, 0xf3, 0x36, 0x23, + 0xd1, 0x46, 0x25, 0x58, 0x6f, 0x7b, 0x22, 0xac, 0x4c, 0x7a, 0xf3, 0x9f, + }, // e2w + { + 0x8d, 0x71, 0xe2, 0xb0, 0x73, 0x2f, 0x4a, 0xba, 0x64, 0xe8, 0x7a, 0x12, + 0xaf, 0xe4, 0x4f, 0xdb, 0x6b, 0x3e, 0x38, 0x07, 0x0c, 0x79, 0x22, 0x48, + 0x1b, 0x9d, 0x33, 0x53, 0x5c, 0x75, 0x3b, 0x40, 0x5e, 0x18, 0xd1, 0x92, + 0x4a, 0xd1, 0x82, 0x1c, 0xc7, 0x3a, 0xf7, 0x7e, 0x32, 0x19, 0x99, 0x5d, + 0x01, 0x0e, 0xb0, 0xf2, 0x8f, 0x80, 0xc6, 0xb9, 0xeb, 0x1f, 0x9e, 0xae, + 0x9e, 0xe0, 0x99, 0xfd, 0xe8, 0x93, 0x11, 0x61, 0x7d, 0xc2, 0x49, 0xdb, + 0xa8, 0x73, 0xa4, 0xa9, 0x33, 0xe2, 0x04, 0xd1, 0x7d, 0x8b, 0xe1, 0xd6, + 0x2b, 0x10, 0x6c, 0x79, 0x02, 0xbf, 0xfc, 0x53, 0x03, 0xa9, 0xbc, 0x30, + 0x4d, 0x4d, 0xf4, 0x32, 0xce, 0x9a, 0x4a, 0xfa, 0xd6, 0x7f, 0x26, 0x17, + 0xc5, 0xf6, 0xed, 0xe4, 0xcc, 0xb9, 0x79, 0xe2, 0xa8, 0x86, 0xbb, 0xd7, + 0xfb, 0x05, 0xd2, 0x81, 0xbe, 0x07, 0x1c, 0x47, 0x48, 0x4f, 0x6d, 0x6b, + 0x52, 0x42, 0xe4, 0xc6, 0x20, 0x46, 0xa3, 0xae, 0x5b, 0x55, 0x55, 0xfe, + 0x4a, 0xad, 0xf2, 0x32, 0x07, 0x0f, 0x91, 0xa9, 0xe5, 0xd3, 0x86, 0x08, + 0x73, 0x93, 0xc7, 0x1e, 0x6b, 0xcd, 0x69, 0xd0, 0xfb, 0xc1, 0x74, 0xc2, + 0xb8, 0x90, 0xc8, 0xf8, 0x93, 0xbf, 0x08, 0x0f, 0x15, 0x19, 0x26, 0x71, + 0x4a, 0x9e, 0xdf, 0xdf, 0xca, 0x6f, 0xca, 0xfd, 0x67, 0xec, 0x4d, 0x21, + 0x5b, 0x99, 0xbd, 0x4b, 0x79, 0x22, 0x2d, 0xe4, 0x24, 0x72, 0x88, 0x93, + 0xce, 0xe6, 0x7f, 0xef, 0x35, 0x83, 0x67, 0x39, 0xb9, 0x34, 0x80, 0x64, + 0x0a, 0xf4, 0xff, 0x42, 0x9d, 0xee, 0xda, 0xb8, 0xd3, 0xdc, 0x1d, 0x0d, + 0x9f, 0x45, 0xe9, 0xbe, 0xf4, 0x3e, 0xa6, 0x58, 0x8b, 0xf0, 0xfd, 0x01, + 0x73, 0x63, 0xd0, 0xc6, 0x9d, 0xb9, 0x32, 0xd1, 0x91, 0xfe, 0xb1, 0xf5, + 0x4b, 0x48, 0xb4, 0x46, 0xae, 0x61, 0xd7, 0x90, 0xfe, 0x86, 0x74, 0x68, + 0xee, 0x78, 0x86, 0x65, 0x99, 0x6d, 0x7b, 0xf0, 0x17, 0x1a, 0x4c, 0xb0, + 0x37, 0x73, 0xdc, 0x38, 0x41, 0xfa, 0x02, 0xd2, 0x13, 0x8f, 0x71, 0xb4, + 0x0a, 0x72, 0x70, 0x0f, 0xe1, 0x2c, 0x9a, 0xa9, 0x51, 0xfa, 0xb2, 0xbf, + 0x84, 0xf2, 0xa6, 0xfb, 0xc3, 0x83, 0x16, 0x7e, 0x27, 0xec, 0x06, 0x5d, + 0x64, 0x79, 0xe7, 0x42, 0x30, 0xf8, 0x2d, 0xbc, 0x0f, 0x07, 0x8b, 0xf2, + 0x99, 0xda, 0x91, 0x4c, 0x65, 0xcf, 0x7f, 0x57, 0x2d, 0x2f, 0x67, 0xe7, + 0xfb, 0x75, 0xe9, 0xb2, 0xa3, 0x72, 0x60, 0x88, 0x2b, 0x14, 0x31, 0x62, + 0xbc, 0x45, 0x59, 0x5c, 0x58, 0x39, 0xb3, 0x4a, 0xeb, 0xb9, 0x18, 0x24, + 0x05, 0xcb, 0xda, 0xd3, 0x5e, 0x54, 0xba, 0xda, 0xfd, 0xfc, 0xa0, 0x02, + 0xb3, 0xde, 0x52, 0x3e, 0xc0, 0xd0, 0xb8, 0x19, 0x85, 0x1b, 0x7b, 0xe3, + } // ea2 +}; + +const std::vector EpidMemberTest::kGroupPublicKeyDataIkgf = { +#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" +}; +const std::vector EpidMemberTest::kMemberPrivateKeyDataIkgf = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" +}; + +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha256 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc" +}; +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha384 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha384.inc" +}; +const std::vector EpidMemberTest::kGrp01Member0SigTest1Sha512 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc" +}; +const std::vector EpidMemberTest::kTest1Msg = {'t', 'e', 's', 't', + '1'}; +std::vector EpidMemberTest::kSigRlData = { +#include "epid/common-testhelper/testdata/grp01/sigrl.inc" +}; +std::vector EpidMemberTest::kSigRl5EntryData = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x00, 0x00, 0x00, 0x05, + // bk's + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, 0x8, + 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, 0x2e, + 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, 0x67, + 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, 0x9d, 0xc7, + 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, 0x7d, 0xfe, + 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, 0x89, 0xb2, + 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, 0xcf, 0xd, 0x40, + 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, 0x4f, 0x7a, 0xb5, + 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, 0x33, 0xad, 0xf6, + 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, 0xce, 0xec, 0xd1, + 0xa8, 0xc, 0x8b, + + 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10, 0xfe, + 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60, 0x3e, 0xc0, + 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82, 0xc4, 0x49, + 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5, 0x77, 0x16, 0x4, + 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8, 0x40, 0xbd, 0x69, + 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9, 0xdd, 0x97, 0x6c, + 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2, 0xca, 0x5, 0x44, 0x9b, + 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa, 0xcf, 0xa4, 0x4, 0xe9, 0xf3, + 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3, 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, + 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60, 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, + 0x11, + + 0x6e, 0x22, 0xaa, 0x10, 0x84, 0x58, 0x8b, 0xff, 0xd8, 0x37, 0x8, 0xa9, 0xe9, + 0xdb, 0xf6, 0x1f, 0x69, 0x10, 0x95, 0x6c, 0xbf, 0xd, 0x11, 0x48, 0x6f, 0x1b, + 0x3c, 0x62, 0x46, 0x13, 0x89, 0x13, 0x5f, 0xa1, 0x3, 0x62, 0xed, 0x62, 0xdf, + 0x3d, 0xbf, 0xcd, 0xb7, 0x41, 0x48, 0x81, 0x3, 0x9f, 0x54, 0xa, 0xe, 0xb3, + 0x35, 0xf9, 0xde, 0x24, 0xba, 0x6d, 0x4c, 0x7f, 0xfc, 0xc1, 0xb4, 0xce, + 0x6d, 0xa1, 0x73, 0x7c, 0xaa, 0xb, 0xad, 0x2, 0xd6, 0x37, 0x85, 0xe, 0xbb, + 0x48, 0x11, 0x38, 0xc4, 0xaa, 0x1b, 0xf, 0xcf, 0xc1, 0x9c, 0x26, 0xcc, 0x95, + 0xc2, 0x5b, 0x49, 0x9, 0x3d, 0xe9, 0x7d, 0xce, 0xc7, 0xa6, 0x4, 0x3e, 0x7c, + 0x9e, 0x28, 0xde, 0x8, 0x11, 0xe, 0x61, 0x3b, 0xc0, 0x9c, 0x6b, 0x58, 0x23, + 0xe6, 0x40, 0x7b, 0xbd, 0xb8, 0x72, 0xf, 0xe0, 0xee, 0xcf, 0xba, 0xb4, + + 0xc4, 0xff, 0xaf, 0x48, 0x15, 0xda, 0x60, 0x40, 0xcc, 0xd7, 0xf2, 0x68, + 0xf7, 0xe2, 0x70, 0x12, 0x8d, 0x15, 0xa5, 0xb7, 0xe6, 0x4c, 0x23, 0xea, + 0x4d, 0x8a, 0x51, 0x6, 0x67, 0x3, 0x4c, 0x83, 0x6f, 0x28, 0x67, 0xcf, 0x63, + 0x46, 0x3e, 0x8a, 0x45, 0x9f, 0xed, 0x1a, 0xde, 0xa7, 0xad, 0xb2, 0x2b, 0xf, + 0x8b, 0xab, 0x7c, 0x70, 0xff, 0xc3, 0xa8, 0x6e, 0x8c, 0xaa, 0xb1, 0xf6, + 0x20, 0xe3, 0xb9, 0xf1, 0xc3, 0x3d, 0x5, 0x6a, 0x1e, 0x26, 0x2d, 0xf4, 0xd, + 0xe4, 0x53, 0x63, 0x67, 0x23, 0x48, 0xa8, 0x1, 0xa8, 0xee, 0xe1, 0x5f, 0x64, + 0xe3, 0x2c, 0x71, 0xe2, 0x10, 0x82, 0x0, 0x52, 0xd7, 0x74, 0x87, 0xff, 0x1c, + 0x0, 0x19, 0xe6, 0x4d, 0x15, 0x91, 0x6d, 0xf3, 0x38, 0x3b, 0xee, 0xf3, 0xd5, + 0xd1, 0xc7, 0x6d, 0xd9, 0x8e, 0x55, 0x70, 0x90, 0xb0, 0xb, 0x3c, 0x4a, 0x67, + 0x19, + + 0x4f, 0x98, 0x92, 0xf9, 0x18, 0x38, 0xf5, 0xb4, 0xf7, 0x2f, 0xa7, 0x21, + 0x71, 0x52, 0x27, 0xd0, 0x57, 0x4f, 0x9c, 0x30, 0xe, 0xb2, 0x27, 0xce, 0xd7, + 0xb2, 0x9f, 0xc0, 0xf6, 0xc3, 0xb0, 0x7c, 0x40, 0x18, 0x75, 0x4a, 0xde, + 0xb0, 0x9f, 0x46, 0x8a, 0x5a, 0xeb, 0x4f, 0xcb, 0x5e, 0x60, 0xf5, 0xca, + 0xf4, 0x98, 0xaf, 0x62, 0x9b, 0x7e, 0x10, 0xda, 0xba, 0x2f, 0x47, 0x64, + 0xf2, 0xc0, 0x84, 0x19, 0x75, 0xe0, 0xe4, 0xff, 0x20, 0xda, 0x7d, 0xe5, 0xd, + 0xc8, 0xf8, 0xe3, 0x83, 0x61, 0x19, 0x17, 0xf1, 0xa9, 0x1b, 0xff, 0x39, + 0x79, 0x88, 0x1, 0xfb, 0xe7, 0x23, 0xd2, 0xac, 0xe0, 0x49, 0x12, 0x2a, 0x38, + 0xb4, 0x7c, 0xc2, 0x1b, 0x88, 0x5f, 0x68, 0x32, 0x11, 0xd9, 0xfd, 0xdc, + 0x65, 0x2, 0xb3, 0x74, 0x2c, 0x13, 0xf2, 0xd8, 0xf1, 0x45, 0xc5, 0xd1, 0xf4, + 0xa3, 0x38, 0x81, 0x92}; +const std::vector EpidMemberTest::kMsg0 = {'m', 's', 'g', '0'}; +const std::vector EpidMemberTest::kBsn0 = {'b', 's', 'n', '0'}; +const std::vector EpidMemberTest::kMsg1 = {'m', 's', 'g', '1'}; +const std::vector EpidMemberTest::kBsn1 = {'b', 's', 'n', '1'}; +const std::vector EpidMemberTest::kData_0_255 = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0xff, +}; + +const GroupPubKey EpidMemberTest::kGrpXKey = { +#include "epid/common-testhelper/testdata/grp_x/pubkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXMember0PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/member0/mprivkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXSigrevokedMember0PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/sigrevoked/mprivatekey000.inc" +}; +const std::vector EpidMemberTest::kGrpXSigRl = { +#include "epid/common-testhelper/testdata/grp_x/sigrl.inc" +}; +const std::vector EpidMemberTest::kGrpXSigRlSingleEntry = { +#include "epid/common-testhelper/testdata/grp_x/sigrl_single_entry.inc" +}; + +const CompressedPrivKey EpidMemberTest::kGrpXMember9CompressedKey = { +#include "epid/common-testhelper/testdata/grp_x/cmember9/cmpprivkey.inc" +}; +const PrivKey EpidMemberTest::kGrpXMember9PrivKey = { +#include "epid/common-testhelper/testdata/grp_x/cmember9/mprivkey.inc" +}; + +const GroupPubKey EpidMemberTest::kGrpYKey = { +#include "epid/common-testhelper/testdata/grp_y/pubkey.inc" +}; + +const CompressedPrivKey EpidMemberTest::kGrpYMember9CompressedKey = { +#include "epid/common-testhelper/testdata/grp_y/cmember9/cmpprivkey.inc" +}; + +const OctStr32 EpidMemberTest::kOctStr32_1 = {0x00, 0x00, 0x00, 0x01}; + +/// Arbitrary test data were generated based on Intel(R) EPID 2.0 parameters +const GroupPubKey EpidMemberTest::kEps0GroupPublicKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d, + 0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce, + 0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}}, + {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7, + 0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45, + 0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}}, // h1 + {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca, + 0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b, + 0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}}, + {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a, + 0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c, + 0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}}, // h2 + {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95, + 0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x07, 0x28, 0xe8, 0x96}}}, + {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a, + 0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c, + 0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}}, + {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72, + 0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2, + 0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}}, + {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88, + 0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25, + 0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}} // w +}; + +const PrivKey EpidMemberTest::kEps0MemberPrivateKey = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}, // group id + {{{{0xae, 0x5a, 0x18, 0x8d, 0xc8, 0xa9, 0xe2, 0x5c, 0xdf, 0xef, 0x62, + 0x6b, 0x34, 0xdf, 0x0d, 0xf2, 0xf6, 0xcf, 0x6a, 0x4d, 0x68, 0x88, + 0xc8, 0x12, 0x08, 0xae, 0xb6, 0x30, 0x54, 0xdf, 0xa7, 0xdc}}}, + {{{0xec, 0x39, 0x86, 0x7b, 0x5c, 0x5e, 0x28, 0x17, 0x5b, 0xfe, 0x93, + 0xa1, 0x31, 0x8a, 0x82, 0x99, 0xb0, 0x84, 0x8c, 0x90, 0xc5, 0x54, + 0x2c, 0x6d, 0xff, 0x75, 0xcf, 0x05, 0x6e, 0x2b, 0x6c, 0xf3}}}}, // A + {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf, + 0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd, + 0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}, // x + {0x7a, 0x57, 0x41, 0x5b, 0x85, 0x44, 0x0e, 0x2b, 0xb3, 0xcc, 0xa7, + 0x99, 0x6d, 0x19, 0x79, 0x45, 0x04, 0xb8, 0x94, 0x07, 0x47, 0x14, + 0xed, 0x8d, 0xf4, 0x1e, 0x7d, 0xa0, 0x17, 0xc5, 0xc4, 0x10} // f +}; diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.h b/external/epid-sdk/epid/member/unittests/member-testhelper.h similarity index 68% rename from external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.h rename to external/epid-sdk/epid/member/unittests/member-testhelper.h index 5d720d20..226fc07c 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/member-testhelper.h +++ b/external/epid-sdk/epid/member/unittests/member-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,43 +21,27 @@ #ifndef EPID_MEMBER_UNITTESTS_MEMBER_TESTHELPER_H_ #define EPID_MEMBER_UNITTESTS_MEMBER_TESTHELPER_H_ +#include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/common-testhelper/member_wrapper-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/member/api.h" } -/// C++ Wrapper to manage memory for MemberCtx via RAII -class MemberCtxObj { - public: - /// Create a MemberCtx - explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, - BitSupplier rnd_func, void* rnd_param); - /// Create a MemberCtx given precomputation blob - MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, - MemberPrecomp const& precomp, BitSupplier rnd_func, - void* rnd_param); +typedef struct G1ElemStr G1ElemStr; +/// compares G1ElemStr values +bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs); - // This class instances are not meant to be copied. - // Explicitly delete copy constructor and assignment operator. - MemberCtxObj(const MemberCtxObj&) = delete; - MemberCtxObj& operator=(const MemberCtxObj&) = delete; +/// compares MembershipCredential values +bool operator==(MembershipCredential const& lhs, + MembershipCredential const& rhs); - /// Destroy the MemberCtx - ~MemberCtxObj(); - /// get a pointer to the stored MemberCtx - MemberCtx* ctx() const; - /// cast operator to get the pointer to the stored MemberCtx - operator MemberCtx*() const; - /// const cast operator to get the pointer to the stored MemberCtx - operator const MemberCtx*() const; - - private: - /// The stored MemberCtx - MemberCtx* ctx_; -}; +/// compares GroupPubKey values +bool operator==(GroupPubKey const& lhs, GroupPubKey const& rhs); /// Test fixture class for EpidMember class EpidMemberTest : public ::testing::Test { @@ -73,8 +57,6 @@ class EpidMemberTest : public ::testing::Test { /// test data static const MemberPrecomp kMemberPrecomp; /// test data - static const PreComputedSignature kPrecomputedSignatures[2]; - /// test data static const std::vector kGrp01Member0SigTest1Sha256; /// test data static const std::vector kGrp01Member0SigTest1Sha384; @@ -94,9 +76,18 @@ class EpidMemberTest : public ::testing::Test { static const std::vector kBsn0; /// a basename static const std::vector kBsn1; - + /// a data with bytes [0,255] + static const std::vector kData_0_255; /// a group key in group X static const GroupPubKey kGrpXKey; + /// a member 0 private key in group X + static const PrivKey kGrpXMember0PrivKey; + /// a member private key in group X revoked in SigRl + static const PrivKey kGrpXSigrevokedMember0PrivKey; + /// a SigRl of group X + static const std::vector kGrpXSigRl; + /// a SigRl with single entry of group X + static const std::vector kGrpXSigRlSingleEntry; /// a compressed private key in group X static const CompressedPrivKey kGrpXMember9CompressedKey; /// a private key in group X @@ -107,6 +98,14 @@ class EpidMemberTest : public ::testing::Test { /// a compressed private key in group Y static const CompressedPrivKey kGrpYMember9CompressedKey; + /// value "1" represented as an octstr constant + static const OctStr32 kOctStr32_1; + + /// EPS specific group public key + static const GroupPubKey kEps0GroupPublicKey; + /// EPS specific member private key + static const PrivKey kEps0MemberPrivateKey; + /// setup called before each TEST_F starts virtual void SetUp() {} /// teardown called after each TEST_F finishes diff --git a/external/epid-sdk/epid/member/unittests/nr_prove-test.cc b/external/epid-sdk/epid/member/unittests/nr_prove-test.cc new file mode 100644 index 00000000..339b26b0 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/nr_prove-test.cc @@ -0,0 +1,413 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ +/// NrProve unit tests. +/*! \file */ + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/src/nrprove.h" +#include "epid/member/src/signbasic.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +namespace { + +TEST_F(EpidMemberTest, NrProveFailsGivenNullParameters) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature const* basic_sig = + &reinterpret_cast( + this->kGrp01Member0SigTest1Sha256.data()) + ->sigma0; + auto& msg = this->kTest1Msg; + auto& bsn = this->kBsn0; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(nullptr, msg.data(), msg.size(), bsn.data(), bsn.size(), + basic_sig, &sig_rl->bk[0], &proof)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, nullptr, msg.size(), bsn.data(), bsn.size(), + basic_sig, &sig_rl->bk[0], &proof)); + EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), nullptr, + 0, basic_sig, &sig_rl->bk[0], &proof)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), bsn.data(), 0, + basic_sig, &sig_rl->bk[0], &proof)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + nullptr, &sig_rl->bk[0], &proof)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + basic_sig, nullptr, &proof)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + basic_sig, &sig_rl->bk[0], nullptr)); +} + +TEST_F(EpidMemberTest, NrProveFailsGivenInvalidSigRlEntry) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + NrProof proof; + BigNumStr rnd_bsn = {0}; + + THROW_ON_EPIDERR(EpidSignBasic(member, msg.data(), msg.size(), nullptr, 0, + &basic_sig, &rnd_bsn)); + + SigRlEntry sig_rl_enty_invalid_k = sig_rl->bk[0]; + sig_rl_enty_invalid_k.k.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), + &rnd_bsn, sizeof(rnd_bsn), &basic_sig, + &sig_rl_enty_invalid_k, &proof)); + + SigRlEntry sig_rl_enty_invalid_b = sig_rl->bk[0]; + sig_rl_enty_invalid_b.b.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), + &rnd_bsn, sizeof(rnd_bsn), &basic_sig, + &sig_rl_enty_invalid_b, &proof)); +} + +TEST_F(EpidMemberTest, + PROTECTED_NrProveFailsWithInvalidSigRlEntryAndCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + NrProof proof; + BigNumStr rnd_bsn = {0}; + + THROW_ON_EPIDERR(EpidSignBasic(member, msg.data(), msg.size(), nullptr, 0, + &basic_sig, &rnd_bsn)); + + SigRlEntry sig_rl_enty_invalid_k = sig_rl->bk[0]; + sig_rl_enty_invalid_k.k.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), + &rnd_bsn, sizeof(rnd_bsn), &basic_sig, + &sig_rl_enty_invalid_k, &proof)); + + SigRlEntry sig_rl_enty_invalid_b = sig_rl->bk[0]; + sig_rl_enty_invalid_b.b.x.data.data[31]++; // make it not in EC group + EXPECT_EQ(kEpidBadArgErr, EpidNrProve(member, msg.data(), msg.size(), + &rnd_bsn, sizeof(rnd_bsn), &basic_sig, + &sig_rl_enty_invalid_b, &proof)); +} + +TEST_F(EpidMemberTest, NrProveFailsGivenInvalidBasicSig) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + NrProof proof; + BigNumStr rnd_bsn = {0}; + + THROW_ON_EPIDERR(EpidSignBasic(member, msg.data(), msg.size(), nullptr, 0, + &basic_sig, &rnd_bsn)); + + // invalid basic sig is only when K value is invalid!! + BasicSignature basic_sig_invalid_K = basic_sig; + basic_sig_invalid_K.K.x.data.data[31]++; // make it not in EC group + EXPECT_EQ( + kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, sizeof(rnd_bsn), + &basic_sig_invalid_K, &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, + PROTECTED_NrProveFailsGivenInvalidBasicSigAndCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + NrProof proof; + BigNumStr rnd_bsn = {0}; + + THROW_ON_EPIDERR(EpidSignBasic(member, msg.data(), msg.size(), nullptr, 0, + &basic_sig, &rnd_bsn)); + + // invalid basic sig is only when K value is invalid!! + BasicSignature basic_sig_invalid_K = basic_sig; + basic_sig_invalid_K.K.x.data.data[31]++; // make it not in EC group + EXPECT_EQ( + kEpidBadArgErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, sizeof(rnd_bsn), + &basic_sig_invalid_K, &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofForEmptyMessage) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, nullptr, 0, nullptr, 0, + &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, nullptr, 0, &rnd_bsn, sizeof(rnd_bsn), + &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidNoErr, + EpidNrVerify(ctx, &basic_sig, nullptr, 0, &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofForMsgContainingAllPossibleBytes) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kData_0_255; + auto& bsn = this->kBsn0; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + + NrProof proof; + + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + ASSERT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProof) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, PROTECTED_GeneratesNrProofWithCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingDefaultHashAlgUsingIKGFData) { + Prng my_prng; + GroupPubKey grp_public_key = *reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + PrivKey mbr_private_key = + *reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + const std::vector sigrl_bin = { +#include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc" + }; + + MemberCtxObj member(grp_public_key, mbr_private_key, &Prng::Generate, + &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(sigrl_bin.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(grp_public_key); + + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha256HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha384HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha384, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha512HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha512, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +TEST_F(EpidMemberTest, GeneratesNrProofUsingSha512256HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + kSha512_256, this->kMemberPrecomp, &Prng::Generate, + &my_prng); + + BasicSignature basic_sig; + auto msg = this->kTest1Msg; + SigRl const* sig_rl = reinterpret_cast(this->kSigRlData.data()); + BigNumStr rnd_bsn = {0}; + + NrProof proof; + + ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_EQ(kEpidNoErr, + EpidNrProve(member, msg.data(), msg.size(), &rnd_bsn, + sizeof(rnd_bsn), &basic_sig, &sig_rl->bk[0], &proof)); + + // Check proof by doing an NrVerify + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256)); + EXPECT_EQ(kEpidNoErr, EpidNrVerify(ctx, &basic_sig, msg.data(), msg.size(), + &sig_rl->bk[0], &proof)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/presig-test.cc b/external/epid-sdk/epid/member/unittests/presig-test.cc new file mode 100644 index 00000000..ca517621 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/presig-test.cc @@ -0,0 +1,116 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief ComputePreSig unit tests. + */ +#include +#include +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +namespace { + +/////////////////////////////////////////////////////////////////////// +// EpidAddPreSigs +TEST_F(EpidMemberTest, AddPreSigsFailsGivenNullPointer) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + EXPECT_EQ(kEpidBadArgErr, EpidAddPreSigs(nullptr, 1)); +} + +TEST_F(EpidMemberTest, AddPreSigsFailsGivenHugeNumberOfPreSigs) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + // number_presigs = 0x80..01 of size equal to sizeof(size_t) + EXPECT_NE(kEpidNoErr, EpidAddPreSigs(member, (SIZE_MAX >> 1) + 2)); +} + +TEST_F(EpidMemberTest, + AddPreSigsComputesSpecifiedNumberOfPresigsIfInputPresigsNull) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 2)); + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 1)); + // request to generate 0 pre-computed signatures do nothing + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0)); + EXPECT_EQ((size_t)3, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, AddPreSigsAddsCorrectNumberOfPresigsGivenValidInput) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + const size_t presigs1_added = 2; + const size_t presigs2_added = 3; + + // add + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs1_added)); + // extend + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs2_added)); + // add empty pre-computed signatures array does not affect internal pool + ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0)); + EXPECT_EQ(presigs1_added + presigs2_added, EpidGetNumPreSigs(member)); +} + +/////////////////////////////////////////////////////////////////////// +// EpidGetNumPreSigs +TEST_F(EpidMemberTest, GetNumPreSigsReturnsZeroGivenNullptr) { + EXPECT_EQ((size_t)0, EpidGetNumPreSigs(nullptr)); +} + +TEST_F(EpidMemberTest, NumPreSigsForNewleyCreatedContextIsZero) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + EXPECT_EQ((size_t)0, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, GetNumPreSigsReturnsNumberOfAddedPresigs) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + + const size_t presigs_added = 5; + + THROW_ON_EPIDERR(EpidAddPreSigs(member, presigs_added)); + EXPECT_EQ(presigs_added, EpidGetNumPreSigs(member)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/privateexp-test.cc b/external/epid-sdk/epid/member/unittests/privateexp-test.cc new file mode 100644 index 00000000..5f413cb4 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/privateexp-test.cc @@ -0,0 +1,155 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// EpidPrivateExp unit tests. +/*! \file */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/src/privateexp.h" +} + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/epid_params-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +namespace { + +//////////////////////////////////////////////// +// EpidPrivateExp +TEST_F(EpidMemberTest, EpidPrivateExpFailsGivenNullPointer) { + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + THROW_ON_EPIDERR(EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, + &this->kMemberPrecomp)); + THROW_ON_EPIDERR(EpidMemberStartup(member)); + + Epid20Params params; + EcPointObj a(¶ms.G1, this->kGroupPublicKey.h1), r(¶ms.G1); + + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(nullptr, a, r)); + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(member, nullptr, r)); + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(member, a, nullptr)); +} + +TEST_F(EpidMemberTest, EpidPrivateExpFailsArgumentsMismatch) { + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + THROW_ON_EPIDERR(EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, + &this->kMemberPrecomp)); + THROW_ON_EPIDERR(EpidMemberStartup(member)); + + Epid20Params params; + EcPointObj a(¶ms.G1, this->kGroupPublicKey.h1), r(¶ms.G1); + EcPointObj g2(¶ms.G2, this->kGroupPublicKey.w); + + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(member, g2, r)); + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(member, a, g2)); + EXPECT_EQ(kEpidBadArgErr, EpidPrivateExp(member, g2, g2)); +} + +TEST_F(EpidMemberTest, EpidPrivateExpSucceedsGivenValidParametersForSha256) { + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + THROW_ON_EPIDERR(EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, + &this->kMemberPrecomp)); + THROW_ON_EPIDERR(EpidMemberStartup(member)); + + Epid20Params params; + EcPointObj a(¶ms.G1, this->kGroupPublicKey.h1), r(¶ms.G1), + r_expected(¶ms.G1); + + G1ElemStr r_str, r_expected_str; + + EXPECT_EQ(kEpidNoErr, EpidPrivateExp(member, a, r)); + + THROW_ON_EPIDERR(EcExp( + params.G1, a, (BigNumStr const*)&this->kMemberPrivateKey.f, r_expected)); + + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r_expected, &r_expected_str, + sizeof(r_expected_str))); + EXPECT_EQ(r_expected_str, r_str); +} + +#ifndef TPM_TSS +TEST_F(EpidMemberTest, EpidPrivateExpSucceedsGivenValidParametersForSha384) { + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha384)); + THROW_ON_EPIDERR(EpidProvisionKey(member, &this->kGroupPublicKey, + &this->kMemberPrivateKey, + &this->kMemberPrecomp)); + THROW_ON_EPIDERR(EpidMemberStartup(member)); + + Epid20Params params; + EcPointObj a(¶ms.G1, this->kGroupPublicKey.h1), r(¶ms.G1), + r_expected(¶ms.G1); + + G1ElemStr r_str, r_expected_str; + + EXPECT_EQ(kEpidNoErr, EpidPrivateExp(member, a, r)); + + THROW_ON_EPIDERR(EcExp( + params.G1, a, (BigNumStr const*)&this->kMemberPrivateKey.f, r_expected)); + + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r_expected, &r_expected_str, + sizeof(r_expected_str))); + EXPECT_EQ(r_expected_str, r_str); +} +#endif + +TEST_F(EpidMemberTest, + PROTECTED_EpidPrivateExpSucceedsByCredentialForSha256_EPS0) { + Prng my_prng; + Epid2ParamsObj epid2params; + MemberCtxObj member(&Prng::Generate, &my_prng); + BigNumStr const f_str = {0x7a, 0x57, 0x41, 0x5b, 0x85, 0x44, 0x0e, 0x2b, + 0xb3, 0xcc, 0xa7, 0x99, 0x6d, 0x19, 0x79, 0x45, + 0x04, 0xb8, 0x94, 0x07, 0x47, 0x14, 0xed, 0x8d, + 0xf4, 0x1e, 0x7d, 0xa0, 0x17, 0xc5, 0xc4, 0x10}; + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); + + Epid20Params params; + EcPointObj a(¶ms.G1, this->kGroupPublicKey.h1), r(¶ms.G1), + r_expected(¶ms.G1); + + G1ElemStr r_str, r_expected_str; + + EXPECT_EQ(kEpidNoErr, EpidPrivateExp(member, a, r)); + + THROW_ON_EPIDERR(EcExp(params.G1, a, (BigNumStr const*)&f_str, r_expected)); + + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r, &r_str, sizeof(r_str))); + THROW_ON_EPIDERR(WriteEcPoint(params.G1, r_expected, &r_expected_str, + sizeof(r_expected_str))); + EXPECT_EQ(r_expected_str, r_str); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/provision_compressed-test.cc b/external/epid-sdk/epid/member/unittests/provision_compressed-test.cc new file mode 100644 index 00000000..001129ea --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/provision_compressed-test.cc @@ -0,0 +1,178 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Provision compressed unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +#include "epid/member/src/context.h" +} + +namespace { + +EpidStatus ProvisionCompressedAndStart( + MemberCtx* ctx, GroupPubKey const* pub_key, + CompressedPrivKey const* compressed_privkey, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionCompressed(ctx, pub_key, compressed_privkey, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, ProvisionCompressedFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(nullptr, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, nullptr, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(nullptr, &pub_key, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, nullptr, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCompressed(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCompressedSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + EXPECT_EQ(kEpidNoErr, + EpidProvisionCompressed(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, + EpidProvisionCompressed(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidGroupPubKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGrpXKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGrpXKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidPrivateKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kGrpXMember9CompressedKey; + priv_key.ax.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); + + priv_key = this->kGrpXMember9CompressedKey; + priv_key.seed.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr)); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/provision_credential-test.cc b/external/epid-sdk/epid/member/unittests/provision_credential-test.cc new file mode 100644 index 00000000..c8ec7ad1 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/provision_credential-test.cc @@ -0,0 +1,318 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief Provision credential unit tests. + */ +#include +#include + +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +#include "epid/member/src/context.h" +#include "epid/member/src/storage.h" +} + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +namespace { + +EpidStatus ProvisionCredentialAndStart(MemberCtx* ctx, + GroupPubKey const* pub_key, + MembershipCredential const* credential, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionCredential(ctx, pub_key, credential, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, ProvisionCredentialFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(nullptr, &pub_key, &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, nullptr, &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(nullptr, &pub_key, &credential, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, nullptr, &credential, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionCredential(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidCredential) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + MembershipCredential base_credential; + base_credential.A = this->kGrpXMember9PrivKey.A; + base_credential.gid = this->kGrpXMember9PrivKey.gid; + base_credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + credential = base_credential; + credential.A.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + credential = base_credential; + credential.A.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + credential = base_credential; + credential.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsInvalidGroupKey) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGroupPublicKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionCredentialRejectsCredentialNotInGroup) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + MembershipCredential base_credential; + base_credential.A = this->kGrpXMember9PrivKey.A; + base_credential.gid = this->kGrpXMember9PrivKey.gid; + base_credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + + credential = base_credential; + credential.gid.data[0] = ~credential.gid.data[0]; + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); + EXPECT_EQ(kEpidBadArgErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialPrecomp) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, &precomp)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingMembershipCredentialNoPrecomp) { + Prng prng; + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + MembershipCredential credential; + credential.A = this->kGrpXMember9PrivKey.A; + credential.gid = this->kGrpXMember9PrivKey.gid; + credential.x = this->kGrpXMember9PrivKey.x; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &credential, nullptr)); +} + +// test that create succeeds with valid IKGF given parameters +TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialPrecomp) { + Prng prng; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + const PrivKey* priv_key = + reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + FpElemStr f = priv_key->f; + MembershipCredential credential; + credential.A = priv_key->A; + credential.gid = priv_key->gid; + credential.x = priv_key->x; + // Note: this MemberPrecomp is for the wrong group, however it should not + // be checked in Provision because doing so would negate the performance + // boost of using the precomp. + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, pub_key, + &credential, &precomp)); +} + +TEST_F(EpidMemberTest, CanProvisionUsingIKGFMembershipCredentialNoPrecomp) { + Prng prng; + const GroupPubKey* pub_key = reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + const PrivKey* priv_key = + reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + FpElemStr f = priv_key->f; + MembershipCredential credential; + credential.A = priv_key->A; + credential.gid = priv_key->gid; + credential.x = priv_key->x; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + ProvisionCredentialAndStart(member, pub_key, &credential, nullptr)); +} + +TEST_F(EpidMemberTest, + ProvisionCredentialCanStoreMembershipCredentialNoPrecomp) { + Prng prng; + uint32_t nv_index = 0x01c10100; + + MembershipCredential const orig_credential = + *(MembershipCredential*)&this->kGrpXMember9PrivKey; + MembershipCredential credential; + + GroupPubKey pub_key = this->kGrpXKey; + FpElemStr f = this->kGrpXMember9PrivKey.f; + + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, ProvisionCredentialAndStart(member, &pub_key, + &orig_credential, nullptr)); + + EXPECT_EQ(kEpidNoErr, + EpidNvReadMembershipCredential(((MemberCtx*)member)->tpm2_ctx, + nv_index, &pub_key, &credential)); + EXPECT_EQ(orig_credential, credential); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/provision_key-test.cc b/external/epid-sdk/epid/member/unittests/provision_key-test.cc new file mode 100644 index 00000000..113de5fe --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/provision_key-test.cc @@ -0,0 +1,244 @@ +/*############################################################################ + # Copyright 2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Provision key unit tests. + */ +#include +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/mem_params-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/api.h" +#include "epid/member/src/context.h" +#include "epid/member/src/storage.h" +} + +namespace { + +EpidStatus ProvisionBulkAndStart(MemberCtx* ctx, GroupPubKey const* pub_key, + PrivKey const* priv_key, + MemberPrecomp const* precomp_str) { + EpidStatus sts; + sts = EpidProvisionKey(ctx, pub_key, priv_key, precomp_str); + if (sts != kEpidNoErr) { + return sts; + } + sts = EpidMemberStartup(ctx); + return sts; +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsGivenNullParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(nullptr, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, nullptr, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, &pub_key, nullptr, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(nullptr, &pub_key, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, nullptr, &priv_key, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidProvisionKey(member, &pub_key, nullptr, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkSucceedsGivenValidParameters) { + Prng prng; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); +} + +// test that create succeeds with valid IKGF given parameters +TEST_F(EpidMemberTest, ProvisionBulkSucceedsGivenValidParametersUsingIKGFData) { + Prng prng; + const GroupPubKey pub_key = { +#include "epid/common-testhelper/testdata/ikgf/groupa/pubkey.inc" + }; + const PrivKey priv_key = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprivkey.inc" + }; + + const MemberPrecomp precomp = { +#include "epid/common-testhelper/testdata/ikgf/groupa/member0/mprecomp.inc" + }; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + EpidProvisionKey(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidNoErr, EpidProvisionKey(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidGroupPubKey) { + Prng prng; + + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + pub_key = this->kGroupPublicKey; + pub_key.h1.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h1.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.h2.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.x[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[0].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + pub_key = this->kGroupPublicKey; + pub_key.w.y[1].data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidF) { + Prng prng; + FpElemStr f = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + }; + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kMemberPrivateKey; + priv_key.f = f; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkFailsForInvalidPrivateKey) { + Prng prng; + + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MemberPrecomp precomp = this->kMemberPrecomp; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms); + MemberCtxObj member(¶ms); + + priv_key = this->kMemberPrivateKey; + priv_key.A.x.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + priv_key = this->kMemberPrivateKey; + priv_key.A.y.data.data[0]++; + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, &precomp)); + EXPECT_EQ(kEpidBadArgErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); +} + +TEST_F(EpidMemberTest, ProvisionBulkCanStoreMembershipCredential) { + Prng prng; + uint32_t nv_index = 0x01c10100; + + GroupPubKey pub_key = this->kGroupPublicKey; + PrivKey priv_key = this->kMemberPrivateKey; + MembershipCredential const orig_credential{priv_key.gid, priv_key.A, + priv_key.x}; + MembershipCredential credential; + MemberParams params = {0}; + SetMemberParams(&Prng::Generate, &prng, &priv_key.f, ¶ms); + MemberCtxObj member(¶ms); + EXPECT_EQ(kEpidNoErr, + ProvisionBulkAndStart(member, &pub_key, &priv_key, nullptr)); + + EXPECT_EQ(kEpidNoErr, + EpidNvReadMembershipCredential(((MemberCtx*)member)->tpm2_ctx, + nv_index, &pub_key, &credential)); + EXPECT_EQ(orig_credential, credential); +} + +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/resize-test.cc b/external/epid-sdk/epid/member/unittests/resize-test.cc new file mode 100644 index 00000000..f674aab4 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/resize-test.cc @@ -0,0 +1,63 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ +/// ResizeOctStr unit tests. +/*! \file */ +#include + +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/src/resize.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +namespace { +TEST(ResizeOctStr, FailsGivenNullPointer) { + uint8_t a[3] = {0, 1, 2}; + uint8_t r[3] = {0}; + EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(nullptr, sizeof(a), r, sizeof(r))); + EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), nullptr, sizeof(r))); +} + +TEST(ResizeOctStr, FailsGivenInvalidSize) { + uint8_t a[3] = {0, 1, 2}; + uint8_t r[3] = {0}; + EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, 0, r, sizeof(r))); + EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), r, 0)); +} + +TEST(ResizeOctStr, FailsGivenResultIsTooSmall) { + uint8_t a[3] = {0, 1, 2}; + uint8_t r[1] = {0}; + EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), r, sizeof(r))); +} + +TEST(ResizeOctStr, CanShrink) { + uint8_t a[3] = {0, 1, 2}; + std::vector r(2); + std::vector r_expected = {1, 2}; + EXPECT_EQ(kEpidNoErr, ResizeOctStr(a, sizeof(a), r.data(), r.size())); + EXPECT_EQ(r_expected, r); +} + +TEST(ResizeOctStr, CanExtend) { + uint8_t a[3] = {0, 1, 2}; + std::vector r(5); + std::vector r_expected = {0, 0, 0, 1, 2}; + EXPECT_EQ(kEpidNoErr, ResizeOctStr(a, sizeof(a), r.data(), r.size())); + EXPECT_EQ(r_expected, r); +} +} // namespace diff --git a/external/epid-sdk/epid/member/unittests/sign-test.cc b/external/epid-sdk/epid/member/unittests/sign-test.cc new file mode 100644 index 00000000..54f2fafb --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/sign-test.cc @@ -0,0 +1,1160 @@ +/*############################################################################ + # Copyright 2016-2017 Intel Corporation + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ############################################################################*/ + +/*! + * \file + * \brief Sign unit tests. + */ +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +extern "C" { +#include "epid/member/api.h" +#include "epid/member/src/context.h" +#include "epid/verifier/api.h" +} + +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" +namespace { + +/// Count of elements in array +#define COUNT_OF(A) (sizeof(A) / sizeof((A)[0])) + +///////////////////////////////////////////////////////////////////////// +// Simple error cases + +TEST_F(EpidMemberTest, SignFailsGivenNullParameters) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + std::vector sig(EpidGetSigSize(&srl)); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(nullptr, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig.data(), sig.size())); + EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), nullptr, sig.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig.data(), sig.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(), + (EpidSignature*)sig.data(), sig.size())); +} + +TEST_F(EpidMemberTest, SignFailsGivenWrongSigLen) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + + // signature buffer one byte less than needed + std::vector sig_small(EpidGetSigSize(&srl) - 1); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig_small.data(), sig_small.size())); + + // signature buffer is one byte - a less than allowed for EpidSignature + std::vector sig_one(1); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig_one.data(), sig_one.size())); +} + +TEST_F(EpidMemberTest, SignFailsGivenUnregisteredBasename) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + auto& bsn1 = this->kBsn1; + SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}}; + srl.gid = this->kGroupPublicKey.gid; + std::vector sig(EpidGetSigSize(&srl)); + THROW_ON_EPIDERR( + EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk))); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidSign(member, msg.data(), msg.size(), bsn1.data(), bsn1.size(), + (EpidSignature*)sig.data(), sig.size())); +} +TEST_F(EpidMemberTest, SignsFailsIfNotProvisioned) { + Prng my_prng; + MemberCtxObj member(&Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidOutOfSequenceError, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); +} + +///////////////////////////////////////////////////////////////////////// +// Anonymity + +TEST_F(EpidMemberTest, SignaturesOfSameMessageAreDifferent) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig1(EpidGetSigSize(nullptr)); + std::vector sig2(EpidGetSigSize(nullptr)); + // without signature based revocation list + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig1.data(), sig1.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig2.data(), sig2.size())); + EXPECT_TRUE(sig1.size() == sig2.size() && + 0 != memcmp(sig1.data(), sig2.data(), sig1.size())); + // with signature based revocation list + uint8_t sig_rl_data_n2_one[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x01, + // one bk + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, + 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, + 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, + 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, + 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, + 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, + 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, + 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, + 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, + 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, + 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b}; + SigRl* srl1 = reinterpret_cast(sig_rl_data_n2_one); + size_t srl1_size = sizeof(sig_rl_data_n2_one); + std::vector sig3(EpidGetSigSize(srl1)); + std::vector sig4(EpidGetSigSize(srl1)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig3.data(), sig3.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0, + (EpidSignature*)sig4.data(), sig4.size())); + EXPECT_TRUE(sig3.size() == sig4.size() && + 0 != memcmp(sig3.data(), sig4.data(), sig3.size())); +} +TEST_F(EpidMemberTest, SignaturesOfSameMessageWithSameBasenameAreDifferent) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + std::vector sig1(EpidGetSigSize(nullptr)); + std::vector sig2(EpidGetSigSize(nullptr)); + // without signature based revocation list + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig1.data(), sig1.size())); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig2.data(), sig2.size())); + EXPECT_TRUE(sig1.size() == sig2.size() && + 0 != memcmp(sig1.data(), sig2.data(), sig1.size())); + + // with signature based revocation list + uint8_t sig_rl_data_n2_one[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x01, + // one bk + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, + 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, + 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, + 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, + 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, + 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, + 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, + 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, + 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, + 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, + 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b}; + SigRl* srl1 = reinterpret_cast(sig_rl_data_n2_one); + size_t srl1_size = sizeof(sig_rl_data_n2_one); + std::vector sig3(EpidGetSigSize(srl1)); + std::vector sig4(EpidGetSigSize(srl1)); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig3.data(), sig3.size())); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(), + (EpidSignature*)sig4.data(), sig4.size())); + EXPECT_TRUE(sig3.size() == sig4.size() && + 0 != memcmp(sig3.data(), sig4.data(), sig3.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Variable basename + +TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageUsingBasenameNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageUsingBasenameWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsUsingRandomBaseWithoutRegisteredBasenamesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, + SignsUsingRandomBaseWithoutRegisteredBasenamesWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +#ifndef TPM_TSS +TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector bsn(1024 * 1024); // exactly 1 MB + uint8_t c = 0; + for (size_t i = 0; i < bsn.size(); ++i) { + bsn[i] = c++; + } + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGrpXKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector bsn(1024 * 1024); // exactly 1 MB + uint8_t c = 0; + for (size_t i = 0; i < bsn.size(); ++i) { + bsn[i] = c++; + } + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + SigRl const* srl = reinterpret_cast(this->kGrpXSigRl.data()); + size_t srl_size = this->kGrpXSigRl.size() * sizeof(this->kGrpXSigRl[0]); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + VerifierCtxObj ctx(this->kGrpXKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); +} + +TEST_F(EpidMemberTest, SignsMsgUsingBsnContainingAllPossibleBytesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kData_0_255; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +#endif + +///////////////////////////////////////////////////////////////////////// +// Variable sigRL + +TEST_F(EpidMemberTest, SignsMessageGivenNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + + size_t sig_len = EpidGetSigSize(nullptr); + std::vector newsig(sig_len); + EpidSignature* sig = (EpidSignature*)newsig.data(); + + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, SignsMessageGivenNoSigRlUsingIKGFData) { + GroupPubKey grp_public_key = *reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + PrivKey mbr_private_key = + *reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + Prng my_prng; + auto& msg = this->kMsg0; + + size_t sig_len = EpidGetSigSize(nullptr); + std::vector newsig(sig_len); + // using ikgf keys + MemberCtxObj member(grp_public_key, mbr_private_key, &Prng::Generate, + &my_prng); + EpidSignature* sig = (EpidSignature*)newsig.data(); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(grp_public_key); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntries) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + + uint8_t sig_rl_data_n2_zero[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x00, + // not bk's + }; + SigRl const* srl = reinterpret_cast(sig_rl_data_n2_zero); + size_t srl_size = sizeof(sig_rl_data_n2_zero); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntriesUsingIkgfData) { + GroupPubKey grp_public_key = *reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + PrivKey mbr_private_key = + *reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + Prng my_prng; + auto& msg = this->kMsg0; + // using ikgf keys + MemberCtxObj member_ikgf(grp_public_key, mbr_private_key, &Prng::Generate, + &my_prng); + uint8_t sig_rl_data_n2_one_gid0[] = { +#include "epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc" + }; + SigRl* srl_ikgf = reinterpret_cast(sig_rl_data_n2_one_gid0); + size_t srl_size = sizeof(sig_rl_data_n2_one_gid0); + std::vector sig_data_ikgf(EpidGetSigSize(srl_ikgf)); + EpidSignature* sig_ikgf = + reinterpret_cast(sig_data_ikgf.data()); + size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr, + 0, sig_ikgf, sig_len)); + VerifierCtxObj ctx_ikgf(grp_public_key); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx_ikgf, sig_ikgf, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntries) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + uint8_t sig_rl_data_n2_one[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x02, + // one bk + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, + 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, + 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, + 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, + 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, + 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, + 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, + 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, + 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, + 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, + 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b, + + 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10, + 0xfe, 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60, + 0x3e, 0xc0, 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82, + 0xc4, 0x49, 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5, + 0x77, 0x16, 0x4, 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8, + 0x40, 0xbd, 0x69, 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9, + 0xdd, 0x97, 0x6c, 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2, + 0xca, 0x5, 0x44, 0x9b, 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa, + 0xcf, 0xa4, 0x4, 0xe9, 0xf3, 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3, + 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60, + 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, 0x11}; + SigRl* srl = reinterpret_cast(sig_rl_data_n2_one); + size_t srl_size = sizeof(sig_rl_data_n2_one); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntriesUsingIKGFData) { + GroupPubKey grp_public_key = *reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + PrivKey mbr_private_key = + *reinterpret_cast(this->kMemberPrivateKeyDataIkgf.data()); + Prng my_prng; + auto& msg = this->kMsg0; + // using ikgf keys + MemberCtxObj member_ikgf(grp_public_key, mbr_private_key, &Prng::Generate, + &my_prng); + uint8_t sig_rl_data_n2_one_gid0[] = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x0, 0x00, 0x00, 0x02, + // one bk + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, + 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, + 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, + 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, + 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, + 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, + 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, + 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, + 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, + 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, + 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b, + + 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10, + 0xfe, 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60, + 0x3e, 0xc0, 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82, + 0xc4, 0x49, 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5, + 0x77, 0x16, 0x4, 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8, + 0x40, 0xbd, 0x69, 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9, + 0xdd, 0x97, 0x6c, 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2, + 0xca, 0x5, 0x44, 0x9b, 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa, + 0xcf, 0xa4, 0x4, 0xe9, 0xf3, 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3, + 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60, + 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, 0x11}; + SigRl* srl_ikgf = reinterpret_cast(sig_rl_data_n2_one_gid0); + size_t srl_size = sizeof(sig_rl_data_n2_one_gid0); + std::vector sig_data_ikgf(EpidGetSigSize(srl_ikgf)); + EpidSignature* sig_ikgf = + reinterpret_cast(sig_data_ikgf.data()); + size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size)); + EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr, + 0, sig_ikgf, sig_len)); + VerifierCtxObj ctx_ikgf(grp_public_key); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx_ikgf, sig_ikgf, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevoked) { + // note: a complete sig + nr proof should still be returned!! + auto& pub_key = this->kGrpXKey; + auto& priv_key = this->kGrpXMember0PrivKey; + auto& msg = this->kMsg0; + Prng my_prng; + MemberCtxObj member(pub_key, priv_key, &Prng::Generate, &my_prng); + const std::vector kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry = { +#include "epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc" + }; + auto srl = reinterpret_cast( + kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.data()); + size_t srl_size = kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.size(); + + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + + VerifierCtxObj ctx(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevokedUsingIKGFData) { + // note: a complete sig + nr proof should still be returned!! + GroupPubKey grp_public_key = *reinterpret_cast( + this->kGroupPublicKeyDataIkgf.data()); + const PrivKey member_private_key_revoked_by_sig = { +#include "epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc" + }; + Prng my_prng; + MemberCtxObj member(grp_public_key, member_private_key_revoked_by_sig, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + const std::vector sig_Rl = { +#include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc" + }; + auto srl = reinterpret_cast(sig_Rl.data()); + size_t srl_size = sig_Rl.size(); + + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + + VerifierCtxObj ctx(grp_public_key); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Revoked member by sigRL for TPM case + +TEST_F(EpidMemberTest, + PROTECTED_SignMessageByCedentialReportsIfMemberRevoked_EPS0) { + // note: a complete sig + nr proof should still be returned!! + auto& pub_key = this->kEps0GroupPublicKey; + auto credential = *(MembershipCredential const*)&this->kEps0MemberPrivateKey; + const std::vector msg = {'t', 'e', 's', 't', '2'}; + Prng my_prng; + MemberCtxObj member(pub_key, credential, &Prng::Generate, &my_prng); + const std::vector kEps0SigRlMember0Sha256Rndbase0Msg0FirstEntry = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x39, 0x97, 0x09, 0x11, 0x30, 0xb0, 0x2a, 0x29, 0xa7, 0x9b, 0xf1, 0xef, + 0xe9, 0xe5, 0xc7, 0x03, 0x17, 0xe6, 0x4f, 0x6f, 0x49, 0x4d, 0xeb, 0x0f, + 0xfd, 0x1c, 0x3f, 0xce, 0xcc, 0xc8, 0x40, 0x6b, 0x23, 0xd3, 0xec, 0x78, + 0x78, 0x15, 0x4a, 0x34, 0x0f, 0xd1, 0xd3, 0xfa, 0xd2, 0xb2, 0x5a, 0xc9, + 0xec, 0xa2, 0x41, 0xe1, 0x46, 0x6d, 0xed, 0xb3, 0x4a, 0xa6, 0xdf, 0xb6, + 0xc2, 0x11, 0x49, 0x0d, 0x8b, 0xc4, 0xdc, 0xe0, 0x3f, 0x86, 0x59, 0xb6, + 0x47, 0x0e, 0x72, 0xd9, 0x04, 0x91, 0x06, 0x8d, 0xe7, 0xb0, 0x4e, 0x40, + 0x4a, 0x72, 0xe2, 0x99, 0xcc, 0xf2, 0x93, 0x1f, 0xcb, 0x32, 0x2e, 0xa3, + 0x62, 0xf5, 0x35, 0x51, 0x8b, 0x8e, 0xc8, 0xf4, 0x1e, 0xbe, 0xc9, 0xf4, + 0xa9, 0xc4, 0x63, 0xd3, 0x86, 0x5d, 0xf6, 0x44, 0x36, 0x5c, 0x44, 0x11, + 0xb4, 0xa3, 0x85, 0xd5, 0x9e, 0xaf, 0x56, 0x83}; + auto srl = reinterpret_cast( + kEps0SigRlMember0Sha256Rndbase0Msg0FirstEntry.data()); + size_t srl_size = kEps0SigRlMember0Sha256Rndbase0Msg0FirstEntry.size(); + + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + + VerifierCtxObj ctx(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + + EXPECT_EQ(kEpidSigRevokedInSigRl, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Variable hash alg + +TEST_F(EpidMemberTest, SignsMessageUsingSha256HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageUsingSha384HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha384, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageUsingSha512HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha512, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageUsingSha512256HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + kSha512_256, this->kMemberPrecomp, &Prng::Generate, + &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Variable hash alg for TPM data + +TEST_F(EpidMemberTest, + PROTECTED_SignsMessageByCredentialUsingSha256HashAlg_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, + DISABLED_PROTECTED_SignsMessageByCredentialUsingSha384HashAlg_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha384)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, + DISABLED_PROTECTED_SignsMessageByCredentialUsingSha512HashAlg_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Variable precomputed signatures + +TEST_F(EpidMemberTest, SignConsumesPrecomputedSignaturesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 3)); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, SignConsumesPrecomputedSignaturesWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 3)); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member)); +} + +TEST_F(EpidMemberTest, SignsMessageWithPrecomputedSignaturesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageWithPrecomputedSignaturesWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + // test sign without precomputed signatures + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + // test sign without precomputed signatures + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +///////////////////////////////////////////////////////////////////////// +// Variable messages + +TEST_F(EpidMemberTest, SignsEmptyMessageNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), 0, bsn.data(), bsn.size(), + sig, sig_len)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), 0)); +} + +TEST_F(EpidMemberTest, SignsEmptyMessageWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), 0, nullptr, 0, sig, sig_len)); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), 0)); +} + +TEST_F(EpidMemberTest, SignsShortMessageNoSigRl) { + // check: 1, 13, 128, 256, 512, 1021, 1024 bytes + // 13 and 1021 are primes + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + VerifierCtxObj ctx(this->kGroupPublicKey); + size_t lengths[] = {1, 13, 128, 256, + 512, 1021, 1024}; // have desired lengths to loop over + std::vector msg( + lengths[COUNT_OF(lengths) - 1]); // allocate message for max size + for (size_t n = 0; n < msg.size(); n++) { + msg[n] = (uint8_t)n; + } + for (auto length : lengths) { + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len)) + << "EpidSign for message_len: " << length << " failed"; + EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length)) + << "EpidVerify for message_len: " << length << " failed"; + } +} + +TEST_F(EpidMemberTest, SignsShortMessageWithSigRl) { + // check: 1, 13, 128, 256, 512, 1021, 1024 bytes + // 13 and 1021 are primes + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + size_t message_len = 0; + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + size_t lengths[] = {1, 13, 128, 256, + 512, 1021, 1024}; // have desired lengths to loop over + std::vector msg( + lengths[COUNT_OF(lengths) - 1]); // allocate message for max size + for (size_t n = 0; n < msg.size(); n++) { + msg.at(n) = (uint8_t)n; + } + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + for (auto length : lengths) { + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len)) + << "EpidSign for message_len: " << message_len << " failed"; + EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length)) + << "EpidVerify for message_len: " << message_len << " failed"; + } +} + +TEST_F(EpidMemberTest, SignsLongMessageNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + VerifierCtxObj ctx(this->kGroupPublicKey); + std::vector msg(1000000); // allocate message for max size + for (size_t n = 0; n < msg.size(); n++) { + msg.at(n) = (uint8_t)n; + } + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)) + << "EpidSign for message_len: " << 1000000 << " failed"; + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())) + << "EpidVerify for message_len: " << 1000000 << " failed"; +} + +TEST_F(EpidMemberTest, SignsLongMessageWithSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + SigRl const* srl = + reinterpret_cast(this->kSigRl5EntryData.data()); + size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t); + std::vector sig_data(EpidGetSigSize(srl)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size)); + std::vector msg(1000000); // allocate message for max size + for (size_t n = 0; n < msg.size(); n++) { + msg.at(n) = (uint8_t)n; + } + THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size)); + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)) + << "EpidSign for message_len: " << 1000000 << " failed"; + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())) + << "EpidVerify for message_len: " << 1000000 << " failed"; +} + +TEST_F(EpidMemberTest, SignsMsgContainingAllPossibleBytesNoSigRl) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + std::vector sig_data(EpidGetSigSize(nullptr)); + EpidSignature* sig = reinterpret_cast(sig_data.data()); + size_t sig_len = sig_data.size() * sizeof(uint8_t); + VerifierCtxObj ctx(this->kGroupPublicKey); + std::vector msg = this->kData_0_255; + EXPECT_EQ(kEpidNoErr, + EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len)); + EXPECT_EQ(kEpidSigValid, + EpidVerify(ctx, sig, sig_len, msg.data(), msg.size())); +} + +} // namespace diff --git a/external/epid-sdk-3.0.0/epid/member/unittests/signbasic-test.cc b/external/epid-sdk/epid/member/unittests/signbasic-test.cc similarity index 50% rename from external/epid-sdk-3.0.0/epid/member/unittests/signbasic-test.cc rename to external/epid-sdk/epid/member/unittests/signbasic-test.cc index d5f75c81..1f515089 100644 --- a/external/epid-sdk-3.0.0/epid/member/unittests/signbasic-test.cc +++ b/external/epid-sdk/epid/member/unittests/signbasic-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,24 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################*/ +/// SignBasic unit tests. +/*! \file */ -/*! - * \file - * \brief SignBasic unit tests. - */ - +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/member/api.h" +#include "epid/member/src/signbasic.h" #include "epid/verifier/api.h" } #include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/prng-testhelper.h" -#include "epid/member/unittests/member-testhelper.h" #include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" +bool operator==(BigNumStr const& lhs, BigNumStr const& rhs) { + return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); +} namespace { /// Count of elements in array @@ -45,14 +48,47 @@ TEST_F(EpidMemberTest, SignBasicFailsGivenNullParameters) { auto& msg = this->kMsg0; auto& bsn = this->kBsn0; BasicSignature basic_sig; - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(nullptr, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidBadArgErr, + EpidSignBasic(nullptr, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), nullptr, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidSignBasic(member, nullptr, msg.size(), bsn.data(), bsn.size(), + &basic_sig, nullptr)); + EXPECT_EQ(kEpidBadArgErr, + EpidSignBasic(member, msg.data(), msg.size(), nullptr, bsn.size(), + &basic_sig, nullptr)); +} +TEST_F(EpidMemberTest, SignBasicFailsGivenNullBasenameAndNullRandomBasename) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + BasicSignature basic_sig; EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), nullptr)); - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, nullptr, msg.size(), - bsn.data(), bsn.size(), &basic_sig)); - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), - nullptr, bsn.size(), &basic_sig)); + nullptr, 0, &basic_sig, nullptr)); +} +TEST_F(EpidMemberTest, SignBasicDoesNotComputeRandomBasenameGivenBasename) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + BigNumStr rnd_bsn = {0}; + BigNumStr zero = {0}; + BasicSignature basic_sig; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, &rnd_bsn)); + EXPECT_EQ(zero, rnd_bsn); + // verify basic signature + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } TEST_F(EpidMemberTest, SignBasicFailsForBasenameWithoutRegisteredBasenames) { Prng my_prng; @@ -61,21 +97,22 @@ TEST_F(EpidMemberTest, SignBasicFailsForBasenameWithoutRegisteredBasenames) { auto& msg = this->kMsg0; auto& bsn = this->kBsn0; BasicSignature basic_sig; - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidBadArgErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); } -TEST_F(EpidMemberTest, SignBasicFailsIfGivenUnregisteredBasename) { +TEST_F(EpidMemberTest, SignBasicFailsForUnregisteredBasename) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn0 = this->kBsn0; auto& bsn1 = this->kBsn1; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn0.data(), bsn0.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn0.data(), bsn0.size())); BasicSignature basic_sig; EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), bsn1.data(), - bsn1.size(), &basic_sig)); + bsn1.size(), &basic_sig, nullptr)); } ///////////////////////////////////////////////////////////////////////// // Anonymity @@ -84,12 +121,13 @@ TEST_F(EpidMemberTest, BasicSignaturesOfSameMessageAreDifferent) { MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; - BasicSignature basic_sig1; - BasicSignature basic_sig2; + BasicSignature basic_sig1 = {0}; + BasicSignature basic_sig2 = {0}; + BigNumStr rnd_bsn = {0}; EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig1)); + 0, &basic_sig1, &rnd_bsn)); EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig2)); + 0, &basic_sig2, &rnd_bsn)); EXPECT_NE(0, memcmp(&basic_sig1, &basic_sig2, sizeof(BasicSignature))); } TEST_F(EpidMemberTest, @@ -101,11 +139,13 @@ TEST_F(EpidMemberTest, auto& bsn = this->kBsn0; BasicSignature basic_sig1; BasicSignature basic_sig2; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig1)); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig2)); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig1, nullptr)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig2, nullptr)); EXPECT_NE(0, memcmp(&basic_sig1, &basic_sig2, sizeof(BasicSignature))); } ///////////////////////////////////////////////////////////////////////// @@ -116,13 +156,36 @@ TEST_F(EpidMemberTest, SignBasicSucceedsUsingRandomBase) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; + BigNumStr zero = {0}; EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); + 0, &basic_sig, &rnd_bsn)); + EXPECT_NE(0, memcmp(&rnd_bsn, &zero, sizeof(BigNumStr))); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsUsingRandomBaseWithCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; + BigNumStr zero = {0}; + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + EXPECT_NE(0, memcmp(&rnd_bsn, &zero, sizeof(BigNumStr))); + // verify basic signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} TEST_F(EpidMemberTest, SignBasicSucceedsUsingBasename) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, @@ -130,15 +193,39 @@ TEST_F(EpidMemberTest, SignBasicSucceedsUsingBasename) { auto& msg = this->kMsg0; auto& bsn = this->kBsn0; BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } + +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsUsingBasenameWithCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + BasicSignature basic_sig; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + // verify basic signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} + TEST_F(EpidMemberTest, SignBasicSucceedsUsingBasenameUsingIKGFData) { Prng my_prng; GroupPubKey grp_public_key = *reinterpret_cast( @@ -150,9 +237,10 @@ TEST_F(EpidMemberTest, SignBasicSucceedsUsingBasenameUsingIKGFData) { auto& msg = this->kMsg0; auto& bsn = this->kBsn0; BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(grp_public_key); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); @@ -166,13 +254,13 @@ TEST_F(EpidMemberTest, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); BasicSignature basic_sig; - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + BigNumStr rnd_bsn = {0}; + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } @@ -183,43 +271,127 @@ TEST_F(EpidMemberTest, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)); + 0, &basic_sig, &rnd_bsn)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } -///////////////////////////////////////////////////////////////////////// -// Variable hash alg -TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha256HashAlg) { +#ifndef TPM_TSS +TEST_F(EpidMemberTest, SignBasicSucceedsUsingBsnContainingAllPossibleBytes) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; - auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + auto& bsn = this->kData_0_255; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + BasicSignature basic_sig; + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} +#endif + +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsAllPossibleBytesForCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kData_0_255; + // 0 - 123 + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), 124)); BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha256)); EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + bsn.data(), 124, &basic_sig, nullptr)); + VerifierCtxObj ctx1(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx1, bsn.data(), 124)); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx1, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx1, &basic_sig, msg.data(), msg.size())); + + // 124 - 247 + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data() + 124, 124)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data() + 124, 124, + &basic_sig, nullptr)); + VerifierCtxObj ctx2(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx2, bsn.data() + 124, 124)); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx2, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx2, &basic_sig, msg.data(), msg.size())); + + // 248 - 255 + THROW_ON_EPIDERR( + EpidRegisterBasename(member, bsn.data() + 124 * 2, 256 - 124 * 2)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data() + 124 * 2, + 256 - 124 * 2, &basic_sig, nullptr)); + VerifierCtxObj ctx3(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR( + EpidVerifierSetBasename(ctx3, bsn.data() + 124 * 2, 256 - 124 * 2)); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx3, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx3, &basic_sig, msg.data(), msg.size())); +} +///////////////////////////////////////////////////////////////////////// +// Variable hash alg +TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha256HashAlg) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + BasicSignature basic_sig; + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsUsingSha256HashAlgWithCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, kSha256, + &Prng::Generate, &my_prng); + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + BasicSignature basic_sig; + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + // verify basic signature + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha384HashAlg) { Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha384, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha384)); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384)); @@ -228,32 +400,33 @@ TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha384HashAlg) { } TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha512HashAlg) { Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha512, this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512)); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512)); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } -TEST_F(EpidMemberTest, DISABLED_SignBasicSucceedsUsingSha512256HashAlg) { +TEST_F(EpidMemberTest, SignBasicSucceedsUsingSha512256HashAlg) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); + kSha512_256, this->kMemberPrecomp, &Prng::Generate, + &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); BasicSignature basic_sig; - THROW_ON_EPIDERR(EpidMemberSetHashAlg(member, kSha512_256)); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256)); @@ -261,60 +434,55 @@ TEST_F(EpidMemberTest, DISABLED_SignBasicSucceedsUsingSha512256HashAlg) { EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } ///////////////////////////////////////////////////////////////////////// -TEST_F(EpidMemberTest, SignBasicFailsForInvalidMemberPrecomp) { - Prng my_prng; - MemberPrecomp mbr_precomp = this->kMemberPrecomp; - mbr_precomp.e12.x[0].data.data[0]++; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - mbr_precomp, &Prng::Generate, &my_prng); - auto& msg = this->kMsg0; - BasicSignature basic_sig; - auto& bsn = this->kBsn0; - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); -} -// Variable precomputed signatures -TEST_F(EpidMemberTest, SignBasicFailsForInvalidPrecomputedSignature) { - Prng my_prng; - MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, - this->kMemberPrecomp, &Prng::Generate, &my_prng); - PreComputedSignature precompsig = this->kPrecomputedSignatures[0]; - precompsig.B.x.data.data[0]++; - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, &precompsig)); - auto& msg = this->kMsg0; - BasicSignature basic_sig; - auto& bsn = this->kBsn0; - EXPECT_EQ(kEpidBadArgErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); -} TEST_F(EpidMemberTest, SignBasicConsumesPrecomputedSignatures) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 3, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 3)); auto& msg = this->kMsg0; BasicSignature basic_sig; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); // use 1 precomputed signature - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + ASSERT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member)); } TEST_F(EpidMemberTest, SignBasicSucceedsWithPrecomputedSignatures) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, nullptr)); auto& msg = this->kMsg0; BasicSignature basic_sig; - auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + BigNumStr rnd_bsn = {0}; + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); - THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsUsingPrecompSigWithCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); + + auto& msg = this->kMsg0; + + BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; + + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, + 0, &basic_sig, &rnd_bsn)); + + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); } @@ -322,16 +490,18 @@ TEST_F(EpidMemberTest, SignBasicSucceedsWithoutPrecomputedSignatures) { Prng my_prng; MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); - THROW_ON_EPIDERR(EpidAddPreSigs(member, 1, nullptr)); + THROW_ON_EPIDERR(EpidAddPreSigs(member, 1)); auto& msg = this->kMsg0; BasicSignature basic_sig; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); - ASSERT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + ASSERT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // test sign without precomputed signatures - EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), - bsn.data(), bsn.size(), &basic_sig)); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); // verify basic signature VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); @@ -346,10 +516,10 @@ TEST_F(EpidMemberTest, SignBasicSucceedsGivenEmptyMessage) { this->kMemberPrecomp, &Prng::Generate, &my_prng); auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - THROW_ON_EPIDERR(EpidRegisterBaseName(member, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); BasicSignature basic_sig; EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), 0, bsn.data(), - bsn.size(), &basic_sig)); + bsn.size(), &basic_sig, nullptr)); VerifierCtxObj ctx(this->kGroupPublicKey); THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); EXPECT_EQ(kEpidSigValid, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), 0)); @@ -361,6 +531,7 @@ TEST_F(EpidMemberTest, SignBasicSucceedsWithShortMessage) { MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; VerifierCtxObj ctx(this->kGroupPublicKey); size_t lengths[] = {1, 13, 128, 256, 512, 1021, 1024}; // have desired lengths to loop over @@ -370,8 +541,8 @@ TEST_F(EpidMemberTest, SignBasicSucceedsWithShortMessage) { msg.at(n) = (uint8_t)n; } for (auto length : lengths) { - EXPECT_EQ(kEpidNoErr, - EpidSignBasic(member, msg.data(), length, nullptr, 0, &basic_sig)) + EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), length, nullptr, 0, + &basic_sig, &rnd_bsn)) << "EpidSignBasic for message_len: " << length << " failed"; EXPECT_EQ(kEpidNoErr, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), length)) @@ -383,6 +554,7 @@ TEST_F(EpidMemberTest, SignBasicSucceedsWithLongMessage) { MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, this->kMemberPrecomp, &Prng::Generate, &my_prng); BasicSignature basic_sig; + BigNumStr rnd_bsn = {0}; VerifierCtxObj ctx(this->kGroupPublicKey); { // 1000000 std::vector msg(1000000); // allocate message for max size @@ -390,12 +562,48 @@ TEST_F(EpidMemberTest, SignBasicSucceedsWithLongMessage) { msg.at(n) = (uint8_t)n; } EXPECT_EQ(kEpidNoErr, EpidSignBasic(member, msg.data(), msg.size(), nullptr, - 0, &basic_sig)) + 0, &basic_sig, &rnd_bsn)) << "EpidSignBasic for message_len: " << 1000000 << " failed"; EXPECT_EQ(kEpidNoErr, EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())) << "EpidVerifyBasicSig for message_len: " << 1000000 << " failed"; } } +TEST_F(EpidMemberTest, SignBasicSucceedsWithMsgContainingAllPossibleBytes) { + Prng my_prng; + MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, + this->kMemberPrecomp, &Prng::Generate, &my_prng); + auto& msg = this->kData_0_255; + auto& bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + BasicSignature basic_sig; + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + VerifierCtxObj ctx(this->kGroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} +TEST_F(EpidMemberTest, + PROTECTED_SignBasicSucceedsMsgAllPossibleBytesForCredential_EPS0) { + Prng my_prng; + MemberCtxObj member( + this->kEps0GroupPublicKey, + *(MembershipCredential const*)&this->kEps0MemberPrivateKey, + &Prng::Generate, &my_prng); + auto& msg = this->kData_0_255; + auto& bsn = this->kBsn0; + BasicSignature basic_sig; + THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, + EpidSignBasic(member, msg.data(), msg.size(), bsn.data(), + bsn.size(), &basic_sig, nullptr)); + VerifierCtxObj ctx(this->kEps0GroupPublicKey); + THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256)); + EXPECT_EQ(kEpidSigValid, + EpidVerifyBasicSig(ctx, &basic_sig, msg.data(), msg.size())); +} } // namespace diff --git a/external/epid-sdk/epid/member/unittests/storage-test.cc b/external/epid-sdk/epid/member/unittests/storage-test.cc new file mode 100644 index 00000000..0548e2b7 --- /dev/null +++ b/external/epid-sdk/epid/member/unittests/storage-test.cc @@ -0,0 +1,126 @@ +/*############################################################################ +# Copyright 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################*/ + +/*! + * \file + * \brief Member credentials storage helper API unit tests. + */ +#include + +#include "epid/common-testhelper/epid_gtest-testhelper.h" +#include "gtest/gtest.h" + +#include "epid/common-testhelper/epid2params_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/prng-testhelper.h" +#include "epid/member/tpm2/unittests/tpm2-testhelper.h" +#include "epid/member/unittests/member-testhelper.h" + +extern "C" { +#include "epid/member/src/storage.h" +#include "epid/member/tpm2/nv.h" +} + +namespace { + +TEST_F(EpidMemberTest, NvWriteMembershipCredentialFailsGivenNullPointer) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + + uint32_t nv_index = 0x01c10100; + GroupPubKey const pub_key = this->kGroupPublicKey; + // PrivKey can be trimed to MembershipCredential + MembershipCredential const credential = + *(MembershipCredential*)&this->kMemberPrivateKey; + + EXPECT_EQ(kEpidBadArgErr, EpidNvWriteMembershipCredential( + nullptr, &pub_key, &credential, nv_index)); + EXPECT_EQ(kEpidBadArgErr, EpidNvWriteMembershipCredential( + tpm, nullptr, &credential, nv_index)); + EXPECT_EQ(kEpidBadArgErr, + EpidNvWriteMembershipCredential(tpm, &pub_key, nullptr, nv_index)); + // cleanup nv_index for next test + Tpm2NvUndefineSpace(tpm, nv_index); +} + +TEST_F(EpidMemberTest, NvReadMembershipCredentialFailsGivenNoCredentials) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + + uint32_t nv_index = 0x01c10101; + GroupPubKey pub_key = this->kGroupPublicKey; + // PrivKey can be trimed to MembershipCredential + MembershipCredential credential = + *(MembershipCredential*)&this->kMemberPrivateKey; + + EXPECT_EQ(kEpidBadArgErr, EpidNvReadMembershipCredential( + tpm, nv_index, &pub_key, &credential)); +} + +TEST_F(EpidMemberTest, NvReadMembershipCredentialFailsGivenNullPointer) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + + uint32_t nv_index = 0x01c10100; + GroupPubKey pub_key = this->kGroupPublicKey; + // PrivKey can be trimed to MembershipCredential + MembershipCredential credential = + *(MembershipCredential*)&this->kMemberPrivateKey; + + // write credentials + EXPECT_EQ(kEpidNoErr, EpidNvWriteMembershipCredential(tpm, &pub_key, + &credential, nv_index)); + + EXPECT_EQ(kEpidBadArgErr, EpidNvReadMembershipCredential( + nullptr, nv_index, &pub_key, &credential)); + EXPECT_EQ(kEpidBadArgErr, EpidNvReadMembershipCredential( + tpm, nv_index, nullptr, &credential)); + EXPECT_EQ(kEpidBadArgErr, + EpidNvReadMembershipCredential(tpm, nv_index, &pub_key, nullptr)); + // cleanup nv_index for next test + Tpm2NvUndefineSpace(tpm, nv_index); +} + +TEST_F(EpidMemberTest, WrittenMembershipCredentialCanBeRead) { + Prng my_prng; + Epid2ParamsObj epid2params; + Tpm2CtxObj tpm(&Prng::Generate, &my_prng, nullptr, epid2params); + + uint32_t nv_index = 0x01c10100; + GroupPubKey pub_key = this->kGroupPublicKey; + // PrivKey can be trimed to MembershipCredential + MembershipCredential credential_expected = + *(MembershipCredential*)&this->kMemberPrivateKey; + MembershipCredential credential; + + // write credentials + EXPECT_EQ(kEpidNoErr, EpidNvWriteMembershipCredential( + tpm, &pub_key, &credential_expected, nv_index)); + + // read credentials + EXPECT_EQ(kEpidNoErr, EpidNvReadMembershipCredential(tpm, nv_index, &pub_key, + &credential)); + + EXPECT_EQ(this->kGroupPublicKey, pub_key); + EXPECT_EQ(credential_expected, credential); + // cleanup nv_index for next test + Tpm2NvUndefineSpace(tpm, nv_index); +} + +} // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/api.h b/external/epid-sdk/epid/verifier/1.1/api.h similarity index 93% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/api.h rename to external/epid-sdk/epid/verifier/1.1/api.h index 415ee398..ef8aa5be 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/api.h +++ b/external/epid-sdk/epid/verifier/1.1/api.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,15 +17,11 @@ #define EPID_VERIFIER_1_1_API_H_ #include -#include "epid/common/stdtypes.h" #include "epid/common/1.1/types.h" #include "epid/common/errors.h" +#include "epid/common/stdtypes.h" #include "epid/verifier/api.h" -#ifdef __cplusplus -extern "C"{ -#endif - /*! * \file * \brief Intel(R) EPID SDK verifier Intel(R) EPID 1.1 API. @@ -33,7 +29,7 @@ extern "C"{ /// Intel(R) EPID 1.1 Verifier functionality /*! - \defgroup Epid11VerifierModule EPID 1.1 support + \defgroup Epid11VerifierModule Intel(R) EPID 1.1 support To verify signatures coming from member devices that belong to an Intel® EPID 1.1 group, you need to use Intel® EPID 1.1 @@ -78,7 +74,7 @@ typedef struct Epid11VerifierCtx Epid11VerifierCtx; This API supports Intel(R) EPID 1.1 verification. \note e12 = 0 implies that this data is not valid - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ #pragma pack(1) @@ -114,7 +110,7 @@ typedef struct Epid11VerifierPrecomp { \see Epid11VerifierDelete \see Epid11VerifierWritePrecomp - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifierCreate(Epid11GroupPubKey const* pub_key, @@ -133,7 +129,7 @@ EpidStatus Epid11VerifierCreate(Epid11GroupPubKey const* pub_key, The verifier context. Can be NULL. \see Epid11VerifierCreate - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ void Epid11VerifierDelete(Epid11VerifierCtx** ctx); @@ -151,7 +147,7 @@ void Epid11VerifierDelete(Epid11VerifierCtx** ctx); \note If the result is not ::kEpidNoErr the content of precomp is undefined. - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifierWritePrecomp(Epid11VerifierCtx const* ctx, @@ -190,7 +186,7 @@ EpidStatus Epid11VerifierWritePrecomp(Epid11VerifierCtx const* ctx, pointed to by the verifier is undefined. \see Epid11VerifierCreate - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifierSetPrivRl(Epid11VerifierCtx* ctx, @@ -231,7 +227,7 @@ EpidStatus Epid11VerifierSetPrivRl(Epid11VerifierCtx* ctx, \see Epid11VerifierCreate \see SdkOverview_11Verifier \see EPID 1.1 + href="group___epid11_verifier_module.html#details">Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifierSetSigRl(Epid11VerifierCtx* ctx, @@ -271,7 +267,7 @@ EpidStatus Epid11VerifierSetSigRl(Epid11VerifierCtx* ctx, to by the verifier is undefined. \see Epid11VerifierCreate - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifierSetGroupRl(Epid11VerifierCtx* ctx, @@ -333,7 +329,7 @@ EpidStatus Epid11VerifierSetBasename(Epid11VerifierCtx* ctx, verify should de considered to have failed. \see Epid11VerifierCreate - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11Verify(Epid11VerifierCtx const* ctx, @@ -368,7 +364,7 @@ EpidStatus Epid11Verify(Epid11VerifierCtx const* ctx, verified. \see Epid11VerifyBasicSig - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ bool Epid11AreSigsLinked(Epid11BasicSignature const* sig1, @@ -400,7 +396,7 @@ bool Epid11AreSigsLinked(Epid11BasicSignature const* sig1, failed. \see Epid11VerifierCreate - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11VerifyBasicSig(Epid11VerifierCtx const* ctx, @@ -446,7 +442,7 @@ EpidStatus Epid11VerifyBasicSig(Epid11VerifierCtx const* ctx, \see Epid11VerifierCreate \see Epid11VerifyBasicSig \see Epid11CheckPrivRlEntry - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11NrVerify(Epid11VerifierCtx const* ctx, @@ -486,16 +482,12 @@ EpidStatus Epid11NrVerify(Epid11VerifierCtx const* ctx, \see Epid11VerifierCreate \see Epid11NrVerify \see Epid11VerifyBasicSig - \see EPID 1.1 + \see Intel(R) EPID 1.1 support */ EpidStatus Epid11CheckPrivRlEntry(Epid11VerifierCtx const* ctx, Epid11BasicSignature const* sig, FpElemStr const* f); -#ifdef __cplusplus -}; -#endif - /*! @} */ #endif // EPID_VERIFIER_1_1_API_H_ diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/check_privrl_entry.c b/external/epid-sdk/epid/verifier/1.1/src/check_privrl_entry.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/check_privrl_entry.c rename to external/epid-sdk/epid/verifier/1.1/src/check_privrl_entry.c diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.c b/external/epid-sdk/epid/verifier/1.1/src/context.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.c rename to external/epid-sdk/epid/verifier/1.1/src/context.c index 2ecae206..3b800071 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.c +++ b/external/epid-sdk/epid/verifier/1.1/src/context.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ /*! * \file -* \brief Intel EPID 1.1 Verifier context implementation. +* \brief Intel Intel(R) EPID 1.1 Verifier context implementation. */ -#include "epid/verifier/1.1/api.h" #include "epid/verifier/1.1/src/context.h" -#include "epid/common/src/memory.h" #include "epid/common/src/endian_convert.h" +#include "epid/common/src/memory.h" +#include "epid/verifier/1.1/api.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.h b/external/epid-sdk/epid/verifier/1.1/src/context.h similarity index 97% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.h rename to external/epid-sdk/epid/verifier/1.1/src/context.h index 62663cbd..653048ba 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/context.h +++ b/external/epid-sdk/epid/verifier/1.1/src/context.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,11 @@ * \file * \brief Intel(R) EPID 1.1 Verifier context interface. */ +#include "epid/common/1.1/src/commitment.h" +#include "epid/common/1.1/src/epid11params.h" #include "epid/common/1.1/src/grouppubkey.h" #include "epid/common/math/ecgroup.h" #include "epid/common/math/finitefield.h" -#include "epid/common/1.1/src/epid11params.h" -#include "epid/common/1.1/src/commitment.h" /// Verifier context definition struct Epid11VerifierCtx { diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/nrverify.c b/external/epid-sdk/epid/verifier/1.1/src/nrverify.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/nrverify.c rename to external/epid-sdk/epid/verifier/1.1/src/nrverify.c index a52e5f4c..7dd71261 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/nrverify.c +++ b/external/epid-sdk/epid/verifier/1.1/src/nrverify.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ * \file * \brief Epid11NrVerify implementation. */ -#include "ext/ipp/include/ippcp.h" +#include "epid/common/math/hash.h" +#include "epid/common/src/endian_convert.h" #include "epid/common/src/memory.h" #include "epid/verifier/1.1/api.h" #include "epid/verifier/1.1/src/context.h" -#include "epid/common/src/endian_convert.h" -#include "epid/common/math/hash.h" +#include "ext/ipp/include/ippcp.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ if (kEpidNoErr != (ret)) { \ diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/sigs_linked.c b/external/epid-sdk/epid/verifier/1.1/src/sigs_linked.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/sigs_linked.c rename to external/epid-sdk/epid/verifier/1.1/src/sigs_linked.c diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/verify.c b/external/epid-sdk/epid/verifier/1.1/src/verify.c similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/verify.c rename to external/epid-sdk/epid/verifier/1.1/src/verify.c index aff1da4c..257aee0f 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/verify.c +++ b/external/epid-sdk/epid/verifier/1.1/src/verify.c @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ */ #include +#include "epid/common/src/endian_convert.h" #include "epid/verifier/1.1/api.h" #include "epid/verifier/1.1/src/context.h" -#include "epid/common/src/endian_convert.h" static size_t Epid11GetSignatureRlCount(Epid11Signature const* sig) { return (!sig) ? 0 : ntohl(sig->n2); @@ -69,6 +69,11 @@ EpidStatus Epid11PrVerify(Epid11VerifierCtx const* ctx, FiniteField* Fp = ctx->epid11_params->Fp; bool eq = false; do { + sts = NewFfElement(Fp, &f); + if (kEpidNoErr != sts) { + sts = kEpidMathErr; + break; + } sts = NewEcPoint(G3, &B); if (kEpidNoErr != sts) { sts = kEpidMathErr; @@ -84,7 +89,8 @@ EpidStatus Epid11PrVerify(Epid11VerifierCtx const* ctx, sts = kEpidMathErr; break; } - sts = NewFfElement(Fp, &f); + // ReadFfElement checks that the value f_str is in the field + sts = ReadFfElement(Fp, f_str, sizeof(BigNumStr), f); if (kEpidNoErr != sts) { sts = kEpidMathErr; break; @@ -194,7 +200,7 @@ EpidStatus Epid11Verify(Epid11VerifierCtx const* ctx, // values in s match with the values in SIG-RL.... if (0 != memcmp(&ctx->sig_rl->version, &sig->rl_ver, sizeof(ctx->sig_rl->version))) { - return kEpidBadArgErr; + return kEpidErr; } if (sigrl_count != rl_count) { diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/verifybasic.c b/external/epid-sdk/epid/verifier/1.1/src/verifybasic.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/src/verifybasic.c rename to external/epid-sdk/epid/verifier/1.1/src/verifybasic.c index d5a1480a..2569a653 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/src/verifybasic.c +++ b/external/epid-sdk/epid/verifier/1.1/src/verifybasic.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ */ #include #include -#include "epid/verifier/1.1/api.h" -#include "epid/verifier/1.1/src/context.h" #include "epid/common/math/src/bignum-internal.h" #include "epid/common/src/memory.h" +#include "epid/verifier/1.1/api.h" +#include "epid/verifier/1.1/src/context.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ if (kEpidNoErr != (ret)) { \ diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/check_privrl_entry-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/check_privrl_entry-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/check_privrl_entry-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/check_privrl_entry-test.cc index ba0f6ea9..f5c96453 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/check_privrl_entry-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/check_privrl_entry-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,14 +19,15 @@ * \brief Epid11CheckPrivRlEntry unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/1.1/api.h" } -#include "epid/verifier/1.1/unittests/verifier-testhelper.h" #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" +#include "epid/verifier/1.1/unittests/verifier-testhelper.h" namespace { diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/context-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/context-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/context-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/context-test.cc index 798f6362..56620fa3 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/context-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/context-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { @@ -28,9 +29,9 @@ extern "C" { #include "epid/verifier/1.1/src/context.h" } -#include "epid/verifier/1.1/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/verifier/1.1/unittests/verifier-testhelper.h" bool operator==(Epid11VerifierPrecomp const& lhs, Epid11VerifierPrecomp const& rhs) { return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); @@ -474,4 +475,15 @@ TEST_F(Epid11VerifierTest, SetBasenameResetsBasenameGivenNullBasename) { THROW_ON_EPIDERR(Epid11VerifierSetBasename(ctx, nullptr, 0)); EXPECT_EQ(nullptr, ctx->basename_hash); } +TEST_F(Epid11VerifierTest, SetBasenameAcceptsBsnContainingAllPossibleBytes) { + Epid11VerifierCtxObj verifier(this->kPubKeyStrForMsg0_255, + this->kVerifierPrecompStr); + Epid11VerifierCtx* ctx = verifier; + auto& basename = this->kData_0_255; + EXPECT_EQ(kEpidNoErr, + Epid11VerifierSetBasename(ctx, basename.data(), basename.size())); + EXPECT_EQ(basename.size(), ctx->basename_len); + EXPECT_EQ(0, memcmp(basename.data(), ctx->basename, ctx->basename_len)); + EXPECT_NE(nullptr, ctx->basename_hash); +} } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/nrverify-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/nrverify-test.cc similarity index 93% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/nrverify-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/nrverify-test.cc index 41d98513..9d572e63 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/nrverify-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/nrverify-test.cc @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,17 +19,18 @@ * \brief Epid11NrVerify unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { +#include "epid/common/1.1/types.h" #include "epid/verifier/1.1/api.h" #include "epid/verifier/1.1/src/context.h" -#include "epid/common/1.1/types.h" } -#include "epid/verifier/1.1/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/errors-testhelper.h" #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" +#include "epid/common-testhelper/errors-testhelper.h" +#include "epid/verifier/1.1/unittests/verifier-testhelper.h" namespace { @@ -216,4 +217,16 @@ TEST_F(Epid11VerifierTest, NrVerifyAcceptsSigWithRandomBaseName) { &sig_rl->bk[0], &epid_signature->sigma[0])); } +TEST_F(Epid11VerifierTest, NrVerifyAcceptsMsgContainingAllPossibleBytes) { + Epid11VerifierCtxObj verifier(this->kPubKeyStrForMsg0_255); + Epid11Signature const* epid_signature = + (Epid11Signature*)kSigGrp01Member0Sha256kBsn0Data_0_255.data(); + Epid11SigRl const* sig_rl = + reinterpret_cast(this->kSigRlForMsg0_255.data()); + EXPECT_EQ(kEpidSigValid, + Epid11NrVerify(verifier, &epid_signature->sigma0, + this->kData_0_255.data(), this->kData_0_255.size(), + &sig_rl->bk[0], &epid_signature->sigma[0])); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/sigs_linked-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/sigs_linked-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/sigs_linked-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/sigs_linked-test.cc index a32a4706..edebf6d3 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/sigs_linked-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/sigs_linked-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ * \brief Epid11AreSigsLinkable unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/testdata/verifier_precmp.inc b/external/epid-sdk/epid/verifier/1.1/unittests/testdata/verifier_precmp.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/testdata/verifier_precmp.inc rename to external/epid-sdk/epid/verifier/1.1/unittests/testdata/verifier_precmp.inc diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.cc b/external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.cc similarity index 56% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.cc index 8dd541d9..9c3906ae 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ * \file * \brief Test fixture class for EpidVerifier. */ -#include #include "epid/verifier/1.1/unittests/verifier-testhelper.h" +#include const Epid11G3ElemStr Epid11VerifierTest::kG3IdentityStr = {0}; const Epid11GroupPubKey Epid11VerifierTest::kPubKeyStr = { // gid @@ -27,44 +27,85 @@ const Epid11GroupPubKey Epid11VerifierTest::kPubKeyStr = { 0x00, 0x00, 0x00, 0x7b, }, // h1 - {{0x08, 0x4a, 0x9d, 0x2e, 0xf9, 0x4f, 0x78, 0x02, 0xd7, 0x89, 0x75, 0xb4, - 0xe7, 0x25, 0x26, 0x9f, 0x00, 0x57, 0xad, 0x33, 0x30, 0xea, 0xa9, 0x6c, - 0x00, 0x9e, 0x8b, 0xc8, 0x13, 0x23, 0xcb, 0x06}, - {0x04, 0xbe, 0x42, 0x74, 0x11, 0x07, 0xb1, 0x06, 0xd7, 0xef, 0x5f, 0x66, - 0x87, 0xd9, 0xfa, 0xdd, 0x53, 0xae, 0xd7, 0xf4, 0x54, 0xf8, 0xd0, 0x21, - 0x75, 0xe0, 0x07, 0x44, 0xc9, 0xc3, 0x4e, 0xf7}}, + {{0x08, 0x4a, 0x9d, 0x2e, 0xf9, 0x4f, 0x78, 0x02, 0xd7, 0x89, 0x75, + 0xb4, 0xe7, 0x25, 0x26, 0x9f, 0x00, 0x57, 0xad, 0x33, 0x30, 0xea, + 0xa9, 0x6c, 0x00, 0x9e, 0x8b, 0xc8, 0x13, 0x23, 0xcb, 0x06}, + {0x04, 0xbe, 0x42, 0x74, 0x11, 0x07, 0xb1, 0x06, 0xd7, 0xef, 0x5f, + 0x66, 0x87, 0xd9, 0xfa, 0xdd, 0x53, 0xae, 0xd7, 0xf4, 0x54, 0xf8, + 0xd0, 0x21, 0x75, 0xe0, 0x07, 0x44, 0xc9, 0xc3, 0x4e, 0xf7}}, // h2 - {{0x06, 0xd8, 0xa9, 0x90, 0x02, 0x8f, 0xca, 0xa5, 0x73, 0x36, 0x24, 0x03, - 0xc9, 0xa8, 0x7e, 0x9d, 0x64, 0x12, 0xac, 0xa7, 0xbd, 0x17, 0x7f, 0x7c, - 0x96, 0x8d, 0x2e, 0x13, 0xd9, 0xb2, 0x69, 0x47}, - {0x09, 0xdb, 0xe3, 0xbf, 0xbc, 0xa1, 0x34, 0x0f, 0xc6, 0xe2, 0x00, 0x3d, - 0x98, 0xa3, 0x7d, 0xab, 0xd4, 0x0e, 0xec, 0xde, 0x4f, 0x97, 0xa9, 0xbb, - 0xdd, 0x60, 0x94, 0x24, 0x7b, 0xb3, 0xf5, 0x94}}, + {{0x06, 0xd8, 0xa9, 0x90, 0x02, 0x8f, 0xca, 0xa5, 0x73, 0x36, 0x24, + 0x03, 0xc9, 0xa8, 0x7e, 0x9d, 0x64, 0x12, 0xac, 0xa7, 0xbd, 0x17, + 0x7f, 0x7c, 0x96, 0x8d, 0x2e, 0x13, 0xd9, 0xb2, 0x69, 0x47}, + {0x09, 0xdb, 0xe3, 0xbf, 0xbc, 0xa1, 0x34, 0x0f, 0xc6, 0xe2, 0x00, + 0x3d, 0x98, 0xa3, 0x7d, 0xab, 0xd4, 0x0e, 0xec, 0xde, 0x4f, 0x97, + 0xa9, 0xbb, 0xdd, 0x60, 0x94, 0x24, 0x7b, 0xb3, 0xf5, 0x94}}, // w - {{{0x02, 0x43, 0x78, 0x9f, 0x54, 0xc1, 0x21, 0x3a, 0x2b, 0x4d, 0x12, 0x65, - 0x2f, 0x51, 0x94, 0xc6, 0x34, 0x24, 0xd9, 0x7b, 0x06, 0x3a, 0xc4, 0xf5, - 0x56, 0xeb, 0x32, 0xe3, 0xee, 0x7b, 0xad, 0x6b}, - {0x04, 0x90, 0x86, 0x31, 0x18, 0x2a, 0xa4, 0xcf, 0xa3, 0x90, 0xa5, 0x80, - 0x7b, 0xae, 0x3b, 0xb1, 0x77, 0x03, 0xe7, 0x7e, 0xf2, 0xfc, 0x6d, 0x3a, - 0xab, 0x8f, 0xbf, 0x95, 0x40, 0xed, 0x08, 0x03}, - {0x01, 0x05, 0x86, 0xf5, 0x42, 0xea, 0x4d, 0xf7, 0x4f, 0xef, 0x46, 0xdf, - 0x8f, 0xe8, 0x2d, 0xbb, 0x5d, 0x0d, 0x2f, 0x4f, 0xf4, 0xd8, 0x31, 0xc6, - 0x5a, 0x97, 0x98, 0x44, 0xcf, 0x42, 0x5a, 0xf3}}, - {{0x03, 0x5f, 0xb6, 0x38, 0x45, 0x5a, 0x15, 0x1e, 0xb9, 0x54, 0xfa, 0x2c, - 0x3f, 0x68, 0x7b, 0x4e, 0x85, 0x35, 0xf3, 0x5b, 0xe5, 0xdc, 0x96, 0x2b, - 0x18, 0x84, 0x5e, 0x1e, 0x53, 0xdc, 0x22, 0x23}, - {0x06, 0x08, 0x91, 0x5a, 0x2d, 0x27, 0xe2, 0x12, 0x69, 0xfa, 0xab, 0x19, - 0x7c, 0x47, 0x6b, 0xec, 0xde, 0xc6, 0x25, 0xd4, 0x43, 0xb4, 0x65, 0x23, - 0x61, 0x0f, 0x1f, 0x2d, 0xfd, 0xb1, 0x18, 0xb0}, - {0x04, 0x8e, 0x1a, 0xc5, 0x95, 0x9a, 0x0e, 0x37, 0x7c, 0x5e, 0x95, 0x38, - 0xc2, 0xcf, 0xfa, 0x1f, 0xe3, 0x3a, 0x2b, 0x85, 0xa5, 0xfd, 0x6b, 0xc4, - 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd}}}}; + {{{0x02, 0x43, 0x78, 0x9f, 0x54, 0xc1, 0x21, 0x3a, 0x2b, 0x4d, 0x12, + 0x65, 0x2f, 0x51, 0x94, 0xc6, 0x34, 0x24, 0xd9, 0x7b, 0x06, 0x3a, + 0xc4, 0xf5, 0x56, 0xeb, 0x32, 0xe3, 0xee, 0x7b, 0xad, 0x6b}, + {0x04, 0x90, 0x86, 0x31, 0x18, 0x2a, 0xa4, 0xcf, 0xa3, 0x90, 0xa5, + 0x80, 0x7b, 0xae, 0x3b, 0xb1, 0x77, 0x03, 0xe7, 0x7e, 0xf2, 0xfc, + 0x6d, 0x3a, 0xab, 0x8f, 0xbf, 0x95, 0x40, 0xed, 0x08, 0x03}, + {0x01, 0x05, 0x86, 0xf5, 0x42, 0xea, 0x4d, 0xf7, 0x4f, 0xef, 0x46, + 0xdf, 0x8f, 0xe8, 0x2d, 0xbb, 0x5d, 0x0d, 0x2f, 0x4f, 0xf4, 0xd8, + 0x31, 0xc6, 0x5a, 0x97, 0x98, 0x44, 0xcf, 0x42, 0x5a, 0xf3}}, + {{0x03, 0x5f, 0xb6, 0x38, 0x45, 0x5a, 0x15, 0x1e, 0xb9, 0x54, 0xfa, + 0x2c, 0x3f, 0x68, 0x7b, 0x4e, 0x85, 0x35, 0xf3, 0x5b, 0xe5, 0xdc, + 0x96, 0x2b, 0x18, 0x84, 0x5e, 0x1e, 0x53, 0xdc, 0x22, 0x23}, + {0x06, 0x08, 0x91, 0x5a, 0x2d, 0x27, 0xe2, 0x12, 0x69, 0xfa, 0xab, + 0x19, 0x7c, 0x47, 0x6b, 0xec, 0xde, 0xc6, 0x25, 0xd4, 0x43, 0xb4, + 0x65, 0x23, 0x61, 0x0f, 0x1f, 0x2d, 0xfd, 0xb1, 0x18, 0xb0}, + {0x04, 0x8e, 0x1a, 0xc5, 0x95, 0x9a, 0x0e, 0x37, 0x7c, 0x5e, 0x95, + 0x38, 0xc2, 0xcf, 0xfa, 0x1f, 0xe3, 0x3a, 0x2b, 0x85, 0xa5, 0xfd, + 0x6b, 0xc4, 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd}}}}; +const Epid11GroupPubKey Epid11VerifierTest::kPubKeyStrForMsg0_255 = { + // gid + { + 0x00, 0x00, 0x00, 0x7b, + }, + // h1 + {{0x02, 0x5a, 0xc4, 0xc5, 0xcd, 0x7d, 0xaa, 0xfd, 0x26, 0xe5, 0x0b, + 0xa9, 0xb4, 0xe1, 0x72, 0xa1, 0x65, 0x2d, 0x84, 0xad, 0x34, 0x34, + 0xf8, 0x62, 0x98, 0x6a, 0x15, 0xbe, 0xea, 0xe3, 0xcc, 0x56}, + {0x05, 0x70, 0x5f, 0x4f, 0x11, 0xaf, 0x45, 0xcf, 0x04, 0x1b, 0x96, + 0xad, 0xeb, 0x26, 0xee, 0x95, 0x65, 0x4b, 0xd3, 0xd6, 0x5c, 0x13, + 0x76, 0xb7, 0x7a, 0xa1, 0xc6, 0xda, 0xed, 0x5a, 0x40, 0xce}}, + // h2 + {{0x06, 0x0e, 0x26, 0xa3, 0xe8, 0xbd, 0xca, 0x35, 0x9d, 0x48, 0x66, + 0xc2, 0x2d, 0x38, 0xf6, 0x57, 0xec, 0x46, 0xec, 0x42, 0x21, 0xd9, + 0x8f, 0x3f, 0x5b, 0x9a, 0xcf, 0xb8, 0x69, 0x2a, 0x40, 0x8f}, + {0x03, 0x20, 0x3d, 0x12, 0x7f, 0x00, 0xe9, 0x84, 0x29, 0x4a, 0x96, + 0xfa, 0x69, 0x61, 0x34, 0x0f, 0x3d, 0x98, 0x67, 0x2f, 0x65, 0xf9, + 0x67, 0x09, 0xa1, 0x2e, 0xe7, 0x81, 0x9f, 0xe1, 0x2f, 0x1f}}, + // w + {{{0x03, 0x05, 0xff, 0x49, 0x41, 0x48, 0xcf, 0x6d, 0x38, 0xce, 0x94, + 0xe8, 0xcd, 0xae, 0x18, 0x44, 0xba, 0x54, 0x0f, 0x84, 0xa5, 0x8a, + 0xb6, 0x58, 0x70, 0x39, 0xe3, 0x33, 0xfb, 0x75, 0xce, 0x98}, + {0x08, 0xb1, 0x96, 0x12, 0xc7, 0x01, 0x20, 0x57, 0x40, 0x42, 0xdc, + 0x83, 0x59, 0xee, 0xdf, 0xf8, 0x20, 0x01, 0x84, 0xa6, 0x15, 0x3c, + 0xfe, 0x46, 0x23, 0xac, 0x2b, 0xcd, 0xb8, 0xab, 0x9f, 0x46}, + {0x06, 0x60, 0xef, 0xd9, 0x2a, 0x5b, 0xb1, 0x96, 0x92, 0x63, 0xe7, + 0x46, 0x23, 0x8b, 0x8f, 0xa2, 0x91, 0xa3, 0x0c, 0x7c, 0x81, 0x75, + 0x1b, 0xc4, 0x38, 0x10, 0x18, 0x2a, 0xc4, 0xe6, 0xe3, 0x7e}}, + {{0x08, 0xeb, 0x6b, 0x8d, 0x0d, 0x4e, 0x40, 0xb2, 0x15, 0xa0, 0x0a, + 0x2d, 0x70, 0xb6, 0x5e, 0xe8, 0xcf, 0xff, 0xcf, 0x59, 0x7f, 0xed, + 0x6c, 0x6a, 0x92, 0xd9, 0x2d, 0x61, 0xbb, 0x22, 0x12, 0x9e}, + {0x08, 0xe2, 0x50, 0x02, 0x97, 0x31, 0x1e, 0xd0, 0x4d, 0xf2, 0x39, + 0xe1, 0xb6, 0x04, 0xce, 0x5f, 0x05, 0xe9, 0xab, 0x38, 0xb3, 0x22, + 0x63, 0x5e, 0xc8, 0x89, 0x88, 0x8f, 0x2c, 0x5b, 0xc0, 0xf6}, + {0x06, 0x4a, 0x1d, 0x49, 0x98, 0x02, 0x1e, 0x42, 0x1c, 0xf2, 0x8d, + 0x0c, 0x7a, 0x86, 0x76, 0x2d, 0xc1, 0x74, 0x53, 0x7a, 0x7c, 0x65, + 0xad, 0x57, 0x1c, 0x92, 0xa8, 0xd3, 0x8a, 0x9b, 0x91, 0xe6}}}}; const Epid11Params Epid11VerifierTest::kParamsStr = { #include "epid/common/1.1/src/epid11params_tate.inc" }; const std::vector Epid11VerifierTest::kGrpXPrivRl = { #include "epid/common-testhelper/1.1/testdata/grp_x/privrl.inc" }; +const std::vector Epid11VerifierTest::kGrpXCorruptedPrivRl = { +#include "epid/common-testhelper/1.1/testdata/grp_x/corrupted_privrl.inc" +}; const std::vector Epid11VerifierTest::kGrpXPrivRlSingleEntry = { #include "epid/common-testhelper/1.1/testdata/grp_x/privrl_single_entry.inc" }; @@ -104,6 +145,26 @@ const std::vector Epid11VerifierTest::kSigRl = { 0xec, 0x7b, 0xf5, 0xe9, 0x29, 0x4a, 0x3e, 0x78, 0xbd, 0xb6, 0x3c, 0x10, 0xf8, 0xec, 0xc6, 0x2c, 0x4b, 0x4d, 0x8a, 0xc1, 0x3d, 0x65, 0xf5, 0x93, 0x8d, 0x5b, 0x07, 0x3f, 0x78, 0x92, 0x1c, 0xfa}; + +const std::vector Epid11VerifierTest::kSigRlForMsg0_255 = { + // gid + 0x00, 0x00, 0x00, 0x7b, + // rev + 0x00, 0x00, 0x00, 0x01, + // n2 + 0x00, 0x00, 0x00, 0x01, + // bks + 0x73, 0x2c, 0x11, 0x04, 0x16, 0x77, 0x2b, 0x90, 0xe3, 0x35, 0x3b, 0x99, + 0xf0, 0x26, 0x09, 0x90, 0x8d, 0xb8, 0xa8, 0x73, 0x94, 0xf9, 0x05, 0x1b, + 0x28, 0xc9, 0x11, 0xdc, 0xf7, 0x44, 0xea, 0x94, 0x80, 0x22, 0x4a, 0x18, + 0x86, 0x42, 0x3e, 0x4c, 0x68, 0x07, 0x91, 0xab, 0x62, 0xbb, 0xd1, 0xb7, + 0x2b, 0xa0, 0xbe, 0x3d, 0x9f, 0xda, 0x1c, 0xf3, 0x6e, 0xe7, 0x08, 0x0e, + 0x5e, 0xcc, 0xb9, 0x28, 0xfb, 0xc9, 0x6e, 0x9c, 0x58, 0x1b, 0xb9, 0x0b, + 0x1b, 0xac, 0x16, 0x81, 0xef, 0x02, 0x02, 0x6f, 0x16, 0xa8, 0x6a, 0xbb, + 0x54, 0xcd, 0xef, 0x1f, 0xbc, 0xd4, 0xd5, 0x84, 0x96, 0xe8, 0x7f, 0x19, + 0xc7, 0xfe, 0xac, 0xc6, 0xc1, 0xd8, 0xed, 0x64, 0xa6, 0xcd, 0x2d, 0xa1, + 0x37, 0x0f, 0x37, 0x41, 0xd9, 0xb5, 0xec, 0x95, 0x13, 0xc6, 0x1d, 0x4b, + 0xe2, 0x35, 0x7f, 0x42, 0x5e, 0xf5, 0x20, 0x71}; const std::vector Epid11VerifierTest::kEmptySigRl = { // gid 0x00, 0x00, 0x00, 0x7b, @@ -140,6 +201,30 @@ const std::vector Epid11VerifierTest::kMsg0 = { const std::vector Epid11VerifierTest::kBsn0 = {'b', 'a', 's', 'e', 'n', 'a', 'm', 'e', '1'}; +const std::vector Epid11VerifierTest::kData_0_255 = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0xff, +}; const std::vector Epid11VerifierTest::kSigGrpXMember0Sha256Bsn0Msg0 = { #include "epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_bsn0_msg0.inc" }; @@ -169,6 +254,11 @@ const std::vector Epid11VerifierTest::kSigGrpXMember0Sha256RandbaseMsg1 = { #include "epid/common-testhelper/1.1/testdata/grp_x/member0/sig_sha256_rndbase_msg1.inc" }; + +const std::vector + Epid11VerifierTest::kSigGrp01Member0Sha256kBsn0Data_0_255 = { +#include "epid/common-testhelper/1.1/testdata/grp01/member0/sig_bsn0_msg_0_255_sha256.inc" +}; const std::vector Epid11VerifierTest::kSigGrpXMember1Sha256Bsn0Msg0 = { #include "epid/common-testhelper/1.1/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc" }; diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.h b/external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.h similarity index 88% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.h rename to external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.h index 9f44fd49..58db1deb 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifier-testhelper.h +++ b/external/epid-sdk/epid/verifier/1.1/unittests/verifier-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { @@ -36,12 +37,20 @@ class Epid11VerifierTest : public ::testing::Test { static const Epid11G3ElemStr kG3IdentityStr; /// test public key static const Epid11GroupPubKey kPubKeyStr; + /// test public key for tests of msg containing all bytes + static const Epid11GroupPubKey kPubKeyStrForMsg0_255; /// the message "test message" static const std::vector kMsg0; /// the basename "basename1" static const std::vector kBsn0; + /// a data with bytes [0,255] + static const std::vector kData_0_255; + /// Signature of kData_0_255 with kBsn0 by Grp01 Member0 using Sha256 + static const std::vector kSigGrp01Member0Sha256kBsn0Data_0_255; /// the privrl of group X static const std::vector kGrpXPrivRl; + /// currpted privrl of group X + static const std::vector kGrpXCorruptedPrivRl; /// a single entry privrl for group X static const std::vector kGrpXPrivRlSingleEntry; /// verifier pre-computation data associated with pub_key_str @@ -89,6 +98,8 @@ class Epid11VerifierTest : public ::testing::Test { /// signature based revocation list static const std::vector kSigRl; + /// signature based revocation list for tests of msg containing all bytes + static const std::vector kSigRlForMsg0_255; /// signature based revocation list (empty rl) static const std::vector kEmptySigRl; diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verify-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/verify-test.cc similarity index 91% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verify-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/verify-test.cc index e755b158..84dbae86 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verify-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/verify-test.cc @@ -1,5 +1,5 @@ /*############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,16 +19,17 @@ * \brief Epid11Verify unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { -#include "epid/verifier/1.1/api.h" #include "epid/common/src/endian_convert.h" +#include "epid/verifier/1.1/api.h" } -#include "epid/verifier/1.1/unittests/verifier-testhelper.h" #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/verifier/1.1/unittests/verifier-testhelper.h" namespace { @@ -47,6 +48,20 @@ TEST_F(Epid11VerifierTest, VerifyFailsGivenNullParameters) { sig.size(), nullptr, msg.size())); } +TEST_F(Epid11VerifierTest, VerifyFailsGivenTooShortSigLen) { + Epid11VerifierCtxObj verifier(this->kPubKeyStr); + auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0; + auto msg = this->kMsg0; + + EXPECT_EQ(kEpidBadArgErr, + Epid11Verify(verifier, (Epid11Signature const*)sig.data(), 0, + msg.data(), msg.size())); + EXPECT_EQ(kEpidBadArgErr, + Epid11Verify(verifier, (Epid11Signature const*)sig.data(), + sizeof(Epid11Signature) - sizeof(Epid11NrProof) - 1, + msg.data(), msg.size())); +} + TEST_F(Epid11VerifierTest, VerifyFailsGivenSigLenTooShortForRlCount) { Epid11VerifierCtxObj verifier(this->kPubKeyStr); Epid11VerifierSetSigRl(verifier, (Epid11SigRl const*)this->kSigRl.data(), @@ -213,15 +228,14 @@ TEST_F(Epid11VerifierTest, VerifyFailsOnSigRlverNotMatchSigRlRlver) { auto bsn = this->kBsn0; auto sig_rl = this->kGrpXSigRlMember0Bsn0Msg0SingleEntry; auto sig_rl_size = sig_rl.size(); - auto sig = this->kGrpXSigRlMember0Bsn0Msg0FirstEntry; + auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0; Epid11SigRl sig_rl_wrong_ver = *(Epid11SigRl const*)sig_rl.data(); sig_rl_wrong_ver.version.data[0]++; THROW_ON_EPIDERR( Epid11VerifierSetSigRl(verifier, &sig_rl_wrong_ver, sig_rl_size)); THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidBadArgErr, - Epid11Verify(verifier, (Epid11Signature const*)sig.data(), - sig.size(), msg.data(), msg.size())); + EXPECT_EQ(kEpidErr, Epid11Verify(verifier, (Epid11Signature const*)sig.data(), + sig.size(), msg.data(), msg.size())); } TEST_F(Epid11VerifierTest, VerifyFailsOnSigN2NotMatchSigRlN2) { @@ -230,14 +244,16 @@ TEST_F(Epid11VerifierTest, VerifyFailsOnSigN2NotMatchSigRlN2) { Epid11VerifierCtxObj verifier(this->kPubKeyStr); auto msg = this->kMsg0; auto bsn = this->kBsn0; - auto sig_rl = this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry; - auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0SingleEntry; - THROW_ON_EPIDERR(Epid11VerifierSetSigRl( - verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size())); + auto* sig_rl = + (Epid11SigRl const*)this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry.data(); + size_t sig_rl_size = this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry.size(); + auto sig_raw = this->kSigGrpXMember0Sha256Bsn0Msg0SingleEntry; + Epid11Signature* sig = (Epid11Signature*)sig_raw.data(); + sig->rl_ver = sig_rl->version; + THROW_ON_EPIDERR(Epid11VerifierSetSigRl(verifier, sig_rl, sig_rl_size)); THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size())); - EXPECT_EQ(kEpidBadArgErr, - Epid11Verify(verifier, (Epid11Signature const*)sig.data(), - sig.size(), msg.data(), msg.size())); + EXPECT_EQ(kEpidBadArgErr, Epid11Verify(verifier, sig, sig_raw.size(), + msg.data(), msg.size())); } TEST_F(Epid11VerifierTest, VerifyFailsSigIsNotBasicAndSigRlIsNotProvided) { @@ -580,6 +596,21 @@ TEST_F(Epid11VerifierTest, VerifyRejectsSigFromPrivRlLastEntry) { sig.size(), msg.data(), msg.size())); } +TEST_F(Epid11VerifierTest, VerifyRejectsSigUsingCorruptedPrivRlEntry) { + auto& pub_key = this->kPubKeyStr; + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + auto& priv_rl = this->kGrpXCorruptedPrivRl; + auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0; + Epid11VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(Epid11VerifierSetPrivRl( + verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size())); + THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigRevokedInPrivRl, + Epid11Verify(verifier, (Epid11Signature const*)sig.data(), + sig.size(), msg.data(), msg.size())); +} + ///////////////////////////////////////////////////////////////////// // // 4.1.2 step 32 - For i = 0, ..., n2-1, the verifier verifies @@ -717,4 +748,25 @@ TEST_F(Epid11VerifierTest, VerifyAcceptsSigWithRandomBaseNameAllRl) { sig.size(), msg.data(), msg.size())); } +TEST_F(Epid11VerifierTest, VerifyAcceptsSigGivenMsgContainingAllPossibleBytes) { + auto& pub_key = this->kPubKeyStrForMsg0_255; + auto& msg = this->kData_0_255; + auto& grp_rl = this->kGroupRlEmptyBuf; + auto& priv_rl = this->kGrpXPrivRl; + auto& sig = this->kSigGrp01Member0Sha256kBsn0Data_0_255; + + Epid11VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(Epid11VerifierSetGroupRl( + verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size())); + THROW_ON_EPIDERR(Epid11VerifierSetPrivRl( + verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size())); + THROW_ON_EPIDERR(Epid11VerifierSetSigRl( + verifier, (Epid11SigRl const*)this->kSigRlForMsg0_255.data(), + this->kSigRlForMsg0_255.size())); + + EXPECT_EQ(kEpidSigValid, + Epid11Verify(verifier, (Epid11Signature const*)sig.data(), + sig.size(), msg.data(), msg.size())); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifybasic-test.cc b/external/epid-sdk/epid/verifier/1.1/unittests/verifybasic-test.cc similarity index 86% rename from external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifybasic-test.cc rename to external/epid-sdk/epid/verifier/1.1/unittests/verifybasic-test.cc index 6f882062..d76a00a7 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/1.1/unittests/verifybasic-test.cc +++ b/external/epid-sdk/epid/verifier/1.1/unittests/verifybasic-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,15 +19,16 @@ * \brief Epid11VerifyBasicSig unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/1.1/api.h" } +#include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" #include "epid/verifier/1.1/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h" namespace { @@ -96,4 +97,16 @@ TEST_F(Epid11VerifierTest, VerifyBasicSigCanVerifyWithBasename) { Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); } +TEST_F(Epid11VerifierTest, + VerifyBasicSigCanVerifyMsgContainingAllPossibleBytes) { + Epid11VerifierCtxObj verifier(kPubKeyStrForMsg0_255); + auto const& sig = (Epid11Signature const*)this + ->kSigGrp01Member0Sha256kBsn0Data_0_255.data(); + const Epid11BasicSignature basic_sig = sig->sigma0; + + auto& msg = this->kData_0_255; + EXPECT_EQ(kEpidNoErr, + Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/Makefile b/external/epid-sdk/epid/verifier/Makefile similarity index 82% rename from external/epid-sdk-3.0.0/epid/verifier/Makefile rename to external/epid-sdk/epid/verifier/Makefile index 4d151c63..ee3386bf 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/Makefile +++ b/external/epid-sdk/epid/verifier/Makefile @@ -19,24 +19,27 @@ VERIFIER_11_INCLUDE_DIR = ../../1.1 VERIFIER_SRC = $(wildcard ./src/*.c) VERIFIER_SRC += $(wildcard ./1.1/src/*.c) -VERIFIER_OBJ = $(sort $(VERIFIER_SRC:.c=.o)) +VERIFIER_OBJ = $(VERIFIER_SRC:.c=.o) VERIFIER_LIB = ./libverifier.a -VERIFIER_UTEST_EXE = ./verifier-utest +VERIFIER_UTEST_EXE = ./verifier-utest$(EXE_EXTENSION) VERIFIER_UTEST_SRC = $(wildcard ./unittests/*.cc) VERIFIER_UTEST_SRC += $(wildcard ./1.1/unittests/*.cc) -VERIFIER_UTEST_OBJ = $(sort $(VERIFIER_UTEST_SRC:.cc=.o)) +VERIFIER_UTEST_OBJ = $(VERIFIER_UTEST_SRC:.cc=.o) LIB_VERIFIER_DIR = . LIB_COMMON_TESTHELPER_DIR = ../common-testhelper LIB_COMMON_DIR = ../common LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src -LIB_IPPCPEPID_DIR = ../../ext/ipp/sources/ippcpepid/src #set flags for linker LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \ - -L$(LIB_VERIFIER_DIR) -L$(LIB_COMMON_DIR) -L$(LIB_IPPCPEPID_DIR) \ + -L$(LIB_VERIFIER_DIR) -L$(LIB_COMMON_DIR) \ -L$(LIB_IPPCP_DIR) -lgtest -lcommon-testhelper -lverifier -lcommon \ - -lippcpepid -lippcp + -lippcp + +ifneq ($(TSS_PATH),) + CFLAGS += -DTPM_TSS +endif #target part $(VERIFIER_OBJ): %.o: %.c @@ -45,13 +48,13 @@ $(VERIFIER_OBJ): %.o: %.c $(VERIFIER_LIB): $(VERIFIER_OBJ) $(AR) rc $(VERIFIER_LIB) $(VERIFIER_OBJ) - ranlib $(VERIFIER_LIB) + $(RANLIB) $(VERIFIER_LIB) $(VERIFIER_UTEST_EXE): $(VERIFIER_UTEST_OBJ) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) + $(CXX) -o $@ $^ $(LDFLAGS) $(VERIFIER_UTEST_OBJ): %.o: %.cc - $(CXX) -o $@ $(CXXFLAGS) -I$(VERIFIER_INCLUDE_DIR) \ + $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(VERIFIER_INCLUDE_DIR) \ -I$(VERIFIER_11_INCLUDE_DIR) -I$(GTEST_INCLUDE_DIR) -c $^ @@ -72,11 +75,13 @@ ifneq (,$(wildcard $(VERIFIER_UTEST_EXE))) cp $(VERIFIER_UTEST_EXE) '$(TEST_INSTALL_DIR)' endif -check: $(VERIFIER_UTEST_EXE) run +utest: $(VERIFIER_UTEST_EXE) -run: +run_utest: $(VERIFIER_UTEST_EXE) $(GTEST_FLAGS) +check: utest run_utest + clean: rm -f $(VERIFIER_OBJ) \ $(VERIFIER_LIB) \ diff --git a/external/epid-sdk-3.0.0/epid/verifier/api.h b/external/epid-sdk/epid/verifier/api.h similarity index 95% rename from external/epid-sdk-3.0.0/epid/verifier/api.h rename to external/epid-sdk/epid/verifier/api.h index 7a8b7905..48db5bd8 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/api.h +++ b/external/epid-sdk/epid/verifier/api.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,13 +17,9 @@ #define EPID_VERIFIER_API_H_ #include +#include "epid/common/errors.h" #include "epid/common/stdtypes.h" #include "epid/common/types.h" -#include "epid/common/errors.h" - -#ifdef __cplusplus -extern "C"{ -#endif /*! * \file @@ -37,6 +33,8 @@ extern "C"{ Defines the APIs needed by Intel(R) EPID verifiers. Each verifier context (::VerifierCtx) represents a verifier for a single group. + To use this module, include the header epid/verifier/api.h. + \ingroup EpidModule @{ */ @@ -86,6 +84,10 @@ typedef struct VerifierPrecomp { \see EpidVerifierDelete \see EpidVerifierWritePrecomp + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierCreate(GroupPubKey const* pub_key, VerifierPrecomp const* precomp, @@ -103,6 +105,10 @@ EpidStatus EpidVerifierCreate(GroupPubKey const* pub_key, The verifier context. Can be NULL. \see EpidVerifierCreate + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ void EpidVerifierDelete(VerifierCtx** ctx); @@ -116,6 +122,10 @@ void EpidVerifierDelete(VerifierCtx** ctx); \note If the result is not ::kEpidNoErr the content of precomp is undefined. + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierWritePrecomp(VerifierCtx const* ctx, VerifierPrecomp* precomp); @@ -151,6 +161,10 @@ EpidStatus EpidVerifierWritePrecomp(VerifierCtx const* ctx, pointed to by the verifier is undefined. \see EpidVerifierCreate + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetPrivRl(VerifierCtx* ctx, PrivRl const* priv_rl, size_t priv_rl_size); @@ -186,6 +200,10 @@ EpidStatus EpidVerifierSetPrivRl(VerifierCtx* ctx, PrivRl const* priv_rl, to by the verifier is undefined. \see EpidVerifierCreate + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetSigRl(VerifierCtx* ctx, SigRl const* sig_rl, size_t sig_rl_size); @@ -221,6 +239,10 @@ EpidStatus EpidVerifierSetSigRl(VerifierCtx* ctx, SigRl const* sig_rl, to by the verifier is undefined. \see EpidVerifierCreate + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetGroupRl(VerifierCtx* ctx, GroupRl const* grp_rl, size_t grp_rl_size); @@ -252,6 +274,10 @@ EpidStatus EpidVerifierSetGroupRl(VerifierCtx* ctx, GroupRl const* grp_rl, \see EpidVerifierCreate \see EpidBlacklistSig \see EpidWriteVerifierRl + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetVerifierRl(VerifierCtx* ctx, VerifierRl const* ver_rl, size_t ver_rl_size); @@ -271,6 +297,10 @@ EpidStatus EpidVerifierSetVerifierRl(VerifierCtx* ctx, VerifierRl const* ver_rl, \see EpidVerifierCreate \see ::HashAlg + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetHashAlg(VerifierCtx* ctx, HashAlg hash_alg); @@ -292,6 +322,9 @@ EpidStatus EpidVerifierSetHashAlg(VerifierCtx* ctx, HashAlg hash_alg); \see EpidVerifierCreate + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerifierSetBasename(VerifierCtx* ctx, void const* basename, size_t basename_len); @@ -331,6 +364,10 @@ EpidStatus EpidVerifierSetBasename(VerifierCtx* ctx, void const* basename, \see EpidVerifierCreate \see EpidSignBasic \see EpidSign + + \b Example + + \ref UserManual_VerifyingAnIntelEpidSignature */ EpidStatus EpidVerify(VerifierCtx const* ctx, EpidSignature const* sig, size_t sig_len, void const* msg, size_t msg_len); @@ -548,8 +585,4 @@ EpidStatus EpidBlacklistSig(VerifierCtx* ctx, EpidSignature const* sig, /*! @} */ -#ifdef __cplusplus -} -#endif - #endif // EPID_VERIFIER_API_H_ diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/check_privrl_entry.c b/external/epid-sdk/epid/verifier/src/check_privrl_entry.c similarity index 84% rename from external/epid-sdk-3.0.0/epid/verifier/src/check_privrl_entry.c rename to external/epid-sdk/epid/verifier/src/check_privrl_entry.c index 631e19fe..23577aec 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/src/check_privrl_entry.c +++ b/external/epid-sdk/epid/verifier/src/check_privrl_entry.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ EpidStatus EpidCheckPrivRlEntry(VerifierCtx const* ctx, EcPoint* k = NULL; EcPoint* t4 = NULL; EcGroup* G1 = NULL; + FfElement* ff_elem = NULL; if (!ctx || !sig || !f) { return kEpidBadArgErr; } @@ -38,7 +39,12 @@ EpidStatus EpidCheckPrivRlEntry(VerifierCtx const* ctx, // Section 4.1.2 Step 4.b For i = 0, ... , n1-1, the verifier computes t4 // =G1.exp(B, f[i]) and verifies that G1.isEqual(t4, K) = false. bool compare_result = false; + FiniteField* Fp = ctx->epid2_params->Fp; G1 = ctx->epid2_params->G1; + result = NewFfElement(Fp, &ff_elem); + if (kEpidNoErr != result) { + break; + } result = NewEcPoint(G1, &b); if (kEpidNoErr != result) { break; @@ -51,6 +57,11 @@ EpidStatus EpidCheckPrivRlEntry(VerifierCtx const* ctx, if (kEpidNoErr != result) { break; } + // ReadFfElement checks that the value f is in the field + result = ReadFfElement(Fp, (BigNumStr const*)f, sizeof(BigNumStr), ff_elem); + if (kEpidNoErr != result) { + break; + } result = ReadEcPoint(G1, &sig->B, sizeof(sig->B), b); if (kEpidNoErr != result) { break; @@ -74,7 +85,7 @@ EpidStatus EpidCheckPrivRlEntry(VerifierCtx const* ctx, result = kEpidNoErr; } } while (0); - + DeleteFfElement(&ff_elem); DeleteEcPoint(&t4); DeleteEcPoint(&k); DeleteEcPoint(&b); diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/context.c b/external/epid-sdk/epid/verifier/src/context.c similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/src/context.c rename to external/epid-sdk/epid/verifier/src/context.c index 811dabbd..c5737d1f 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/src/context.c +++ b/external/epid-sdk/epid/verifier/src/context.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,14 +18,14 @@ * \file * \brief Verifier context implementation. */ -#include -#include "epid/verifier/api.h" #include "epid/verifier/src/context.h" -#include "epid/common/src/epid2params.h" -#include "epid/common/src/memory.h" +#include #include "epid/common/math/pairing.h" #include "epid/common/src/endian_convert.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/memory.h" #include "epid/common/src/sigrlvalid.h" +#include "epid/verifier/api.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ @@ -127,8 +127,11 @@ EpidStatus EpidVerifierCreate(GroupPubKey const* pubkey, break; } - // set SHA512 as the default hash algorithm + // set the default hash algorithm verifier_ctx->hash_alg = kSha512; +#ifdef TPM_TSS // if build for TSS, make Sha256 default + verifier_ctx->hash_alg = kSha256; +#endif // Internal representation of Epid2Params result = CreateEpid2Params(&verifier_ctx->epid2_params); @@ -481,9 +484,9 @@ EpidStatus EpidBlacklistSig(VerifierCtx* ctx, EpidSignature const* sig, result = kEpidBadArgErr; break; } - ver_rl = - SAFE_REALLOC(ctx->verifier_rl, EpidGetVerifierRlSize(ctx) + - sizeof(((VerifierRl*)0)->K[0])); + ver_rl = SAFE_REALLOC( + ctx->verifier_rl, + EpidGetVerifierRlSize(ctx) + sizeof(((VerifierRl*)0)->K[0])); if (!ver_rl) { result = kEpidMemAllocErr; break; @@ -507,7 +510,8 @@ EpidStatus EpidVerifierSetHashAlg(VerifierCtx* ctx, HashAlg hash_alg) { if (!ctx) { return kEpidBadArgErr; } - if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg) + if (kSha256 != hash_alg && kSha384 != hash_alg && kSha512 != hash_alg && + kSha512_256 != hash_alg) return kEpidBadArgErr; if (ctx->hash_alg != hash_alg) { @@ -554,7 +558,8 @@ EpidStatus EpidVerifierSetBasename(VerifierCtx* ctx, void const* basename, break; } - result = EcHash(G1, basename, basename_len, ctx->hash_alg, basename_hash); + result = + EcHash(G1, basename, basename_len, ctx->hash_alg, basename_hash, NULL); if (kEpidNoErr != result) { break; } @@ -613,22 +618,22 @@ static EpidStatus DoPrecomputation(VerifierCtx* ctx) { ps_ctx = params->pairing_state; // do precomputation // 1. The verifier computes e12 = pairing(h1, g2). - result = Pairing(ps_ctx, e12, pub_key->h1, params->g2); + result = Pairing(ps_ctx, pub_key->h1, params->g2, e12); if (kEpidNoErr != result) { return result; } // 2. The verifier computes e22 = pairing(h2, g2). - result = Pairing(ps_ctx, e22, pub_key->h2, params->g2); + result = Pairing(ps_ctx, pub_key->h2, params->g2, e22); if (kEpidNoErr != result) { return result; } // 3. The verifier computes e2w = pairing(h2, w). - result = Pairing(ps_ctx, e2w, pub_key->h2, pub_key->w); + result = Pairing(ps_ctx, pub_key->h2, pub_key->w, e2w); if (kEpidNoErr != result) { return result; } // 4. The verifier computes eg12 = pairing(g1, g2). - result = Pairing(ps_ctx, eg12, params->g1, params->g2); + result = Pairing(ps_ctx, params->g1, params->g2, eg12); if (kEpidNoErr != result) { return result; } diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/context.h b/external/epid-sdk/epid/verifier/src/context.h similarity index 98% rename from external/epid-sdk-3.0.0/epid/verifier/src/context.h rename to external/epid-sdk/epid/verifier/src/context.h index 705c55ed..783e4519 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/src/context.h +++ b/external/epid-sdk/epid/verifier/src/context.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,11 @@ * \file * \brief Verifier context interface. */ -#include "epid/common/src/grouppubkey.h" #include "epid/common/math/ecgroup.h" #include "epid/common/math/finitefield.h" -#include "epid/common/src/epid2params.h" #include "epid/common/src/commitment.h" +#include "epid/common/src/epid2params.h" +#include "epid/common/src/grouppubkey.h" /// Verifier context definition struct VerifierCtx { diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/nrverify.c b/external/epid-sdk/epid/verifier/src/nrverify.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/src/nrverify.c rename to external/epid-sdk/epid/verifier/src/nrverify.c diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/sigs_linked.c b/external/epid-sdk/epid/verifier/src/sigs_linked.c similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/src/sigs_linked.c rename to external/epid-sdk/epid/verifier/src/sigs_linked.c diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/verify.c b/external/epid-sdk/epid/verifier/src/verify.c similarity index 99% rename from external/epid-sdk-3.0.0/epid/verifier/src/verify.c rename to external/epid-sdk/epid/verifier/src/verify.c index 6fce3db3..b0b60aea 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/src/verify.c +++ b/external/epid-sdk/epid/verifier/src/verify.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ * \brief Verify implementation. */ #include +#include "epid/common/src/endian_convert.h" #include "epid/verifier/api.h" #include "epid/verifier/src/context.h" -#include "epid/common/src/endian_convert.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ @@ -146,7 +146,7 @@ EpidStatus EpidVerify(VerifierCtx const* ctx, EpidSignature const* sig, // mismatch, abort and output "operation failed". if (0 != memcmp(&ctx->sig_rl->version, &sig->rl_ver, sizeof(ctx->sig_rl->version))) { - return kEpidBadArgErr; + return kEpidErr; } // c. The verifier verifies that n2 in Sigma and in SigRL match. If diff --git a/external/epid-sdk-3.0.0/epid/verifier/src/verifybasic.c b/external/epid-sdk/epid/verifier/src/verifybasic.c similarity index 98% rename from external/epid-sdk-3.0.0/epid/verifier/src/verifybasic.c rename to external/epid-sdk/epid/verifier/src/verifybasic.c index 3e7b15b1..119f7eea 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/src/verifybasic.c +++ b/external/epid-sdk/epid/verifier/src/verifybasic.c @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ * \brief VerifyBasicSig implementation. */ +#include "epid/common/src/memory.h" #include "epid/verifier/api.h" #include "epid/verifier/src/context.h" -#include "epid/common/src/memory.h" /// Handle SDK Error with Break #define BREAK_ON_EPID_ERROR(ret) \ @@ -245,7 +245,7 @@ EpidStatus EpidVerifyBasicSig(VerifierCtx const* ctx, BasicSignature const* sig, BREAK_ON_EPID_ERROR(res); } // k. The verifier computes R2 = pairing(T, t1). - res = Pairing(ctx->epid2_params->pairing_state, R2, T, t1); + res = Pairing(ctx->epid2_params->pairing_state, T, t1, R2); BREAK_ON_EPID_ERROR(res); // l. The verifier compute t2 = GT.multiExp(e12, sf, e22, sb, // e2w, sa, eg12, c). diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/check_privrl_entry-test.cc b/external/epid-sdk/epid/verifier/unittests/check_privrl_entry-test.cc similarity index 97% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/check_privrl_entry-test.cc rename to external/epid-sdk/epid/verifier/unittests/check_privrl_entry-test.cc index 20ceb079..4efc40e1 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/check_privrl_entry-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/check_privrl_entry-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,15 +19,16 @@ * \brief CheckPrivRlEntry unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/api.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" namespace { diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/context-test.cc b/external/epid-sdk/epid/verifier/unittests/context-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/context-test.cc rename to external/epid-sdk/epid/verifier/unittests/context-test.cc index 119baeaf..1054bd51 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/context-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/context-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,20 +19,21 @@ * \brief VerifierCreate unit tests. */ -#include #include +#include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { +#include "epid/common/src/endian_convert.h" #include "epid/verifier/api.h" #include "epid/verifier/src/context.h" -#include "epid/common/src/endian_convert.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" bool operator==(VerifierPrecomp const& lhs, VerifierPrecomp const& rhs) { return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs)); } @@ -990,18 +991,47 @@ TEST_F(EpidVerifierTest, EXPECT_EQ(rlver_expected, ver_rl->version); // missing K checks } +TEST_F(EpidVerifierTest, BlacklistSigWorksForMsgContainingAllPossibleBytes) { + VerifierCtxObj verifier(this->kPubKeySigRlVerify); + auto sig = this->kSigGrp01Member0Sha512kBsn0Data_0_255; + auto msg = this->kData_0_255; + auto bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidNoErr, EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), + sig.size(), msg.data(), msg.size())); + + std::vector ver_rl_vec(EpidGetVerifierRlSize(verifier)); + VerifierRl* ver_rl = (VerifierRl*)ver_rl_vec.data(); + size_t ver_rl_size = ver_rl_vec.size(); + + THROW_ON_EPIDERR(EpidWriteVerifierRl(verifier, ver_rl, ver_rl_size)); + + OctStr32 n4_expected = {0x00, 0x00, 0x00, 0x01}; + OctStr32 rlver_expected = {0x00, 0x00, 0x00, 0x01}; + EXPECT_EQ(n4_expected, ver_rl->n4); + EXPECT_EQ(rlver_expected, ver_rl->version); +} ////////////////////////////////////////////////////////////////////////// // EpidVerifierSetHashAlg TEST_F(EpidVerifierTest, SetHashAlgFailsGivenNullPointer) { EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(nullptr, kSha256)); } -TEST_F(EpidVerifierTest, SetHashAlgCanSetValidAlgoritm) { +TEST_F(EpidVerifierTest, CanSetHashAlgoToSHA256) { VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha256)); +} +TEST_F(EpidVerifierTest, CanSetHashAlgoToSHA384) { + VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha384)); +} +TEST_F(EpidVerifierTest, CanSetHashAlgoToSHA512) { + VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha512)); - // DE2089 - SHA-512/256 Hash Alg is not supported by EpidMemberSetHashAlg - // EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha512_256)); +} +TEST_F(EpidVerifierTest, CanSetHashAlgoToSHA512256) { + VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); + EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha512_256)); } TEST_F(EpidVerifierTest, SetHashAlgCanFailForNonSupportedAlgoritms) { VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); @@ -1071,4 +1101,11 @@ TEST_F(EpidVerifierTest, SetBasenameResetsVerifierBlacklist) { EXPECT_EQ(nullptr, ctx->verifier_rl); } +TEST_F(EpidVerifierTest, SetBasenameAcceptsBsnContainingAllPossibleBytes) { + VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr); + VerifierCtx* ctx = verifier; + auto& basename = this->kData_0_255; + EXPECT_EQ(kEpidNoErr, + EpidVerifierSetBasename(ctx, basename.data(), basename.size())); +} } // namespace diff --git a/external/epid-sdk-3.0.0/epid/common/math/unittests/main-test.cc b/external/epid-sdk/epid/verifier/unittests/main-test.cc similarity index 90% rename from external/epid-sdk-3.0.0/epid/common/math/unittests/main-test.cc rename to external/epid-sdk/epid/verifier/unittests/main-test.cc index 70f2d3a1..a8bb2fa9 100644 --- a/external/epid-sdk-3.0.0/epid/common/math/unittests/main-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/main-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * \brief Main entry point for unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" int main(int argc, char** argv) { diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/nrverify-test.cc b/external/epid-sdk/epid/verifier/unittests/nrverify-test.cc similarity index 85% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/nrverify-test.cc rename to external/epid-sdk/epid/verifier/unittests/nrverify-test.cc index 9eb7e089..2b0f5537 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/nrverify-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/nrverify-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,15 +19,16 @@ * \brief NrVerify unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/api.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" namespace { @@ -177,25 +178,32 @@ TEST_F(EpidVerifierTest, NrVerifyRejectsSigWithValidCommitmentDiffHashAlg) { // Refer to Section 7.1 for hash operation over a // prime field. // result must be kEpidBadArgErr - VerifierCtxObj verifier(this->kGrp01Key); + VerifierCtxObj verifier(this->kGrpXKey); EpidSignature const* epid_signature_sha256 = reinterpret_cast( - this->kSigGrp01Member0Sha256RandombaseTest0.data()); + this->kSigGrpXMember0Sha256RandbaseMsg0.data()); EpidSignature const* epid_signature_sha384 = reinterpret_cast( - this->kSigGrp01Member0Sha384RandombaseTest0.data()); - SigRl const* sig_rl = - reinterpret_cast(this->kGrp01SigRl.data()); + this->kSigGrpXMember0Sha384RandbaseMsg0.data()); + EpidSignature const* epid_signature_sha512 = + reinterpret_cast( + this->kSigGrpXMember0Sha512RandbaseMsg0.data()); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha384)); EXPECT_EQ(kEpidBadArgErr, EpidNrVerify(verifier, &epid_signature_sha256->sigma0, - this->kTest0.data(), this->kTest0.size(), - &sig_rl->bk[0], &epid_signature_sha256->sigma[0])); + this->kMsg0.data(), this->kMsg0.size(), &sig_rl->bk[0], + &epid_signature_sha256->sigma[0])); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); EXPECT_EQ(kEpidBadArgErr, EpidNrVerify(verifier, &epid_signature_sha384->sigma0, - this->kTest0.data(), this->kTest0.size(), - &sig_rl->bk[0], &epid_signature_sha384->sigma[0])); + this->kMsg0.data(), this->kMsg0.size(), &sig_rl->bk[0], + &epid_signature_sha384->sigma[0])); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512_256)); + EXPECT_EQ(kEpidBadArgErr, + EpidNrVerify(verifier, &epid_signature_sha512->sigma0, + this->kMsg0.data(), this->kMsg0.size(), &sig_rl->bk[0], + &epid_signature_sha512->sigma[0])); } ///////////////////////////////////////////////////////////////////// @@ -256,18 +264,29 @@ TEST_F(EpidVerifierTest, NrVerifyAcceptsSigWithRandomBaseNameSha512) { &epid_signature->sigma[0])); } -TEST_F(EpidVerifierTest, - DISABLED_NrVerifyAcceptsSigWithRandomBaseNameSha512256) { - VerifierCtxObj verifier(this->kGrp01Key); +TEST_F(EpidVerifierTest, NrVerifyAcceptsSigWithRandomBaseNameSha512256) { + VerifierCtxObj verifier(this->kGrpXKey); EpidSignature const* epid_signature = reinterpret_cast( - this->kSigGrp01Member0Sha512256RandombaseTest1.data()); - SigRl const* sig_rl = - reinterpret_cast(this->kGrp01SigRl.data()); + this->kSigGrpXMember0Sha512256RandombaseMsg0.data()); + SigRl const* sig_rl = reinterpret_cast(this->kGrpXSigRl.data()); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512_256)); EXPECT_EQ(kEpidSigValid, - EpidNrVerify(verifier, &epid_signature->sigma0, this->kTest1.data(), - this->kTest1.size(), &sig_rl->bk[0], + EpidNrVerify(verifier, &epid_signature->sigma0, this->kMsg0.data(), + this->kMsg0.size(), &sig_rl->bk[0], &epid_signature->sigma[0])); } +TEST_F(EpidVerifierTest, NrVerifyAcceptsMsgContainingAllPossibleBytes) { + VerifierCtxObj verifier(this->kPubKeySigRlVerify); + EpidSignature const* epid_signature = + (EpidSignature*)kSigGrp01Member0Sha512kBsn0Data_0_255.data(); + SigRl const* sig_rl = + reinterpret_cast(this->kGrp01SigRl.data()); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + EXPECT_EQ(kEpidSigValid, + EpidNrVerify(verifier, &epid_signature->sigma0, + this->kData_0_255.data(), this->kData_0_255.size(), + &sig_rl->bk[0], &epid_signature->sigma[0])); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/sigs_linked-test.cc b/external/epid-sdk/epid/verifier/unittests/sigs_linked-test.cc similarity index 96% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/sigs_linked-test.cc rename to external/epid-sdk/epid/verifier/unittests/sigs_linked-test.cc index a131cdb4..a7c7598a 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/sigs_linked-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/sigs_linked-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,14 +19,15 @@ * \brief AreSigsLinkable unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/api.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" #include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" namespace { diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc similarity index 95% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc index 0a05d35e..1f5b34ea 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc +++ b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/pub_key_sigrl_verify.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ ############################################################################*/ // group_pub_key 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xB3, 0x6F, 0xFF, 0x81, 0xE2, 0x1B, 0x17, 0xEB, 0x3D, + 0x00, 0x00, 0x2a, 0xB3, 0x6F, 0xFF, 0x81, 0xE2, 0x1B, 0x17, 0xEB, 0x3D, 0x75, 0x3D, 0x61, 0x7E, 0x27, 0xB0, 0xCB, 0xD0, 0x6D, 0x8F, 0x9D, 0x64, 0xCE, 0xE3, 0xCE, 0x43, 0x4C, 0x62, 0xFD, 0xB5, 0x80, 0xE0, 0x99, 0x3A, 0x07, 0x56, 0x80, 0xE0, 0x88, 0x59, 0xA4, 0xFD, 0xB5, 0xB7, 0x9D, 0xE9, diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_first.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_first.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_first.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_first.inc diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_last.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_last.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_last.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_last.inc diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_middle.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_middle.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/signature_sigrl_middle.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/signature_sigrl_middle.inc diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc similarity index 97% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc index eaa49b2e..11ba8c8d 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc +++ b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/sigrl_five_entries.inc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -31,83 +31,83 @@ 0x03, 0xD2, 0xC1, 0xEB, 0xC8, 0x74, 0xA0, 0x40, 0x32, 0x94, 0xCD, 0x5B, 0xC6, 0xCD, 0xA6, 0x4B, 0xC6, 0xF2, 0x4B, 0xB9, 0xB6, 0xC8, 0x41, 0x49, -0x71, 0xAC, 0x52, 0x30, 0xF0, 0xFE, 0x70, 0xF9, -0x95, 0x50, 0xAA, 0xE0, 0xD5, 0xC9, 0xE2, 0x1A, -0xEA, 0xB9, 0xB2, 0x0D, 0x6C, 0xB4, 0x40, 0x41, -0x06, 0x83, 0x82, 0xE6, 0x69, 0x72, 0xB3, 0x51, -0x54, 0x96, 0x07, 0xF0, 0xB8, 0x0D, 0x39, 0x25, -0x4E, 0x11, 0x81, 0xA1, 0xF8, 0xFE, 0x39, 0xF6, -0xAA, 0x70, 0x6C, 0x1D, 0x44, 0x38, 0x08, 0x6F, -0x4E, 0x0F, 0xA3, 0x6B, 0x8D, 0xD2, 0x29, 0x88, -0x23, 0x18, 0x56, 0x3E, 0x6D, 0x67, 0xDF, 0x54, -0x38, 0xCD, 0x42, 0x5B, 0x13, 0x2B, 0x32, 0xC6, -0x77, 0x19, 0x42, 0x0A, 0x04, 0x91, 0xBF, 0xFF, -0x90, 0x60, 0x83, 0xD9, 0x60, 0x4B, 0xBA, 0x93, - -0x39, 0x97, 0x09, 0x11, 0x30, 0xB0, 0x2A, 0x29, -0xA7, 0x9B, 0xF1, 0xEF, 0xE9, 0xE5, 0xC7, 0x03, -0x17, 0xE6, 0x4F, 0x6F, 0x49, 0x4D, 0xEB, 0x0F, -0xFD, 0x1C, 0x3F, 0xCE, 0xCC, 0xC8, 0x40, 0x6B, -0x23, 0xD3, 0xEC, 0x78, 0x78, 0x15, 0x4A, 0x34, -0x0F, 0xD1, 0xD3, 0xFA, 0xD2, 0xB2, 0x5A, 0xC9, -0xEC, 0xA2, 0x41, 0xE1, 0x46, 0x6D, 0xED, 0xB3, -0x4A, 0xA6, 0xDF, 0xB6, 0xC2, 0x11, 0x49, 0x0D, -0xC9, 0x23, 0xD9, 0x1D, 0x7A, 0xC8, 0x45, 0xAA, -0x02, 0xBA, 0x44, 0xE0, 0xA4, 0xF0, 0xC0, 0x51, -0xAE, 0x67, 0xB3, 0x88, 0x58, 0xB2, 0x92, 0xEA, -0x1D, 0x12, 0x6E, 0x49, 0xC3, 0x13, 0xEA, 0x8E, -0xB7, 0x99, 0x4F, 0x57, 0x7E, 0x06, 0x99, 0xE1, -0x3B, 0x59, 0x2C, 0xD1, 0x43, 0x5D, 0x9E, 0x68, -0xF2, 0x8E, 0x0C, 0xAF, 0x3E, 0x68, 0x6B, 0xD5, -0xD9, 0x3A, 0x30, 0xF4, 0x0B, 0x01, 0x49, 0x9B, - -0x76, 0xD1, 0xFF, 0xBE, 0xD4, 0xE4, 0x71, 0x78, -0x1A, 0xD4, 0x98, 0xFD, 0x00, 0x2C, 0x71, 0x76, -0x13, 0xB9, 0xF4, 0xF0, 0x22, 0x0A, 0xA1, 0x22, -0xDB, 0x59, 0x6A, 0xEC, 0xBC, 0x25, 0xDC, 0xAB, -0x14, 0x9B, 0x0A, 0x4E, 0x1C, 0x15, 0xD0, 0x6A, -0xD4, 0x3C, 0xDD, 0xE5, 0x26, 0x13, 0x6B, 0xB0, -0xAF, 0xD0, 0x93, 0xFF, 0x3A, 0x6A, 0xDC, 0x39, -0x64, 0x73, 0x77, 0x1F, 0x86, 0xAF, 0x69, 0x80, -0x1D, 0x85, 0x34, 0xF2, 0x71, 0x94, 0xDE, 0x90, -0xD5, 0xA8, 0x7B, 0x7D, 0x6F, 0xB5, 0xA8, 0x36, -0xD0, 0x2D, 0x85, 0xDE, 0x6E, 0x4D, 0xB8, 0x41, -0x57, 0x56, 0x33, 0xCA, 0xF3, 0x42, 0xA9, 0x04, -0x87, 0x38, 0x46, 0xC6, 0x8C, 0x29, 0x65, 0x53, -0xFC, 0xD6, 0x2C, 0xE7, 0x9B, 0x29, 0xDD, 0x70, -0x0C, 0xBE, 0x84, 0xE6, 0x7B, 0x97, 0xC0, 0x48, -0x61, 0x01, 0x97, 0x7A, 0xE4, 0x5C, 0xD5, 0xFB, - -0xFC, 0xF6, 0x00, 0xD1, 0xB9, 0x82, 0xAA, 0x79, -0x6C, 0x96, 0xE1, 0xB6, 0x15, 0x93, 0x4D, 0xF4, -0xFB, 0xBF, 0xBC, 0x3E, 0xE3, 0x87, 0xB6, 0xA3, -0xB5, 0xFD, 0x25, 0x42, 0xBC, 0x58, 0x52, 0x09, -0x4E, 0x99, 0x15, 0x66, 0x56, 0x44, 0x1C, 0x5D, -0xDE, 0x8F, 0xE0, 0x40, 0x08, 0x49, 0xDB, 0x4E, -0xDA, 0x8B, 0x77, 0x44, 0x3F, 0x77, 0xEE, 0x7B, -0x48, 0x0E, 0xCC, 0x5F, 0x1C, 0x05, 0x74, 0x6B, -0x2F, 0xD8, 0x1C, 0x01, 0x7E, 0xDF, 0x65, 0x7B, -0x17, 0x8F, 0xA7, 0xC3, 0x03, 0x04, 0x27, 0xEC, -0xFA, 0x0A, 0x22, 0x8E, 0x4E, 0xBF, 0x67, 0x9D, -0x81, 0xA2, 0x6D, 0xF4, 0x21, 0x66, 0xC5, 0x17, -0x3D, 0x55, 0x29, 0xF3, 0x53, 0x61, 0x26, 0x8D, -0xB5, 0x32, 0xF4, 0xD0, 0x94, 0x5D, 0xA9, 0x0E, -0x52, 0x2C, 0x48, 0x7B, 0xA4, 0xFE, 0x4F, 0x98, -0x5F, 0xF1, 0x4D, 0xD9, 0x69, 0xC4, 0x94, 0x70, - -0x72, 0x78, 0x08, 0xEE, 0x07, 0xE2, 0x27, 0x1F, -0x7B, 0x96, 0x64, 0xED, 0x20, 0x8E, 0x41, 0x4C, -0x3A, 0x03, 0x3D, 0x9E, 0x4C, 0xA2, 0x60, 0x9D, -0xD2, 0x3D, 0x03, 0x0D, 0xF6, 0x2D, 0x9A, 0x65, -0x30, 0xAB, 0x45, 0x2C, 0x1E, 0xA1, 0xE7, 0x3E, -0x2E, 0xFD, 0x13, 0x1B, 0xF0, 0x45, 0x04, 0xBB, -0x1B, 0x18, 0xCA, 0x11, 0x8B, 0xC8, 0xB7, 0x89, -0x27, 0x4E, 0xC4, 0x52, 0xA9, 0x2C, 0x1B, 0x4F, -0x86, 0x05, 0x9B, 0x8B, 0x5E, 0x75, 0xA7, 0x24, -0x03, 0x85, 0xCB, 0xAB, 0x84, 0xAD, 0x79, 0xCE, -0x89, 0x0F, 0x8D, 0x96, 0x9F, 0xBE, 0xDE, 0xF3, -0xA8, 0xA2, 0x1C, 0x96, 0x83, 0xB2, 0xC9, 0xC4, -0x2F, 0xB9, 0x68, 0x42, 0x5D, 0x40, 0x2F, 0x99, -0x7A, 0xFB, 0x7B, 0xD4, 0x69, 0x94, 0xA1, 0x27, -0x79, 0xD1, 0x25, 0xD5, 0x68, 0xB4, 0xB1, 0x6A, -0x6D, 0xCC, 0x0E, 0xB4, 0x28, 0xBA, 0x1C, 0x6D, +0x71, 0xAC, 0x52, 0x30, 0xF0, 0xFE, 0x70, 0xF9, +0x95, 0x50, 0xAA, 0xE0, 0xD5, 0xC9, 0xE2, 0x1A, +0xEA, 0xB9, 0xB2, 0x0D, 0x6C, 0xB4, 0x40, 0x41, +0x06, 0x83, 0x82, 0xE6, 0x69, 0x72, 0xB3, 0x51, +0x54, 0x96, 0x07, 0xF0, 0xB8, 0x0D, 0x39, 0x25, +0x4E, 0x11, 0x81, 0xA1, 0xF8, 0xFE, 0x39, 0xF6, +0xAA, 0x70, 0x6C, 0x1D, 0x44, 0x38, 0x08, 0x6F, +0x4E, 0x0F, 0xA3, 0x6B, 0x8D, 0xD2, 0x29, 0x88, +0x23, 0x18, 0x56, 0x3E, 0x6D, 0x67, 0xDF, 0x54, +0x38, 0xCD, 0x42, 0x5B, 0x13, 0x2B, 0x32, 0xC6, +0x77, 0x19, 0x42, 0x0A, 0x04, 0x91, 0xBF, 0xFF, +0x90, 0x60, 0x83, 0xD9, 0x60, 0x4B, 0xBA, 0x93, + +0x39, 0x97, 0x09, 0x11, 0x30, 0xB0, 0x2A, 0x29, +0xA7, 0x9B, 0xF1, 0xEF, 0xE9, 0xE5, 0xC7, 0x03, +0x17, 0xE6, 0x4F, 0x6F, 0x49, 0x4D, 0xEB, 0x0F, +0xFD, 0x1C, 0x3F, 0xCE, 0xCC, 0xC8, 0x40, 0x6B, +0x23, 0xD3, 0xEC, 0x78, 0x78, 0x15, 0x4A, 0x34, +0x0F, 0xD1, 0xD3, 0xFA, 0xD2, 0xB2, 0x5A, 0xC9, +0xEC, 0xA2, 0x41, 0xE1, 0x46, 0x6D, 0xED, 0xB3, +0x4A, 0xA6, 0xDF, 0xB6, 0xC2, 0x11, 0x49, 0x0D, +0xC9, 0x23, 0xD9, 0x1D, 0x7A, 0xC8, 0x45, 0xAA, +0x02, 0xBA, 0x44, 0xE0, 0xA4, 0xF0, 0xC0, 0x51, +0xAE, 0x67, 0xB3, 0x88, 0x58, 0xB2, 0x92, 0xEA, +0x1D, 0x12, 0x6E, 0x49, 0xC3, 0x13, 0xEA, 0x8E, +0xB7, 0x99, 0x4F, 0x57, 0x7E, 0x06, 0x99, 0xE1, +0x3B, 0x59, 0x2C, 0xD1, 0x43, 0x5D, 0x9E, 0x68, +0xF2, 0x8E, 0x0C, 0xAF, 0x3E, 0x68, 0x6B, 0xD5, +0xD9, 0x3A, 0x30, 0xF4, 0x0B, 0x01, 0x49, 0x9B, + +0x76, 0xD1, 0xFF, 0xBE, 0xD4, 0xE4, 0x71, 0x78, +0x1A, 0xD4, 0x98, 0xFD, 0x00, 0x2C, 0x71, 0x76, +0x13, 0xB9, 0xF4, 0xF0, 0x22, 0x0A, 0xA1, 0x22, +0xDB, 0x59, 0x6A, 0xEC, 0xBC, 0x25, 0xDC, 0xAB, +0x14, 0x9B, 0x0A, 0x4E, 0x1C, 0x15, 0xD0, 0x6A, +0xD4, 0x3C, 0xDD, 0xE5, 0x26, 0x13, 0x6B, 0xB0, +0xAF, 0xD0, 0x93, 0xFF, 0x3A, 0x6A, 0xDC, 0x39, +0x64, 0x73, 0x77, 0x1F, 0x86, 0xAF, 0x69, 0x80, +0x1D, 0x85, 0x34, 0xF2, 0x71, 0x94, 0xDE, 0x90, +0xD5, 0xA8, 0x7B, 0x7D, 0x6F, 0xB5, 0xA8, 0x36, +0xD0, 0x2D, 0x85, 0xDE, 0x6E, 0x4D, 0xB8, 0x41, +0x57, 0x56, 0x33, 0xCA, 0xF3, 0x42, 0xA9, 0x04, +0x87, 0x38, 0x46, 0xC6, 0x8C, 0x29, 0x65, 0x53, +0xFC, 0xD6, 0x2C, 0xE7, 0x9B, 0x29, 0xDD, 0x70, +0x0C, 0xBE, 0x84, 0xE6, 0x7B, 0x97, 0xC0, 0x48, +0x61, 0x01, 0x97, 0x7A, 0xE4, 0x5C, 0xD5, 0xFB, + +0xFC, 0xF6, 0x00, 0xD1, 0xB9, 0x82, 0xAA, 0x79, +0x6C, 0x96, 0xE1, 0xB6, 0x15, 0x93, 0x4D, 0xF4, +0xFB, 0xBF, 0xBC, 0x3E, 0xE3, 0x87, 0xB6, 0xA3, +0xB5, 0xFD, 0x25, 0x42, 0xBC, 0x58, 0x52, 0x09, +0x4E, 0x99, 0x15, 0x66, 0x56, 0x44, 0x1C, 0x5D, +0xDE, 0x8F, 0xE0, 0x40, 0x08, 0x49, 0xDB, 0x4E, +0xDA, 0x8B, 0x77, 0x44, 0x3F, 0x77, 0xEE, 0x7B, +0x48, 0x0E, 0xCC, 0x5F, 0x1C, 0x05, 0x74, 0x6B, +0x2F, 0xD8, 0x1C, 0x01, 0x7E, 0xDF, 0x65, 0x7B, +0x17, 0x8F, 0xA7, 0xC3, 0x03, 0x04, 0x27, 0xEC, +0xFA, 0x0A, 0x22, 0x8E, 0x4E, 0xBF, 0x67, 0x9D, +0x81, 0xA2, 0x6D, 0xF4, 0x21, 0x66, 0xC5, 0x17, +0x3D, 0x55, 0x29, 0xF3, 0x53, 0x61, 0x26, 0x8D, +0xB5, 0x32, 0xF4, 0xD0, 0x94, 0x5D, 0xA9, 0x0E, +0x52, 0x2C, 0x48, 0x7B, 0xA4, 0xFE, 0x4F, 0x98, +0x5F, 0xF1, 0x4D, 0xD9, 0x69, 0xC4, 0x94, 0x70, + +0x72, 0x78, 0x08, 0xEE, 0x07, 0xE2, 0x27, 0x1F, +0x7B, 0x96, 0x64, 0xED, 0x20, 0x8E, 0x41, 0x4C, +0x3A, 0x03, 0x3D, 0x9E, 0x4C, 0xA2, 0x60, 0x9D, +0xD2, 0x3D, 0x03, 0x0D, 0xF6, 0x2D, 0x9A, 0x65, +0x30, 0xAB, 0x45, 0x2C, 0x1E, 0xA1, 0xE7, 0x3E, +0x2E, 0xFD, 0x13, 0x1B, 0xF0, 0x45, 0x04, 0xBB, +0x1B, 0x18, 0xCA, 0x11, 0x8B, 0xC8, 0xB7, 0x89, +0x27, 0x4E, 0xC4, 0x52, 0xA9, 0x2C, 0x1B, 0x4F, +0x86, 0x05, 0x9B, 0x8B, 0x5E, 0x75, 0xA7, 0x24, +0x03, 0x85, 0xCB, 0xAB, 0x84, 0xAD, 0x79, 0xCE, +0x89, 0x0F, 0x8D, 0x96, 0x9F, 0xBE, 0xDE, 0xF3, +0xA8, 0xA2, 0x1C, 0x96, 0x83, 0xB2, 0xC9, 0xC4, +0x2F, 0xB9, 0x68, 0x42, 0x5D, 0x40, 0x2F, 0x99, +0x7A, 0xFB, 0x7B, 0xD4, 0x69, 0x94, 0xA1, 0x27, +0x79, 0xD1, 0x25, 0xD5, 0x68, 0xB4, 0xB1, 0x6A, +0x6D, 0xCC, 0x0E, 0xB4, 0x28, 0xBA, 0x1C, 0x6D, diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/sigrl_single_entry.inc b/external/epid-sdk/epid/verifier/unittests/testdata/sigrl/sigrl_single_entry.inc similarity index 100% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/testdata/sigrl/sigrl_single_entry.inc rename to external/epid-sdk/epid/verifier/unittests/testdata/sigrl/sigrl_single_entry.inc diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.cc b/external/epid-sdk/epid/verifier/unittests/verifier-testhelper.cc similarity index 87% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.cc rename to external/epid-sdk/epid/verifier/unittests/verifier-testhelper.cc index ab9d8707..68130dc2 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.cc +++ b/external/epid-sdk/epid/verifier/unittests/verifier-testhelper.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,12 +22,12 @@ #include "epid/verifier/unittests/verifier-testhelper.h" const G1ElemStr EpidVerifierTest::kG1IdentityStr = { - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, - {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}; + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}, + {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}}; const GroupPubKey EpidVerifierTest::kPubKeyStr = { // gid @@ -36,60 +36,60 @@ const GroupPubKey EpidVerifierTest::kPubKeyStr = { 0x00, 0x00, 0x00, 0x2A, }, // h1 - {{0xB3, 0x6F, 0xFF, 0x81, 0xE2, 0x1B, 0x17, 0xEB, 0x3D, 0x75, 0x3D, 0x61, - 0x7E, 0x27, 0xB0, 0xCB, 0xD0, 0x6D, 0x8F, 0x9D, 0x64, 0xCE, 0xE3, 0xCE, - 0x43, 0x4C, 0x62, 0xFD, 0xB5, 0x80, 0xE0, 0x99}, - {0x3A, 0x07, 0x56, 0x80, 0xE0, 0x88, 0x59, 0xA4, 0xFD, 0xB5, 0xB7, 0x9D, - 0xE9, 0x4D, 0xAE, 0x9C, 0xEE, 0x3D, 0x66, 0x42, 0x82, 0x45, 0x7E, 0x7F, - 0xD8, 0x69, 0x3E, 0xA1, 0x74, 0xF4, 0x59, 0xEE}}, + {{0xB3, 0x6F, 0xFF, 0x81, 0xE2, 0x1B, 0x17, 0xEB, 0x3D, 0x75, 0x3D, + 0x61, 0x7E, 0x27, 0xB0, 0xCB, 0xD0, 0x6D, 0x8F, 0x9D, 0x64, 0xCE, + 0xE3, 0xCE, 0x43, 0x4C, 0x62, 0xFD, 0xB5, 0x80, 0xE0, 0x99}, + {0x3A, 0x07, 0x56, 0x80, 0xE0, 0x88, 0x59, 0xA4, 0xFD, 0xB5, 0xB7, + 0x9D, 0xE9, 0x4D, 0xAE, 0x9C, 0xEE, 0x3D, 0x66, 0x42, 0x82, 0x45, + 0x7E, 0x7F, 0xD8, 0x69, 0x3E, 0xA1, 0x74, 0xF4, 0x59, 0xEE}}, // h2 - {{0xD2, 0x74, 0x2E, 0x9F, 0x63, 0xC2, 0x51, 0x8E, 0xD5, 0xDB, 0xCA, 0x1C, - 0x54, 0x74, 0x10, 0x7B, 0xDC, 0x99, 0xED, 0x42, 0xD5, 0x5B, 0xA7, 0x04, - 0x29, 0x66, 0x61, 0x63, 0xBC, 0xDD, 0x7F, 0xE1}, - {0x76, 0x5D, 0xC0, 0x6E, 0xE3, 0x14, 0xAC, 0x72, 0x48, 0x12, 0x0A, 0xA6, - 0xE8, 0x5B, 0x08, 0x7B, 0xDA, 0x3F, 0x51, 0x7D, 0xDE, 0x4C, 0xEA, 0xCB, - 0x93, 0xA5, 0x6E, 0xCC, 0xE7, 0x8E, 0x10, 0x84}}, + {{0xD2, 0x74, 0x2E, 0x9F, 0x63, 0xC2, 0x51, 0x8E, 0xD5, 0xDB, 0xCA, + 0x1C, 0x54, 0x74, 0x10, 0x7B, 0xDC, 0x99, 0xED, 0x42, 0xD5, 0x5B, + 0xA7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xBC, 0xDD, 0x7F, 0xE1}, + {0x76, 0x5D, 0xC0, 0x6E, 0xE3, 0x14, 0xAC, 0x72, 0x48, 0x12, 0x0A, + 0xA6, 0xE8, 0x5B, 0x08, 0x7B, 0xDA, 0x3F, 0x51, 0x7D, 0xDE, 0x4C, + 0xEA, 0xCB, 0x93, 0xA5, 0x6E, 0xCC, 0xE7, 0x8E, 0x10, 0x84}}, // w - {{{0xBD, 0x19, 0x5A, 0x95, 0xE2, 0x0F, 0xCA, 0x1C, 0x50, 0x71, 0x94, 0x51, - 0x40, 0x1B, 0xA5, 0xB6, 0x78, 0x87, 0x53, 0xF6, 0x6A, 0x95, 0xCA, 0xC6, - 0x8D, 0xCD, 0x36, 0x88, 0x07, 0x28, 0xE8, 0x96}, - {0xCA, 0x78, 0x11, 0x5B, 0xB8, 0x6A, 0xE7, 0xE5, 0xA6, 0x65, 0x7A, 0x68, - 0x15, 0xD7, 0x75, 0xF8, 0x24, 0x14, 0xCF, 0xD1, 0x0F, 0x6C, 0x56, 0xF5, - 0x22, 0xD9, 0xFD, 0xE0, 0xE2, 0xF4, 0xB3, 0xA1}}, - {{0x90, 0x21, 0xA7, 0xE0, 0xE8, 0xB3, 0xC7, 0x25, 0xBC, 0x07, 0x72, 0x30, - 0x5D, 0xEE, 0xF5, 0x6A, 0x89, 0x88, 0x46, 0xDD, 0x89, 0xC2, 0x39, 0x9C, - 0x0A, 0x3B, 0x58, 0x96, 0x57, 0xE4, 0xF3, 0x3C}, - {0x79, 0x51, 0x69, 0x36, 0x1B, 0xB6, 0xF7, 0x05, 0x5D, 0x0A, 0x88, 0xDB, - 0x1F, 0x3D, 0xEA, 0xA2, 0xBA, 0x6B, 0xF0, 0xDA, 0x8E, 0x25, 0xC6, 0xAD, - 0x83, 0x7D, 0x3E, 0x31, 0xEE, 0x11, 0x40, 0xA9}}}}; + {{{0xBD, 0x19, 0x5A, 0x95, 0xE2, 0x0F, 0xCA, 0x1C, 0x50, 0x71, 0x94, + 0x51, 0x40, 0x1B, 0xA5, 0xB6, 0x78, 0x87, 0x53, 0xF6, 0x6A, 0x95, + 0xCA, 0xC6, 0x8D, 0xCD, 0x36, 0x88, 0x07, 0x28, 0xE8, 0x96}, + {0xCA, 0x78, 0x11, 0x5B, 0xB8, 0x6A, 0xE7, 0xE5, 0xA6, 0x65, 0x7A, + 0x68, 0x15, 0xD7, 0x75, 0xF8, 0x24, 0x14, 0xCF, 0xD1, 0x0F, 0x6C, + 0x56, 0xF5, 0x22, 0xD9, 0xFD, 0xE0, 0xE2, 0xF4, 0xB3, 0xA1}}, + {{0x90, 0x21, 0xA7, 0xE0, 0xE8, 0xB3, 0xC7, 0x25, 0xBC, 0x07, 0x72, + 0x30, 0x5D, 0xEE, 0xF5, 0x6A, 0x89, 0x88, 0x46, 0xDD, 0x89, 0xC2, + 0x39, 0x9C, 0x0A, 0x3B, 0x58, 0x96, 0x57, 0xE4, 0xF3, 0x3C}, + {0x79, 0x51, 0x69, 0x36, 0x1B, 0xB6, 0xF7, 0x05, 0x5D, 0x0A, 0x88, + 0xDB, 0x1F, 0x3D, 0xEA, 0xA2, 0xBA, 0x6B, 0xF0, 0xDA, 0x8E, 0x25, + 0xC6, 0xAD, 0x83, 0x7D, 0x3E, 0x31, 0xEE, 0x11, 0x40, 0xA9}}}}; const GroupPubKey EpidVerifierTest::kPubKeyIkgfStr = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // group id - {{{{0x45, 0xcb, 0x06, 0x04, 0xb3, 0xf7, 0x23, 0xb2, 0xd1, 0xd1, 0x0d, 0x4f, - 0x51, 0x7b, 0xbb, 0x8f, 0x71, 0x15, 0xd7, 0xf1, 0xdc, 0x15, 0x37, 0xc8, - 0xb8, 0x3d, 0x68, 0x0a, 0x18, 0xa5, 0x34, 0x14}}}, - {{{0x0c, 0xdc, 0xd9, 0x15, 0x7e, 0xba, 0x56, 0xc5, 0xe5, 0x61, 0xfa, 0x6a, - 0x86, 0xa0, 0xac, 0x6a, 0x81, 0x36, 0x6d, 0x01, 0x5f, 0x86, 0xc0, 0x04, - 0x8b, 0x1e, 0xff, 0x49, 0xd9, 0x37, 0x96, 0x66}}}}, // h1 - {{{{0xf1, 0xc3, 0x16, 0xb5, 0xc5, 0x1c, 0x67, 0xb6, 0xff, 0x28, 0x23, 0x79, - 0x59, 0xea, 0x80, 0xe6, 0x09, 0x07, 0xe7, 0xd3, 0x38, 0xec, 0xb9, 0x16, - 0x83, 0x88, 0xda, 0x64, 0xdd, 0xc4, 0x9d, 0x6a}}}, - {{{0x5c, 0xb2, 0x1c, 0x88, 0x97, 0xea, 0xaf, 0xa9, 0xf3, 0x3e, 0x07, 0xea, - 0xb6, 0x2a, 0xd5, 0x7a, 0xed, 0x32, 0xd9, 0x3d, 0x90, 0xd7, 0xb9, 0x91, - 0x08, 0x05, 0x9e, 0xe3, 0x22, 0x75, 0x06, 0x35}}}}, // h2 - {{{{{0xe5, 0xc4, 0x77, 0xad, 0x52, 0xb9, 0x7c, 0x04, 0x2d, 0x7e, 0x81, 0xf2, - 0x5d, 0x5d, 0x52, 0x7d, 0xd7, 0x1d, 0x29, 0xfb, 0x6a, 0xa7, 0xbc, 0xb5, - 0xa9, 0x1a, 0xa6, 0xfd, 0x20, 0xea, 0xf2, 0x98}}}, - {{{0xe2, 0x67, 0x33, 0x28, 0x67, 0x5f, 0xbe, 0x23, 0xa0, 0x43, 0xe8, 0x71, - 0xaa, 0xab, 0xf6, 0xf0, 0x6a, 0x2b, 0x52, 0xa8, 0x61, 0x51, 0x22, 0x44, - 0x00, 0x91, 0xd7, 0xf1, 0x7e, 0x05, 0x48, 0xdc}}}}, - {{{{0x51, 0x0c, 0xef, 0xa0, 0xf3, 0x72, 0xcd, 0x59, 0xd4, 0x7a, 0x2a, 0x60, - 0xa3, 0x62, 0x54, 0xa8, 0xb6, 0x8f, 0xed, 0x90, 0xdf, 0x3e, 0x94, 0xe8, - 0xa4, 0x89, 0x32, 0xaa, 0x52, 0x5a, 0x97, 0xae}}}, - {{{0x4c, 0x86, 0xf4, 0xba, 0xec, 0xc6, 0x36, 0x13, 0x87, 0x42, 0x5d, 0x16, - 0x49, 0x12, 0x66, 0xc5, 0xe0, 0xe4, 0x9b, 0xf9, 0x68, 0xaa, 0xa9, 0x95, - 0x81, 0x16, 0x5c, 0xd2, 0xca, 0xd4, 0x2e, 0x61}}}}} // w + {{{{0x45, 0xcb, 0x06, 0x04, 0xb3, 0xf7, 0x23, 0xb2, 0xd1, 0xd1, 0x0d, + 0x4f, 0x51, 0x7b, 0xbb, 0x8f, 0x71, 0x15, 0xd7, 0xf1, 0xdc, 0x15, + 0x37, 0xc8, 0xb8, 0x3d, 0x68, 0x0a, 0x18, 0xa5, 0x34, 0x14}}}, + {{{0x0c, 0xdc, 0xd9, 0x15, 0x7e, 0xba, 0x56, 0xc5, 0xe5, 0x61, 0xfa, + 0x6a, 0x86, 0xa0, 0xac, 0x6a, 0x81, 0x36, 0x6d, 0x01, 0x5f, 0x86, + 0xc0, 0x04, 0x8b, 0x1e, 0xff, 0x49, 0xd9, 0x37, 0x96, 0x66}}}}, // h1 + {{{{0xf1, 0xc3, 0x16, 0xb5, 0xc5, 0x1c, 0x67, 0xb6, 0xff, 0x28, 0x23, + 0x79, 0x59, 0xea, 0x80, 0xe6, 0x09, 0x07, 0xe7, 0xd3, 0x38, 0xec, + 0xb9, 0x16, 0x83, 0x88, 0xda, 0x64, 0xdd, 0xc4, 0x9d, 0x6a}}}, + {{{0x5c, 0xb2, 0x1c, 0x88, 0x97, 0xea, 0xaf, 0xa9, 0xf3, 0x3e, 0x07, + 0xea, 0xb6, 0x2a, 0xd5, 0x7a, 0xed, 0x32, 0xd9, 0x3d, 0x90, 0xd7, + 0xb9, 0x91, 0x08, 0x05, 0x9e, 0xe3, 0x22, 0x75, 0x06, 0x35}}}}, // h2 + {{{{{0xe5, 0xc4, 0x77, 0xad, 0x52, 0xb9, 0x7c, 0x04, 0x2d, 0x7e, 0x81, + 0xf2, 0x5d, 0x5d, 0x52, 0x7d, 0xd7, 0x1d, 0x29, 0xfb, 0x6a, 0xa7, + 0xbc, 0xb5, 0xa9, 0x1a, 0xa6, 0xfd, 0x20, 0xea, 0xf2, 0x98}}}, + {{{0xe2, 0x67, 0x33, 0x28, 0x67, 0x5f, 0xbe, 0x23, 0xa0, 0x43, 0xe8, + 0x71, 0xaa, 0xab, 0xf6, 0xf0, 0x6a, 0x2b, 0x52, 0xa8, 0x61, 0x51, + 0x22, 0x44, 0x00, 0x91, 0xd7, 0xf1, 0x7e, 0x05, 0x48, 0xdc}}}}, + {{{{0x51, 0x0c, 0xef, 0xa0, 0xf3, 0x72, 0xcd, 0x59, 0xd4, 0x7a, 0x2a, + 0x60, 0xa3, 0x62, 0x54, 0xa8, 0xb6, 0x8f, 0xed, 0x90, 0xdf, 0x3e, + 0x94, 0xe8, 0xa4, 0x89, 0x32, 0xaa, 0x52, 0x5a, 0x97, 0xae}}}, + {{{0x4c, 0x86, 0xf4, 0xba, 0xec, 0xc6, 0x36, 0x13, 0x87, 0x42, 0x5d, + 0x16, 0x49, 0x12, 0x66, 0xc5, 0xe0, 0xe4, 0x9b, 0xf9, 0x68, 0xaa, + 0xa9, 0x95, 0x81, 0x16, 0x5c, 0xd2, 0xca, 0xd4, 0x2e, 0x61}}}}} // w }; const GroupPubKey EpidVerifierTest::kPubKeyRevGroupIkgfStr = { @@ -476,6 +476,10 @@ const std::vector EpidVerifierTest::kSigGrp01Member0Sha256RandombaseTest0 = { #include "epid/common-testhelper/testdata/grp01/member0/sig_test0_sha256_sigrl.inc" }; +const std::vector + EpidVerifierTest::kSigGrp01Member0Sha512kBsn0Data_0_255 = { +#include "epid/common-testhelper/testdata/grp01/member0/sig_bsn0_msg_0_255_sha512.inc" +}; const std::vector EpidVerifierTest::kSigMember0Sha256RandombaseMsg0Ikgf = { #include "epid/common-testhelper/testdata/ikgf/groupa/sig_msg0_sha256_sigrl.inc" @@ -489,7 +493,9 @@ const std::vector #include "epid/common-testhelper/testdata/grp01/member0/sig_test0_sha512_sigrl.inc" }; const std::vector - EpidVerifierTest::kSigGrp01Member0Sha512256RandombaseTest1 = {0}; + EpidVerifierTest::kSigGrpXMember0Sha512256RandombaseMsg0 = { +#include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0.inc" +}; const std::vector EpidVerifierTest::kSigGrp01Member0Sha256RandombaseTest1NoSigRl = { #include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha256.inc" @@ -510,6 +516,10 @@ const std::vector EpidVerifierTest::kSigGrp01Member0Sha512RandombaseTest1NoSigRl = { #include "epid/common-testhelper/testdata/grp01/member0/sig_test1_sha512.inc" }; +const std::vector + EpidVerifierTest::kSigGrpXMember0Sha512256RandombaseMsg0NoSigRl = { +#include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_rndbase_msg0_no_sigrl.inc" +}; const std::vector EpidVerifierTest::kTest0 = { 't', 'e', 's', 't', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e', 0x0}; @@ -519,6 +529,30 @@ const std::vector EpidVerifierTest::kBasename = {'b', 'a', 's', 'e', const std::vector EpidVerifierTest::kBasename1 = { 'b', 'a', 's', 'e', 'n', 'a', 'm', 'e', '1'}; +const std::vector EpidVerifierTest::kData_0_255 = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0xff, +}; const OctStr32 EpidVerifierTest::kOctStr32_1 = {0x00, 0x00, 0x00, 0x01}; const GroupPubKey EpidVerifierTest::kPubKeySigRlVerify = { @@ -568,6 +602,9 @@ const GroupPubKey EpidVerifierTest::kGrpXKey = { const std::vector EpidVerifierTest::kGrpXPrivRl = { #include "epid/common-testhelper/testdata/grp_x/privrl.inc" }; +const std::vector EpidVerifierTest::kGrpXCorruptedPrivRl = { +#include "epid/common-testhelper/testdata/grp_x/corrupted_privrl.inc" +}; const std::vector EpidVerifierTest::kPrivRlIkgf = { #include "epid/common-testhelper/testdata/ikgf/groupa/privrl.inc" }; @@ -613,7 +650,7 @@ const std::vector EpidVerifierTest::kGrpXBsn0Sha512VerRl = { #include "epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512.inc" }; const std::vector EpidVerifierTest::kGrpXBsn0Sha512256VerRl = { - // #include "testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc" +#include "epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_sha512_256.inc" }; const std::vector EpidVerifierTest::kGrpXBsn0VerRlSingleEntry = { #include "epid/common-testhelper/testdata/grp_x/verrevoked/bsn0/verrl_1entry.inc" @@ -712,17 +749,20 @@ const std::vector EpidVerifierTest::kSigGrpXMember0Sha512Bsn0Msg0 = { #include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_bsn0_msg0.inc" }; const std::vector +EpidVerifierTest::kSigGrpXMember0Sha512HugeBsnMsg0 = { +#include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_huge_bsn_msg0.inc" +}; +const std::vector EpidVerifierTest::kSigGrpXMember0Sha512RandbaseMsg0 = { #include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_rndbase_msg0.inc" }; const std::vector EpidVerifierTest::kSigGrpXMember0Sha512256Bsn0Msg0 = { - // #include "testdata/grp_x/member0/sig_sha512256_bsn0_msg0.inc" +#include "epid/common-testhelper/testdata/grp_x/member0/sig_sha512_256_bsn0_msg0.inc" }; const std::vector -EpidVerifierTest::kSigGrpXMember0Sha512256RandbaseMsg0 = { - // #include "testdata/grp_x/member0/sig_sha512256_rndbase_msg0.inc" -}; +EpidVerifierTest::kSigGrpXMember0Sha512256RandbaseMsg0 = + kSigGrpXMember0Sha512256RandombaseMsg0; const std::vector EpidVerifierTest::kSigGrpXMember1Sha256Bsn0Msg0 = { #include "epid/common-testhelper/testdata/grp_x/member1/sig_sha256_bsn0_msg0.inc" }; diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.h b/external/epid-sdk/epid/verifier/unittests/verifier-testhelper.h similarity index 93% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.h rename to external/epid-sdk/epid/verifier/unittests/verifier-testhelper.h index 4bbb7d1c..5e3f9f9e 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifier-testhelper.h +++ b/external/epid-sdk/epid/verifier/unittests/verifier-testhelper.h @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { @@ -72,6 +73,10 @@ class EpidVerifierTest : public ::testing::Test { static const std::vector kBasename; /// the basename "basename1" static const std::vector kBasename1; + /// a data with bytes [0,255] + static const std::vector kData_0_255; + /// Signature of kData_0_255 with kBsn0 by Grp01 Member0 using Sha512 + static const std::vector kSigGrp01Member0Sha512kBsn0Data_0_255; /// Signature of Test0 with RandomBase by Grp01 Member0 using Sha256 static const std::vector kSigGrp01Member0Sha256RandombaseTest0; /// Signature of Test with RandomBase, Member0 using Sha256 from Ikgf @@ -80,8 +85,8 @@ class EpidVerifierTest : public ::testing::Test { static const std::vector kSigGrp01Member0Sha384RandombaseTest0; /// Signature of Test1 with RandomBase by Grp01 Member0 using Sha512 static const std::vector kSigGrp01Member0Sha512RandombaseTest0; - /// Signature of Test1 with RandomBase by Grp01 Member0 using Sha512_256 - static const std::vector kSigGrp01Member0Sha512256RandombaseTest1; + /// Signature of msg0 with RandomBase by GrpX Member0 using Sha512/256 + static const std::vector kSigGrpXMember0Sha512256RandombaseMsg0; /// Sig of Test1 with RandomBase by Grp01(no SigRl) Member0 using Sha256 static const std::vector kSigGrp01Member0Sha256RandombaseTest1NoSigRl; @@ -95,6 +100,9 @@ class EpidVerifierTest : public ::testing::Test { /// Sig of Test1 with RandomBase by Grp01(no SigRl) Member0 using Sha512 static const std::vector kSigGrp01Member0Sha512RandombaseTest1NoSigRl; + /// Sig of msg0 with RandomBase by GrpX(no SigRl) Member0 using Sha512/256 + static const std::vector + kSigGrpXMember0Sha512256RandombaseMsg0NoSigRl; /// group based rl test data (empty rl) static const std::vector kGroupRlEmptyBuf; /// group based rl test data (v=3, n=3, 3 revoked gid) @@ -135,7 +143,8 @@ class EpidVerifierTest : public ::testing::Test { static const GroupPubKey kGrpXKey; /// the privrl of group X static const std::vector kGrpXPrivRl; - + /// currpted privrl of group X + static const std::vector kGrpXCorruptedPrivRl; /// the privrl of group X with single entry PrivKey000 revoked static const std::vector kGrpXPrivRlRevokedPrivKey000OnlyEntry; /// the sigrl of group X @@ -219,6 +228,8 @@ class EpidVerifierTest : public ::testing::Test { static const std::vector kSigGrpXMember0Sha384RandbaseMsg0; /// signature of msg0 by member0 of groupX with Sha512 bsn0 static const std::vector kSigGrpXMember0Sha512Bsn0Msg0; + /// signature of msg0 by member0 of groupX with Sha512 huge bsn + static const std::vector kSigGrpXMember0Sha512HugeBsnMsg0; /// signature of msg0 by member0 of groupX with Sha512 rnd base static const std::vector kSigGrpXMember0Sha512RandbaseMsg0; /// signature of msg0 by member0 of groupX with Sha512256 bsn0 diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/verify-test.cc b/external/epid-sdk/epid/verifier/unittests/verify-test.cc similarity index 87% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/verify-test.cc rename to external/epid-sdk/epid/verifier/unittests/verify-test.cc index ffac4d2a..d221742c 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/verify-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/verify-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,16 +19,17 @@ * \brief Verify unit tests. */ +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { -#include "epid/verifier/api.h" #include "epid/common/src/endian_convert.h" +#include "epid/verifier/api.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" namespace { @@ -37,7 +38,7 @@ namespace { TEST_F(EpidVerifierTest, VerifyFailsGivenNullParameters) { VerifierCtxObj verifier(this->kGrp01Key); - auto& sig = this->kSigGrp01Member0Sha256RandombaseTest0; + auto& sig = this->kSigGrp01Member0Sha512RandombaseTest0; auto& msg = this->kTest0; EXPECT_EQ(kEpidBadArgErr, @@ -50,11 +51,25 @@ TEST_F(EpidVerifierTest, VerifyFailsGivenNullParameters) { nullptr, msg.size())); } +TEST_F(EpidVerifierTest, VerifyFailsGivenTooShortSigLen) { + VerifierCtxObj verifier(this->kGrp01Key); + auto& sig = this->kSigGrp01Member0Sha512RandombaseTest0; + auto& msg = this->kTest0; + + EXPECT_EQ(kEpidBadArgErr, + EpidVerify(verifier, (EpidSignature const*)sig.data(), 0, + msg.data(), msg.size())); + EXPECT_EQ(kEpidBadArgErr, + EpidVerify(verifier, (EpidSignature const*)sig.data(), + sizeof(EpidSignature) - sizeof(NrProof) - 1, msg.data(), + msg.size())); +} + TEST_F(EpidVerifierTest, VerifyFailsGivenSigLenTooShortForRlCount) { VerifierCtxObj verifier(this->kGrp01Key); EpidVerifierSetSigRl(verifier, (SigRl const*)this->kGrp01SigRl.data(), this->kGrp01SigRl.size()); - auto sig = this->kSigGrp01Member0Sha256RandombaseTest0; + auto sig = this->kSigGrp01Member0Sha512RandombaseTest0; auto n2 = this->kGrp01SigRlN2; sig.resize(sizeof(EpidSignature) + (n2 - 2) * sizeof(((EpidSignature*)0)->sigma)); @@ -69,7 +84,7 @@ TEST_F(EpidVerifierTest, VerifyFailsGivenSigLenTooLongForRlCount) { VerifierCtxObj verifier(this->kGrp01Key); EpidVerifierSetSigRl(verifier, (SigRl const*)this->kGrp01SigRl.data(), this->kGrp01SigRl.size()); - auto sig = this->kSigGrp01Member0Sha256RandombaseTest0; + auto sig = this->kSigGrp01Member0Sha512RandombaseTest0; auto n2 = this->kGrp01SigRlN2; sig.resize(sizeof(EpidSignature) + n2 * sizeof(((EpidSignature*)0)->sigma)); auto& msg = this->kTest0; @@ -84,7 +99,7 @@ TEST_F(EpidVerifierTest, VerifyFailsGivenRlCountTooBig) { VerifierCtxObj verifier(this->kGrp01Key); EpidVerifierSetSigRl(verifier, (SigRl const*)this->kGrp01SigRl.data(), this->kGrp01SigRl.size()); - auto sig = this->kSigGrp01Member0Sha256RandombaseTest0; + auto sig = this->kSigGrp01Member0Sha512RandombaseTest0; uint32_t n2 = SIZE_MAX / sizeof(NrProof) + 1; uint32_t n2_ = ntohl(n2); EpidSignature* sig_struct = (EpidSignature*)sig.data(); @@ -114,9 +129,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithBNotInG1) { // result must be kEpidSigInvalid VerifierCtxObj verifier(this->kGrp01Key); auto& msg = this->kTest0; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.B.x.data.data[31]++; EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); @@ -129,9 +144,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithBIdentityOfG1) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.B = this->kG1IdentityStr; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -141,7 +156,7 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithDiffBaseNameSameHashAlg) { // B = G1.hash(bsn). // result must be kEpidSigInvalid auto& pub_key = this->kGrpXKey; - auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0; + auto& sig = this->kSigGrpXMember0Sha512Bsn0Msg0; auto& msg = this->kMsg0; auto& bsn = this->kBasename1; @@ -170,6 +185,30 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithSameBaseNameDiffHashAlg) { msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyRejectsSigWithDifferentHugeBaseName) { + // * 4.1.2 step 2.c - If bsn is provided, the verifier verifies + // B = G1.hash(bsn). + // result must be kEpidSigInvalid + auto& pub_key = this->kGrpXKey; + auto& sig = this->kSigGrpXMember0Sha512HugeBsnMsg0; + auto& msg = this->kMsg0; + std::vector bsn(1024 * 1024); + uint8_t c = 0; + for (size_t i = 0; i < bsn.size(); ++i) { + // change middle kilobyte + if (i == 512 * 1024) c++; + if (i == 513 * 1024) c--; + bsn[i] = c++; + } + + VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); + EXPECT_EQ(kEpidSigInvalid, + EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), + msg.data(), msg.size())); +} + TEST_F(EpidVerifierTest, VerifyRejectsSigWithKNotInG1) { // * 4.1.2 step 2.d - The verifier verifies G1.inGroup(K) = true. // result must be kEpidSigInvalid @@ -177,9 +216,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithKNotInG1) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.K.x.data.data[31]++; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -191,9 +230,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithTNotInG1) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.T.x.data.data[31]++; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -205,9 +244,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithCNotInRange) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.c.data = this->kParamsStr.p.data; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -219,9 +258,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithSxNotInRange) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.sx.data = this->kParamsStr.p.data; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -233,9 +272,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithSfNotInRange) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.sf.data = this->kParamsStr.p.data; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -247,9 +286,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithSaNotInRange) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.sa.data = this->kParamsStr.p.data; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -261,9 +300,9 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigWithSbNotInRange) { auto& msg = this->kTest0; EpidSignature sig = *( - const EpidSignature*)(this->kSigGrp01Member0Sha256RandombaseTest0.data()); + const EpidSignature*)(this->kSigGrp01Member0Sha512RandombaseTest0.data()); sig.sigma0.sb.data = this->kParamsStr.p.data; - size_t size = this->kSigGrp01Member0Sha256RandombaseTest0.size(); + size_t size = this->kSigGrp01Member0Sha512RandombaseTest0.size(); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, &sig, size, msg.data(), msg.size())); } @@ -300,7 +339,7 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigDifferingOnlyInMsg) { // * 4.1.2 step 2.o - The verifier verifies c = Fp.hash(t3 || m). // result must be kEpidSigInvalid VerifierCtxObj verifier(this->kGrp01Key); - auto& sig = this->kSigGrp01Member0Sha256RandombaseTest0; + auto& sig = this->kSigGrp01Member0Sha512RandombaseTest0; auto msg = this->kTest0; msg[0]++; @@ -312,14 +351,16 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigDifferingOnlyInMsg) { TEST_F(EpidVerifierTest, VerifyRejectsSigDifferingOnlyInBaseName) { // * 4.1.2 step 2.o - The verifier verifies c = Fp.hash(t3 || m). // result must be kEpidSigInvalid - VerifierCtxObj verifier(this->kGrp01Key); + VerifierCtxObj verifier(this->kGrpXKey); // copy sig data to a local buffer - auto sig_data = this->kSigGrpXMember0Sha256Bsn0Msg0; + auto sig_data = this->kSigGrpXMember0Sha512Bsn0Msg0; EpidSignature* sig = (EpidSignature*)sig_data.data(); // simulate change to basename sig->sigma0.B.x.data.data[0] += 1; - auto msg = this->kTest1; + auto msg = this->kMsg0; + auto bsn = this->kBsn0; + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, sig, sig_data.size(), msg.data(), msg.size())); } @@ -327,14 +368,14 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigDifferingOnlyInBaseName) { TEST_F(EpidVerifierTest, VerifyRejectsSigDifferingOnlyInGroup) { // * 4.1.2 step 2.o - The verifier verifies c = Fp.hash(t3 || m). // result must be kEpidSigInvalid - VerifierCtxObj verifier(this->kGrp01Key); + VerifierCtxObj verifier(this->kGrpXKey); // copy sig data to a local buffer - auto sig_data = this->kSigGrpXMember0Sha256Bsn0Msg0; + auto sig_data = this->kSigGrpXMember0Sha512RandbaseMsg0; EpidSignature* sig = (EpidSignature*)sig_data.data(); // simulate change to h1 sig->sigma0.T.x.data.data[0] += 1; - auto msg = this->kTest1; + auto msg = this->kMsg0; EXPECT_EQ(kEpidSigInvalid, EpidVerify(verifier, sig, sig_data.size(), msg.data(), msg.size())); } @@ -595,6 +636,24 @@ TEST_F(EpidVerifierTest, VerifyRejectsSigFromPrivRlLastEntry) { msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyRejectsSigUsingCorruptedPrivRlEntry) { + auto& pub_key = this->kGrpXKey; + auto& msg = this->kMsg0; + auto& bsn = this->kBsn0; + auto& priv_rl = this->kGrpXCorruptedPrivRl; + auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0; + + VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256)); + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetPrivRl( + verifier, (PrivRl const*)priv_rl.data(), priv_rl.size())); + + EXPECT_EQ(kEpidSigRevokedInPrivRl, + EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), + msg.data(), msg.size())); +} + TEST_F(EpidVerifierTest, VerifyAcceptsSigFromEmptyPrivRlUsingIkgfData) { auto& pub_key = this->kPubKeyIkgfStr; auto& msg = this->kMsg0; @@ -640,9 +699,8 @@ TEST_F(EpidVerifierTest, VerifyFailsOnSigRlverNotMatchSigRlRlver) { THROW_ON_EPIDERR(EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(), sig_rl.size())); - EXPECT_EQ(kEpidBadArgErr, - EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), - msg.data(), msg.size())); + EXPECT_EQ(kEpidErr, EpidVerify(verifier, (EpidSignature const*)sig.data(), + sig.size(), msg.data(), msg.size())); } TEST_F(EpidVerifierTest, VerifyFailsOnSigN2NotMatchSigRlN2) { @@ -652,17 +710,19 @@ TEST_F(EpidVerifierTest, VerifyFailsOnSigN2NotMatchSigRlN2) { auto& pub_key = this->kGrpXKey; auto& msg = this->kMsg0; auto& bsn = this->kBsn0; - auto& sig_rl = this->kGrpXSigRlMember0Sha256Bsn0Msg0OnlyEntry; - auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0; + auto* sig_rl = + (SigRl const*)this->kGrpXSigRlMember0Sha256Bsn0Msg0OnlyEntry.data(); + size_t sig_rl_size = this->kGrpXSigRlMember0Sha256Bsn0Msg0OnlyEntry.size(); + auto sig_raw = this->kSigGrpXMember0Sha256Bsn0Msg0; + EpidSignature* sig = (EpidSignature*)sig_raw.data(); + sig->rl_ver = sig_rl->version; VerifierCtxObj verifier(pub_key); THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256)); THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); - THROW_ON_EPIDERR(EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(), - sig_rl.size())); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(verifier, sig_rl, sig_rl_size)); EXPECT_EQ(kEpidBadArgErr, - EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), - msg.data(), msg.size())); + EpidVerify(verifier, sig, sig_raw.size(), msg.data(), msg.size())); } TEST_F(EpidVerifierTest, VerifyRejectsSigFromSigRlSingleEntry) { @@ -779,9 +839,8 @@ TEST_F(EpidVerifierTest, THROW_ON_EPIDERR(EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(), sig_rl.size())); - EXPECT_EQ(kEpidBadArgErr, - EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), - msg.data(), msg.size())); + EXPECT_EQ(kEpidErr, EpidVerify(verifier, (EpidSignature const*)sig.data(), + sig.size(), msg.data(), msg.size())); } TEST_F(EpidVerifierTest, VerifyAcceptsSigFromEmptySigRlUsingIkgfData) { @@ -1121,6 +1180,25 @@ TEST_F(EpidVerifierTest, VerifyAcceptsSigWithBaseNameAllRlSha512) { msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyAcceptsSigWithHugeBaseNameNoRlSha512) { + auto& pub_key = this->kGrpXKey; + auto& msg = this->kMsg0; + auto& sig = this->kSigGrpXMember0Sha512HugeBsnMsg0; + std::vector bsn(1024 * 1024); + uint8_t c = 0; + for (int i = 0; i < 1024 * 1024; ++i) { + bsn[i] = c++; + } + + VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); + + EXPECT_EQ(kEpidSigValid, + EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), + msg.data(), msg.size())); +} + TEST_F(EpidVerifierTest, VerifyAcceptsSigWithRandomBaseNameAllRlSha512) { auto& pub_key = this->kGrpXKey; auto& msg = this->kMsg0; @@ -1143,7 +1221,7 @@ TEST_F(EpidVerifierTest, VerifyAcceptsSigWithRandomBaseNameAllRlSha512) { msg.data(), msg.size())); } -TEST_F(EpidVerifierTest, DISABLED_VerifyAcceptsSigWithBaseNameAllRlSha512256) { +TEST_F(EpidVerifierTest, VerifyAcceptsSigWithBaseNameAllRlSha512256) { auto& pub_key = this->kGrpXKey; auto& msg = this->kMsg0; auto& bsn = this->kBsn0; @@ -1170,8 +1248,7 @@ TEST_F(EpidVerifierTest, DISABLED_VerifyAcceptsSigWithBaseNameAllRlSha512256) { msg.data(), msg.size())); } -TEST_F(EpidVerifierTest, - DISABLED_VerifyAcceptsSigWithRandomBaseNameAllRlSha512256) { +TEST_F(EpidVerifierTest, VerifyAcceptsSigWithRandomBaseNameAllRlSha512256) { auto& pub_key = this->kGrpXKey; auto& msg = this->kMsg0; auto& grp_rl = this->kGrpRl; @@ -1193,4 +1270,48 @@ TEST_F(EpidVerifierTest, msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyAcceptsSigGivenMsgContainingAllPossibleBytes) { + auto& pub_key = this->kPubKeySigRlVerify; + auto& msg = this->kData_0_255; + auto& bsn = this->kBsn0; + auto& grp_rl = this->kGrpRl; + auto& priv_rl = this->kGrp01PrivRl; + std::vector sig_rl = { + // gid + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2A, + // version + 0x00, 0x00, 0x00, 0x00, + // n2 + 0x00, 0x00, 0x00, 0x01, + // bk's + 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd, + 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea, + 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94, + 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57, + 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad, + 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2, + 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9, + 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d, + 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a, + 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37, + 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b, + }; + auto& sig = this->kSigGrp01Member0Sha512kBsn0Data_0_255; + + VerifierCtxObj verifier(pub_key); + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size())); + THROW_ON_EPIDERR(EpidVerifierSetGroupRl( + verifier, (GroupRl const*)grp_rl.data(), grp_rl.size())); + THROW_ON_EPIDERR(EpidVerifierSetPrivRl( + verifier, (PrivRl const*)priv_rl.data(), priv_rl.size())); + THROW_ON_EPIDERR(EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(), + sig_rl.size())); + + EXPECT_EQ(kEpidSigValid, + EpidVerify(verifier, (EpidSignature const*)sig.data(), sig.size(), + msg.data(), msg.size())); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifybasic-test.cc b/external/epid-sdk/epid/verifier/unittests/verifybasic-test.cc similarity index 83% rename from external/epid-sdk-3.0.0/epid/verifier/unittests/verifybasic-test.cc rename to external/epid-sdk/epid/verifier/unittests/verifybasic-test.cc index 9f6b3e57..20c1bac8 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/unittests/verifybasic-test.cc +++ b/external/epid-sdk/epid/verifier/unittests/verifybasic-test.cc @@ -1,5 +1,5 @@ /*############################################################################ - # Copyright 2016 Intel Corporation + # Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,16 +22,17 @@ #include #include +#include "epid/common-testhelper/epid_gtest-testhelper.h" #include "gtest/gtest.h" extern "C" { #include "epid/verifier/api.h" } -#include "epid/verifier/unittests/verifier-testhelper.h" -#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/common-testhelper/errors-testhelper.h" +#include "epid/common-testhelper/verifier_wrapper-testhelper.h" #include "epid/member/unittests/member-testhelper.h" +#include "epid/verifier/unittests/verifier-testhelper.h" namespace { @@ -96,6 +97,17 @@ TEST_F(EpidVerifierTest, VerifyBasicSigCanVerifyValidSignatureWithSHA512) { EpidVerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyBasicSigCanVerifyValidSignatureWithSHA512256) { + VerifierCtxObj verifier(this->kGrpXKey); + auto const& sig = (EpidSignature const*)this + ->kSigGrpXMember0Sha512256RandombaseMsg0NoSigRl.data(); + const BasicSignature basic_sig = sig->sigma0; + auto& msg = this->kMsg0; + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512_256)); + EXPECT_EQ(kEpidNoErr, + EpidVerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); +} + TEST_F(EpidVerifierTest, VerifyBasicSigDetectsInvalidSignatureGivenMatchingMessage) { VerifierCtxObj verifier(this->kGrp01Key); @@ -149,4 +161,19 @@ TEST_F(EpidVerifierTest, VerifyBasicSigCanVerifyWithBasenameUsingIkgfData) { EpidVerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); } +TEST_F(EpidVerifierTest, VerifyBasicSigCanVerifyMsgContainingAllPossibleBytes) { + VerifierCtxObj verifier(this->kPubKeySigRlVerify); + auto const& sig = + (EpidSignature const*)this->kSigGrp01Member0Sha512kBsn0Data_0_255.data(); + const BasicSignature basic_sig = sig->sigma0; + + auto& msg = this->kData_0_255; + auto& basename = this->kBsn0; + THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha512)); + THROW_ON_EPIDERR( + EpidVerifierSetBasename(verifier, basename.data(), basename.size())); + EXPECT_EQ(kEpidNoErr, + EpidVerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size())); +} + } // namespace diff --git a/external/epid-sdk-3.0.0/epid/verifier/verifier.parts b/external/epid-sdk/epid/verifier/verifier.parts similarity index 97% rename from external/epid-sdk-3.0.0/epid/verifier/verifier.parts rename to external/epid-sdk/epid/verifier/verifier.parts index 5f2f140a..2671811b 100644 --- a/external/epid-sdk-3.0.0/epid/verifier/verifier.parts +++ b/external/epid-sdk/epid/verifier/verifier.parts @@ -1,5 +1,5 @@ ############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -89,6 +89,9 @@ else: env.Append(CPPPATH='#') + if 'use_tss' in env['MODE']: + env.Append(CPPDEFINES=['TPM_TSS']) + testenv = env.Clone() outputs = env.Library('${PART_NAME}', src_files + epid11_src_files) env.Sdk(outputs) diff --git a/external/epid-sdk-3.0.0/example/Makefile b/external/epid-sdk/example/Makefile similarity index 77% rename from external/epid-sdk-3.0.0/example/Makefile rename to external/epid-sdk/example/Makefile index 004cf871..5ee6f069 100644 --- a/external/epid-sdk-3.0.0/example/Makefile +++ b/external/epid-sdk/example/Makefile @@ -7,49 +7,55 @@ COMPRESSED_DEFAULT_FILES_INSTALL_DIR = $(epidinstalldir)/compressed_example SIGNMSG_INCLUDE_DIR = ./signmsg SIGNMSG_SRC = $(wildcard ./signmsg/src/*.c) -SIGNMSG_OBJ = $(sort $(SIGNMSG_SRC:.c=.o)) -SIGNMSG_EXE = ./signmsg/src/signmsg +SIGNMSG_OBJ = $(SIGNMSG_SRC:.c=.o) +SIGNMSG_EXE = ./signmsg/src/signmsg$(EXE_EXTENSION) VERIFYSIG_INCLUDE_DIR = ./verifysig VERIFYSIG_SRC = $(wildcard ./verifysig/src/*.c) -VERIFYSIG_OBJ = $(sort $(VERIFYSIG_SRC:.c=.o)) -VERIFYSIG_EXE = ./verifysig/src/verifysig +VERIFYSIG_OBJ = $(VERIFYSIG_SRC:.c=.o) +VERIFYSIG_EXE = ./verifysig/src/verifysig$(EXE_EXTENSION) LIB_UTIL_DIR = ./util/src -LIB_DROPT_DIR = ../ext/dropt/src +LIB_ARGTABLE_DIR = ../ext/argtable3 LIB_IPPCP_DIR = ../ext/ipp/sources/ippcp/src -LIB_IPPCPEPID_DIR = ../ext/ipp/sources/ippcpepid/src LIB_MEMBER_DIR = ../epid/member LIB_VERIFIER_DIR = ../epid/verifier LIB_COMMON_DIR = ../epid/common #set linker flags LDFLAGS += -L$(LIB_UTIL_DIR) \ - -L$(LIB_DROPT_DIR) \ + -L$(LIB_ARGTABLE_DIR) \ -L$(LIB_IPPCP_DIR) \ -L$(LIB_COMMON_DIR) \ - -L$(LIB_IPPCPEPID_DIR) \ - -lcommon -lippcpepid \ - -lippcp -lutil -ldropt + -lcommon \ + -lippcp -lutil -largtable3 + +ifneq ($(TSS_PATH),) + LDFLAGS += -L$(TSS_PATH) -ltss -lcrypto +endif + +ifneq ($(TINY),) + LDFLAGS += -L$(LIB_MEMBER_DIR) -lmath -ltiny_stdlib +endif $(VERIFYSIG_EXE): $(VERIFYSIG_OBJ) - $(CC) -o $@ $^ $(CFLAGS) -L$(LIB_VERIFIER_DIR) -lverifier $(LDFLAGS) + $(CC) -o $@ $^ -L$(LIB_VERIFIER_DIR) -lverifier $(LDFLAGS) $(VERIFYSIG_OBJ): %.o: %.c $(CC) -o $@ $(CFLAGS) -I$(LIB_UTIL_DIR)/../.. \ - -I$(LIB_DROPT_DIR)/../include \ + -I$(LIB_ARGTABLE_DIR) \ -I$(LIB_VERIFIER_DIR)/../.. \ -I$(VERIFYSIG_INCLUDE_DIR) \ -I$(IPP_API_INCLUDE_DIR) -c $^ $(SIGNMSG_EXE): $(SIGNMSG_OBJ) - $(CC) -o $@ $^ $(CFLAGS) -L$(LIB_MEMBER_DIR) -lmember $(LDFLAGS) + $(CC) -o $@ $^ -L$(LIB_MEMBER_DIR) -lmember $(LDFLAGS) $(SIGNMSG_OBJ): %.o: %.c $(CC) -o $@ $(CFLAGS) -I$(LIB_UTIL_DIR)/../.. \ - -I$(LIB_DROPT_DIR)/../include \ + -I$(LIB_ARGTABLE_DIR) \ -I$(LIB_MEMBER_DIR)/../.. \ -I$(SIGNMSG_INCLUDE_DIR) \ -I$(IPP_API_INCLUDE_DIR) -c $^ diff --git a/external/epid-sdk-3.0.0/example/compressed_data/README.md b/external/epid-sdk/example/compressed_data/README.md similarity index 82% rename from external/epid-sdk-3.0.0/example/compressed_data/README.md rename to external/epid-sdk/example/compressed_data/README.md index 4075c753..74c33415 100644 --- a/external/epid-sdk-3.0.0/example/compressed_data/README.md +++ b/external/epid-sdk/example/compressed_data/README.md @@ -8,7 +8,7 @@ corresponding uncompressed groups and members._ ## Directory Structure - data + compressed_data |__ groupa | |__ member0 | | |__ mprivkey.dat @@ -134,7 +134,7 @@ In addition, **groupb** contain the following revocation lists: - `privrl.bin` - private key based revocation list with 1 entry - **privrevokedmember0** -- `sigrl.bin` - signature based revocation list with 1 entries - +- `sigrl.bin` - signature based revocation list with 1 entry - **sigrevokedmember0** - `privrl_empty.bin` - private key based revocation list with 0 entries @@ -144,36 +144,36 @@ In addition, **groupb** contain the following revocation lists: ### Default files -- `/data/cacert.bin` - CA certificate used as default input to signmsg +- `cacert.bin` - CA certificate used as default input to signmsg and `verifysig` -- `/data/grprl.bin` - group revocation list with one entry **groupb** used +- `grprl.bin` - group revocation list with one entry **groupb** used as default input to `verifysig` -- `/data/pubkey.bin` - public key in **groupa** used as default input +- `pubkey.bin` - public key in **groupa** used as default input to signmsg and `verifysig` -- `/data/mprivkey.dat` - private key of a **member0** in the +- `mprivkey.dat` - private key of a **member0** in the **groupa** used as default input to `signmsg` -- `/data/privrl.bin` - private key based revocation list in the - **groupa** with 0 entries used as default input to `verifysig` +- `privrl.bin` - private key based revocation list in the + **groupa** with 3 entries used as default input to `verifysig` -- `/data/sigrl.bin` - signature based revocation list in the - **groupa** with 0 entries used as default input to `signmsg` +- `sigrl.bin` - signature based revocation list in the + **groupa** with 3 entries used as default input to `signmsg` and `verifysig` ### Group revocation lists There are 2 group revocation lists: -- `grprl.bin` - group revocation list with 1 entry - **groupb** +- `grprl.bin` - group revocation list with 100 entries - `grprl_empty.bin` - group revocation list with 0 entries -### IoT EPID Issuing CA certificate +### IoT Issuing CA certificate -- `/data/cacert.bin` - CA certificate used to check that revocation +- `cacert.bin` - CA certificate used to check that revocation lists and group public keys are authorized by the issuer, e.g., signed by the issuer diff --git a/external/epid-sdk-3.0.0/example/compressed_data/cacert.bin b/external/epid-sdk/example/compressed_data/cacert.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/cacert.bin rename to external/epid-sdk/example/compressed_data/cacert.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/compressed_data.parts b/external/epid-sdk/example/compressed_data/compressed_data.parts similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/compressed_data.parts rename to external/epid-sdk/example/compressed_data/compressed_data.parts diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/member0/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/member0/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/member0/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/member0/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/member1/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/member1/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/member1/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/member1/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember0/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/privrevokedmember0/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember0/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/privrevokedmember0/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember1/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/privrevokedmember1/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember1/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/privrevokedmember1/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember2/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/privrevokedmember2/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/privrevokedmember2/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/privrevokedmember2/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/privrl.bin b/external/epid-sdk/example/compressed_data/groupa/privrl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/privrl.bin rename to external/epid-sdk/example/compressed_data/groupa/privrl.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/privrl_empty.bin b/external/epid-sdk/example/compressed_data/groupa/privrl_empty.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/privrl_empty.bin rename to external/epid-sdk/example/compressed_data/groupa/privrl_empty.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/pubkey.bin b/external/epid-sdk/example/compressed_data/groupa/pubkey.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/pubkey.bin rename to external/epid-sdk/example/compressed_data/groupa/pubkey.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember0/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/sigrevokedmember0/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember0/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/sigrevokedmember0/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember1/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/sigrevokedmember1/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember1/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/sigrevokedmember1/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember2/mprivkey.dat b/external/epid-sdk/example/compressed_data/groupa/sigrevokedmember2/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrevokedmember2/mprivkey.dat rename to external/epid-sdk/example/compressed_data/groupa/sigrevokedmember2/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrl.bin b/external/epid-sdk/example/compressed_data/groupa/sigrl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrl.bin rename to external/epid-sdk/example/compressed_data/groupa/sigrl.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrl_empty.bin b/external/epid-sdk/example/compressed_data/groupa/sigrl_empty.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupa/sigrl_empty.bin rename to external/epid-sdk/example/compressed_data/groupa/sigrl_empty.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/groupb/privrl.bin b/external/epid-sdk/example/compressed_data/groupb/privrl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/groupb/privrl.bin rename to external/epid-sdk/example/compressed_data/groupb/privrl.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/grprl.bin b/external/epid-sdk/example/compressed_data/grprl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/grprl.bin rename to external/epid-sdk/example/compressed_data/grprl.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/grprl_empty.bin b/external/epid-sdk/example/compressed_data/grprl_empty.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/grprl_empty.bin rename to external/epid-sdk/example/compressed_data/grprl_empty.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/mprivkey.dat b/external/epid-sdk/example/compressed_data/mprivkey.dat similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/mprivkey.dat rename to external/epid-sdk/example/compressed_data/mprivkey.dat diff --git a/external/epid-sdk-3.0.0/example/compressed_data/privrl.bin b/external/epid-sdk/example/compressed_data/privrl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/privrl.bin rename to external/epid-sdk/example/compressed_data/privrl.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/pubkey.bin b/external/epid-sdk/example/compressed_data/pubkey.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/pubkey.bin rename to external/epid-sdk/example/compressed_data/pubkey.bin diff --git a/external/epid-sdk-3.0.0/example/compressed_data/sigrl.bin b/external/epid-sdk/example/compressed_data/sigrl.bin similarity index 100% rename from external/epid-sdk-3.0.0/example/compressed_data/sigrl.bin rename to external/epid-sdk/example/compressed_data/sigrl.bin diff --git a/external/epid-sdk/ext/argtable3/LICENSE b/external/epid-sdk/ext/argtable3/LICENSE new file mode 100644 index 00000000..1a28ef95 --- /dev/null +++ b/external/epid-sdk/ext/argtable3/LICENSE @@ -0,0 +1,26 @@ +Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of STEWART HEITMANN nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/external/epid-sdk/ext/argtable3/Makefile b/external/epid-sdk/ext/argtable3/Makefile new file mode 100644 index 00000000..db761277 --- /dev/null +++ b/external/epid-sdk/ext/argtable3/Makefile @@ -0,0 +1,22 @@ +#!/usr/bin/make -f + +ARGTABLE_SRC = $(wildcard *.c) +ARGTABLE_OBJ = $(ARGTABLE_SRC:.c=.o) + +ARGTABLE_LIB = libargtable3.a + +$(ARGTABLE_OBJ): %.o: %.c + $(CC) -o $@ -c $(CFLAGS) $< + +$(ARGTABLE_LIB): $(ARGTABLE_OBJ) + $(AR) rc $@ $^ + $(RANLIB) $@ + +build: all + +all: $(ARGTABLE_LIB) + +install: + +clean: + rm -f $(ARGTABLE_OBJ) $(ARGTABLE_LIB) diff --git a/external/epid-sdk/ext/argtable3/argtable3.c b/external/epid-sdk/ext/argtable3/argtable3.c new file mode 100644 index 00000000..a551005b --- /dev/null +++ b/external/epid-sdk/ext/argtable3/argtable3.c @@ -0,0 +1,5062 @@ +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + // THIS FILE HAS BEEN ALTERED from original version to: + // * fix warnings + // * fix issues found by static code analisys: + // - Null pointer dereference in trex_compile + +#include "argtable3.h" + +// On Windows isspace crashes app in case of using Unicode character set and string to be above ASCII +// so you have to use _istspace instead of space +#ifdef UNICODE +#include + #define ISSPACE _istspace +#else + #define ISSPACE isspace +#endif + +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 2013 Tom G. Huang + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#ifndef ARG_UTILS_H +#define ARG_UTILS_H + +#define ARG_ENABLE_TRACE 0 +#define ARG_ENABLE_LOG 1 + +#ifdef __cplusplus +extern "C" { +#endif + +enum +{ + EMINCOUNT = 1, + EMAXCOUNT, + EBADINT, + // The same name define EOVERFLOW in errno.h on windows platform +#ifdef __STDC_WANT_SECURE_LIB__ + EOVERFLOW_, +#else + EOVERFLOW, +#endif + EBADDOUBLE, + EBADDATE, + EREGNOMATCH +}; + + +#if defined(_MSC_VER) +#define ARG_TRACE(x) \ + __pragma(warning(push)) \ + __pragma(warning(disable:4127)) \ + do { if (ARG_ENABLE_TRACE) dbg_printf x; } while (0) \ + __pragma(warning(pop)) + +#define ARG_LOG(x) \ + __pragma(warning(push)) \ + __pragma(warning(disable:4127)) \ + do { if (ARG_ENABLE_LOG) dbg_printf x; } while (0) \ + __pragma(warning(pop)) +#else +#define ARG_TRACE(x) \ + do { if (ARG_ENABLE_TRACE) dbg_printf x; } while (0) + +#define ARG_LOG(x) \ + do { if (ARG_ENABLE_LOG) dbg_printf x; } while (0) +#endif + +extern void dbg_printf(const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +#endif + +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include +#include + + +void dbg_printf(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +/* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ +/* $OpenBSD: getopt.h,v 1.1 2002/12/03 20:24:29 millert Exp $ */ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#if 0 +#include +#endif + +/* + * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DEFINED +#define _GETOPT_DEFINED +int getopt(int, char * const *, const char *); +int getsubopt(char **, char * const *, char **); + +extern char *optarg; /* getopt(3) external variables */ +extern int opterr; +extern int optind; +extern int optopt; +extern int optreset; +extern char *suboptarg; /* getsubopt(3) external variable */ +#endif /* _GETOPT_DEFINED */ + +#ifdef __cplusplus +} +#endif +#endif /* !_GETOPT_H_ */ +/* $Id: getopt_long.c,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ +/* $OpenBSD: getopt_long.c,v 1.23 2007/10/31 12:34:57 chl Exp $ */ +/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ + +/* + * Copyright (c) 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if 0 +#include +#endif +#include +#include +#include + + +#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */ + +#ifdef REPLACE_GETOPT +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ +#endif + +#define PRINT_ERROR ((opterr) && (*options != ':')) + +#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ +#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ +#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ + +/* return values */ +#define BADCH (int)'?' +#define BADARG ((*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#define EMSG "" + +static int getopt_internal(int, char * const *, const char *, + const struct option *, int *, int); +static int parse_long_options(char * const *, const char *, + const struct option *, int *, int); +static int gcd(int, int); +static void permute_args(int, int, int, char * const *); + +static char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptchar[] = "unknown option -- %c"; +static const char illoptstring[] = "unknown option -- %s"; + + + +#ifdef _WIN32 + +/* Windows needs warnx(). We change the definition though: + * 1. (another) global is defined, opterrmsg, which holds the error message + * 2. errors are always printed out on stderr w/o the program name + * Note that opterrmsg always gets set no matter what opterr is set to. The + * error message will not be printed if opterr is 0 as usual. + */ + +#include +#include + +#define MAX_OPTER_MSG_SIZE 128 + +extern char opterrmsg[MAX_OPTER_MSG_SIZE]; +char opterrmsg[MAX_OPTER_MSG_SIZE]; /* buffer for the last error message */ + +static void warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + /* + Make sure opterrmsg is always zero-terminated despite the _vsnprintf() + implementation specifics and manually suppress the warning. + */ + memset(opterrmsg, 0, sizeof opterrmsg); + if (fmt != NULL) +#ifdef __STDC_WANT_SECURE_LIB__ + _vsnprintf_s(opterrmsg, MAX_OPTER_MSG_SIZE, sizeof(opterrmsg) - 1, fmt, ap); +#else + _vsnprintf(opterrmsg, sizeof(opterrmsg) - 1, fmt, ap); +#endif + va_end(ap); + +#ifndef __ICL +#pragma warning(suppress: 6053) +#endif + fprintf(stderr, "%s\n", opterrmsg); +} + +#else +#include +#endif /*_WIN32*/ + + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(int a, int b) +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return (b); +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(int panonopt_start, int panonopt_end, int opt_end, + char * const *nargv) +{ + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +/* + * parse_long_options -- + * Parse long options in argc/argv argument vector. + * Returns -1 if short_too is set and the option does not match long_options. + */ +static int +parse_long_options(char * const *nargv, const char *options, + const struct option *long_options, int *idx, int short_too) +{ + char *current_argv, *has_equal; + size_t current_argv_len; + int i, match; + + current_argv = place; + match = -1; + + optind++; + + if ((has_equal = strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == current_argv_len) { + /* exact match */ + match = i; + break; + } + /* + * If this is a known short option, don't allow + * a partial match of a single character. + */ + if (short_too && current_argv_len == 1) + continue; + + if (match == -1) /* partial match */ + match = i; + else { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, (int)current_argv_len, + current_argv); + optopt = 0; + return (BADCH); + } + } + if (match != -1) { /* option found */ + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + return (BADARG); + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + /* + * optional argument doesn't use next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' indicates no error + * should be generated. + */ + if (PRINT_ERROR) + warnx(recargstring, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return (BADARG); + } + } else { /* unknown option */ + if (short_too) { + --optind; + return (-1); + } + if (PRINT_ERROR) + warnx(illoptstring, current_argv); + optopt = 0; + return (BADCH); + } + if (idx) + *idx = match; + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + return (0); + } else + return (long_options[match].val); +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + */ +static int +getopt_internal(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx, int flags) +{ + char *oli; /* option letter list index */ + int optchar, short_too; + static int posixly_correct = -1; +#ifdef __STDC_WANT_SECURE_LIB__ + char* buffer = NULL; + size_t buffer_size = 0; + errno_t err = 0; +#endif + + if (options == NULL) + return (-1); + + /* + * Disable GNU extensions if POSIXLY_CORRECT is set or options + * string begins with a '+'. + */ + +#ifdef __STDC_WANT_SECURE_LIB__ + if (posixly_correct == -1) { + err = _dupenv_s(&buffer, &buffer_size, "POSIXLY_CORRECT") == 0; + posixly_correct = buffer != NULL; + if(buffer != NULL && err == 0) { + free(buffer); + } + } +#else + if (posixly_correct == -1) + posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); +#endif + if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; + else if (*options == '-') + flags |= FLAG_ALLARGS; + if (*options == '+' || *options == '-') + options++; + + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + optarg = NULL; + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + if (*(place = nargv[optind]) != '-' || + (place[1] == '\0' && strchr(options, '-') == NULL)) { + place = EMSG; /* found non-option */ + if (flags & FLAG_ALLARGS) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return (INORDER); + } + if (!(flags & FLAG_PERMUTE)) { + /* + * If no permutation wanted, stop parsing + * at first non-option. + */ + return (-1); + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + + /* + * If we have "-" do nothing, if "--" we are done. + */ + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { + optind++; + place = EMSG; + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + } + + /* + * Check long options if: + * 1) we were passed some + * 2) the arg is not just "-" + * 3) either the arg starts with -- we are getopt_long_only() + */ + if (long_options != NULL && place != nargv[optind] && + (*place == '-' || (flags & FLAG_LONGONLY))) { + short_too = 0; + if (*place == '-') + place++; /* --foo long option */ + else if (*place != ':' && strchr(options, *place) != NULL) + short_too = 1; /* could be short option too */ + + optchar = parse_long_options(nargv, options, long_options, + idx, short_too); + if (optchar != -1) { + place = EMSG; + return (optchar); + } + } + + if ((optchar = (int)*place++) == (int)':' || + (optchar == (int)'-' && *place != '\0') || + (oli = strchr(options, optchar)) == NULL) { + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (!*place) + ++optind; + if (PRINT_ERROR) + warnx(illoptchar, optchar); + optopt = optchar; + return (BADCH); + } + if (long_options != NULL && optchar == 'W' && oli[1] == ';') { + /* -W long-option */ + if (*place) /* no space */ + /* NOTHING */; + else if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else /* white space */ + place = nargv[optind]; + optchar = parse_long_options(nargv, options, long_options, + idx, 0); + place = EMSG; + return (optchar); + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = place; + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else + optarg = nargv[optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return (optchar); +} + +#ifdef REPLACE_GETOPT +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the BSD getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) +{ + + /* + * We don't pass FLAG_PERMUTE to getopt_internal() since + * the BSD getopt(3) (unlike GNU) has never done this. + * + * Furthermore, since many privileged programs call getopt() + * before dropping privileges it makes sense to keep things + * as simple (and bug-free) as possible. + */ + return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); +} +#endif /* REPLACE_GETOPT */ + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE)); +} + +/* + * getopt_long_only -- + * Parse argc/argv argument vector. + */ +int +getopt_long_only(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx) +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE|FLAG_LONGONLY)); +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include +#include + +#include "argtable3.h" + + +char * arg_strptime(const char *buf, const char *fmt, struct tm *tm); + + +static void arg_date_resetfn(struct arg_date *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +static int arg_date_scanfn(struct arg_date *parent, const char *argval) +{ + int errorcode = 0; + + if (parent->count == parent->hdr.maxcount) + { + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* no argument value was given, leave parent->tmval[] unaltered but still count it */ + parent->count++; + } + else + { + const char *pend; + struct tm tm = parent->tmval[parent->count]; + + /* parse the given argument value, store result in parent->tmval[] */ + pend = arg_strptime(argval, parent->format, &tm); + if (pend && pend[0] == '\0') + parent->tmval[parent->count++] = tm; + else + errorcode = EBADDATE; + } + + ARG_TRACE(("%s:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static int arg_date_checkfn(struct arg_date *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + + ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static void arg_date_errorfn( + struct arg_date *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + case EBADDATE: + { + struct tm tm; + char buff[200]; + + fprintf(fp, "illegal timestamp format \"%s\"\n", argval); + memset(&tm, 0, sizeof(tm)); + arg_strptime("1999-12-31 23:59:59", "%F %H:%M:%S", &tm); + strftime(buff, sizeof(buff), parent->format, &tm); + printf("correct format is \"%s\"\n", buff); + break; + } + } +} + + +struct arg_date * arg_date0( + const char * shortopts, + const char * longopts, + const char * format, + const char *datatype, + const char *glossary) +{ + return arg_daten(shortopts, longopts, format, datatype, 0, 1, glossary); +} + + +struct arg_date * arg_date1( + const char * shortopts, + const char * longopts, + const char * format, + const char *datatype, + const char *glossary) +{ + return arg_daten(shortopts, longopts, format, datatype, 1, 1, glossary); +} + + +struct arg_date * arg_daten( + const char * shortopts, + const char * longopts, + const char * format, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) +{ + size_t nbytes; + struct arg_date *result; + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + /* default time format is the national date format for the locale */ + if (!format) + format = "%x"; + + nbytes = sizeof(struct arg_date) /* storage for struct arg_date */ + + maxcount * sizeof(struct tm); /* storage for tmval[maxcount] array */ + + /* allocate storage for the arg_date struct + tmval[] array. */ + /* we use calloc because we want the tmval[] array zero filled. */ + result = (struct arg_date *)calloc(1, nbytes); + if (result) + { + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = datatype ? datatype : format; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_date_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_date_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_date_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_date_errorfn; + + /* store the tmval[maxcount] array immediately after the arg_date struct */ + result->tmval = (struct tm *)(result + 1); + + /* init the remaining arg_date member variables */ + result->count = 0; + result->format = format; + } + + ARG_TRACE(("arg_daten() returns %p\n", result)); + return result; +} + + +/*- + * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code was contributed to The NetBSD Foundation by Klaus Klein. + * Heavily optimised by David Laight + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +/* + * We do not implement alternate representations. However, we always + * check whether a given modifier is allowed for a certain conversion. + */ +#define ALT_E 0x01 +#define ALT_O 0x02 +#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } +#define TM_YEAR_BASE (1900) + +static int conv_num(const char * *, int *, int, int); + +static const char *day[7] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", + "Friday", "Saturday" +}; + +static const char *abday[7] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char *mon[12] = { + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December" +}; + +static const char *abmon[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static const char *am_pm[2] = { + "AM", "PM" +}; + + +static int arg_strcasecmp(const char *s1, const char *s2) +{ + const unsigned char *us1 = (const unsigned char *)s1; + const unsigned char *us2 = (const unsigned char *)s2; + while (tolower(*us1) == tolower(*us2++)) + if (*us1++ == '\0') + return 0; + + return tolower(*us1) - tolower(*--us2); +} + + +static int arg_strncasecmp(const char *s1, const char *s2, size_t n) +{ + if (n != 0) + { + const unsigned char *us1 = (const unsigned char *)s1; + const unsigned char *us2 = (const unsigned char *)s2; + do + { + if (tolower(*us1) != tolower(*us2++)) + return tolower(*us1) - tolower(*--us2); + + if (*us1++ == '\0') + break; + } while (--n != 0); + } + + return 0; +} + + +char * arg_strptime(const char *buf, const char *fmt, struct tm *tm) +{ + char c; + const char *bp; + size_t len = 0; + int alt_format, i, split_year = 0; + + bp = buf; + + while ((c = *fmt) != '\0') { + /* Clear `alternate' modifier prior to new conversion. */ + alt_format = 0; + + /* Eat up white-space. */ + if (ISSPACE(c)) { + while (ISSPACE(*bp)) + bp++; + + fmt++; + continue; + } + + if ((c = *fmt++) != '%') + goto literal; + + +again: + switch (c = *fmt++) + { + case '%': /* "%%" is converted to "%". */ +literal: + if (c != *bp++) + return (0); + break; + + /* + * "Alternative" modifiers. Just set the appropriate flag + * and start over again. + */ + case 'E': /* "%E?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_E; + goto again; + + case 'O': /* "%O?" alternative conversion modifier. */ + LEGAL_ALT(0); + alt_format |= ALT_O; + goto again; + + /* + * "Complex" conversion rules, implemented through recursion. + */ + case 'c': /* Date and time, using the locale's format. */ + LEGAL_ALT(ALT_E); + bp = arg_strptime(bp, "%x %X", tm); + if (!bp) + return (0); + break; + + case 'D': /* The date as "%m/%d/%y". */ + LEGAL_ALT(0); + bp = arg_strptime(bp, "%m/%d/%y", tm); + if (!bp) + return (0); + break; + + case 'R': /* The time as "%H:%M". */ + LEGAL_ALT(0); + bp = arg_strptime(bp, "%H:%M", tm); + if (!bp) + return (0); + break; + + case 'r': /* The time in 12-hour clock representation. */ + LEGAL_ALT(0); + bp = arg_strptime(bp, "%I:%M:%S %p", tm); + if (!bp) + return (0); + break; + + case 'T': /* The time as "%H:%M:%S". */ + LEGAL_ALT(0); + bp = arg_strptime(bp, "%H:%M:%S", tm); + if (!bp) + return (0); + break; + + case 'X': /* The time, using the locale's format. */ + LEGAL_ALT(ALT_E); + bp = arg_strptime(bp, "%H:%M:%S", tm); + if (!bp) + return (0); + break; + + case 'x': /* The date, using the locale's format. */ + LEGAL_ALT(ALT_E); + bp = arg_strptime(bp, "%m/%d/%y", tm); + if (!bp) + return (0); + break; + + /* + * "Elementary" conversion rules. + */ + case 'A': /* The day of week, using the locale's form. */ + case 'a': + LEGAL_ALT(0); + for (i = 0; i < 7; i++) { + /* Full name. */ + len = strlen(day[i]); + if (arg_strncasecmp(day[i], bp, len) == 0) + break; + + /* Abbreviated name. */ + len = strlen(abday[i]); + if (arg_strncasecmp(abday[i], bp, len) == 0) + break; + } + + /* Nothing matched. */ + if (i == 7) + return (0); + + tm->tm_wday = i; + bp += len; + break; + + case 'B': /* The month, using the locale's form. */ + case 'b': + case 'h': + LEGAL_ALT(0); + for (i = 0; i < 12; i++) { + /* Full name. */ + len = strlen(mon[i]); + if (arg_strncasecmp(mon[i], bp, len) == 0) + break; + + /* Abbreviated name. */ + len = strlen(abmon[i]); + if (arg_strncasecmp(abmon[i], bp, len) == 0) + break; + } + + /* Nothing matched. */ + if (i == 12) + return (0); + + tm->tm_mon = i; + bp += len; + break; + + case 'C': /* The century number. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); + + if (split_year) { + tm->tm_year = (tm->tm_year % 100) + (i * 100); + } else { + tm->tm_year = i * 100; + split_year = 1; + } + break; + + case 'd': /* The day of month. */ + case 'e': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) + return (0); + break; + + case 'k': /* The hour (24-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ + case 'H': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) + return (0); + break; + + case 'l': /* The hour (12-hour clock representation). */ + LEGAL_ALT(0); + /* FALLTHROUGH */ + case 'I': + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) + return (0); + if (tm->tm_hour == 12) + tm->tm_hour = 0; + break; + + case 'j': /* The day of year. */ + LEGAL_ALT(0); + if (!(conv_num(&bp, &i, 1, 366))) + return (0); + tm->tm_yday = i - 1; + break; + + case 'M': /* The minute. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_min, 0, 59))) + return (0); + break; + + case 'm': /* The month. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &i, 1, 12))) + return (0); + tm->tm_mon = i - 1; + break; + + case 'p': /* The locale's equivalent of AM/PM. */ + LEGAL_ALT(0); + /* AM? */ + if (arg_strcasecmp(am_pm[0], bp) == 0) { + if (tm->tm_hour > 11) + return (0); + + bp += strlen(am_pm[0]); + break; + } + /* PM? */ + else if (arg_strcasecmp(am_pm[1], bp) == 0) { + if (tm->tm_hour > 11) + return (0); + + tm->tm_hour += 12; + bp += strlen(am_pm[1]); + break; + } + + /* Nothing matched. */ + return (0); + + case 'S': /* The seconds. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) + return (0); + break; + + case 'U': /* The week of year, beginning on sunday. */ + case 'W': /* The week of year, beginning on monday. */ + LEGAL_ALT(ALT_O); + /* + * XXX This is bogus, as we can not assume any valid + * information present in the tm structure at this + * point to calculate a real value, so just check the + * range for now. + */ + if (!(conv_num(&bp, &i, 0, 53))) + return (0); + break; + + case 'w': /* The day of week, beginning on sunday. */ + LEGAL_ALT(ALT_O); + if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) + return (0); + break; + + case 'Y': /* The year. */ + LEGAL_ALT(ALT_E); + if (!(conv_num(&bp, &i, 0, 9999))) + return (0); + + tm->tm_year = i - TM_YEAR_BASE; + break; + + case 'y': /* The year within 100 years of the epoch. */ + LEGAL_ALT(ALT_E | ALT_O); + if (!(conv_num(&bp, &i, 0, 99))) + return (0); + + if (split_year) { + tm->tm_year = ((tm->tm_year / 100) * 100) + i; + break; + } + split_year = 1; + if (i <= 68) + tm->tm_year = i + 2000 - TM_YEAR_BASE; + else + tm->tm_year = i + 1900 - TM_YEAR_BASE; + break; + + /* + * Miscellaneous conversions. + */ + case 'n': /* Any kind of white-space. */ + case 't': + LEGAL_ALT(0); + while (ISSPACE(*bp)) + bp++; + break; + + + default: /* Unknown/unsupported conversion. */ + return (0); + } + + + } + + /* LINTED functional specification */ + return ((char *)bp); +} + + +static int conv_num(const char * *buf, int *dest, int llim, int ulim) +{ + int result = 0; + + /* The limit also determines the number of valid digits. */ + int rulim = ulim; + + if (**buf < '0' || **buf > '9') + return (0); + + do { + result *= 10; + result += *(*buf)++ - '0'; + rulim /= 10; + } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); + + if (result < llim || result > ulim) + return (0); + + *dest = result; + return (1); +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include + +#include "argtable3.h" + + +static void arg_dbl_resetfn(struct arg_dbl *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +static int arg_dbl_scanfn(struct arg_dbl *parent, const char *argval) +{ + int errorcode = 0; + + if (parent->count == parent->hdr.maxcount) + { + /* maximum number of arguments exceeded */ + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* a valid argument with no argument value was given. */ + /* This happens when an optional argument value was invoked. */ + /* leave parent argument value unaltered but still count the argument. */ + parent->count++; + } + else + { + double val; + char *end; + + /* extract double from argval into val */ + val = strtod(argval, &end); + + /* if success then store result in parent->dval[] array otherwise return error*/ + if (*end == 0) + parent->dval[parent->count++] = val; + else + errorcode = EBADDOUBLE; + } + + ARG_TRACE(("%s:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static int arg_dbl_checkfn(struct arg_dbl *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + + ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static void arg_dbl_errorfn( + struct arg_dbl *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + case EBADDOUBLE: + fprintf(fp, "invalid argument \"%s\" to option ", argval); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + } +} + + +struct arg_dbl * arg_dbl0( + const char * shortopts, + const char * longopts, + const char *datatype, + const char *glossary) +{ + return arg_dbln(shortopts, longopts, datatype, 0, 1, glossary); +} + + +struct arg_dbl * arg_dbl1( + const char * shortopts, + const char * longopts, + const char *datatype, + const char *glossary) +{ + return arg_dbln(shortopts, longopts, datatype, 1, 1, glossary); +} + + +struct arg_dbl * arg_dbln( + const char * shortopts, + const char * longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) +{ + size_t nbytes; + struct arg_dbl *result; + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + nbytes = sizeof(struct arg_dbl) /* storage for struct arg_dbl */ + + (maxcount + 1) * sizeof(double); /* storage for dval[maxcount] array plus one extra for padding to memory boundary */ + + result = (struct arg_dbl *)malloc(nbytes); + if (result) + { + size_t addr; + size_t rem; + + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = datatype ? datatype : ""; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_dbl_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_dbl_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_dbl_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_dbl_errorfn; + + /* Store the dval[maxcount] array on the first double boundary that + * immediately follows the arg_dbl struct. We do the memory alignment + * purely for SPARC and Motorola systems. They require floats and + * doubles to be aligned on natural boundaries. + */ + addr = (size_t)(result + 1); + rem = addr % sizeof(double); + result->dval = (double *)(addr + sizeof(double) - rem); + ARG_TRACE(("addr=%p, dval=%p, sizeof(double)=%d rem=%d\n", addr, result->dval, (int)sizeof(double), (int)rem)); + + result->count = 0; + } + + ARG_TRACE(("arg_dbln() returns %p\n", result)); + return result; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include + +#include "argtable3.h" + + +static void arg_end_resetfn(struct arg_end *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + +static void arg_end_errorfn( + void *parent, + FILE *fp, + int error, + const char *argval, + const char *progname) +{ + /* suppress unreferenced formal parameter warning */ + (void)parent; + + progname = progname ? progname : ""; + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(error) + { + case ARG_ELIMIT: + fputs("too many errors to display", fp); + break; + case ARG_EMALLOC: + fputs("insufficent memory", fp); + break; + case ARG_ENOMATCH: + fprintf(fp, "unexpected argument \"%s\"", argval); + break; + case ARG_EMISSARG: + fprintf(fp, "option \"%s\" requires an argument", argval); + break; + case ARG_ELONGOPT: + fprintf(fp, "invalid option \"%s\"", argval); + break; + default: + fprintf(fp, "invalid option \"-%c\"", error); + break; + } + + fputc('\n', fp); +} + + +struct arg_end * arg_end(int maxcount) +{ + size_t nbytes; + struct arg_end *result; + + nbytes = sizeof(struct arg_end) + + maxcount * sizeof(int) /* storage for int error[maxcount] array*/ + + maxcount * sizeof(void *) /* storage for void* parent[maxcount] array */ + + maxcount * sizeof(char *); /* storage for char* argval[maxcount] array */ + + result = (struct arg_end *)malloc(nbytes); + if (result) + { + /* init the arg_hdr struct */ + result->hdr.flag = ARG_TERMINATOR; + result->hdr.shortopts = NULL; + result->hdr.longopts = NULL; + result->hdr.datatype = NULL; + result->hdr.glossary = NULL; + result->hdr.mincount = 1; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_end_resetfn; + result->hdr.scanfn = NULL; + result->hdr.checkfn = NULL; + result->hdr.errorfn = (arg_errorfn *)arg_end_errorfn; + + /* store error[maxcount] array immediately after struct arg_end */ + result->error = (int *)(result + 1); + + /* store parent[maxcount] array immediately after error[] array */ + result->parent = (void * *)(result->error + maxcount ); + + /* store argval[maxcount] array immediately after parent[] array */ + result->argval = (const char * *)(result->parent + maxcount ); + } + + ARG_TRACE(("arg_end(%d) returns %p\n", maxcount, result)); + return result; +} + + +void arg_print_errors(FILE * fp, struct arg_end * end, const char * progname) +{ + int i; + ARG_TRACE(("arg_errors()\n")); + for (i = 0; i < end->count; i++) + { + struct arg_hdr *errorparent = (struct arg_hdr *)(end->parent[i]); + if (errorparent->errorfn) + errorparent->errorfn(end->parent[i], + fp, + end->error[i], + end->argval[i], + progname); + } +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ +// THIS FILE HAS BEEN ALTERED from original version to: +// * fix issues found by static code analisys: +// - Possible null pointer dereference at arg_basename + +#include +#include + +#include "argtable3.h" + +#ifdef WIN32 +# define FILESEPARATOR1 '\\' +# define FILESEPARATOR2 '/' +#else +# define FILESEPARATOR1 '/' +# define FILESEPARATOR2 '/' +#endif + + +static void arg_file_resetfn(struct arg_file *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +/* Returns ptr to the base filename within *filename */ +static const char * arg_basename(const char *filename) +{ + const char *result = NULL, *result1, *result2; + + /* Find the last occurrence of eother file separator character. */ + /* Two alternative file separator chars are supported as legal */ + /* file separators but not both together in the same filename. */ + result1 = (filename ? strrchr(filename, FILESEPARATOR1) : NULL); + result2 = (filename ? strrchr(filename, FILESEPARATOR2) : NULL); + + if (result2) + result = result2 + 1; /* using FILESEPARATOR2 (the alternative file separator) */ + + if (result1) + result = result1 + 1; /* using FILESEPARATOR1 (the preferred file separator) */ + + if (!result) + result = filename; /* neither file separator was found so basename is the whole filename */ + + /* special cases of "." and ".." are not considered basenames */ + if (filename && result && + (strcmp(".", result) == 0 || strcmp("..", result) == 0)) + result = filename + strlen(filename); + + return result; +} + + +/* Returns ptr to the file extension within *basename */ +static const char * arg_extension(const char *basename) +{ + /* find the last occurrence of '.' in basename */ + const char *result = (basename ? strrchr(basename, '.') : NULL); + + /* if no '.' was found then return pointer to end of basename */ + if (basename && !result) + result = basename + strlen(basename); + + /* special case: basenames with a single leading dot (eg ".foo") are not considered as true extensions */ + if (basename && result == basename) + result = basename + strlen(basename); + + /* special case: empty extensions (eg "foo.","foo..") are not considered as true extensions */ + if (basename && result && result[1] == '\0') + result = basename + strlen(basename); + + return result; +} + + +static int arg_file_scanfn(struct arg_file *parent, const char *argval) +{ + int errorcode = 0; + + if (parent->count == parent->hdr.maxcount) + { + /* maximum number of arguments exceeded */ + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* a valid argument with no argument value was given. */ + /* This happens when an optional argument value was invoked. */ + /* leave parent arguiment value unaltered but still count the argument. */ + parent->count++; + } + else + { + parent->filename[parent->count] = argval; + parent->basename[parent->count] = arg_basename(argval); + parent->extension[parent->count] = + arg_extension(parent->basename[parent->count]); /* only seek extensions within the basename (not the file path)*/ + parent->count++; + } + + ARG_TRACE(("%s4:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static int arg_file_checkfn(struct arg_file *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + + ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static void arg_file_errorfn( + struct arg_file *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + default: + fprintf(fp, "unknown error at \"%s\"\n", argval); + } +} + + +struct arg_file * arg_file0( + const char * shortopts, + const char * longopts, + const char *datatype, + const char *glossary) +{ + return arg_filen(shortopts, longopts, datatype, 0, 1, glossary); +} + + +struct arg_file * arg_file1( + const char * shortopts, + const char * longopts, + const char *datatype, + const char *glossary) +{ + return arg_filen(shortopts, longopts, datatype, 1, 1, glossary); +} + + +struct arg_file * arg_filen( + const char * shortopts, + const char * longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) +{ + size_t nbytes; + struct arg_file *result; + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + nbytes = sizeof(struct arg_file) /* storage for struct arg_file */ + + sizeof(char *) * maxcount /* storage for filename[maxcount] array */ + + sizeof(char *) * maxcount /* storage for basename[maxcount] array */ + + sizeof(char *) * maxcount; /* storage for extension[maxcount] array */ + + result = (struct arg_file *)malloc(nbytes); + if (result) + { + int i; + + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.glossary = glossary; + result->hdr.datatype = datatype ? datatype : ""; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_file_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_file_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_file_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_file_errorfn; + + /* store the filename,basename,extension arrays immediately after the arg_file struct */ + result->filename = (const char * *)(result + 1); + result->basename = result->filename + maxcount; + result->extension = result->basename + maxcount; + result->count = 0; + + /* foolproof the string pointers by initialising them with empty strings */ + for (i = 0; i < maxcount; i++) + { + result->filename[i] = ""; + result->basename[i] = ""; + result->extension[i] = ""; + } + } + + ARG_TRACE(("arg_filen() returns %p\n", result)); + return result; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include +#include +#include + +#include "argtable3.h" + + +static void arg_int_resetfn(struct arg_int *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +/* strtol0x() is like strtol() except that the numeric string is */ +/* expected to be prefixed by "0X" where X is a user supplied char. */ +/* The string may optionally be prefixed by white space and + or - */ +/* as in +0X123 or -0X123. */ +/* Once the prefix has been scanned, the remainder of the numeric */ +/* string is converted using strtol() with the given base. */ +/* eg: to parse hex str="-0X12324", specify X='X' and base=16. */ +/* eg: to parse oct str="+0o12324", specify X='O' and base=8. */ +/* eg: to parse bin str="-0B01010", specify X='B' and base=2. */ +/* Failure of conversion is indicated by result where *endptr==str. */ +static long int strtol0X(const char * str, + const char * *endptr, + char X, + int base) +{ + long int val; /* stores result */ + int s = 1; /* sign is +1 or -1 */ + const char *ptr = str; /* ptr to current position in str */ + + /* skip leading whitespace */ + while (ISSPACE(*ptr)) + ptr++; + /* printf("1) %s\n",ptr); */ + + /* scan optional sign character */ + switch (*ptr) + { + case '+': + ptr++; + s = 1; + break; + case '-': + ptr++; + s = -1; + break; + default: + s = 1; + break; + } + /* printf("2) %s\n",ptr); */ + + /* '0X' prefix */ + if ((*ptr++) != '0') + { + /* printf("failed to detect '0'\n"); */ + *endptr = str; + return 0; + } + /* printf("3) %s\n",ptr); */ + if (toupper(*ptr++) != toupper(X)) + { + /* printf("failed to detect '%c'\n",X); */ + *endptr = str; + return 0; + } + /* printf("4) %s\n",ptr); */ + + /* attempt conversion on remainder of string using strtol() */ + val = strtol(ptr, (char * *)endptr, base); + if (*endptr == ptr) + { + /* conversion failed */ + *endptr = str; + return 0; + } + + /* success */ + return s * val; +} + + +/* Returns 1 if str matches suffix (case insensitive). */ +/* Str may contain trailing whitespace, but nothing else. */ +static int detectsuffix(const char *str, const char *suffix) +{ + /* scan pairwise through strings until mismatch detected */ + while( toupper(*str) == toupper(*suffix) ) + { + /* printf("'%c' '%c'\n", *str, *suffix); */ + + /* return 1 (success) if match persists until the string terminator */ + if (*str == '\0') + return 1; + + /* next chars */ + str++; + suffix++; + } + /* printf("'%c' '%c' mismatch\n", *str, *suffix); */ + + /* return 0 (fail) if the matching did not consume the entire suffix */ + if (*suffix != 0) + return 0; /* failed to consume entire suffix */ + + /* skip any remaining whitespace in str */ + while (ISSPACE(*str)) + str++; + + /* return 1 (success) if we have reached end of str else return 0 (fail) */ + return (*str == '\0') ? 1 : 0; +} + + +static int arg_int_scanfn(struct arg_int *parent, const char *argval) +{ + int errorcode = 0; + + if (parent->count == parent->hdr.maxcount) + { + /* maximum number of arguments exceeded */ + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* a valid argument with no argument value was given. */ + /* This happens when an optional argument value was invoked. */ + /* leave parent arguiment value unaltered but still count the argument. */ + parent->count++; + } + else + { + long int val; + const char *end; + + /* attempt to extract hex integer (eg: +0x123) from argval into val conversion */ + val = strtol0X(argval, &end, 'X', 16); + if (end == argval) + { + /* hex failed, attempt octal conversion (eg +0o123) */ + val = strtol0X(argval, &end, 'O', 8); + if (end == argval) + { + /* octal failed, attempt binary conversion (eg +0B101) */ + val = strtol0X(argval, &end, 'B', 2); + if (end == argval) + { + /* binary failed, attempt decimal conversion with no prefix (eg 1234) */ + val = strtol(argval, (char * *)&end, 10); + if (end == argval) + { + /* all supported number formats failed */ + return EBADINT; + } + } + } + } + + /* Safety check for integer overflow. WARNING: this check */ + /* achieves nothing on machines where size(int)==size(long). */ + if ( val > INT_MAX || val < INT_MIN ) +#ifdef __STDC_WANT_SECURE_LIB__ + errorcode = EOVERFLOW_; +#else + errorcode = EOVERFLOW; +#endif + + /* Detect any suffixes (KB,MB,GB) and multiply argument value appropriately. */ + /* We need to be mindful of integer overflows when using such big numbers. */ + if (detectsuffix(end, "KB")) /* kilobytes */ + { + if ( val > (INT_MAX / 1024) || val < (INT_MIN / 1024) ) +#ifdef __STDC_WANT_SECURE_LIB__ + errorcode = EOVERFLOW_; /* Overflow would occur if we proceed */ +#else + errorcode = EOVERFLOW; /* Overflow would occur if we proceed */ +#endif + else + val *= 1024; /* 1KB = 1024 */ + } + else if (detectsuffix(end, "MB")) /* megabytes */ + { + if ( val > (INT_MAX / 1048576) || val < (INT_MIN / 1048576) ) +#ifdef __STDC_WANT_SECURE_LIB__ + errorcode = EOVERFLOW_; /* Overflow would occur if we proceed */ +#else + errorcode = EOVERFLOW; /* Overflow would occur if we proceed */ +#endif + else + val *= 1048576; /* 1MB = 1024*1024 */ + } + else if (detectsuffix(end, "GB")) /* gigabytes */ + { + if ( val > (INT_MAX / 1073741824) || val < (INT_MIN / 1073741824) ) +#ifdef __STDC_WANT_SECURE_LIB__ + errorcode = EOVERFLOW_; /* Overflow would occur if we proceed */ +#else + errorcode = EOVERFLOW; /* Overflow would occur if we proceed */ +#endif + else + val *= 1073741824; /* 1GB = 1024*1024*1024 */ + } + else if (!detectsuffix(end, "")) + errorcode = EBADINT; /* invalid suffix detected */ + + /* if success then store result in parent->ival[] array */ + if (errorcode == 0) + parent->ival[parent->count++] = val; + } + + /* printf("%s:scanfn(%p,%p) returns %d\n",__FILE__,parent,argval,errorcode); */ + return errorcode; +} + + +static int arg_int_checkfn(struct arg_int *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + /*printf("%s:checkfn(%p) returns %d\n",__FILE__,parent,errorcode);*/ + return errorcode; +} + + +static void arg_int_errorfn( + struct arg_int *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + case EBADINT: + fprintf(fp, "invalid argument \"%s\" to option ", argval); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + +#ifdef __STDC_WANT_SECURE_LIB__ + case EOVERFLOW_: +#else + case EOVERFLOW: +#endif + fputs("integer overflow at option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, " "); + fprintf(fp, "(%s is too large)\n", argval); + break; + } +} + + +struct arg_int * arg_int0( + const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary) +{ + return arg_intn(shortopts, longopts, datatype, 0, 1, glossary); +} + + +struct arg_int * arg_int1( + const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary) +{ + return arg_intn(shortopts, longopts, datatype, 1, 1, glossary); +} + + +struct arg_int * arg_intn( + const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) +{ + size_t nbytes; + struct arg_int *result; + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + nbytes = sizeof(struct arg_int) /* storage for struct arg_int */ + + maxcount * sizeof(int); /* storage for ival[maxcount] array */ + + result = (struct arg_int *)malloc(nbytes); + if (result) + { + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = datatype ? datatype : ""; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_int_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_int_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_int_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_int_errorfn; + + /* store the ival[maxcount] array immediately after the arg_int struct */ + result->ival = (int *)(result + 1); + result->count = 0; + } + + ARG_TRACE(("arg_intn() returns %p\n", result)); + return result; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include + +#include "argtable3.h" + + +static void arg_lit_resetfn(struct arg_lit *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +static int arg_lit_scanfn(struct arg_lit *parent, const char *argval) +{ + int errorcode = 0; + if (parent->count < parent->hdr.maxcount ) + parent->count++; + else + errorcode = EMAXCOUNT; + + ARG_TRACE(("%s:scanfn(%p,%s) returns %d\n", __FILE__, parent, argval, + errorcode)); + return errorcode; +} + + +static int arg_lit_checkfn(struct arg_lit *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static void arg_lit_errorfn( + struct arg_lit *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + switch(errorcode) + { + case EMINCOUNT: + fprintf(fp, "%s: missing option ", progname); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + fprintf(fp, "\n"); + break; + + case EMAXCOUNT: + fprintf(fp, "%s: extraneous option ", progname); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + } + + ARG_TRACE(("%s:errorfn(%p, %p, %d, %s, %s)\n", __FILE__, parent, fp, + errorcode, argval, progname)); +} + + +struct arg_lit * arg_lit0( + const char * shortopts, + const char * longopts, + const char * glossary) +{ + return arg_litn(shortopts, longopts, 0, 1, glossary); +} + + +struct arg_lit * arg_lit1( + const char *shortopts, + const char *longopts, + const char *glossary) +{ + return arg_litn(shortopts, longopts, 1, 1, glossary); +} + + +struct arg_lit * arg_litn( + const char *shortopts, + const char *longopts, + int mincount, + int maxcount, + const char *glossary) +{ + struct arg_lit *result; + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + result = (struct arg_lit *)malloc(sizeof(struct arg_lit)); + if (result) + { + /* init the arg_hdr struct */ + result->hdr.flag = 0; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = NULL; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_lit_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_lit_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_lit_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_lit_errorfn; + + /* init local variables */ + result->count = 0; + } + + ARG_TRACE(("arg_litn() returns %p\n", result)); + return result; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include + +#include "argtable3.h" + +struct arg_rem *arg_rem(const char *datatype, const char *glossary) +{ + struct arg_rem *result = (struct arg_rem *)malloc(sizeof(struct arg_rem)); + if (result) + { + result->hdr.flag = 0; + result->hdr.shortopts = NULL; + result->hdr.longopts = NULL; + result->hdr.datatype = datatype; + result->hdr.glossary = glossary; + result->hdr.mincount = 1; + result->hdr.maxcount = 1; + result->hdr.parent = result; + result->hdr.resetfn = NULL; + result->hdr.scanfn = NULL; + result->hdr.checkfn = NULL; + result->hdr.errorfn = NULL; + } + + ARG_TRACE(("arg_rem() returns %p\n", result)); + return result; +} + +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include +#include + +#include "argtable3.h" + + +#ifndef _TREX_H_ +#define _TREX_H_ +/*************************************************************** + T-Rex a tiny regular expression library + + Copyright (C) 2003-2006 Alberto Demichelis + + This software is provided 'as-is', without any express + or implied warranty. In no event will the authors be held + liable for any damages arising from the use of this software. + + Permission is granted to anyone to use this software for + any purpose, including commercial applications, and to alter + it and redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment + in the product documentation would be appreciated but + is not required. + + 2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any + source distribution. + +****************************************************************/ +// THIS FILE HAS BEEN ALTERED from original version to: +// * fix issues found by static code analisys: +// - Null pointer dereference in trex_newnode, arg_rex_scanfn and trex_compile +// * Fix implicit-fallthrough GCC error in trex_charnode +// * Fix clobbered GCC error in trex_compile + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _UNICODE +#define TRexChar unsigned short +#define MAX_CHAR 0xFFFF +#define _TREXC(c) L##c +#define trex_strlen wcslen +#define trex_printf wprintf +#else +#define TRexChar char +#define MAX_CHAR 0xFF +#define _TREXC(c) (c) +#define trex_strlen strlen +#define trex_printf printf +#endif + +#ifndef TREX_API +#define TREX_API extern +#endif + +#define TRex_True 1 +#define TRex_False 0 + +#define TREX_ICASE ARG_REX_ICASE + +typedef unsigned int TRexBool; +typedef struct TRex TRex; + +typedef struct { + const TRexChar *begin; + int len; +} TRexMatch; + +TREX_API TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags); +TREX_API void trex_free(TRex *exp); +TREX_API TRexBool trex_match(TRex* exp, const TRexChar* text); +TREX_API TRexBool trex_search(TRex* exp, const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end); +TREX_API TRexBool trex_searchrange(TRex* exp, const TRexChar* text_begin, const TRexChar* text_end, const TRexChar** out_begin, const TRexChar** out_end); +TREX_API int trex_getsubexpcount(TRex* exp); +TREX_API TRexBool trex_getsubexp(TRex* exp, int n, TRexMatch *subexp); + +#ifdef __cplusplus +} +#endif + +#endif + + + +struct privhdr +{ + const char *pattern; + int flags; +}; + + +static void arg_rex_resetfn(struct arg_rex *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + +static int arg_rex_scanfn(struct arg_rex *parent, const char *argval) +{ + int errorcode = 0; + const TRexChar *error = NULL; + TRex *rex = NULL; + TRexBool is_match = TRex_False; + + if (parent->count == parent->hdr.maxcount ) + { + /* maximum number of arguments exceeded */ + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* a valid argument with no argument value was given. */ + /* This happens when an optional argument value was invoked. */ + /* leave parent argument value unaltered but still count the argument. */ + parent->count++; + } + else + { + struct privhdr *priv = (struct privhdr *)parent->hdr.priv; + + /* test the current argument value for a match with the regular expression */ + /* if a match is detected, record the argument value in the arg_rex struct */ + + rex = trex_compile(priv->pattern, &error, priv->flags); + if (!rex) + { + errorcode = EREGNOMATCH; + } + else + { + is_match = trex_match(rex, argval); + if (!is_match) + errorcode = EREGNOMATCH; + else + parent->sval[parent->count++] = argval; + + trex_free(rex); + } + } + + ARG_TRACE(("%s:scanfn(%p) returns %d\n",__FILE__,parent,errorcode)); + return errorcode; +} + +static int arg_rex_checkfn(struct arg_rex *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + //struct privhdr *priv = (struct privhdr*)parent->hdr.priv; + + /* free the regex "program" we constructed in resetfn */ + //regfree(&(priv->regex)); + + /*printf("%s:checkfn(%p) returns %d\n",__FILE__,parent,errorcode);*/ + return errorcode; +} + +static void arg_rex_errorfn(struct arg_rex *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + case EREGNOMATCH: + fputs("illegal value ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + + default: + { + //char errbuff[256]; + //regerror(errorcode, NULL, errbuff, sizeof(errbuff)); + //printf("%s\n", errbuff); + } + break; + } +} + + +struct arg_rex * arg_rex0(const char * shortopts, + const char * longopts, + const char * pattern, + const char *datatype, + int flags, + const char *glossary) +{ + return arg_rexn(shortopts, + longopts, + pattern, + datatype, + 0, + 1, + flags, + glossary); +} + +struct arg_rex * arg_rex1(const char * shortopts, + const char * longopts, + const char * pattern, + const char *datatype, + int flags, + const char *glossary) +{ + return arg_rexn(shortopts, + longopts, + pattern, + datatype, + 1, + 1, + flags, + glossary); +} + + +struct arg_rex * arg_rexn(const char * shortopts, + const char * longopts, + const char * pattern, + const char *datatype, + int mincount, + int maxcount, + int flags, + const char *glossary) +{ + size_t nbytes; + struct arg_rex *result; + struct privhdr *priv; + int i; + const TRexChar *error = NULL; + TRex *rex = NULL; + + if (!pattern) + { + printf( + "argtable: ERROR - illegal regular expression pattern \"(NULL)\"\n"); + printf("argtable: Bad argument table.\n"); + return NULL; + } + + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + nbytes = sizeof(struct arg_rex) /* storage for struct arg_rex */ + + sizeof(struct privhdr) /* storage for private arg_rex data */ + + maxcount * sizeof(char *); /* storage for sval[maxcount] array */ + + result = (struct arg_rex *)malloc(nbytes); + if (result == NULL) + return result; + + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = datatype ? datatype : pattern; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_rex_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_rex_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_rex_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_rex_errorfn; + + /* store the arg_rex_priv struct immediately after the arg_rex struct */ + result->hdr.priv = result + 1; + priv = (struct privhdr *)(result->hdr.priv); + priv->pattern = pattern; + priv->flags = flags; + + /* store the sval[maxcount] array immediately after the arg_rex_priv struct */ + result->sval = (const char * *)(priv + 1); + result->count = 0; + + /* foolproof the string pointers by initializing them to reference empty strings */ + for (i = 0; i < maxcount; i++) + result->sval[i] = ""; + + /* here we construct and destroy a regex representation of the regular + * expression for no other reason than to force any regex errors to be + * trapped now rather than later. If we don't, then errors may go undetected + * until an argument is actually parsed. + */ + + rex = trex_compile(priv->pattern, &error, priv->flags); + if (rex == NULL) + { + ARG_LOG(("argtable: %s \"%s\"\n", error ? error : _TREXC("undefined"), priv->pattern)); + ARG_LOG(("argtable: Bad argument table.\n")); + } + + trex_free(rex); + + ARG_TRACE(("arg_rexn() returns %p\n", result)); + return result; +} + + + +/* see copyright notice in trex.h */ +#include +#include +#include +#include + +#ifdef _UINCODE +#define scisprint iswprint +#define scstrlen wcslen +#define scprintf wprintf +#define _SC(x) L(x) +#else +#define scisprint isprint +#define scstrlen strlen +#define scprintf printf +#define _SC(x) (x) +#endif + +#ifdef _DEBUG +#include + +static const TRexChar *g_nnames[] = +{ + _SC("NONE"),_SC("OP_GREEDY"), _SC("OP_OR"), + _SC("OP_EXPR"),_SC("OP_NOCAPEXPR"),_SC("OP_DOT"), _SC("OP_CLASS"), + _SC("OP_CCLASS"),_SC("OP_NCLASS"),_SC("OP_RANGE"),_SC("OP_CHAR"), + _SC("OP_EOL"),_SC("OP_BOL"),_SC("OP_WB") +}; + +#endif +#define OP_GREEDY (MAX_CHAR+1) // * + ? {n} +#define OP_OR (MAX_CHAR+2) +#define OP_EXPR (MAX_CHAR+3) //parentesis () +#define OP_NOCAPEXPR (MAX_CHAR+4) //parentesis (?:) +#define OP_DOT (MAX_CHAR+5) +#define OP_CLASS (MAX_CHAR+6) +#define OP_CCLASS (MAX_CHAR+7) +#define OP_NCLASS (MAX_CHAR+8) //negates class the [^ +#define OP_RANGE (MAX_CHAR+9) +#define OP_CHAR (MAX_CHAR+10) +#define OP_EOL (MAX_CHAR+11) +#define OP_BOL (MAX_CHAR+12) +#define OP_WB (MAX_CHAR+13) + +#define TREX_SYMBOL_ANY_CHAR ('.') +#define TREX_SYMBOL_GREEDY_ONE_OR_MORE ('+') +#define TREX_SYMBOL_GREEDY_ZERO_OR_MORE ('*') +#define TREX_SYMBOL_GREEDY_ZERO_OR_ONE ('?') +#define TREX_SYMBOL_BRANCH ('|') +#define TREX_SYMBOL_END_OF_STRING ('$') +#define TREX_SYMBOL_BEGINNING_OF_STRING ('^') +#define TREX_SYMBOL_ESCAPE_CHAR ('\\') + + +typedef int TRexNodeType; + +typedef struct tagTRexNode{ + TRexNodeType type; + int left; + int right; + int next; +}TRexNode; + +struct TRex{ + const TRexChar *_eol; + const TRexChar *_bol; + const TRexChar *_p; + int _first; + int _op; + TRexNode *_nodes; + int _nallocated; + int _nsize; + int _nsubexpr; + TRexMatch *_matches; + int _currsubexp; + void *_jmpbuf; + const TRexChar **_error; + int _flags; +}; + +static int trex_list(TRex *exp); + +static int trex_newnode(TRex *exp, TRexNodeType type) +{ + TRexNode n; + int newid; + n.type = type; + n.next = n.right = n.left = -1; + if(type == OP_EXPR) + n.right = exp->_nsubexpr++; + if(exp->_nallocated < (exp->_nsize + 1)) { + TRexNode *new_nodes = NULL; + exp->_nallocated *= 2; + new_nodes = (TRexNode *)realloc(exp->_nodes, exp->_nallocated * sizeof(TRexNode)); + if (!new_nodes) + return 0; // return id of _nodes[0] in case of re-allocation failure + exp->_nodes = new_nodes; + } + exp->_nodes[exp->_nsize++] = n; + newid = exp->_nsize - 1; + return (int)newid; +} + +static void trex_error(TRex *exp,const TRexChar *error) +{ + if(exp->_error) *exp->_error = error; + longjmp(*((jmp_buf*)exp->_jmpbuf),-1); +} + +static void trex_expect(TRex *exp, int n){ + if((*exp->_p) != n) + trex_error(exp, _SC("expected paren")); + exp->_p++; +} + +static TRexChar trex_escapechar(TRex *exp) +{ + if(*exp->_p == TREX_SYMBOL_ESCAPE_CHAR){ + exp->_p++; + switch(*exp->_p) { + case 'v': exp->_p++; return '\v'; + case 'n': exp->_p++; return '\n'; + case 't': exp->_p++; return '\t'; + case 'r': exp->_p++; return '\r'; + case 'f': exp->_p++; return '\f'; + default: return (*exp->_p++); + } + } else if(!scisprint(*exp->_p)) trex_error(exp,_SC("letter expected")); + return (*exp->_p++); +} + +static int trex_charclass(TRex *exp,int classid) +{ + int n = trex_newnode(exp,OP_CCLASS); + exp->_nodes[n].left = classid; + return n; +} + +static int trex_charnode(TRex *exp,TRexBool isclass) +{ + TRexChar t; + if(*exp->_p == TREX_SYMBOL_ESCAPE_CHAR) { + exp->_p++; + switch(*exp->_p) { + case 'n': exp->_p++; return trex_newnode(exp,'\n'); + case 't': exp->_p++; return trex_newnode(exp,'\t'); + case 'r': exp->_p++; return trex_newnode(exp,'\r'); + case 'f': exp->_p++; return trex_newnode(exp,'\f'); + case 'v': exp->_p++; return trex_newnode(exp,'\v'); + case 'a': case 'A': case 'w': case 'W': case 's': case 'S': + case 'd': case 'D': case 'x': case 'X': case 'c': case 'C': + case 'p': case 'P': case 'l': case 'u': + { + t = *exp->_p; exp->_p++; + return trex_charclass(exp,t); + } + case 'b': + case 'B': + if(!isclass) { + int node = trex_newnode(exp,OP_WB); + exp->_nodes[node].left = *exp->_p; + exp->_p++; + return node; + } // fallthrough + //else default + default: + t = *exp->_p; exp->_p++; + return trex_newnode(exp,t); + } + } + else if(!scisprint(*exp->_p)) { + + trex_error(exp,_SC("letter expected")); + } + t = *exp->_p; exp->_p++; + return trex_newnode(exp,t); +} +static int trex_class(TRex *exp) +{ + int ret = -1; + int first = -1,chain; + if(*exp->_p == TREX_SYMBOL_BEGINNING_OF_STRING){ + ret = trex_newnode(exp,OP_NCLASS); + exp->_p++; + }else ret = trex_newnode(exp,OP_CLASS); + + if(*exp->_p == ']') trex_error(exp,_SC("empty class")); + chain = ret; + while(*exp->_p != ']' && exp->_p != exp->_eol) { + if(*exp->_p == '-' && first != -1){ + int r,t; + if(*exp->_p++ == ']') trex_error(exp,_SC("unfinished range")); + r = trex_newnode(exp,OP_RANGE); + if(first>*exp->_p) trex_error(exp,_SC("invalid range")); + if(exp->_nodes[first].type == OP_CCLASS) trex_error(exp,_SC("cannot use character classes in ranges")); + exp->_nodes[r].left = exp->_nodes[first].type; + t = trex_escapechar(exp); + exp->_nodes[r].right = t; + exp->_nodes[chain].next = r; + chain = r; + first = -1; + } + else{ + if(first!=-1){ + int c = first; + exp->_nodes[chain].next = c; + chain = c; + first = trex_charnode(exp,TRex_True); + } + else{ + first = trex_charnode(exp,TRex_True); + } + } + } + if(first!=-1){ + int c = first; + exp->_nodes[chain].next = c; + chain = c; + first = -1; + } + /* hack? */ + exp->_nodes[ret].left = exp->_nodes[ret].next; + exp->_nodes[ret].next = -1; + return ret; +} + +static int trex_parsenumber(TRex *exp) +{ + int ret = *exp->_p-'0'; + int positions = 10; + exp->_p++; + while(isdigit(*exp->_p)) { + ret = ret*10+(*exp->_p++-'0'); + if(positions==1000000000) trex_error(exp,_SC("overflow in numeric constant")); + positions *= 10; + }; + return ret; +} + +static int trex_element(TRex *exp) +{ + int ret = -1; + switch(*exp->_p) + { + case '(': { + int expr,newn; + exp->_p++; + + + if(*exp->_p =='?') { + exp->_p++; + trex_expect(exp,':'); + expr = trex_newnode(exp,OP_NOCAPEXPR); + } + else + expr = trex_newnode(exp,OP_EXPR); + newn = trex_list(exp); + exp->_nodes[expr].left = newn; + ret = expr; + trex_expect(exp,')'); + } + break; + case '[': + exp->_p++; + ret = trex_class(exp); + trex_expect(exp,']'); + break; + case TREX_SYMBOL_END_OF_STRING: exp->_p++; ret = trex_newnode(exp,OP_EOL);break; + case TREX_SYMBOL_ANY_CHAR: exp->_p++; ret = trex_newnode(exp,OP_DOT);break; + default: + ret = trex_charnode(exp,TRex_False); + break; + } + + { + TRexBool isgreedy = TRex_False; + unsigned short p0 = 0, p1 = 0; + switch(*exp->_p){ + case TREX_SYMBOL_GREEDY_ZERO_OR_MORE: p0 = 0; p1 = 0xFFFF; exp->_p++; isgreedy = TRex_True; break; + case TREX_SYMBOL_GREEDY_ONE_OR_MORE: p0 = 1; p1 = 0xFFFF; exp->_p++; isgreedy = TRex_True; break; + case TREX_SYMBOL_GREEDY_ZERO_OR_ONE: p0 = 0; p1 = 1; exp->_p++; isgreedy = TRex_True; break; + case '{': + exp->_p++; + if(!isdigit(*exp->_p)) trex_error(exp,_SC("number expected")); + p0 = (unsigned short)trex_parsenumber(exp); + /*******************************/ + switch(*exp->_p) { + case '}': + p1 = p0; exp->_p++; + break; + case ',': + exp->_p++; + p1 = 0xFFFF; + if(isdigit(*exp->_p)){ + p1 = (unsigned short)trex_parsenumber(exp); + } + trex_expect(exp,'}'); + break; + default: + trex_error(exp,_SC(", or } expected")); + } + /*******************************/ + isgreedy = TRex_True; + break; + + } + if(isgreedy) { + int nnode = trex_newnode(exp,OP_GREEDY); + exp->_nodes[nnode].left = ret; + exp->_nodes[nnode].right = ((p0)<<16)|p1; + ret = nnode; + } + } + if((*exp->_p != TREX_SYMBOL_BRANCH) && (*exp->_p != ')') && (*exp->_p != TREX_SYMBOL_GREEDY_ZERO_OR_MORE) && (*exp->_p != TREX_SYMBOL_GREEDY_ONE_OR_MORE) && (*exp->_p != '\0')) { + int nnode = trex_element(exp); + exp->_nodes[ret].next = nnode; + } + + return ret; +} + +static int trex_list(TRex *exp) +{ + int ret=-1,e; + if(*exp->_p == TREX_SYMBOL_BEGINNING_OF_STRING) { + exp->_p++; + ret = trex_newnode(exp,OP_BOL); + } + e = trex_element(exp); + if(ret != -1) { + exp->_nodes[ret].next = e; + } + else ret = e; + + if(*exp->_p == TREX_SYMBOL_BRANCH) { + int temp,tright; + exp->_p++; + temp = trex_newnode(exp,OP_OR); + exp->_nodes[temp].left = ret; + tright = trex_list(exp); + exp->_nodes[temp].right = tright; + ret = temp; + } + return ret; +} + +static TRexBool trex_matchcclass(int cclass,TRexChar c) +{ + switch(cclass) { + case 'a': return isalpha(c)?TRex_True:TRex_False; + case 'A': return !isalpha(c)?TRex_True:TRex_False; + case 'w': return (isalnum(c) || c == '_')?TRex_True:TRex_False; + case 'W': return (!isalnum(c) && c != '_')?TRex_True:TRex_False; + case 's': return ISSPACE(c)?TRex_True:TRex_False; + case 'S': return !ISSPACE(c)?TRex_True:TRex_False; + case 'd': return isdigit(c)?TRex_True:TRex_False; + case 'D': return !isdigit(c)?TRex_True:TRex_False; + case 'x': return isxdigit(c)?TRex_True:TRex_False; + case 'X': return !isxdigit(c)?TRex_True:TRex_False; + case 'c': return iscntrl(c)?TRex_True:TRex_False; + case 'C': return !iscntrl(c)?TRex_True:TRex_False; + case 'p': return ispunct(c)?TRex_True:TRex_False; + case 'P': return !ispunct(c)?TRex_True:TRex_False; + case 'l': return islower(c)?TRex_True:TRex_False; + case 'u': return isupper(c)?TRex_True:TRex_False; + } + return TRex_False; /*cannot happen*/ +} + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4706 ) +#endif + +static TRexBool trex_matchclass(TRex* exp,TRexNode *node,TRexChar c) +{ + do { + switch(node->type) { + case OP_RANGE: + if (exp->_flags & TREX_ICASE) + { + if(c >= toupper(node->left) && c <= toupper(node->right)) return TRex_True; + if(c >= tolower(node->left) && c <= tolower(node->right)) return TRex_True; + } + else + { + if(c >= node->left && c <= node->right) return TRex_True; + } + break; + case OP_CCLASS: + if(trex_matchcclass(node->left,c)) return TRex_True; + break; + default: + if (exp->_flags & TREX_ICASE) + { + if (c == tolower(node->type) || c == toupper(node->type)) return TRex_True; + } + else + { + if(c == node->type)return TRex_True; + } + + } + } while((node->next != -1) && (node = &exp->_nodes[node->next])); + return TRex_False; +} + +static const TRexChar *trex_matchnode(TRex* exp,TRexNode *node,const TRexChar *str,TRexNode *next) +{ + + TRexNodeType type = node->type; + switch(type) { + case OP_GREEDY: { + //TRexNode *greedystop = (node->next != -1) ? &exp->_nodes[node->next] : NULL; + TRexNode *greedystop = NULL; + int p0 = (node->right >> 16)&0x0000FFFF, p1 = node->right&0x0000FFFF, nmaches = 0; + const TRexChar *s=str, *good = str; + + if(node->next != -1) { + greedystop = &exp->_nodes[node->next]; + } + else { + greedystop = next; + } + + while((nmaches == 0xFFFF || nmaches < p1)) { + + const TRexChar *stop; + if(!(s = trex_matchnode(exp,&exp->_nodes[node->left],s,greedystop))) + break; + nmaches++; + good=s; + if(greedystop) { + //checks that 0 matches satisfy the expression(if so skips) + //if not would always stop(for instance if is a '?') + if(greedystop->type != OP_GREEDY || + (greedystop->type == OP_GREEDY && ((greedystop->right >> 16)&0x0000FFFF) != 0)) + { + TRexNode *gnext = NULL; + if(greedystop->next != -1) { + gnext = &exp->_nodes[greedystop->next]; + }else if(next && next->next != -1){ + gnext = &exp->_nodes[next->next]; + } + stop = trex_matchnode(exp,greedystop,s,gnext); + if(stop) { + //if satisfied stop it + if(p0 == p1 && p0 == nmaches) break; + else if(nmaches >= p0 && p1 == 0xFFFF) break; + else if(nmaches >= p0 && nmaches <= p1) break; + } + } + } + + if(s >= exp->_eol) + break; + } + if(p0 == p1 && p0 == nmaches) return good; + else if(nmaches >= p0 && p1 == 0xFFFF) return good; + else if(nmaches >= p0 && nmaches <= p1) return good; + return NULL; + } + case OP_OR: { + const TRexChar *asd = str; + TRexNode *temp=&exp->_nodes[node->left]; + while( (asd = trex_matchnode(exp,temp,asd,NULL)) ) { + if(temp->next != -1) + temp = &exp->_nodes[temp->next]; + else + return asd; + } + asd = str; + temp = &exp->_nodes[node->right]; + while( (asd = trex_matchnode(exp,temp,asd,NULL)) ) { + if(temp->next != -1) + temp = &exp->_nodes[temp->next]; + else + return asd; + } + return NULL; + break; + } + case OP_EXPR: + case OP_NOCAPEXPR:{ + TRexNode *n = &exp->_nodes[node->left]; + const TRexChar *cur = str; + int capture = -1; + if(node->type != OP_NOCAPEXPR && node->right == exp->_currsubexp) { + capture = exp->_currsubexp; + exp->_matches[capture].begin = cur; + exp->_currsubexp++; + } + + do { + TRexNode *subnext = NULL; + if(n->next != -1) { + subnext = &exp->_nodes[n->next]; + }else { + subnext = next; + } + if(!(cur = trex_matchnode(exp,n,cur,subnext))) { + if(capture != -1){ + exp->_matches[capture].begin = 0; + exp->_matches[capture].len = 0; + } + return NULL; + } + } while((n->next != -1) && (n = &exp->_nodes[n->next])); + + if(capture != -1) + exp->_matches[capture].len = (int)(cur - exp->_matches[capture].begin); + return cur; + } + case OP_WB: + if((str == exp->_bol && !ISSPACE(*str)) + || ((str == exp->_eol && !ISSPACE(*(str-1)))) + || ((!ISSPACE(*str) && ISSPACE(*(str+1)))) + || ((ISSPACE(*str) && !ISSPACE(*(str+1)))) ) { + return (node->left == 'b')?str:NULL; + } + return (node->left == 'b')?NULL:str; + case OP_BOL: + if(str == exp->_bol) return str; + return NULL; + case OP_EOL: + if(str == exp->_eol) return str; + return NULL; + case OP_DOT: + str++; + return str; + case OP_NCLASS: + case OP_CLASS: + if(trex_matchclass(exp,&exp->_nodes[node->left],*str)?(type == OP_CLASS?TRex_True:TRex_False):(type == OP_NCLASS?TRex_True:TRex_False)) { + str++; + return str; + } + return NULL; + case OP_CCLASS: + if(trex_matchcclass(node->left,*str)) { + str++; + return str; + } + return NULL; + default: /* char */ + if (exp->_flags & TREX_ICASE) + { + if(*str != tolower(node->type) && *str != toupper(node->type)) return NULL; + } + else + { + if (*str != node->type) return NULL; + } + str++; + return str; + } +} +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +/* public api */ +TRex *trex_compile(const TRexChar *pattern,const TRexChar **error,int flags) +{ + // allocated data is volatile, its safe to setjmp + TRex * volatile exp = NULL; + do { + exp = (TRex *)malloc(sizeof(TRex)); + if (!exp) break; + memset((void*)exp, 0, sizeof(TRex)); + + exp->_eol = exp->_bol = NULL; + exp->_p = pattern; + exp->_nallocated = (int)scstrlen(pattern) * sizeof(TRexChar); + exp->_nodes = (TRexNode *)malloc(exp->_nallocated * sizeof(TRexNode)); + if (!exp->_nodes) break; + exp->_nsize = 0; + exp->_matches = 0; + exp->_nsubexpr = 0; + exp->_first = trex_newnode((TRex*)exp,OP_EXPR); + exp->_error = error; + exp->_jmpbuf = malloc(sizeof(jmp_buf)); + if (!exp->_jmpbuf) break; + exp->_flags = flags; + if(setjmp(*((jmp_buf*)exp->_jmpbuf)) == 0) { + int res = trex_list((TRex*)exp); + exp->_nodes[exp->_first].left = res; + if(*exp->_p!='\0') + trex_error((TRex*)exp,_SC("unexpected character")); +#ifdef _DEBUG + { + int nsize,i; + TRexNode *t; + nsize = exp->_nsize; + t = &exp->_nodes[0]; + scprintf(_SC("\n")); + for(i = 0;i < nsize; i++) { + if(exp->_nodes[i].type>MAX_CHAR) + scprintf(_SC("[%02d] %10s "),i,g_nnames[exp->_nodes[i].type-MAX_CHAR]); + else + scprintf(_SC("[%02d] %10c "),i,exp->_nodes[i].type); + scprintf(_SC("left %02d right %02d next %02d\n"),exp->_nodes[i].left,exp->_nodes[i].right,exp->_nodes[i].next); + } + scprintf(_SC("\n")); + } +#endif + exp->_matches = (TRexMatch *) malloc(exp->_nsubexpr * sizeof(TRexMatch)); + if (!exp->_matches) break; + memset(exp->_matches,0,exp->_nsubexpr * sizeof(TRexMatch)); + } + else { + break; + } + return (TRex*)exp; + } while (0); + + trex_free((TRex*)exp); + return NULL; +} + +void trex_free(TRex *exp) +{ + if(exp) { + if(exp->_nodes) free(exp->_nodes); + if(exp->_jmpbuf) free(exp->_jmpbuf); + if(exp->_matches) free(exp->_matches); + free(exp); + } +} + +TRexBool trex_match(TRex* exp,const TRexChar* text) +{ + const TRexChar* res = NULL; + exp->_bol = text; + exp->_eol = text + scstrlen(text); + exp->_currsubexp = 0; + res = trex_matchnode(exp,exp->_nodes,text,NULL); + if(res == NULL || res != exp->_eol) + return TRex_False; + return TRex_True; +} + +TRexBool trex_searchrange(TRex* exp,const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end) +{ + const TRexChar *cur = NULL; + int node = exp->_first; + if(text_begin >= text_end) return TRex_False; + exp->_bol = text_begin; + exp->_eol = text_end; + do { + cur = text_begin; + while(node != -1) { + exp->_currsubexp = 0; + cur = trex_matchnode(exp,&exp->_nodes[node],cur,NULL); + if(!cur) + break; + node = exp->_nodes[node].next; + } + text_begin++; + } while(cur == NULL && text_begin != text_end); + + if(cur == NULL) + return TRex_False; + + --text_begin; + + if(out_begin) *out_begin = text_begin; + if(out_end) *out_end = cur; + return TRex_True; +} + +TRexBool trex_search(TRex* exp,const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end) +{ + return trex_searchrange(exp,text,text + scstrlen(text),out_begin,out_end); +} + +int trex_getsubexpcount(TRex* exp) +{ + return exp->_nsubexpr; +} + +TRexBool trex_getsubexp(TRex* exp, int n, TRexMatch *subexp) +{ + if( n<0 || n >= exp->_nsubexpr) return TRex_False; + *subexp = exp->_matches[n]; + return TRex_True; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include + +#include "argtable3.h" + + +static void arg_str_resetfn(struct arg_str *parent) +{ + ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); + parent->count = 0; +} + + +static int arg_str_scanfn(struct arg_str *parent, const char *argval) +{ + int errorcode = 0; + + if (parent->count == parent->hdr.maxcount) + { + /* maximum number of arguments exceeded */ + errorcode = EMAXCOUNT; + } + else if (!argval) + { + /* a valid argument with no argument value was given. */ + /* This happens when an optional argument value was invoked. */ + /* leave parent arguiment value unaltered but still count the argument. */ + parent->count++; + } + else + { + parent->sval[parent->count++] = argval; + } + + ARG_TRACE(("%s:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static int arg_str_checkfn(struct arg_str *parent) +{ + int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; + + ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); + return errorcode; +} + + +static void arg_str_errorfn( + struct arg_str *parent, + FILE *fp, + int errorcode, + const char *argval, + const char *progname) +{ + const char *shortopts = parent->hdr.shortopts; + const char *longopts = parent->hdr.longopts; + const char *datatype = parent->hdr.datatype; + + /* make argval NULL safe */ + argval = argval ? argval : ""; + + fprintf(fp, "%s: ", progname); + switch(errorcode) + { + case EMINCOUNT: + fputs("missing option ", fp); + arg_print_option(fp, shortopts, longopts, datatype, "\n"); + break; + + case EMAXCOUNT: + fputs("excess option ", fp); + arg_print_option(fp, shortopts, longopts, argval, "\n"); + break; + } +} + + +struct arg_str * arg_str0( + const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary) +{ + return arg_strn(shortopts, longopts, datatype, 0, 1, glossary); +} + + +struct arg_str * arg_str1( + const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary) +{ + return arg_strn(shortopts, longopts, datatype, 1, 1, glossary); +} + + +struct arg_str * arg_strn( + const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) +{ + size_t nbytes; + struct arg_str *result; + + /* should not allow this stupid error */ + /* we should return an error code warning this logic error */ + /* foolproof things by ensuring maxcount is not less than mincount */ + maxcount = (maxcount < mincount) ? mincount : maxcount; + + nbytes = sizeof(struct arg_str) /* storage for struct arg_str */ + + maxcount * sizeof(char *); /* storage for sval[maxcount] array */ + + result = (struct arg_str *)malloc(nbytes); + if (result) + { + int i; + + /* init the arg_hdr struct */ + result->hdr.flag = ARG_HASVALUE; + result->hdr.shortopts = shortopts; + result->hdr.longopts = longopts; + result->hdr.datatype = datatype ? datatype : ""; + result->hdr.glossary = glossary; + result->hdr.mincount = mincount; + result->hdr.maxcount = maxcount; + result->hdr.parent = result; + result->hdr.resetfn = (arg_resetfn *)arg_str_resetfn; + result->hdr.scanfn = (arg_scanfn *)arg_str_scanfn; + result->hdr.checkfn = (arg_checkfn *)arg_str_checkfn; + result->hdr.errorfn = (arg_errorfn *)arg_str_errorfn; + + /* store the sval[maxcount] array immediately after the arg_str struct */ + result->sval = (const char * *)(result + 1); + result->count = 0; + + /* foolproof the string pointers by initialising them to reference empty strings */ + for (i = 0; i < maxcount; i++) + result->sval[i] = ""; + } + + ARG_TRACE(("arg_strn() returns %p\n", result)); + return result; +} +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#include +#include +#include +#include + +#include "argtable3.h" + +static +void arg_register_error(struct arg_end *end, + void *parent, + int error, + const char *argval) +{ + /* printf("arg_register_error(%p,%p,%d,%s)\n",end,parent,error,argval); */ + if (end->count < end->hdr.maxcount) + { + end->error[end->count] = error; + end->parent[end->count] = parent; + end->argval[end->count] = argval; + end->count++; + } + else + { + end->error[end->hdr.maxcount - 1] = ARG_ELIMIT; + end->parent[end->hdr.maxcount - 1] = end; + end->argval[end->hdr.maxcount - 1] = NULL; + } +} + + +/* + * Return index of first table entry with a matching short option + * or -1 if no match was found. + */ +static +int find_shortoption(struct arg_hdr * *table, char shortopt) +{ + int tabindex; + for(tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + if (table[tabindex]->shortopts && + strchr(table[tabindex]->shortopts, shortopt)) + return tabindex; + } + return -1; +} + + +struct longoptions +{ + int getoptval; + int noptions; + struct option *options; +}; + +#if 0 +static +void dump_longoptions(struct longoptions * longoptions) +{ + int i; + printf("getoptval = %d\n", longoptions->getoptval); + printf("noptions = %d\n", longoptions->noptions); + for (i = 0; i < longoptions->noptions; i++) + { + printf("options[%d].name = \"%s\"\n", + i, + longoptions->options[i].name); + printf("options[%d].has_arg = %d\n", i, longoptions->options[i].has_arg); + printf("options[%d].flag = %p\n", i, longoptions->options[i].flag); + printf("options[%d].val = %d\n", i, longoptions->options[i].val); + } +} +#endif + +static +struct longoptions * alloc_longoptions(struct arg_hdr * *table) +{ + struct longoptions *result; + size_t nbytes; + int noptions = 1; + size_t longoptlen = 0; + int tabindex; + + /* + * Determine the total number of option structs required + * by counting the number of comma separated long options + * in all table entries and return the count in noptions. + * note: noptions starts at 1 not 0 because we getoptlong + * requires a NULL option entry to terminate the option array. + * While we are at it, count the number of chars required + * to store private copies of all the longoption strings + * and return that count in logoptlen. + */ + tabindex = 0; + do + { + const char *longopts = table[tabindex]->longopts; + longoptlen += (longopts ? strlen(longopts) : 0) + 1; + while (longopts) + { + noptions++; + longopts = strchr(longopts + 1, ','); + } + } while(!(table[tabindex++]->flag & ARG_TERMINATOR)); + /*printf("%d long options consuming %d chars in total\n",noptions,longoptlen);*/ + + + /* allocate storage for return data structure as: */ + /* (struct longoptions) + (struct options)[noptions] + char[longoptlen] */ + nbytes = sizeof(struct longoptions) + + sizeof(struct option) * noptions + + longoptlen; + result = (struct longoptions *)malloc(nbytes); + if (result) + { + int option_index = 0; + char *store; + + result->getoptval = 0; + result->noptions = noptions; + result->options = (struct option *)(result + 1); + store = (char *)(result->options + noptions); + + for(tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + const char *longopts = table[tabindex]->longopts; + + while(longopts && *longopts) + { + char *storestart = store; + + /* copy progressive longopt strings into the store */ + while (*longopts != 0 && *longopts != ',') + *store++ = *longopts++; + *store++ = 0; + if (*longopts == ',') + longopts++; + /*fprintf(stderr,"storestart=\"%s\"\n",storestart);*/ + + result->options[option_index].name = storestart; + result->options[option_index].flag = &(result->getoptval); + result->options[option_index].val = tabindex; + if (table[tabindex]->flag & ARG_HASOPTVALUE) + result->options[option_index].has_arg = 2; + else if (table[tabindex]->flag & ARG_HASVALUE) + result->options[option_index].has_arg = 1; + else + result->options[option_index].has_arg = 0; + + option_index++; + } + } + /* terminate the options array with a zero-filled entry */ + result->options[option_index].name = 0; + result->options[option_index].has_arg = 0; + result->options[option_index].flag = 0; + result->options[option_index].val = 0; + } + + /*dump_longoptions(result);*/ + return result; +} + +static +char * alloc_shortoptions(struct arg_hdr * *table) +{ + char *result; + size_t len = 2; + int tabindex; + + /* determine the total number of option chars required */ + for(tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + struct arg_hdr *hdr = table[tabindex]; + len += 3 * (hdr->shortopts ? strlen(hdr->shortopts) : 0); + } + + result = malloc(len); + if (result) + { + char *res = result; + + /* add a leading ':' so getopt return codes distinguish */ + /* unrecognised option and options missing argument values */ + *res++ = ':'; + + for(tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + struct arg_hdr *hdr = table[tabindex]; + const char *shortopts = hdr->shortopts; + while(shortopts && *shortopts) + { + *res++ = *shortopts++; + if (hdr->flag & ARG_HASVALUE) + *res++ = ':'; + if (hdr->flag & ARG_HASOPTVALUE) + *res++ = ':'; + } + } + /* null terminate the string */ + *res = 0; + } + + /*printf("alloc_shortoptions() returns \"%s\"\n",(result?result:"NULL"));*/ + return result; +} + + +/* return index of the table terminator entry */ +static +int arg_endindex(struct arg_hdr * *table) +{ + int tabindex = 0; + while (!(table[tabindex]->flag & ARG_TERMINATOR)) + tabindex++; + return tabindex; +} + + +static +void arg_parse_tagged(int argc, + char * *argv, + struct arg_hdr * *table, + struct arg_end *endtable) +{ + struct longoptions *longoptions; + char *shortoptions; + int copt; + + /*printf("arg_parse_tagged(%d,%p,%p,%p)\n",argc,argv,table,endtable);*/ + + /* allocate short and long option arrays for the given opttable[]. */ + /* if the allocs fail then put an error msg in the last table entry. */ + longoptions = alloc_longoptions(table); + shortoptions = alloc_shortoptions(table); + if (!longoptions || !shortoptions) + { + /* one or both memory allocs failed */ + arg_register_error(endtable, endtable, ARG_EMALLOC, NULL); + /* free anything that was allocated (this is null safe) */ + free(shortoptions); + free(longoptions); + return; + } + + /*dump_longoptions(longoptions);*/ + + /* reset getopts internal option-index to zero, and disable error reporting */ + optind = 0; + opterr = 0; + + /* fetch and process args using getopt_long */ + while( (copt = + getopt_long(argc, argv, shortoptions, longoptions->options, + NULL)) != -1) + { + /* + printf("optarg='%s'\n",optarg); + printf("optind=%d\n",optind); + printf("copt=%c\n",(char)copt); + printf("optopt=%c (%d)\n",optopt, (int)(optopt)); + */ + switch(copt) + { + case 0: + { + int tabindex = longoptions->getoptval; + void *parent = table[tabindex]->parent; + /*printf("long option detected from argtable[%d]\n", tabindex);*/ + if (optarg && optarg[0] == 0 && + (table[tabindex]->flag & ARG_HASVALUE)) + { + /* printf(": long option %s requires an argument\n",argv[optind-1]); */ + arg_register_error(endtable, endtable, ARG_EMISSARG, + argv[optind - 1]); + /* continue to scan the (empty) argument value to enforce argument count checking */ + } + if (table[tabindex]->scanfn) + { + int errorcode = table[tabindex]->scanfn(parent, optarg); + if (errorcode != 0) + arg_register_error(endtable, parent, errorcode, optarg); + } + } + break; + + case '?': + /* + * getopt_long() found an unrecognised short option. + * if it was a short option its value is in optopt + * if it was a long option then optopt=0 + */ + switch (optopt) + { + case 0: + /*printf("?0 unrecognised long option %s\n",argv[optind-1]);*/ + arg_register_error(endtable, endtable, ARG_ELONGOPT, + argv[optind - 1]); + break; + default: + /*printf("?* unrecognised short option '%c'\n",optopt);*/ + arg_register_error(endtable, endtable, optopt, NULL); + break; + } + break; + + case ':': + /* + * getopt_long() found an option with its argument missing. + */ + /*printf(": option %s requires an argument\n",argv[optind-1]); */ + arg_register_error(endtable, endtable, ARG_EMISSARG, + argv[optind - 1]); + break; + + default: + { + /* getopt_long() found a valid short option */ + int tabindex = find_shortoption(table, (char)copt); + /*printf("short option detected from argtable[%d]\n", tabindex);*/ + if (tabindex == -1) + { + /* should never get here - but handle it just in case */ + /*printf("unrecognised short option %d\n",copt);*/ + arg_register_error(endtable, endtable, copt, NULL); + } + else + { + if (table[tabindex]->scanfn) + { + void *parent = table[tabindex]->parent; + int errorcode = table[tabindex]->scanfn(parent, optarg); + if (errorcode != 0) + arg_register_error(endtable, parent, errorcode, optarg); + } + } + break; + } + } + } + + free(shortoptions); + free(longoptions); +} + + +static +void arg_parse_untagged(int argc, + char * *argv, + struct arg_hdr * *table, + struct arg_end *endtable) +{ + int tabindex = 0; + int errorlast = 0; + const char *optarglast = NULL; + void *parentlast = NULL; + + /*printf("arg_parse_untagged(%d,%p,%p,%p)\n",argc,argv,table,endtable);*/ + while (!(table[tabindex]->flag & ARG_TERMINATOR)) + { + void *parent; + int errorcode; + + /* if we have exhausted our argv[optind] entries then we have finished */ + if (optind >= argc) + { + /*printf("arg_parse_untagged(): argv[] exhausted\n");*/ + return; + } + + /* skip table entries with non-null long or short options (they are not untagged entries) */ + if (table[tabindex]->longopts || table[tabindex]->shortopts) + { + /*printf("arg_parse_untagged(): skipping argtable[%d] (tagged argument)\n",tabindex);*/ + tabindex++; + continue; + } + + /* skip table entries with NULL scanfn */ + if (!(table[tabindex]->scanfn)) + { + /*printf("arg_parse_untagged(): skipping argtable[%d] (NULL scanfn)\n",tabindex);*/ + tabindex++; + continue; + } + + /* attempt to scan the current argv[optind] with the current */ + /* table[tabindex] entry. If it succeeds then keep it, otherwise */ + /* try again with the next table[] entry. */ + parent = table[tabindex]->parent; + errorcode = table[tabindex]->scanfn(parent, argv[optind]); + if (errorcode == 0) + { + /* success, move onto next argv[optind] but stay with same table[tabindex] */ + /*printf("arg_parse_untagged(): argtable[%d] successfully matched\n",tabindex);*/ + optind++; + + /* clear the last tentative error */ + errorlast = 0; + } + else + { + /* failure, try same argv[optind] with next table[tabindex] entry */ + /*printf("arg_parse_untagged(): argtable[%d] failed match\n",tabindex);*/ + tabindex++; + + /* remember this as a tentative error we may wish to reinstate later */ + errorlast = errorcode; + optarglast = argv[optind]; + parentlast = parent; + } + + } + + /* if a tenative error still remains at this point then register it as a proper error */ + if (errorlast) + { + arg_register_error(endtable, parentlast, errorlast, optarglast); + optind++; + } + + /* only get here when not all argv[] entries were consumed */ + /* register an error for each unused argv[] entry */ + while (optind < argc) + { + /*printf("arg_parse_untagged(): argv[%d]=\"%s\" not consumed\n",optind,argv[optind]);*/ + arg_register_error(endtable, endtable, ARG_ENOMATCH, argv[optind++]); + } + + return; +} + + +static +void arg_parse_check(struct arg_hdr * *table, struct arg_end *endtable) +{ + int tabindex = 0; + /* printf("arg_parse_check()\n"); */ + do + { + if (table[tabindex]->checkfn) + { + void *parent = table[tabindex]->parent; + int errorcode = table[tabindex]->checkfn(parent); + if (errorcode != 0) + arg_register_error(endtable, parent, errorcode, NULL); + } + } while(!(table[tabindex++]->flag & ARG_TERMINATOR)); +} + + +static +void arg_reset(void * *argtable) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int tabindex = 0; + /*printf("arg_reset(%p)\n",argtable);*/ + do + { + if (table[tabindex]->resetfn) + table[tabindex]->resetfn(table[tabindex]->parent); + } while(!(table[tabindex++]->flag & ARG_TERMINATOR)); +} + + +int arg_parse(int argc, char * *argv, void * *argtable) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + struct arg_end *endtable; + int endindex; + char * *argvcopy = NULL; + + /*printf("arg_parse(%d,%p,%p)\n",argc,argv,argtable);*/ + + /* reset any argtable data from previous invocations */ + arg_reset(argtable); + + /* locate the first end-of-table marker within the array */ + endindex = arg_endindex(table); + endtable = (struct arg_end *)table[endindex]; + + /* Special case of argc==0. This can occur on Texas Instruments DSP. */ + /* Failure to trap this case results in an unwanted NULL result from */ + /* the malloc for argvcopy (next code block). */ + if (argc == 0) + { + /* We must still perform post-parse checks despite the absence of command line arguments */ + arg_parse_check(table, endtable); + + /* Now we are finished */ + return endtable->count; + } + + argvcopy = (char **)malloc(sizeof(char *) * (argc + 1)); + if (argvcopy) + { + int i; + + /* + Fill in the local copy of argv[]. We need a local copy + because getopt rearranges argv[] which adversely affects + susbsequent parsing attempts. + */ + for (i = 0; i < argc; i++) + argvcopy[i] = argv[i]; + + argvcopy[argc] = NULL; + + /* parse the command line (local copy) for tagged options */ + arg_parse_tagged(argc, argvcopy, table, endtable); + + /* parse the command line (local copy) for untagged options */ + arg_parse_untagged(argc, argvcopy, table, endtable); + + /* if no errors so far then perform post-parse checks otherwise dont bother */ + if (endtable->count == 0) + arg_parse_check(table, endtable); + + /* release the local copt of argv[] */ + free(argvcopy); + } + else + { + /* memory alloc failed */ + arg_register_error(endtable, endtable, ARG_EMALLOC, NULL); + } + + return endtable->count; +} + + +/* + * Concatenate contents of src[] string onto *pdest[] string. + * The *pdest pointer is altered to point to the end of the + * target string and *pndest is decremented by the same number + * of chars. + * Does not append more than *pndest chars into *pdest[] + * so as to prevent buffer overruns. + * Its something like strncat() but more efficient for repeated + * calls on the same destination string. + * Example of use: + * char dest[30] = "good" + * size_t ndest = sizeof(dest); + * char *pdest = dest; + * arg_char(&pdest,"bye ",&ndest); + * arg_char(&pdest,"cruel ",&ndest); + * arg_char(&pdest,"world!",&ndest); + * Results in: + * dest[] == "goodbye cruel world!" + * ndest == 10 + */ +static +void arg_cat(char * *pdest, const char *src, size_t *pndest) +{ + char *dest = *pdest; + char *end = dest + *pndest; + + /*locate null terminator of dest string */ + while(dest < end && *dest != 0) + dest++; + + /* concat src string to dest string */ + while(dest < end && *src != 0) + *dest++ = *src++; + + /* null terminate dest string */ + *dest = 0; + + /* update *pdest and *pndest */ + *pndest = end - dest; + *pdest = dest; +} + + +static +void arg_cat_option(char *dest, + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue) +{ + if (shortopts) + { + char option[3]; + + /* note: option array[] is initialiazed dynamically here to satisfy */ + /* a deficiency in the watcom compiler wrt static array initializers. */ + option[0] = '-'; + option[1] = shortopts[0]; + option[2] = 0; + + arg_cat(&dest, option, &ndest); + if (datatype) + { + arg_cat(&dest, " ", &ndest); + if (optvalue) + { + arg_cat(&dest, "[", &ndest); + arg_cat(&dest, datatype, &ndest); + arg_cat(&dest, "]", &ndest); + } + else + arg_cat(&dest, datatype, &ndest); + } + } + else if (longopts) + { + size_t ncspn; + + /* add "--" tag prefix */ + arg_cat(&dest, "--", &ndest); + + /* add comma separated option tag */ + ncspn = strcspn(longopts, ","); +#ifdef __STDC_WANT_SECURE_LIB__ + strncat_s(dest, ndest, longopts, (ncspn < ndest) ? ncspn : ndest); +#else + strncat(dest, longopts, (ncspn < ndest) ? ncspn : ndest); +#endif + + if (datatype) + { + arg_cat(&dest, "=", &ndest); + if (optvalue) + { + arg_cat(&dest, "[", &ndest); + arg_cat(&dest, datatype, &ndest); + arg_cat(&dest, "]", &ndest); + } + else + arg_cat(&dest, datatype, &ndest); + } + } + else if (datatype) + { + if (optvalue) + { + arg_cat(&dest, "[", &ndest); + arg_cat(&dest, datatype, &ndest); + arg_cat(&dest, "]", &ndest); + } + else + arg_cat(&dest, datatype, &ndest); + } +} + +static +void arg_cat_optionv(char *dest, + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue, + const char *separator) +{ + separator = separator ? separator : ""; + + if (shortopts) + { + const char *c = shortopts; + while(*c) + { + /* "-a|-b|-c" */ + char shortopt[3]; + + /* note: shortopt array[] is initialiazed dynamically here to satisfy */ + /* a deficiency in the watcom compiler wrt static array initializers. */ + shortopt[0] = '-'; + shortopt[1] = *c; + shortopt[2] = 0; + + arg_cat(&dest, shortopt, &ndest); + if (*++c) + arg_cat(&dest, separator, &ndest); + } + } + + /* put separator between long opts and short opts */ + if (shortopts && longopts) + arg_cat(&dest, separator, &ndest); + + if (longopts) + { + const char *c = longopts; + while(*c) + { + size_t ncspn; + + /* add "--" tag prefix */ + arg_cat(&dest, "--", &ndest); + + /* add comma separated option tag */ + ncspn = strcspn(c, ","); +#ifdef __STDC_WANT_SECURE_LIB__ + strncat_s(dest, ndest, c, (ncspn < ndest) ? ncspn : ndest); +#else + strncat(dest, c, (ncspn < ndest) ? ncspn : ndest); +#endif + c += ncspn; + + /* add given separator in place of comma */ + if (*c == ',') + { + arg_cat(&dest, separator, &ndest); + c++; + } + } + } + + if (datatype) + { + if (longopts) + arg_cat(&dest, "=", &ndest); + else if (shortopts) + arg_cat(&dest, " ", &ndest); + + if (optvalue) + { + arg_cat(&dest, "[", &ndest); + arg_cat(&dest, datatype, &ndest); + arg_cat(&dest, "]", &ndest); + } + else + arg_cat(&dest, datatype, &ndest); + } +} + + +/* this function should be deprecated because it doesnt consider optional argument values (ARG_HASOPTVALUE) */ +void arg_print_option(FILE *fp, + const char *shortopts, + const char *longopts, + const char *datatype, + const char *suffix) +{ + char syntax[200] = ""; + suffix = suffix ? suffix : ""; + + /* there is no way of passing the proper optvalue for optional argument values here, so we must ignore it */ + arg_cat_optionv(syntax, + sizeof(syntax), + shortopts, + longopts, + datatype, + 0, + "|"); + + fputs(syntax, fp); + fputs(suffix, fp); +} + + +/* + * Print a GNU style [OPTION] string in which all short options that + * do not take argument values are presented in abbreviated form, as + * in: -xvfsd, or -xvf[sd], or [-xvsfd] + */ +static +void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) +{ + int tabindex; + char *format1 = " -%c"; + char *format2 = " [-%c"; + char *suffix = ""; + + /* print all mandatory switches that are without argument values */ + for(tabindex = 0; + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) + { + /* skip optional options */ + if (table[tabindex]->mincount < 1) + continue; + + /* skip non-short options */ + if (table[tabindex]->shortopts == NULL) + continue; + + /* skip options that take argument values */ + if (table[tabindex]->flag & ARG_HASVALUE) + continue; + + /* print the short option (only the first short option char, ignore multiple choices)*/ + fprintf(fp, format1, table[tabindex]->shortopts[0]); + format1 = "%c"; + format2 = "[%c"; + } + + /* print all optional switches that are without argument values */ + for(tabindex = 0; + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) + { + /* skip mandatory args */ + if (table[tabindex]->mincount > 0) + continue; + + /* skip args without short options */ + if (table[tabindex]->shortopts == NULL) + continue; + + /* skip args with values */ + if (table[tabindex]->flag & ARG_HASVALUE) + continue; + + /* print first short option */ + fprintf(fp, format2, table[tabindex]->shortopts[0]); + format2 = "%c"; + suffix = "]"; + } + + fprintf(fp, "%s", suffix); +} + + +void arg_print_syntax(FILE *fp, void * *argtable, const char *suffix) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int i, tabindex; + + /* print GNU style [OPTION] string */ + arg_print_gnuswitch(fp, table); + + /* print remaining options in abbreviated style */ + for(tabindex = 0; + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) + { + char syntax[200] = ""; + const char *shortopts, *longopts, *datatype; + + /* skip short options without arg values (they were printed by arg_print_gnu_switch) */ + if (table[tabindex]->shortopts && + !(table[tabindex]->flag & ARG_HASVALUE)) + continue; + + shortopts = table[tabindex]->shortopts; + longopts = table[tabindex]->longopts; + datatype = table[tabindex]->datatype; + arg_cat_option(syntax, + sizeof(syntax), + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE); + + if (strlen(syntax) > 0) + { + /* print mandatory instances of this option */ + for (i = 0; i < table[tabindex]->mincount; i++) + fprintf(fp, " %s", syntax); + + /* print optional instances enclosed in "[..]" */ + switch ( table[tabindex]->maxcount - table[tabindex]->mincount ) + { + case 0: + break; + case 1: + fprintf(fp, " [%s]", syntax); + break; + case 2: + fprintf(fp, " [%s] [%s]", syntax, syntax); + break; + default: + fprintf(fp, " [%s]...", syntax); + break; + } + } + } + + if (suffix) + fprintf(fp, "%s", suffix); +} + + +void arg_print_syntaxv(FILE *fp, void * *argtable, const char *suffix) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int i, tabindex; + + /* print remaining options in abbreviated style */ + for(tabindex = 0; + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) + { + char syntax[200] = ""; + const char *shortopts, *longopts, *datatype; + + shortopts = table[tabindex]->shortopts; + longopts = table[tabindex]->longopts; + datatype = table[tabindex]->datatype; + arg_cat_optionv(syntax, + sizeof(syntax), + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE, + "|"); + + /* print mandatory options */ + for (i = 0; i < table[tabindex]->mincount; i++) + fprintf(fp, " %s", syntax); + + /* print optional args enclosed in "[..]" */ + switch ( table[tabindex]->maxcount - table[tabindex]->mincount ) + { + case 0: + break; + case 1: + fprintf(fp, " [%s]", syntax); + break; + case 2: + fprintf(fp, " [%s] [%s]", syntax, syntax); + break; + default: + fprintf(fp, " [%s]...", syntax); + break; + } + } + + if (suffix) + fprintf(fp, "%s", suffix); +} + + +void arg_print_glossary(FILE *fp, void * *argtable, const char *format) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int tabindex; + + format = format ? format : " %-20s %s\n"; + for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + if (table[tabindex]->glossary) + { + char syntax[200] = ""; + const char *shortopts = table[tabindex]->shortopts; + const char *longopts = table[tabindex]->longopts; + const char *datatype = table[tabindex]->datatype; + const char *glossary = table[tabindex]->glossary; + arg_cat_optionv(syntax, + sizeof(syntax), + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE, + ", "); + fprintf(fp, format, syntax, glossary); + } + } +} + + +/** + * Print a piece of text formatted, which means in a column with a + * left and a right margin. The lines are wrapped at whitspaces next + * to right margin. The function does not indent the first line, but + * only the following ones. + * + * Example: + * arg_print_formatted( fp, 0, 5, "Some text that doesn't fit." ) + * will result in the following output: + * + * Some + * text + * that + * doesn' + * t fit. + * + * Too long lines will be wrapped in the middle of a word. + * + * arg_print_formatted( fp, 2, 7, "Some text that doesn't fit." ) + * will result in the following output: + * + * Some + * text + * that + * doesn' + * t fit. + * + * As you see, the first line is not indented. This enables output of + * lines, which start in a line where output already happened. + * + * Author: Uli Fouquet + */ +static +void arg_print_formatted( FILE *fp, + const unsigned lmargin, + const unsigned rmargin, + const char *text ) +{ + const unsigned textlen = (unsigned)strlen( text ); + unsigned line_start = 0; + unsigned line_end = textlen + 1; + const unsigned colwidth = (rmargin - lmargin) + 1; + + /* Someone doesn't like us... */ + if ( line_end < line_start ) + { fprintf( fp, "%s\n", text ); } + + while (line_end - 1 > line_start ) + { + /* Eat leading whitespaces. This is essential because while + wrapping lines, there will often be a whitespace at beginning + of line */ + while ( ISSPACE(*(text + line_start)) ) + { line_start++; } + + if ((line_end - line_start) > colwidth ) + { line_end = line_start + colwidth; } + + /* Find last whitespace, that fits into line */ + while ( ( line_end > line_start ) + && ( line_end - line_start > colwidth ) + && !ISSPACE(*(text + line_end))) + { line_end--; } + + /* Do not print trailing whitespace. If this text + has got only one line, line_end now points to the + last char due to initialization. */ + line_end--; + + /* Output line of text */ + while ( line_start < line_end ) + { + fputc(*(text + line_start), fp ); + line_start++; + } + fputc( '\n', fp ); + + /* Initialize another line */ + if ( line_end + 1 < textlen ) + { + unsigned i; + + for (i = 0; i < lmargin; i++ ) + { fputc( ' ', fp ); } + + line_end = textlen; + } + + /* If we have to print another line, get also the last char. */ + line_end++; + + } /* lines of text */ +} + +/** + * Prints the glossary in strict GNU format. + * Differences to arg_print_glossary() are: + * - wraps lines after 80 chars + * - indents lines without shortops + * - does not accept formatstrings + * + * Contributed by Uli Fouquet + */ +void arg_print_glossary_gnu(FILE *fp, void * *argtable ) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int tabindex; + + for(tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) + { + if (table[tabindex]->glossary) + { + char syntax[200] = ""; + const char *shortopts = table[tabindex]->shortopts; + const char *longopts = table[tabindex]->longopts; + const char *datatype = table[tabindex]->datatype; + const char *glossary = table[tabindex]->glossary; + + if ( !shortopts && longopts ) + { + /* Indent trailing line by 4 spaces... */ + memset( syntax, ' ', 4 ); + *(syntax + 4) = '\0'; + } + + arg_cat_optionv(syntax, + sizeof(syntax), + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE, + ", "); + + /* If syntax fits not into column, print glossary in new line... */ + if ( strlen(syntax) > 25 ) + { + fprintf( fp, " %-25s %s\n", syntax, "" ); + *syntax = '\0'; + } + + fprintf( fp, " %-25s ", syntax ); + arg_print_formatted( fp, 28, 79, glossary ); + } + } /* for each table entry */ + + fputc( '\n', fp ); +} + + +/** + * Checks the argtable[] array for NULL entries and returns 1 + * if any are found, zero otherwise. + */ +int arg_nullcheck(void * *argtable) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int tabindex; + /*printf("arg_nullcheck(%p)\n",argtable);*/ + + if (!table) + return 1; + + tabindex = 0; + do + { + /*printf("argtable[%d]=%p\n",tabindex,argtable[tabindex]);*/ + if (!table[tabindex]) + return 1; + } while(!(table[tabindex++]->flag & ARG_TERMINATOR)); + + return 0; +} + + +/* + * arg_free() is deprecated in favour of arg_freetable() due to a flaw in its design. + * The flaw results in memory leak in the (very rare) case that an intermediate + * entry in the argtable array failed its memory allocation while others following + * that entry were still allocated ok. Those subsequent allocations will not be + * deallocated by arg_free(). + * Despite the unlikeliness of the problem occurring, and the even unlikelier event + * that it has any deliterious effect, it is fixed regardless by replacing arg_free() + * with the newer arg_freetable() function. + * We still keep arg_free() for backwards compatibility. + */ +void arg_free(void * *argtable) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + int tabindex = 0; + int flag; + /*printf("arg_free(%p)\n",argtable);*/ + do + { + /* + if we encounter a NULL entry then somewhat incorrectly we presume + we have come to the end of the array. It isnt strictly true because + an intermediate entry could be NULL with other non-NULL entries to follow. + The subsequent argtable entries would then not be freed as they should. + */ + if (table[tabindex] == NULL) + break; + + flag = table[tabindex]->flag; + free(table[tabindex]); + table[tabindex++] = NULL; + + } while(!(flag & ARG_TERMINATOR)); +} + +/* frees each non-NULL element of argtable[], where n is the size of the number of entries in the array */ +void arg_freetable(void * *argtable, size_t n) +{ + struct arg_hdr * *table = (struct arg_hdr * *)argtable; + size_t tabindex = 0; + /*printf("arg_freetable(%p)\n",argtable);*/ + for (tabindex = 0; tabindex < n; tabindex++) + { + if (table[tabindex] == NULL) + continue; + + free(table[tabindex]); + table[tabindex] = NULL; + }; +} + diff --git a/external/epid-sdk/ext/argtable3/argtable3.h b/external/epid-sdk/ext/argtable3/argtable3.h new file mode 100644 index 00000000..1107de25 --- /dev/null +++ b/external/epid-sdk/ext/argtable3/argtable3.h @@ -0,0 +1,305 @@ +/******************************************************************************* + * This file is part of the argtable3 library. + * + * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of STEWART HEITMANN nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +#ifndef ARGTABLE3 +#define ARGTABLE3 + +#include /* FILE */ +#include /* struct tm */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define ARG_REX_ICASE 1 + +/* bit masks for arg_hdr.flag */ +enum +{ + ARG_TERMINATOR=0x1, + ARG_HASVALUE=0x2, + ARG_HASOPTVALUE=0x4 +}; + +typedef void (arg_resetfn)(void *parent); +typedef int (arg_scanfn)(void *parent, const char *argval); +typedef int (arg_checkfn)(void *parent); +typedef void (arg_errorfn)(void *parent, FILE *fp, int error, const char *argval, const char *progname); + + +/* +* The arg_hdr struct defines properties that are common to all arg_xxx structs. +* The argtable library requires each arg_xxx struct to have an arg_hdr +* struct as its first data member. +* The argtable library functions then use this data to identify the +* properties of the command line option, such as its option tags, +* datatype string, and glossary strings, and so on. +* Moreover, the arg_hdr struct contains pointers to custom functions that +* are provided by each arg_xxx struct which perform the tasks of parsing +* that particular arg_xxx arguments, performing post-parse checks, and +* reporting errors. +* These functions are private to the individual arg_xxx source code +* and are the pointer to them are initiliased by that arg_xxx struct's +* constructor function. The user could alter them after construction +* if desired, but the original intention is for them to be set by the +* constructor and left unaltered. +*/ +struct arg_hdr +{ + char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */ + const char *shortopts; /* String defining the short options */ + const char *longopts; /* String defiing the long options */ + const char *datatype; /* Description of the argument data type */ + const char *glossary; /* Description of the option as shown by arg_print_glossary function */ + int mincount; /* Minimum number of occurences of this option accepted */ + int maxcount; /* Maximum number of occurences if this option accepted */ + void *parent; /* Pointer to parent arg_xxx struct */ + arg_resetfn *resetfn; /* Pointer to parent arg_xxx reset function */ + arg_scanfn *scanfn; /* Pointer to parent arg_xxx scan function */ + arg_checkfn *checkfn; /* Pointer to parent arg_xxx check function */ + arg_errorfn *errorfn; /* Pointer to parent arg_xxx error function */ + void *priv; /* Pointer to private header data for use by arg_xxx functions */ +}; + +struct arg_rem +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ +}; + +struct arg_lit +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args */ +}; + +struct arg_int +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args */ + int *ival; /* Array of parsed argument values */ +}; + +struct arg_dbl +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args */ + double *dval; /* Array of parsed argument values */ +}; + +struct arg_str +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args */ + const char **sval; /* Array of parsed argument values */ +}; + +struct arg_rex +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args */ + const char **sval; /* Array of parsed argument values */ +}; + +struct arg_file +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of matching command line args*/ + const char **filename; /* Array of parsed filenames (eg: /home/foo.bar) */ + const char **basename; /* Array of parsed basenames (eg: foo.bar) */ + const char **extension; /* Array of parsed extensions (eg: .bar) */ +}; + +struct arg_date +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + const char *format; /* strptime format string used to parse the date */ + int count; /* Number of matching command line args */ + struct tm *tmval; /* Array of parsed time values */ +}; + +enum {ARG_ELIMIT=1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG}; +struct arg_end +{ + struct arg_hdr hdr; /* The mandatory argtable header struct */ + int count; /* Number of errors encountered */ + int *error; /* Array of error codes */ + void **parent; /* Array of pointers to offending arg_xxx struct */ + const char **argval; /* Array of pointers to offending argv[] string */ +}; + + +/**** arg_xxx constructor functions *********************************/ + +struct arg_rem* arg_rem(const char* datatype, const char* glossary); + +struct arg_lit* arg_lit0(const char* shortopts, + const char* longopts, + const char* glossary); +struct arg_lit* arg_lit1(const char* shortopts, + const char* longopts, + const char *glossary); +struct arg_lit* arg_litn(const char* shortopts, + const char* longopts, + int mincount, + int maxcount, + const char *glossary); + +struct arg_key* arg_key0(const char* keyword, + int flags, + const char* glossary); +struct arg_key* arg_key1(const char* keyword, + int flags, + const char* glossary); +struct arg_key* arg_keyn(const char* keyword, + int flags, + int mincount, + int maxcount, + const char* glossary); + +struct arg_int* arg_int0(const char* shortopts, + const char* longopts, + const char* datatype, + const char* glossary); +struct arg_int* arg_int1(const char* shortopts, + const char* longopts, + const char* datatype, + const char *glossary); +struct arg_int* arg_intn(const char* shortopts, + const char* longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary); + +struct arg_dbl* arg_dbl0(const char* shortopts, + const char* longopts, + const char* datatype, + const char* glossary); +struct arg_dbl* arg_dbl1(const char* shortopts, + const char* longopts, + const char* datatype, + const char *glossary); +struct arg_dbl* arg_dbln(const char* shortopts, + const char* longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary); + +struct arg_str* arg_str0(const char* shortopts, + const char* longopts, + const char* datatype, + const char* glossary); +struct arg_str* arg_str1(const char* shortopts, + const char* longopts, + const char* datatype, + const char *glossary); +struct arg_str* arg_strn(const char* shortopts, + const char* longopts, + const char* datatype, + int mincount, + int maxcount, + const char *glossary); + +struct arg_rex* arg_rex0(const char* shortopts, + const char* longopts, + const char* pattern, + const char* datatype, + int flags, + const char* glossary); +struct arg_rex* arg_rex1(const char* shortopts, + const char* longopts, + const char* pattern, + const char* datatype, + int flags, + const char *glossary); +struct arg_rex* arg_rexn(const char* shortopts, + const char* longopts, + const char* pattern, + const char* datatype, + int mincount, + int maxcount, + int flags, + const char *glossary); + +struct arg_file* arg_file0(const char* shortopts, + const char* longopts, + const char* datatype, + const char* glossary); +struct arg_file* arg_file1(const char* shortopts, + const char* longopts, + const char* datatype, + const char *glossary); +struct arg_file* arg_filen(const char* shortopts, + const char* longopts, + const char* datatype, + int mincount, + int maxcount, + const char *glossary); + +struct arg_date* arg_date0(const char* shortopts, + const char* longopts, + const char* format, + const char* datatype, + const char* glossary); +struct arg_date* arg_date1(const char* shortopts, + const char* longopts, + const char* format, + const char* datatype, + const char *glossary); +struct arg_date* arg_daten(const char* shortopts, + const char* longopts, + const char* format, + const char* datatype, + int mincount, + int maxcount, + const char *glossary); + +struct arg_end* arg_end(int maxerrors); + + +/**** other functions *******************************************/ +int arg_nullcheck(void **argtable); +int arg_parse(int argc, char **argv, void **argtable); +void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, const char *suffix); +void arg_print_syntax(FILE *fp, void **argtable, const char *suffix); +void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix); +void arg_print_glossary(FILE *fp, void **argtable, const char *format); +void arg_print_glossary_gnu(FILE *fp, void **argtable); +void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname); +void arg_freetable(void **argtable, size_t n); + +/**** deprecated functions, for back-compatibility only ********/ +void arg_free(void **argtable); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/external/epid-sdk-3.0.0/ext/dropt/dropt.parts b/external/epid-sdk/ext/argtable3/argtable3.parts similarity index 50% rename from external/epid-sdk-3.0.0/ext/dropt/dropt.parts rename to external/epid-sdk/ext/argtable3/argtable3.parts index e2d9b85f..f6a3528b 100644 --- a/external/epid-sdk-3.0.0/ext/dropt/dropt.parts +++ b/external/epid-sdk/ext/argtable3/argtable3.parts @@ -1,5 +1,5 @@ ############################################################################ -# Copyright 2016 Intel Corporation +# Copyright 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,37 +15,29 @@ ############################################################################ Import('*') -env.PartVersion("1.1.1") -env.PartName("dropt") +env.PartVersion("3.0.3") +env.PartName("argtable3") # sourcefiles -src_files = Pattern(src_dir='src/', - includes=['*.c'], - excludes=['test_*'], - recursive=True).files() +src_files = Pattern(src_dir='.', + includes=['argtable3.c']).files() #includes to install -install_headers = Pattern(src_dir='include/', - includes=['dropt.h'], - recursive=True).files() +install_headers = Pattern(src_dir='.', + includes=['argtable3.h']).files() -internal_headers = Pattern(src_dir='include/', - includes=['dropt_string.h'], - recursive=True).files() - -parts_file = ['dropt.parts'] +parts_file = ['argtable3.parts'] license_file = ['LICENSE'] makefile = ['Makefile'] if 'install_package' in env['MODE']: - env.InstallTopLevel(src_files, sub_dir='ext/dropt/src') - env.InstallTopLevel(install_headers + internal_headers, - sub_dir='ext/dropt/include') - env.InstallTopLevel(parts_file, sub_dir='ext/dropt') - env.InstallTopLevel(license_file, sub_dir='ext/dropt') - env.InstallTopLevel(makefile, sub_dir='ext/dropt') + env.InstallTopLevel(src_files, sub_dir='ext/argtable3') + env.InstallTopLevel(install_headers, sub_dir='ext/argtable3') + env.InstallTopLevel(parts_file, sub_dir='ext/argtable3') + env.InstallTopLevel(license_file, sub_dir='ext/argtable3') + env.InstallTopLevel(makefile, sub_dir='ext/argtable3') else: - env.Append(CPPPATH=[AbsDir('include')]) + env.Append(CPPPATH='.') outputs = env.Library('${PART_NAME}', src_files) sdk_outs = env.Sdk(outputs) diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ippbase.h b/external/epid-sdk/ext/ipp/include/ippbase.h similarity index 80% rename from external/epid-sdk-3.0.0/ext/ipp/include/ippbase.h rename to external/epid-sdk/ext/ipp/include/ippbase.h index 532f151c..c7784a73 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ippbase.h +++ b/external/epid-sdk/ext/ipp/include/ippbase.h @@ -1,18 +1,25 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ +/* +// Copyright 1999 2016 Intel Corporation All Rights Reserved. +// +// The source code, information and material ("Material") contained herein is +// owned by Intel Corporation or its suppliers or licensors, and title +// to such Material remains with Intel Corporation or its suppliers or +// licensors. The Material contains proprietary information of Intel +// or its suppliers and licensors. The Material is protected by worldwide +// copyright laws and treaty provisions. No part of the Material may be used, +// copied, reproduced, modified, published, uploaded, posted, transmitted, +// distributed or disclosed in any way without Intel's prior express written +// permission. No license under any patent, copyright or other intellectual +// property rights in the Material is granted to or conferred upon you, +// either expressly, by implication, inducement, estoppel or otherwise. +// Any license under such intellectual property rights must be express and +// approved by Intel in writing. +// +// Unless otherwise agreed by Intel in writing, +// you may not remove or alter this notice or any other notice embedded in +// Materials by Intel or Intel's suppliers or licensors in any way. +// +*/ /* // Intel(R) Integrated Performance Primitives diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ippcp.h b/external/epid-sdk/ext/ipp/include/ippcp.h similarity index 62% rename from external/epid-sdk-3.0.0/ext/ipp/include/ippcp.h rename to external/epid-sdk/ext/ipp/include/ippcp.h index a571c229..5fd51da5 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ippcp.h +++ b/external/epid-sdk/ext/ipp/include/ippcp.h @@ -1,41 +1,41 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ +/* +// Copyright 2002-2018 Intel Corporation All Rights Reserved. +// +// The source code, information and material ("Material") contained herein is +// owned by Intel Corporation or its suppliers or licensors, and title +// to such Material remains with Intel Corporation or its suppliers or +// licensors. The Material contains proprietary information of Intel +// or its suppliers and licensors. The Material is protected by worldwide +// copyright laws and treaty provisions. No part of the Material may be used, +// copied, reproduced, modified, published, uploaded, posted, transmitted, +// distributed or disclosed in any way without Intel's prior express written +// permission. No license under any patent, copyright or other intellectual +// property rights in the Material is granted to or conferred upon you, +// either expressly, by implication, inducement, estoppel or otherwise. +// Any license under such intellectual property rights must be express and +// approved by Intel in writing. +// +// Unless otherwise agreed by Intel in writing, +// you may not remove or alter this notice or any other notice embedded in +// Materials by Intel or Intel's suppliers or licensors in any way. +// +*/ /* -// Intel(R) Integrated Performance Primitives +// Intel(R) Integrated Performance Primitives (Intel(R) IPP) // Cryptographic Primitives (ippCP) // // */ -#if !defined( __IPPCP_H__ ) || defined( _OWN_BLDPCS ) -#define __IPPCP_H__ +#if !defined( IPPCP_H__ ) || defined( _OWN_BLDPCS ) +#define IPPCP_H__ - -#if defined (_WIN32_WCE) && defined (_M_IX86) && defined (__stdcall) - #define _IPP_STDCALL_CDECL - #undef __stdcall +#ifndef _SGX_IPPCP_H_ +#include "sgx_ippcp.h" #endif - -#ifndef __IPPDEFS_H__ - #include "ippdefs.h" -#endif - -#ifndef __IPPCPDEFS_H__ +#ifndef IPPCPDEFS_H__ #include "ippcpdefs.h" #endif @@ -44,19 +44,15 @@ extern "C" { #endif -#if !defined( _IPP_NO_DEFAULT_LIB ) +#if !defined( IPP_NO_DEFAULT_LIB ) #if defined( _IPP_SEQUENTIAL_DYNAMIC ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcp" ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcore" ) + #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippcp" ) #elif defined( _IPP_SEQUENTIAL_STATIC ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcpmt" ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcoremt" ) + #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "ippcpmt" ) #elif defined( _IPP_PARALLEL_DYNAMIC ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcp" ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcore" ) + #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippcp" ) #elif defined( _IPP_PARALLEL_STATIC ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcpmt" ) - #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcoremt" ) + #pragma comment( lib, __FILE__ "/../../lib/" INTEL_PLATFORM "threaded/ippcpmt" ) #endif #endif @@ -72,7 +68,6 @@ extern "C" { IPPAPI( const IppLibraryVersion*, ippcpGetLibVersion, (void) ) - /* // ========================================================= // Symmetric Ciphers @@ -149,9 +144,27 @@ IPPAPI(IppStatus, ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IPPAPI(IppStatus, ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) IPPAPI(IppStatus, ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + const Ipp8u* pIV)) IPPAPI(IppStatus, ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, @@ -174,6 +187,16 @@ IPPAPI(IppStatus, ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, ippsAESEncryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, + const Ipp8u* pTweakPT, + const Ipp8u* pKey, int keyBitsize, + int dataUnitBitsize)) +IPPAPI(IppStatus, ippsAESDecryptXTS_Direct,(const Ipp8u* pSrc, Ipp8u* pDst, int encBitsize, int aesBlkNo, + const Ipp8u* pTweakPT, + const Ipp8u* pKey, int keyBitsize, + int dataUnitBitsize)) + + /* SMS4 */ IPPAPI(IppStatus, ippsSMS4GetSize,(int *pSize)) IPPAPI(IppStatus, ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) @@ -187,9 +210,27 @@ IPPAPI(IppStatus, ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IPPAPI(IppStatus, ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) IPPAPI(IppStatus, ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) +IPPAPI(IppStatus, ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsSMS4Spec* pCtx, + const Ipp8u* pIV)) IPPAPI(IppStatus, ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, @@ -212,6 +253,17 @@ IPPAPI(IppStatus, ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) +/* SMS4-CCM */ +IPPAPI(IppStatus, ippsSMS4_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) + +IPPAPI(IppStatus, ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) + +IPPAPI(IppStatus, ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) /* // ========================================================= @@ -219,9 +271,7 @@ IPPAPI(IppStatus, ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, // ========================================================= */ -/* -// AES-CCM -*/ +/* AES-CCM */ IPPAPI(IppStatus, ippsAES_CCMGetSize,(int* pSize)) IPPAPI(IppStatus, ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pCtx, int ctxSize)) @@ -233,9 +283,7 @@ IPPAPI(IppStatus, ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, I IPPAPI(IppStatus, ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pCtx)) IPPAPI(IppStatus, ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pCtx)) -/* -// AES-GCM -*/ +/* AES-GCM */ IPPAPI(IppStatus, ippsAES_GCMGetSize,(int * pSize)) IPPAPI(IppStatus, ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) @@ -251,9 +299,35 @@ IPPAPI(IppStatus, ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, I IPPAPI(IppStatus, ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) IPPAPI(IppStatus, ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) -/* -// AES-CMAC -*/ +/* AES-XTS */ +IPPAPI(IppStatus, ippsAES_XTSGetSize,(int * pSize)) +IPPAPI(IppStatus, ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, + int duBitsize, + IppsAES_XTSSpec* pCtx,int ctxSize)) +IPPAPI(IppStatus, ippsAES_XTSEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, + const IppsAES_XTSSpec* pCtx, + const Ipp8u* pTweak, + int startCipherBlkNo)) +IPPAPI(IppStatus, ippsAES_XTSDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int bitSizeLen, + const IppsAES_XTSSpec* pCtx, + const Ipp8u* pTweak, + int startCipherBlkNo)) + +/* AES-SIV (RFC 5297) */ +IPPAPI(IppStatus, ippsAES_S2V_CMAC,(const Ipp8u* pKey, int keyLen, + const Ipp8u* pAD[], const int pADlen[], int numAD, + Ipp8u* pV)) +IPPAPI(IppStatus, ippsAES_SIVEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + Ipp8u* pSIV, + const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, + const Ipp8u* pAD[], const int pADlen[], int numAD)) +IPPAPI(IppStatus, ippsAES_SIVDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + int* pAuthPassed, + const Ipp8u* pAuthKey, const Ipp8u* pConfKey, int keyLen, + const Ipp8u* pAD[], const int pADlen[], int numAD, + const Ipp8u* pSIV)) + +/* AES-CMAC */ IPPAPI(IppStatus, ippsAES_CMACGetSize,(int* pSize)) IPPAPI(IppStatus, ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) @@ -261,6 +335,7 @@ IPPAPI(IppStatus, ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACSt IPPAPI(IppStatus, ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) IPPAPI(IppStatus, ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) + /* // ========================================================= // RC4 Stream Ciphers @@ -284,6 +359,7 @@ IPPAPI(IppStatus, ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int lengt // One-Way Hash Functions // ========================================================= */ + /* SHA1 Hash Primitives */ IPPAPI(IppStatus, ippsSHA1GetSize,(int* pSize)) IPPAPI(IppStatus, ippsSHA1Init,(IppsSHA1State* pCtx)) @@ -388,8 +464,43 @@ IPPAPI(IppStatus, ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* p IPPAPI(IppStatus, ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) IPPAPI(IppStatus, ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +/* method based generalized (reduced memory footprint) Hash Primitives */ +IPPAPI( const IppsHashMethod*, ippsHashMethod_MD5, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SM3, (void) ) + +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA1, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA1_NI, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA1_TT, (void) ) + +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA256, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA256_NI, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA256_TT, (void) ) + +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA224, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA224_NI, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA224_TT, (void) ) + +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA512, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA384, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA512_256, (void) ) +IPPAPI( const IppsHashMethod*, ippsHashMethod_SHA512_224, (void) ) + +IPPAPI(IppStatus, ippsHashGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, ippsHashInit_rmf,(IppsHashState_rmf* pCtx, const IppsHashMethod* pMethod)) + +IPPAPI(IppStatus, ippsHashPack_rmf,(const IppsHashState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcCtx, IppsHashState_rmf* pDstCtx)) + +IPPAPI(IppStatus, ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) + /* general MGF Primitives*/ IPPAPI(IppStatus, ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) /* @@ -397,6 +508,8 @@ IPPAPI(IppStatus, ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int ma // Keyed-Hash Message Authentication Codes // ========================================================= */ + +/* generalized Keyed HMAC primitives */ IPPAPI(IppStatus, ippsHMAC_GetSize,(int* pSize)) IPPAPI(IppStatus, ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) @@ -412,6 +525,24 @@ IPPAPI(IppStatus, ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD, int mdLen, IppHashAlgId hashAlg)) +/* method based generalized (reduced memory footprint) Keyed HMAC primitives */ +IPPAPI(IppStatus, ippsHMACGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, + IppsHMACState_rmf* pCtx, + const IppsHashMethod* pMethod)) + +IPPAPI(IppStatus, ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) + +IPPAPI(IppStatus, ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, ippsHMACMessage_rmf,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pKey, int keyLen, + Ipp8u* pMD, int mdLen, + const IppsHashMethod* pMethod)) + /* // ========================================================= @@ -587,6 +718,21 @@ IPPAPI(IppStatus, ippsRSADecrypt_OAEP,(const Ipp8u* pSrc, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, ippsRSAEncrypt_OAEP_rmf,(const Ipp8u* pSrc, int srcLen, + const Ipp8u* pLabel, int labLen, + const Ipp8u* pSeed, + Ipp8u* pDst, + const IppsRSAPublicKeyState* pKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + +IPPAPI(IppStatus, ippsRSADecrypt_OAEP_rmf,(const Ipp8u* pSrc, + const Ipp8u* pLab, int labLen, + Ipp8u* pDst, int* pDstLen, + const IppsRSAPrivateKeyState* pKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + /* encryption scheme: RSAES-PKCS_v1_5 */ IPPAPI(IppStatus, ippsRSAEncrypt_PKCSv15,(const Ipp8u* pSrc, int srcLen, const Ipp8u* pRndPS, @@ -599,7 +745,6 @@ IPPAPI(IppStatus, ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) - /* signature scheme : RSA-SSA-PSS */ IPPAPI(IppStatus, ippsRSASign_PSS,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSalt, int saltLen, @@ -616,6 +761,21 @@ IPPAPI(IppStatus, ippsRSAVerify_PSS,(const Ipp8u* pMsg, int msgLen, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, ippsRSASign_PSS_rmf,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pSalt, int saltLen, + Ipp8u* pSign, + const IppsRSAPrivateKeyState* pPrvKey, + const IppsRSAPublicKeyState* pPubKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + +IPPAPI(IppStatus, ippsRSAVerify_PSS_rmf,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pSign, + int* pIsValid, + const IppsRSAPublicKeyState* pKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + /* signature scheme : RSA-SSA-PKCS1-v1_5 */ IPPAPI(IppStatus, ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, Ipp8u* pSign, @@ -624,13 +784,26 @@ IPPAPI(IppStatus, ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, IppHashAlgId hashAlg, Ipp8u* pBuffer)) - IPPAPI(IppStatus, ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, const Ipp8u* pSign, int* pIsValid, const IppsRSAPublicKeyState* pKey, IppHashAlgId hashAlg, Ipp8u* pBuffer)) +IPPAPI(IppStatus, ippsRSASign_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, + Ipp8u* pSign, + const IppsRSAPrivateKeyState* pPrvKey, + const IppsRSAPublicKeyState* pPubKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + +IPPAPI(IppStatus, ippsRSAVerify_PKCS1v15_rmf,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pSign, int* pIsValid, + const IppsRSAPublicKeyState* pKey, + const IppsHashMethod* pMethod, + Ipp8u* pBuffer)) + + /* // ========================================================= // DL Cryptography @@ -718,15 +891,6 @@ IPPAPI( const char*, ippsECCGetResultString, (IppECResult code)) */ /* general EC initialization */ IPPAPI(IppStatus, ippsECCPGetSize,(int feBitSize, int* pSize)) -IPPAPI(IppStatus, ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) - -IPPAPI(IppStatus, ippsECCPSet,(const IppsBigNumState* pPrime, - const IppsBigNumState* pA, const IppsBigNumState* pB, - const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, - int cofactor, - IppsECCPState* pECC)) - -/* standard EC initialization */ IPPAPI(IppStatus, ippsECCPGetSizeStd128r1,(int* pSize)) IPPAPI(IppStatus, ippsECCPGetSizeStd128r2,(int* pSize)) IPPAPI(IppStatus, ippsECCPGetSizeStd192r1,(int* pSize)) @@ -736,6 +900,7 @@ IPPAPI(IppStatus, ippsECCPGetSizeStd384r1,(int* pSize)) IPPAPI(IppStatus, ippsECCPGetSizeStd521r1,(int* pSize)) IPPAPI(IppStatus, ippsECCPGetSizeStdSM2,(int* pSize)) +IPPAPI(IppStatus, ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPInitStd128r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPInitStd128r2,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPInitStd192r1,(IppsECCPState* pECC)) @@ -745,6 +910,12 @@ IPPAPI(IppStatus, ippsECCPInitStd384r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPInitStd521r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPInitStdSM2,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPSet,(const IppsBigNumState* pPrime, + const IppsBigNumState* pA, const IppsBigNumState* pB, + const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, + int cofactor, + IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPSetStd128r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPSetStd128r2,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPSetStd192r1,(IppsECCPState* pECC)) @@ -754,7 +925,12 @@ IPPAPI(IppStatus, ippsECCPSetStd384r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPSetStd521r1,(IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPSetStdSM2,(IppsECCPState* pECC)) -IPPAPI(IppStatus, ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStd192r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStd224r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStd256r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStd384r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStd521r1,(IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPBindGxyTblStdSM2, (IppsECCPState* pECC)) IPPAPI(IppStatus, ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, @@ -846,15 +1022,184 @@ IPPAPI(IppStatus, ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, IppECResult* pResult, IppsECCPState* pECC)) +/* +// GF over prime and its extension +*/ +IPPAPI(IppStatus, ippsGFpGetSize, (int bitSize, int* pStateSizeInBytes)) +IPPAPI(IppStatus, ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGF)) +IPPAPI(IppStatus, ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI(IppStatus, ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* method, IppsGFpState* pGF)) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p192r1,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p224r1,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p256r1,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p384r1,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p521r1,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p256sm2,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p256bn, (void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_p256, (void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpMethod_pArb, (void) ) + +IPPAPI(IppStatus, ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pStateSizeInBytes)) +IPPAPI(IppStatus, ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int ne, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* method, IppsGFpState* pGFpx)) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_binom2_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_binom3_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_binom2,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_binom3,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_binom,(void) ) +IPPAPI( const IppsGFpMethod*, ippsGFpxMethod_com, (void) ) + +IPPAPI(IppStatus, ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGF, int* pBufferSize)) + +IPPAPI(IppStatus, ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPAPI(IppStatus, ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) + +IPPAPI(IppStatus, ippsGFpSetElement, (const Ipp32u* pA, int nsA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pElm, IppsGFpState* pGF)) +IPPAPI(IppStatus, ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, IppHashAlgId hashID)) +IPPAPI(IppStatus, ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGF, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int nsA, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) + +IPPAPI(IppStatus, ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) + +IPPAPI(IppStatus, ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pElmR, IppsGFpState* pGF, Ipp8u* pScratchBuffer)) + +IPPAPI(IppStatus, ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) + +/* ================== */ +IPPAPI(IppStatus, ippsGFpECGetSize,(const IppsGFpState* pGF, int* pCtxSizeInBytes)) +IPPAPI(IppStatus, ippsGFpECInit, (const IppsGFpState* pGF, + const IppsGFpElement* pA, const IppsGFpElement* pB, + IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, + IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, + const IppsBigNumState* pOrder, + const IppsBigNumState* pCofactor, + IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECInitStd128r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd128r2,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd192r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd224r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd256r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd384r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStd521r1,(const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStdSM2, (const IppsGFpState* pGF, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECInitStdBN256,(const IppsGFpState* pGF, IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECGet,(IppsGFpState** const ppGF, + IppsGFpElement* pA, IppsGFpElement* pB, + const IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECGetSubgroup,(IppsGFpState** const ppGF, + IppsGFpElement* pX, IppsGFpElement* pY, + IppsBigNumState* pOrder,IppsBigNumState* pCofactor, + const IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) + +IPPAPI(IppStatus, ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPAPI(IppStatus, ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSizeInBytes)) +IPPAPI(IppStatus, ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECSetPointHash_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) + +IPPAPI(IppStatus, ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +/* keys */ +IPPAPI(IppStatus, ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, + IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +/* DH shared secret */ +IPPAPI(IppStatus, ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, + IppsBigNumState* pShare, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, + const IppsGFpECPoint* pPublicB, + IppsBigNumState* pShare, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +/* sign generation/verification of DSA, NR, SM2 */ +IPPAPI(IppStatus, ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pRegPrivate, + const IppsBigNumState* pEphPrivate, + IppsBigNumState* pSignR, IppsBigNumState* pSignS, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECVerifyDSA,(const IppsBigNumState* pMsgDigest, + const IppsGFpECPoint* pRegPublic, + const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, + IppECResult* pResult, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPAPI(IppStatus, ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pRegPrivate, + const IppsBigNumState* pEphPrivate, + IppsBigNumState* pSignR, IppsBigNumState* pSignS, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECVerifyNR,(const IppsBigNumState* pMsgDigest, + const IppsGFpECPoint* pRegPublic, + const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, + IppECResult* pResult, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPAPI(IppStatus, ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pRegPrivate, + const IppsBigNumState* pEphPrivate, + IppsBigNumState* pSignR, IppsBigNumState* pSignS, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsGFpECVerifySM2,(const IppsBigNumState* pMsgDigest, + const IppsGFpECPoint* pRegPublic, + const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, + IppECResult* pResult, + IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) #ifdef __cplusplus } #endif -#if defined (_IPP_STDCALL_CDECL) - #undef _IPP_STDCALL_CDECL - #define __stdcall __cdecl -#endif - -#endif /* __IPPCP_H__ */ +#endif /* IPPCP_H__ */ diff --git a/external/epid-sdk/ext/ipp/include/ippcpdefs.h b/external/epid-sdk/ext/ipp/include/ippcpdefs.h new file mode 100644 index 00000000..f078b105 --- /dev/null +++ b/external/epid-sdk/ext/ipp/include/ippcpdefs.h @@ -0,0 +1,785 @@ +/* +// Copyright 2012-2018 Intel Corporation All Rights Reserved. +// +// The source code, information and material ("Material") contained herein is +// owned by Intel Corporation or its suppliers or licensors, and title +// to such Material remains with Intel Corporation or its suppliers or +// licensors. The Material contains proprietary information of Intel +// or its suppliers and licensors. The Material is protected by worldwide +// copyright laws and treaty provisions. No part of the Material may be used, +// copied, reproduced, modified, published, uploaded, posted, transmitted, +// distributed or disclosed in any way without Intel's prior express written +// permission. No license under any patent, copyright or other intellectual +// property rights in the Material is granted to or conferred upon you, +// either expressly, by implication, inducement, estoppel or otherwise. +// Any license under such intellectual property rights must be express and +// approved by Intel in writing. +// +// Unless otherwise agreed by Intel in writing, +// you may not remove or alter this notice or any other notice embedded in +// Materials by Intel or Intel's suppliers or licensors in any way. +// +*/ + +/* +// Intel(R) Integrated Performance Primitives (Intel(R) IPP) +// Cryptographic Primitives (ippCP) definitions. +// +// +*/ + +/* +// Intel(R) Integrated Performance Primitives (Intel(R) IPP) +// Basic Types and Macro Definitions +// +// +*/ + + +#ifndef IPPBASE_H__ +#define IPPBASE_H__ + +#ifdef __cplusplus +extern "C" { +#endif +#if defined (_WIN64) +#define INTEL_PLATFORM "intel64/" +#elif defined (_WIN32) +#define INTEL_PLATFORM "ia32/" +#endif + +#if !defined( IPPAPI ) + + #if defined( IPP_W32DLL ) && (defined( _WIN32 ) || defined( _WIN64 )) + #if defined( _MSC_VER ) || defined( __ICL ) + #define IPPAPI( type,name,arg ) \ + __declspec(dllimport) type IPP_STDCALL name arg; + #else + #define IPPAPI( type,name,arg ) type IPP_STDCALL name arg; + #endif + #else + #define IPPAPI( type,name,arg ) type IPP_STDCALL name arg; + #endif + +#endif + +#if (defined( __ICL ) || defined( __ECL ) || defined(_MSC_VER)) && !defined( _PCS ) && !defined( _PCS_GENSTUBS ) + #if( __INTEL_COMPILER >= 1100 ) /* icl 11.0 supports additional comment */ + #if( _MSC_VER >= 1400 ) + #define IPP_DEPRECATED( comment ) __declspec( deprecated ( comment )) + #else + #pragma message ("your icl version supports additional comment for deprecated functions but it can't be displayed") + #pragma message ("because internal _MSC_VER macro variable setting requires compatibility with MSVC7.1") + #pragma message ("use -Qvc8 switch for icl command line to see these additional comments") + #define IPP_DEPRECATED( comment ) __declspec( deprecated ) + #endif + #elif( _MSC_FULL_VER >= 140050727 )&&( !defined( __INTEL_COMPILER )) /* VS2005 supports additional comment */ + #define IPP_DEPRECATED( comment ) __declspec( deprecated ( comment )) + #elif( _MSC_VER <= 1200 )&&( !defined( __INTEL_COMPILER )) /* VS 6 doesn't support deprecation */ + #define IPP_DEPRECATED( comment ) + #else + #define IPP_DEPRECATED( comment ) __declspec( deprecated ) + #endif +#elif (defined(__ICC) || defined(__ECC) || defined( __GNUC__ )) && !defined( _PCS ) && !defined( _PCS_GENSTUBS ) + #if defined( __GNUC__ ) + #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 5 + #define IPP_DEPRECATED( message ) __attribute__(( deprecated( message ))) + #else + #define IPP_DEPRECATED( message ) __attribute__(( deprecated )) + #endif + #else + #define IPP_DEPRECATED( comment ) __attribute__(( deprecated )) + #endif +#else + #define IPP_DEPRECATED( comment ) +#endif + +#if (defined( __ICL ) || defined( __ECL ) || defined(_MSC_VER)) + #if !defined( IPP_NO_DEFAULT_LIB ) + #if (( defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && defined( _IPP_SEQUENTIAL_STATIC ))) + #elif (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) + #define IPP_NO_DEFAULT_LIB + #else + #error Illegal combination of _IPP_PARALLEL_DYNAMIC/_IPP_PARALLEL_STATIC/_IPP_SEQUENTIAL_DYNAMIC/_IPP_SEQUENTIAL_STATIC, only one definition can be defined + #endif + #endif +#else + #define IPP_NO_DEFAULT_LIB + #if (defined( _IPP_PARALLEL_DYNAMIC ) || defined( _IPP_PARALLEL_STATIC ) || defined(_IPP_SEQUENTIAL_DYNAMIC) || defined(_IPP_SEQUENTIAL_STATIC)) + #pragma message ("defines _IPP_PARALLEL_DYNAMIC/_IPP_PARALLEL_STATIC/_IPP_SEQUENTIAL_DYNAMIC/_IPP_SEQUENTIAL_STATIC do not have any effect in current configuration") + #endif +#endif + +#if !defined( IPP_NO_DEFAULT_LIB ) + #if defined( _IPP_PARALLEL_STATIC ) + #pragma comment( lib, "libiomp5md" ) + #endif +#endif + +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define IPP_STDCALL __stdcall + #define IPP_CDECL __cdecl + #define IPP_INT64 __int64 + #define IPP_UINT64 unsigned __int64 +#else + #define IPP_STDCALL + #define IPP_CDECL + #define IPP_INT64 long long + #define IPP_UINT64 unsigned long long +#endif + +#define IPP_PI ( 3.14159265358979323846 ) /* ANSI C does not support M_PI */ +#define IPP_2PI ( 6.28318530717958647692 ) /* 2*pi */ +#define IPP_PI2 ( 1.57079632679489661923 ) /* pi/2 */ +#define IPP_PI4 ( 0.78539816339744830961 ) /* pi/4 */ +#define IPP_PI180 ( 0.01745329251994329577 ) /* pi/180 */ +#define IPP_RPI ( 0.31830988618379067154 ) /* 1/pi */ +#define IPP_SQRT2 ( 1.41421356237309504880 ) /* sqrt(2) */ +#define IPP_SQRT3 ( 1.73205080756887729353 ) /* sqrt(3) */ +#define IPP_LN2 ( 0.69314718055994530942 ) /* ln(2) */ +#define IPP_LN3 ( 1.09861228866810969139 ) /* ln(3) */ +#define IPP_E ( 2.71828182845904523536 ) /* e */ +#define IPP_RE ( 0.36787944117144232159 ) /* 1/e */ +#define IPP_EPS23 ( 1.19209289e-07f ) +#define IPP_EPS52 ( 2.2204460492503131e-016 ) + +#define IPP_MAX_8U ( 0xFF ) +#define IPP_MAX_16U ( 0xFFFF ) +#define IPP_MAX_32U ( 0xFFFFFFFF ) +#define IPP_MIN_8U ( 0 ) +#define IPP_MIN_16U ( 0 ) +#define IPP_MIN_32U ( 0 ) +#define IPP_MIN_8S (-128 ) +#define IPP_MAX_8S ( 127 ) +#define IPP_MIN_16S (-32768 ) +#define IPP_MAX_16S ( 32767 ) +#define IPP_MIN_32S (-2147483647 - 1 ) +#define IPP_MAX_32S ( 2147483647 ) +#define IPP_MIN_64U ( 0 ) + +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define IPP_MAX_64S ( 9223372036854775807i64 ) + #define IPP_MIN_64S (-9223372036854775807i64 - 1 ) + #define IPP_MAX_64U ( 0xffffffffffffffffL ) /* 18446744073709551615 */ +#else + #define IPP_MAX_64S ( 9223372036854775807LL ) + #define IPP_MIN_64S (-9223372036854775807LL - 1 ) + #define IPP_MAX_64U ( 0xffffffffffffffffLL ) /* 18446744073709551615 */ +#endif + +#define IPP_MINABS_32F ( 1.175494351e-38f ) +#define IPP_MAXABS_32F ( 3.402823466e+38f ) +#define IPP_EPS_32F ( 1.192092890e-07f ) +#define IPP_MINABS_64F ( 2.2250738585072014e-308 ) +#define IPP_MAXABS_64F ( 1.7976931348623158e+308 ) +#define IPP_EPS_64F ( 2.2204460492503131e-016 ) + +#define IPP_MAX( a, b ) ( ((a) > (b)) ? (a) : (b) ) +#define IPP_MIN( a, b ) ( ((a) < (b)) ? (a) : (b) ) + +#define IPP_ABS( a ) ( ((a) < 0) ? (-(a)) : (a) ) + +typedef struct { + int major; /* e.g. 1 */ + int minor; /* e.g. 2 */ + int majorBuild; /* e.g. 3 */ + int build; /* e.g. 10, always >= majorBuild */ + char targetCpu[4]; /* corresponding to Intel(R) processor */ + const char* Name; /* e.g. "ippsw7" */ + const char* Version; /* e.g. "v1.2 Beta" */ + const char* BuildDate; /* e.g. "Jul 20 99" */ +} IppLibraryVersion; + +typedef unsigned char Ipp8u; +typedef unsigned short Ipp16u; +typedef unsigned int Ipp32u; +typedef signed char Ipp8s; +typedef signed short Ipp16s; +typedef signed int Ipp32s; +typedef float Ipp32f; +typedef IPP_INT64 Ipp64s; +typedef IPP_UINT64 Ipp64u; +typedef double Ipp64f; +typedef Ipp16s Ipp16f; + +typedef struct { + Ipp8s re; + Ipp8s im; +} Ipp8sc; + +typedef struct { + Ipp16s re; + Ipp16s im; +} Ipp16sc; + +typedef struct { + Ipp16u re; + Ipp16u im; +} Ipp16uc; + +typedef struct { + Ipp32s re; + Ipp32s im; +} Ipp32sc; + +typedef struct { + Ipp32f re; + Ipp32f im; +} Ipp32fc; + +typedef struct { + Ipp64s re; + Ipp64s im; +} Ipp64sc; + +typedef struct { + Ipp64f re; + Ipp64f im; +} Ipp64fc; + +typedef enum { + ippUndef = -1, + ipp1u = 0, + ipp8u = 1, + ipp8uc = 2, + ipp8s = 3, + ipp8sc = 4, + ipp16u = 5, + ipp16uc = 6, + ipp16s = 7, + ipp16sc = 8, + ipp32u = 9, + ipp32uc = 10, + ipp32s = 11, + ipp32sc = 12, + ipp32f = 13, + ipp32fc = 14, + ipp64u = 15, + ipp64uc = 16, + ipp64s = 17, + ipp64sc = 18, + ipp64f = 19, + ipp64fc = 20 +} IppDataType; + +typedef enum { + ippFalse = 0, + ippTrue = 1 +} IppBool; + +#ifdef __cplusplus +} +#endif + +#endif /* IPPBASE_H__ */ + +#ifndef IPP_CPU_FEATURES__ +#define IPP_CPU_FEATURES__ + +#define ippCPUID_MMX 0x00000001 /* Intel(R) Architecture MMX technology supported */ +#define ippCPUID_SSE 0x00000002 /* Intel(R) Streaming SIMD Extensions */ +#define ippCPUID_SSE2 0x00000004 /* Intel(R) Streaming SIMD Extensions 2 */ +#define ippCPUID_SSE3 0x00000008 /* Intel(R) Streaming SIMD Extensions 3 */ +#define ippCPUID_SSSE3 0x00000010 /* Supplemental Streaming SIMD Extensions 3 */ +#define ippCPUID_MOVBE 0x00000020 /* Intel(R) MOVBE instruction */ +#define ippCPUID_SSE41 0x00000040 /* Intel(R) Streaming SIMD Extensions 4.1 */ +#define ippCPUID_SSE42 0x00000080 /* Intel(R) Streaming SIMD Extensions 4.2 */ +#define ippCPUID_AVX 0x00000100 /* Intel(R) Advanced Vector Extensions instruction set */ +#define ippAVX_ENABLEDBYOS 0x00000200 /* Intel(R) Advanced Vector Extensions instruction set is supported by OS */ +#define ippCPUID_AES 0x00000400 /* Intel(R) AES New Instructions */ +#define ippCPUID_CLMUL 0x00000800 /* Intel(R) CLMUL instruction */ +#define ippCPUID_ABR 0x00001000 /* Reserved */ +#define ippCPUID_RDRAND 0x00002000 /* Intel(R) RDRAND instruction */ +#define ippCPUID_F16C 0x00004000 /* Intel(R) F16C new instructions */ +#define ippCPUID_AVX2 0x00008000 /* Intel(R) Advanced Vector Extensions 2 instruction set */ +#define ippCPUID_ADCOX 0x00010000 /* Intel(R) ADOX/ADCX new instructions */ +#define ippCPUID_RDSEED 0x00020000 /* Intel(R) RDSEED instruction */ +#define ippCPUID_PREFETCHW 0x00040000 /* Intel(R) PREFETCHW instruction */ +#define ippCPUID_SHA 0x00080000 /* Intel(R) SHA new instructions */ +#define ippCPUID_AVX512F 0x00100000 /* Intel(R) Advanced Vector Extensions 512 Foundation instruction set */ +#define ippCPUID_AVX512CD 0x00200000 /* Intel(R) Advanced Vector Extensions 512 CD instruction set */ +#define ippCPUID_AVX512ER 0x00400000 /* Intel(R) Advanced Vector Extensions 512 ER instruction set */ +#define ippCPUID_AVX512PF 0x00800000 /* Intel(R) Advanced Vector Extensions 512 PF instruction set */ +#define ippCPUID_AVX512BW 0x01000000 /* Intel(R) Advanced Vector Extensions 512 BW instruction set */ +#define ippCPUID_AVX512DQ 0x02000000 /* Intel(R) Advanced Vector Extensions 512 DQ instruction set */ +#define ippCPUID_AVX512VL 0x04000000 /* Intel(R) Advanced Vector Extensions 512 VL instruction set */ +#define ippCPUID_AVX512VBMI 0x08000000 /* Intel(R) Advanced Vector Extensions 512 Bit Manipulation instructions */ +#define ippCPUID_MPX 0x10000000 /* Intel(R) Memory Protection Extensions */ +#define ippCPUID_AVX512_4FMADDPS 0x20000000 /* Intel(R) Advanced Vector Extensions 512 DL floating-point single precision */ +#define ippCPUID_AVX512_4VNNIW 0x40000000 /* Intel(R) Advanced Vector Extensions 512 DL enhanced word variable precision */ +#define ippCPUID_KNC 0x80000000 /* Intel(R) Xeon Phi(TM) Coprocessor */ +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define INT64_SUFFIX(name) name##L +#else + #define INT64_SUFFIX(name) name##LL +#endif + #define ippCPUID_AVX512IFMA INT64_SUFFIX(0x100000000) /* Intel(R) Advanced Vector Extensions 512 IFMA (PMADD52) instruction set */ + #define ippCPUID_NOCHECK INT64_SUFFIX(0x8000000000000000) /* Force ippSetCpuFeatures to set CPU features without check */ + #define ippCPUID_GETINFO_A INT64_SUFFIX(0x616f666e69746567) /* Force ippGetCpuFeatures to work as cpuid instruction */ + #define ippAVX512_ENABLEDBYOS INT64_SUFFIX(0x200000000) /* Intel(R) Advanced Vector Extensions 512 is supported by OS */ + + +#endif /* IPP_CPU_FEATURES__ */ + + +#ifndef IPPSTATUS_H__ +#define IPPSTATUS_H__ + +#ifdef __cplusplus +extern "C" { +#endif +typedef signed int IppStatus; + + /* start of common with ippCrypto part - any changes MUST be done in both repositories - IPP & ippCrypto */ +#define ippStsLoadDynErr -221 /* Error when loading the dynamic library. */ +#define ippStsLengthErr -15 /* Incorrect value for string length. */ +#define ippStsNotSupportedModeErr -14 /* The requested mode is currently not supported. */ +#define ippStsContextMatchErr -13 /* Context parameter does not match the operation. */ +#define ippStsScaleRangeErr -12 /* Scale bounds are out of range. */ +#define ippStsOutOfRangeErr -11 /* Argument is out of range, or point is outside the image. */ +#define ippStsDivByZeroErr -10 /* An attempt to divide by zero. */ +#define ippStsMemAllocErr -9 /* Memory allocated for the operation is not enough.*/ +#define ippStsNullPtrErr -8 /* Null pointer error. */ +#define ippStsRangeErr -7 /* Incorrect values for bounds: the lower bound is greater than the upper bound. */ +#define ippStsSizeErr -6 /* Incorrect value for data size. */ +#define ippStsBadArgErr -5 /* Incorrect arg/param of the function. */ +#define ippStsNoMemErr -4 /* Not enough memory for the operation. */ +#define ippStsErr -2 /* Unknown/unspecified error */ + /* no errors */ +#define ippStsNoErr 0 /* No errors. */ + /* warnings */ +#define ippStsNoOperation 1 /* No operation has been executed. */ +#define ippStsDivByZero 2 /* Zero value(s) for the divisor in the Div function. */ +#define ippStsWaterfall 43 /* Cannot load required library, waterfall is used. */ + /* end of common with ippCrypto part */ + +#ifdef __cplusplus +} +#endif + +#endif /* IPPSTATUS_H__ */ +#define ippStsCpuNotSupportedErr -9999/* The target CPU is not supported. */ + + /* ippCrypto specific statuses - any changes MUST be done in both repositories - IPP & ippCrypto */ +#define ippStsQuadraticNonResidueErr -1016 /* SQRT operation on quadratic non-residue value. */ +#define ippStsPointAtInfinity -1015 /* Point at infinity is detected. */ +#define ippStsOFBSizeErr -1014 /* Incorrect value for crypto OFB block size. */ +#define ippStsIncompleteContextErr -1013 /* Crypto: set up of context is not complete. */ +#define ippStsCTRSizeErr -1012 /* Incorrect value for crypto CTR block size. */ +#define ippStsEphemeralKeyErr -1011 /* ECC: Invalid ephemeral key. */ +#define ippStsMessageErr -1010 /* ECC: Invalid message digest. */ +#define ippStsShareKeyErr -1009 /* ECC: Invalid share key. */ +#define ippStsIvalidPrivateKey -1008 /* ECC: Invalid private key. */ +#define ippStsOutOfECErr -1007 /* ECC: Point out of EC. */ +#define ippStsECCInvalidFlagErr -1006 /* ECC: Invalid Flag. */ +#define ippStsUnderRunErr -1005 /* Error in data under run. */ +#define ippStsPaddingErr -1004 /* Detected padding error indicates the possible data corruption. */ +#define ippStsCFBSizeErr -1003 /* Incorrect value for crypto CFB block size. */ +#define ippStsPaddingSchemeErr -1002 /* Invalid padding scheme. */ +#define ippStsBadModulusErr -1001 /* Bad modulus caused a failure in module inversion. */ +#define ippStsInsufficientEntropy 25 /* Generation of the prime/key failed due to insufficient entropy in the random seed and stimulus bit string. */ + /* end of ippCrypto specific statuses - any changes MUST be done in both repositories - IPP & ippCrypto */ + +#ifndef IPPCPDEFS_H__ +#define IPPCPDEFS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + + +#if !defined( _OWN_BLDPCS ) + +typedef Ipp32u IppAlgId; + +/* +// ========================================================= +// Symmetric Ciphers +// ========================================================= +*/ +typedef enum { + ippPaddingNONE = 0, /*NONE = 0,*/ IppsCPPaddingNONE = 0, + ippPaddingPKCS7 = 1, /*PKCS7 = 1,*/ IppsCPPaddingPKCS7 = 1, + ippPaddingZEROS = 2, /*ZEROS = 2,*/ IppsCPPaddingZEROS = 2 +} IppsPadding, IppsCPPadding; + +typedef struct _cpDES IppsDESSpec; +typedef struct _cpRijndael128 IppsAESSpec; +typedef struct _cpRijndael128 IppsRijndael128Spec; +typedef struct _cpSMS4 IppsSMS4Spec; + +/* TDES */ +#define DES_BLOCKSIZE (64) /* cipher blocksize (bits) */ +#define TDES_BLOCKSIZE DES_BLOCKSIZE + +#define DES_KEYSIZE (64) /* cipher keysize (bits) */ +#define TDES_KEYSIZE DES_KEYSIZE + +/* AES */ +#define IPP_AES_BLOCK_BITSIZE (128) /* cipher blocksizes (bits) */ + +/* Rijndael */ +typedef enum { + ippRijndaelKey128 = 128, IppsRijndaelKey128 = 128, /* 128-bit key */ + ippRijndaelKey192 = 192, IppsRijndaelKey192 = 192, /* 192-bit key */ + ippRijndaelKey256 = 256, IppsRijndaelKey256 = 256 /* 256-bit key */ +} IppsRijndaelKeyLength; + +/* AES-CCM (authentication & confidence) */ +typedef struct _cpAES_CCM IppsAES_CCMState; +/* AES-GCM (authentication & confidence) */ +typedef struct _cpAES_GCM IppsAES_GCMState; +/* AES-XTS (confidence) */ +typedef struct _cpAES_XTS IppsAES_XTSSpec; + +/* SMS4-CCM (authentication & confidence) */ +typedef struct _cpSMS4_CCM IppsSMS4_CCMState; + +/* +// ========================================================= +// ARCFOUR Stream Cipher +// ========================================================= +*/ +typedef struct _cpARCfour IppsARCFourState; + +#define IPP_ARCFOUR_KEYMAX_SIZE (256) /* max key length (bytes) */ +#define MAX_ARCFOUR_KEY_LEN IPP_ARCFOUR_KEYMAX_SIZE /* obsolete */ + +/* +// ========================================================= +// One-Way Hash Functions +// ========================================================= +*/ +typedef enum { + ippHashAlg_Unknown, + ippHashAlg_SHA1, + ippHashAlg_SHA256, + ippHashAlg_SHA224, + ippHashAlg_SHA512, + ippHashAlg_SHA384, + ippHashAlg_MD5, + ippHashAlg_SM3, + ippHashAlg_SHA512_224, + ippHashAlg_SHA512_256, + ippHashAlg_MaxNo +} IppHashAlgId; + +#define IPP_ALG_HASH_UNKNOWN (ippHashAlg_Unknown) /* unknown */ +#define IPP_ALG_HASH_SHA1 (ippHashAlg_SHA1) /* SHA1 */ +#define IPP_ALG_HASH_SHA256 (ippHashAlg_SHA256) /* SHA256 */ +#define IPP_ALG_HASH_SHA224 (ippHashAlg_SHA224) /* SHA224 or SHA256/224 */ +#define IPP_ALG_HASH_SHA512 (ippHashAlg_SHA512) /* SHA512 */ +#define IPP_ALG_HASH_SHA384 (ippHashAlg_SHA384) /* SHA384 or SHA512/384 */ +#define IPP_ALG_HASH_MD5 (ippHashAlg_MD5) /* MD5 */ +#define IPP_ALG_HASH_SM3 (ippHashAlg_SM3) /* SM3 */ +#define IPP_ALG_HASH_SHA512_224 (ippHashAlg_SHA512_224) /* SHA512/224 */ +#define IPP_ALG_HASH_SHA512_256 (ippHashAlg_SHA512_256) /* SHA512/256 */ +#define IPP_ALG_HASH_LIMIT (ippHashAlg_MaxNo) /* hash alg limiter*/ + +typedef struct _cpSHA1 IppsSHA1State; +typedef struct _cpSHA256 IppsSHA256State; +typedef struct _cpSHA256 IppsSHA224State; +typedef struct _cpSHA512 IppsSHA512State; +typedef struct _cpSHA512 IppsSHA384State; +typedef struct _cpMD5 IppsMD5State; +typedef struct _cpSM3 IppsSM3State; +typedef struct _cpHashCtx IppsHashState; + +typedef struct _cpHashMethod_rmf IppsHashMethod; +typedef struct _cpHashCtx_rmf IppsHashState_rmf; + + +/* MGF */ +typedef IppStatus (IPP_STDCALL *IppMGF)(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen); +/* HASH function */ +typedef IppStatus (IPP_STDCALL *IppHASH)(const Ipp8u* pMsg, int len, Ipp8u* pMD); + +#define IPP_SHA1_DIGEST_BITSIZE 160 /* digest size (bits) */ +#define IPP_SHA256_DIGEST_BITSIZE 256 +#define IPP_SHA224_DIGEST_BITSIZE 224 +#define IPP_SHA384_DIGEST_BITSIZE 384 +#define IPP_SHA512_DIGEST_BITSIZE 512 +#define IPP_MD5_DIGEST_BITSIZE 128 +#define IPP_SM3_DIGEST_BITSIZE 256 +#define IPP_SHA512_224_DIGEST_BITSIZE 224 +#define IPP_SHA512_256_DIGEST_BITSIZE 256 + +/* +// ========================================================= +// Keyed-Hash Message Authentication Codes +// ========================================================= +*/ +typedef struct _cpHMAC IppsHMACState; +typedef struct _cpHMAC IppsHMACSHA1State; +typedef struct _cpHMAC IppsHMACSHA256State; +typedef struct _cpHMAC IppsHMACSHA224State; +typedef struct _cpHMAC IppsHMACSHA384State; +typedef struct _cpHMAC IppsHMACSHA512State; +typedef struct _cpHMAC IppsHMACMD5State; +typedef struct _cpHMAC_rmf IppsHMACState_rmf; + +/* +// ========================================================= +// Data Authentication Codes +// ========================================================= +*/ +typedef struct _cpAES_CMAC IppsAES_CMACState; + +/* +// ========================================================= +// Big Number Integer Arithmetic +// ========================================================= +*/ +#define BN_MAXBITSIZE (16*1024) /* bn max size (bits) */ + +typedef enum { + ippBigNumNEG = 0, IppsBigNumNEG = 0, + ippBigNumPOS = 1, IppsBigNumPOS = 1 +} IppsBigNumSGN; + +typedef enum { + ippBinaryMethod = 0, IppsBinaryMethod = 0, + ippSlidingWindows = 1, IppsSlidingWindows = 1 +} IppsExpMethod; + +typedef struct _cpBigNum IppsBigNumState; +typedef struct _cpMontgomery IppsMontState; +typedef struct _cpPRNG IppsPRNGState; +typedef struct _cpPrime IppsPrimeState; + +/* External Bit Supplier */ +typedef IppStatus (IPP_STDCALL *IppBitSupplier)(Ipp32u* pRand, int nBits, void* pEbsParams); + +#define IPP_IS_EQ (0) +#define IPP_IS_GT (1) +#define IPP_IS_LT (2) +#define IPP_IS_NE (3) +#define IPP_IS_NA (4) + +#define IPP_IS_PRIME (5) +#define IPP_IS_COMPOSITE (6) + +#define IPP_IS_VALID (7) +#define IPP_IS_INVALID (8) +#define IPP_IS_INCOMPLETE (9) +#define IPP_IS_ATINFINITY (10) + +#define IS_ZERO IPP_IS_EQ +#define GREATER_THAN_ZERO IPP_IS_GT +#define LESS_THAN_ZERO IPP_IS_LT +#define IS_PRIME IPP_IS_PRIME +#define IS_COMPOSITE IPP_IS_COMPOSITE +#define IS_VALID_KEY IPP_IS_VALID +#define IS_INVALID_KEY IPP_IS_INVALID +#define IS_INCOMPLETED_KEY IPP_IS_INCOMPLETE + +/* +// ========================================================= +// RSA Cryptography +// ========================================================= +*/ +#define MIN_RSA_SIZE (8) +#define MAX_RSA_SIZE (8*1024) + +typedef struct _cpRSA IppsRSAState; + +/* key types */ +typedef enum { + ippRSApublic = 0x20000000, IppRSApublic = 0x20000000, + ippRSAprivate = 0x40000000, IppRSAprivate = 0x40000000 +} IppRSAKeyType; + +/* key component's tag */ +typedef enum { + ippRSAkeyN = 0x01, IppRSAkeyN = 0x01, + ippRSAkeyE = 0x02, IppRSAkeyE = 0x02, + ippRSAkeyD = 0x04, IppRSAkeyD = 0x04, + ippRSAkeyP = 0x08, IppRSAkeyP = 0x08, + ippRSAkeyQ = 0x10, IppRSAkeyQ = 0x10, + ippRSAkeyDp = 0x20, IppRSAkeyDp = 0x20, + ippRSAkeyDq = 0x40, IppRSAkeyDq = 0x40, + ippRSAkeyQinv = 0x80, IppRSAkeyQinv = 0x80 +} IppRSAKeyTag; + +typedef struct _cpRSA_public_key IppsRSAPublicKeyState; +typedef struct _cpRSA_private_key IppsRSAPrivateKeyState; + + +/* +// ========================================================= +// DL Cryptography +// ========================================================= +*/ +#define MIN_DLP_BITSIZE (512) +#define MIN_DLP_BITSIZER (160) + +#define MIN_DLPDH_BITSIZE (512) +#define MIN_DLPDH_BITSIZER (160) +#define DEF_DLPDH_BITSIZER (160) + +#define MIN_DLPDSA_BITSIZE (512) +#define MAX_DLPDSA_BITSIZE (1024) +#define MIN_DLPDSA_BITSIZER (160) +#define DEF_DLPDSA_BITSIZER (160) +#define MAX_DLPDSA_BITSIZER (160) +#define MIN_DLPDSA_SEEDSIZE (160) + +typedef struct _cpDLP IppsDLPState; + +/* domain parameter tags */ +typedef enum { + ippDLPkeyP = 0x01, IppDLPkeyP = 0x01, + ippDLPkeyR = 0x02, IppDLPkeyR = 0x02, + ippDLPkeyG = 0x04, IppDLPkeyG = 0x04 +} IppDLPKeyTag; + +typedef enum { + ippDLValid, /* validation pass successfully */ + + ippDLBaseIsEven, /* !(P is odd) */ + ippDLOrderIsEven, /* !(R is odd) */ + ippDLInvalidBaseRange, /* !(2^(L-1) < P < 2^L) */ + ippDLInvalidOrderRange, /* !(2^(M-1) < R < 2^M) */ + ippDLCompositeBase, + ippDLCompositeOrder, + ippDLInvalidCofactor, /* !( R|(P-1) ) */ + ippDLInvalidGenerator, /* !( G^R == 1 (mod P) ) */ + /* !(1 < G < (P-1)) */ + ippDLInvalidPrivateKey, /* !(1 < private < (R-1)) */ + ippDLInvalidPublicKey, /* !(1 < public <=(P-1)) */ + ippDLInvalidKeyPair, /* !(G^private == public */ + + ippDLInvalidSignature /* invalid signature */ +} IppDLResult; + +/* +// ========================================================= +// EC Cryptography +// ========================================================= +*/ +#define EC_GFP_MAXBITSIZE (1024) + +/* operation result */ +typedef enum { + ippECValid, /* validation pass successfully */ + + ippECCompositeBase, /* field based on composite */ + ippECComplicatedBase, /* number of non-zero terms in the polynomial (> PRIME_ARR_MAX) */ + ippECIsZeroDiscriminant,/* zero discriminant */ + ippECCompositeOrder, /* composite order of base point */ + ippECInvalidOrder, /* invalid base point order */ + ippECIsWeakMOV, /* weak Meneze-Okamoto-Vanstone reduction attack */ + ippECIsWeakSSSA, /* weak Semaev-Smart,Satoh-Araki reduction attack */ + ippECIsSupersingular, /* supersingular curve */ + + ippECInvalidPrivateKey, /* !(0 < Private < order) */ + ippECInvalidPublicKey, /* (order*PublicKey != Infinity) */ + ippECInvalidKeyPair, /* (Private*BasePoint != PublicKey) */ + + ippECPointOutOfGroup, /* out of group (order*P != Infinity) */ + ippECPointIsAtInfinite, /* point (P=(Px,Py)) at Infinity */ + ippECPointIsNotValid, /* point (P=(Px,Py)) out-of EC */ + + ippECPointIsEqual, /* compared points are equal */ + ippECPointIsNotEqual, /* compared points are different */ + + ippECInvalidSignature /* invalid signature */ +} IppECResult; + +/* domain parameter set/get flags */ +typedef enum { + ippECarbitrary =0x00000, IppECCArbitrary = 0x00000, /* arbitrary ECC */ + + ippECPstd = 0x10000, IppECCPStd = 0x10000, /* random (recommended) EC over FG(p): */ + ippECPstd112r1 = ippECPstd, IppECCPStd112r1 = IppECCPStd, /* secp112r1 curve */ + ippECPstd112r2 = ippECPstd+1, IppECCPStd112r2 = IppECCPStd+1, /* secp112r2 curve */ + ippECPstd128r1 = ippECPstd+2, IppECCPStd128r1 = IppECCPStd+2, /* secp128r1 curve */ + ippECPstd128r2 = ippECPstd+3, IppECCPStd128r2 = IppECCPStd+3, /* secp128r2 curve */ + ippECPstd160r1 = ippECPstd+4, IppECCPStd160r1 = IppECCPStd+4, /* secp160r1 curve */ + ippECPstd160r2 = ippECPstd+5, IppECCPStd160r2 = IppECCPStd+5, /* secp160r2 curve */ + ippECPstd192r1 = ippECPstd+6, IppECCPStd192r1 = IppECCPStd+6, /* secp192r1 curve */ + ippECPstd224r1 = ippECPstd+7, IppECCPStd224r1 = IppECCPStd+7, /* secp224r1 curve */ + ippECPstd256r1 = ippECPstd+8, IppECCPStd256r1 = IppECCPStd+8, /* secp256r1 curve */ + ippECPstd384r1 = ippECPstd+9, IppECCPStd384r1 = IppECCPStd+9, /* secp384r1 curve */ + ippECPstd521r1 = ippECPstd+10, IppECCPStd521r1 = IppECCPStd+10, /* secp521r1 curve */ + ippECPstdSM2 = ippECPstd+11, IppECCPStdSM2 = IppECCPStd+11, /* TMP SM2 curve */ + ippEC_TPM_SM2_P256= ippECPstd+11, + ippEC_TPM_BN_P256 = ippECPstd+12, /* TPM BN_P256 curve */ + + /* curves over binary finit fields are not supported in Intel(R) IPP 9.0 */ + IppECCBStd = 0x20000, /* random (recommended) EC over FG(2^m): */ + IppECCBStd113r1 = IppECCBStd, /* sect113r1 curve */ + IppECCBStd113r2 = IppECCBStd+1, /* sect113r2 curve */ + IppECCBStd131r1 = IppECCBStd+2, /* sect131r1 curve */ + IppECCBStd131r2 = IppECCBStd+3, /* sect131r2 curve */ + IppECCBStd163r1 = IppECCBStd+4, /* sect163r1 curve */ + IppECCBStd163r2 = IppECCBStd+5, /* sect163r2 curve */ + IppECCBStd193r1 = IppECCBStd+6, /* sect193r1 curve */ + IppECCBStd193r2 = IppECCBStd+7, /* sect193r2 curve */ + IppECCBStd233r1 = IppECCBStd+8, /* sect233r1 curve */ + IppECCBStd283r1 = IppECCBStd+9, /* sect283r1 curve */ + IppECCBStd409r1 = IppECCBStd+10, /* sect409r1 curve */ + IppECCBStd571r1 = IppECCBStd+11, /* sect571r1 curve */ + + IppECCKStd = 0x40000, /* Koblitz (recommended) EC over FG(2^m): */ + IppECCBStd163k1 = IppECCKStd, /* Koblitz 163 curve */ + IppECCBStd233k1 = IppECCKStd+1, /* Koblitz 233 curve */ + IppECCBStd239k1 = IppECCKStd+2, /* Koblitz 239 curve */ + IppECCBStd283k1 = IppECCKStd+3, /* Koblitz 283 curve */ + IppECCBStd409k1 = IppECCKStd+4, /* Koblitz 409 curve */ + IppECCBStd571k1 = IppECCKStd+5 /* Koblitz 571 curve */ +} IppsECType, IppECCType; + +/* +// GF over prime and its extension +*/ +#define IPP_MIN_GF_CHAR (3) /* min characteristic of GF */ + +#define IPP_MIN_GF_BITSIZE (2) /* min bitsize of element over prime GF */ +#define IPP_MAX_GF_BITSIZE (1024) /* max bitsize of element over prime GF */ + +#define IPP_MIN_GF_EXTDEG (2) /* min GF extension degree */ +#define IPP_MAX_GF_EXTDEG (8) /* max GF extension degree */ + +#define IPP_MAX_EXPONENT_NUM (6) /* max number of exponents, equals to LOG_CACHE_LINE_SIZE */ + +typedef struct _cpGFpMethod IppsGFpMethod; + +typedef struct _cpGFp IppsGFpState; +typedef struct _cpGFpElement IppsGFpElement; + +typedef struct _cpGFpEC IppsGFpECState; +typedef struct _cpGFpECPoint IppsGFpECPoint; + +typedef struct _cpGFpEC IppsECCPState; +typedef struct _cpGFpECPoint IppsECCPPointState; + +typedef struct { + const IppsGFpState* pBasicGF; + const IppsGFpState* pGroundGF; + int basicGFdegree; + int groundGFdegree; + int elementLen; +} IppsGFpInfo; + +#endif /* _OWN_BLDPCS */ +#ifndef _PCS +IPPAPI( IppStatus, ippcpSetNumThreads, ( int numThr )) +IPPAPI( IppStatus, ippcpGetNumThreads, (int* pNumThr) ) +IPPAPI( IppStatus, ippcpGetCpuFeatures, ( Ipp64u* pFeaturesMask )) +IPPAPI( IppStatus, ippcpSetCpuFeatures, ( Ipp64u features )) +IPPAPI( Ipp64u, ippcpGetEnabledCpuFeatures, ( void ) ) +IPPAPI( IppStatus, ippcpInit,( void )) +IPPAPI( const char*, ippcpGetStatusString, ( IppStatus StsCode )) +IPPAPI( int, ippcpGetEnabledNumThreads, ( void ) ) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* IPPCPDEFS_H__ */ diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ippdefs.h b/external/epid-sdk/ext/ipp/include/ippdefs.h similarity index 77% rename from external/epid-sdk-3.0.0/ext/ipp/include/ippdefs.h rename to external/epid-sdk/ext/ipp/include/ippdefs.h index f3b52487..7a3529f5 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ippdefs.h +++ b/external/epid-sdk/ext/ipp/include/ippdefs.h @@ -1,18 +1,25 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ +/* +// Copyright 1999 2016 Intel Corporation All Rights Reserved. +// +// The source code, information and material ("Material") contained herein is +// owned by Intel Corporation or its suppliers or licensors, and title +// to such Material remains with Intel Corporation or its suppliers or +// licensors. The Material contains proprietary information of Intel +// or its suppliers and licensors. The Material is protected by worldwide +// copyright laws and treaty provisions. No part of the Material may be used, +// copied, reproduced, modified, published, uploaded, posted, transmitted, +// distributed or disclosed in any way without Intel's prior express written +// permission. No license under any patent, copyright or other intellectual +// property rights in the Material is granted to or conferred upon you, +// either expressly, by implication, inducement, estoppel or otherwise. +// Any license under such intellectual property rights must be express and +// approved by Intel in writing. +// +// Unless otherwise agreed by Intel in writing, +// you may not remove or alter this notice or any other notice embedded in +// Materials by Intel or Intel's suppliers or licensors in any way. +// +*/ /* // Intel(R) Integrated Performance Primitives @@ -30,10 +37,6 @@ extern "C" { #endif -#if defined( _IPP_PARALLEL_STATIC ) || defined( _IPP_PARALLEL_DYNAMIC ) - #pragma message("Threaded versions of IPP libraries are deprecated and will be removed in one of the future IPP releases. Use the following link for details: https://software.intel.com/sites/products/ipp-deprecated-features-feedback/") -#endif - #if defined (_WIN64) #define _INTEL_PLATFORM "intel64/" #elif defined (_WIN32) @@ -107,9 +110,6 @@ extern "C" { #if !defined( _IPP_NO_DEFAULT_LIB ) #if defined( _IPP_PARALLEL_STATIC ) - #pragma comment( lib, "libircmt" ) - #pragma comment( lib, "libmmt" ) - #pragma comment( lib, "svml_dispmt" ) #pragma comment( lib, "libiomp5md" ) #endif #endif diff --git a/external/epid-sdk-3.0.0/ext/ipp/include/ipptypes.h b/external/epid-sdk/ext/ipp/include/ipptypes.h similarity index 97% rename from external/epid-sdk-3.0.0/ext/ipp/include/ipptypes.h rename to external/epid-sdk/ext/ipp/include/ipptypes.h index 3f6961f5..6000064d 100644 --- a/external/epid-sdk-3.0.0/ext/ipp/include/ipptypes.h +++ b/external/epid-sdk/ext/ipp/include/ipptypes.h @@ -1,18 +1,25 @@ -/*############################################################################ - # Copyright 2016 Intel Corporation - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ############################################################################*/ +/* +// Copyright 1999 2016 Intel Corporation All Rights Reserved. +// +// The source code, information and material ("Material") contained herein is +// owned by Intel Corporation or its suppliers or licensors, and title +// to such Material remains with Intel Corporation or its suppliers or +// licensors. The Material contains proprietary information of Intel +// or its suppliers and licensors. The Material is protected by worldwide +// copyright laws and treaty provisions. No part of the Material may be used, +// copied, reproduced, modified, published, uploaded, posted, transmitted, +// distributed or disclosed in any way without Intel's prior express written +// permission. No license under any patent, copyright or other intellectual +// property rights in the Material is granted to or conferred upon you, +// either expressly, by implication, inducement, estoppel or otherwise. +// Any license under such intellectual property rights must be express and +// approved by Intel in writing. +// +// Unless otherwise agreed by Intel in writing, +// you may not remove or alter this notice or any other notice embedded in +// Materials by Intel or Intel's suppliers or licensors in any way. +// +*/ /* // Intel(R) Integrated Performance Primitives @@ -82,7 +89,6 @@ extern "C" { /*****************************************************************************/ /* Below are ippSP domain specific definitions */ /*****************************************************************************/ - typedef enum { ippRndZero, ippRndNear, @@ -789,6 +795,7 @@ typedef enum { ippStsCpuNotSupportedErr = -9998,/* The target CPU is not supported. */ ippStsInplaceModeNotSupportedErr = -9997,/* The inplace operation is currently not supported. */ + ippStsIIRIIRLengthErr = -234, /* Vector length for IIRIIR function is less than 3*(IIR order) */ ippStsWarpTransformTypeErr = -233, /* The warp transform type is illegal */ ippStsExceededSizeErr = -232, /* Requested size exceeded the maximum supported ROI size */ ippStsWarpDirectionErr = -231, /* The warp transform direction is illegal */ diff --git a/external/epid-sdk/ext/ipp/include/sgx_ippcp.h b/external/epid-sdk/ext/ipp/include/sgx_ippcp.h new file mode 100644 index 00000000..022cf2cd --- /dev/null +++ b/external/epid-sdk/ext/ipp/include/sgx_ippcp.h @@ -0,0 +1,534 @@ +/* + * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _SGX_IPPCP_H_ +#define _SGX_IPPCP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + + #define ippcpGetLibVersion sgx_disp_ippcpGetLibVersion + #define ippsDESGetSize sgx_disp_ippsDESGetSize + #define ippsDESInit sgx_disp_ippsDESInit + #define ippsDESPack sgx_disp_ippsDESPack + #define ippsDESUnpack sgx_disp_ippsDESUnpack + #define ippsTDESEncryptECB sgx_disp_ippsTDESEncryptECB + #define ippsTDESDecryptECB sgx_disp_ippsTDESDecryptECB + #define ippsTDESEncryptCBC sgx_disp_ippsTDESEncryptCBC + #define ippsTDESDecryptCBC sgx_disp_ippsTDESDecryptCBC + #define ippsTDESEncryptCFB sgx_disp_ippsTDESEncryptCFB + #define ippsTDESDecryptCFB sgx_disp_ippsTDESDecryptCFB + #define ippsTDESEncryptOFB sgx_disp_ippsTDESEncryptOFB + #define ippsTDESDecryptOFB sgx_disp_ippsTDESDecryptOFB + #define ippsTDESEncryptCTR sgx_disp_ippsTDESEncryptCTR + #define ippsTDESDecryptCTR sgx_disp_ippsTDESDecryptCTR + #define ippsAESGetSize sgx_disp_ippsAESGetSize + #define ippsAESInit sgx_disp_ippsAESInit + #define ippsAESSetKey sgx_disp_ippsAESSetKey + #define ippsAESPack sgx_disp_ippsAESPack + #define ippsAESUnpack sgx_disp_ippsAESUnpack + #define ippsAESEncryptECB sgx_disp_ippsAESEncryptECB + #define ippsAESDecryptECB sgx_disp_ippsAESDecryptECB + #define ippsAESEncryptCBC sgx_disp_ippsAESEncryptCBC + #define ippsAESEncryptCBC_CS1 sgx_disp_ippsAESEncryptCBC_CS1 + #define ippsAESEncryptCBC_CS2 sgx_disp_ippsAESEncryptCBC_CS2 + #define ippsAESEncryptCBC_CS3 sgx_disp_ippsAESEncryptCBC_CS3 + #define ippsAESDecryptCBC sgx_disp_ippsAESDecryptCBC + #define ippsAESDecryptCBC_CS1 sgx_disp_ippsAESDecryptCBC_CS1 + #define ippsAESDecryptCBC_CS2 sgx_disp_ippsAESDecryptCBC_CS2 + #define ippsAESDecryptCBC_CS3 sgx_disp_ippsAESDecryptCBC_CS3 + #define ippsAESEncryptCFB sgx_disp_ippsAESEncryptCFB + #define ippsAESDecryptCFB sgx_disp_ippsAESDecryptCFB + #define ippsAESEncryptOFB sgx_disp_ippsAESEncryptOFB + #define ippsAESDecryptOFB sgx_disp_ippsAESDecryptOFB + #define ippsAESEncryptCTR sgx_disp_ippsAESEncryptCTR + #define ippsAESDecryptCTR sgx_disp_ippsAESDecryptCTR + #define ippsAESEncryptXTS_Direct sgx_disp_ippsAESEncryptXTS_Direct + #define ippsAESDecryptXTS_Direct sgx_disp_ippsAESDecryptXTS_Direct + #define ippsSMS4GetSize sgx_disp_ippsSMS4GetSize + #define ippsSMS4Init sgx_disp_ippsSMS4Init + #define ippsSMS4SetKey sgx_disp_ippsSMS4SetKey + #define ippsSMS4EncryptECB sgx_disp_ippsSMS4EncryptECB + #define ippsSMS4DecryptECB sgx_disp_ippsSMS4DecryptECB + #define ippsSMS4EncryptCBC sgx_disp_ippsSMS4EncryptCBC + #define ippsSMS4EncryptCBC_CS1 sgx_disp_ippsSMS4EncryptCBC_CS1 + #define ippsSMS4EncryptCBC_CS2 sgx_disp_ippsSMS4EncryptCBC_CS2 + #define ippsSMS4EncryptCBC_CS3 sgx_disp_ippsSMS4EncryptCBC_CS3 + #define ippsSMS4DecryptCBC sgx_disp_ippsSMS4DecryptCBC + #define ippsSMS4DecryptCBC_CS1 sgx_disp_ippsSMS4DecryptCBC_CS1 + #define ippsSMS4DecryptCBC_CS2 sgx_disp_ippsSMS4DecryptCBC_CS2 + #define ippsSMS4DecryptCBC_CS3 sgx_disp_ippsSMS4DecryptCBC_CS3 + #define ippsSMS4EncryptCFB sgx_disp_ippsSMS4EncryptCFB + #define ippsSMS4DecryptCFB sgx_disp_ippsSMS4DecryptCFB + #define ippsSMS4EncryptOFB sgx_disp_ippsSMS4EncryptOFB + #define ippsSMS4DecryptOFB sgx_disp_ippsSMS4DecryptOFB + #define ippsSMS4EncryptCTR sgx_disp_ippsSMS4EncryptCTR + #define ippsSMS4DecryptCTR sgx_disp_ippsSMS4DecryptCTR + #define ippsSMS4_CCMGetSize sgx_disp_ippsSMS4_CCMGetSize + #define ippsSMS4_CCMInit sgx_disp_ippsSMS4_CCMInit + #define ippsSMS4_CCMMessageLen sgx_disp_ippsSMS4_CCMMessageLen + #define ippsSMS4_CCMTagLen sgx_disp_ippsSMS4_CCMTagLen + #define ippsSMS4_CCMStart sgx_disp_ippsSMS4_CCMStart + #define ippsSMS4_CCMEncrypt sgx_disp_ippsSMS4_CCMEncrypt + #define ippsSMS4_CCMDecrypt sgx_disp_ippsSMS4_CCMDecrypt + #define ippsSMS4_CCMGetTag sgx_disp_ippsSMS4_CCMGetTag + #define ippsAES_CCMGetSize sgx_disp_ippsAES_CCMGetSize + #define ippsAES_CCMInit sgx_disp_ippsAES_CCMInit + #define ippsAES_CCMMessageLen sgx_disp_ippsAES_CCMMessageLen + #define ippsAES_CCMTagLen sgx_disp_ippsAES_CCMTagLen + #define ippsAES_CCMStart sgx_disp_ippsAES_CCMStart + #define ippsAES_CCMEncrypt sgx_disp_ippsAES_CCMEncrypt + #define ippsAES_CCMDecrypt sgx_disp_ippsAES_CCMDecrypt + #define ippsAES_CCMGetTag sgx_disp_ippsAES_CCMGetTag + #define ippsAES_GCMGetSize sgx_disp_ippsAES_GCMGetSize + #define ippsAES_GCMInit sgx_disp_ippsAES_GCMInit + #define ippsAES_GCMReset sgx_disp_ippsAES_GCMReset + #define ippsAES_GCMProcessIV sgx_disp_ippsAES_GCMProcessIV + #define ippsAES_GCMProcessAAD sgx_disp_ippsAES_GCMProcessAAD + #define ippsAES_GCMStart sgx_disp_ippsAES_GCMStart + #define ippsAES_GCMEncrypt sgx_disp_ippsAES_GCMEncrypt + #define ippsAES_GCMDecrypt sgx_disp_ippsAES_GCMDecrypt + #define ippsAES_GCMGetTag sgx_disp_ippsAES_GCMGetTag + #define ippsAES_XTSGetSize sgx_disp_ippsAES_XTSGetSize + #define ippsAES_XTSInit sgx_disp_ippsAES_XTSInit + #define ippsAES_XTSEncrypt sgx_disp_ippsAES_XTSEncrypt + #define ippsAES_XTSDecrypt sgx_disp_ippsAES_XTSDecrypt + #define ippsAES_S2V_CMAC sgx_disp_ippsAES_S2V_CMAC + #define ippsAES_SIVEncrypt sgx_disp_ippsAES_SIVEncrypt + #define ippsAES_SIVDecrypt sgx_disp_ippsAES_SIVDecrypt + #define ippsAES_CMACGetSize sgx_disp_ippsAES_CMACGetSize + #define ippsAES_CMACInit sgx_disp_ippsAES_CMACInit + #define ippsAES_CMACUpdate sgx_disp_ippsAES_CMACUpdate + #define ippsAES_CMACFinal sgx_disp_ippsAES_CMACFinal + #define ippsAES_CMACGetTag sgx_disp_ippsAES_CMACGetTag + #define ippsARCFourCheckKey sgx_disp_ippsARCFourCheckKey + #define ippsARCFourGetSize sgx_disp_ippsARCFourGetSize + #define ippsARCFourInit sgx_disp_ippsARCFourInit + #define ippsARCFourReset sgx_disp_ippsARCFourReset + #define ippsARCFourPack sgx_disp_ippsARCFourPack + #define ippsARCFourUnpack sgx_disp_ippsARCFourUnpack + #define ippsARCFourEncrypt sgx_disp_ippsARCFourEncrypt + #define ippsARCFourDecrypt sgx_disp_ippsARCFourDecrypt + #define ippsSHA1GetSize sgx_disp_ippsSHA1GetSize + #define ippsSHA1Init sgx_disp_ippsSHA1Init + #define ippsSHA1Duplicate sgx_disp_ippsSHA1Duplicate + #define ippsSHA1Pack sgx_disp_ippsSHA1Pack + #define ippsSHA1Unpack sgx_disp_ippsSHA1Unpack + #define ippsSHA1Update sgx_disp_ippsSHA1Update + #define ippsSHA1GetTag sgx_disp_ippsSHA1GetTag + #define ippsSHA1Final sgx_disp_ippsSHA1Final + #define ippsSHA1MessageDigest sgx_disp_ippsSHA1MessageDigest + #define ippsSHA224GetSize sgx_disp_ippsSHA224GetSize + #define ippsSHA224Init sgx_disp_ippsSHA224Init + #define ippsSHA224Duplicate sgx_disp_ippsSHA224Duplicate + #define ippsSHA224Pack sgx_disp_ippsSHA224Pack + #define ippsSHA224Unpack sgx_disp_ippsSHA224Unpack + #define ippsSHA224Update sgx_disp_ippsSHA224Update + #define ippsSHA224GetTag sgx_disp_ippsSHA224GetTag + #define ippsSHA224Final sgx_disp_ippsSHA224Final + #define ippsSHA224MessageDigest sgx_disp_ippsSHA224MessageDigest + #define ippsSHA256GetSize sgx_disp_ippsSHA256GetSize + #define ippsSHA256Init sgx_disp_ippsSHA256Init + #define ippsSHA256Duplicate sgx_disp_ippsSHA256Duplicate + #define ippsSHA256Pack sgx_disp_ippsSHA256Pack + #define ippsSHA256Unpack sgx_disp_ippsSHA256Unpack + #define ippsSHA256Update sgx_disp_ippsSHA256Update + #define ippsSHA256GetTag sgx_disp_ippsSHA256GetTag + #define ippsSHA256Final sgx_disp_ippsSHA256Final + #define ippsSHA256MessageDigest sgx_disp_ippsSHA256MessageDigest + #define ippsSHA384GetSize sgx_disp_ippsSHA384GetSize + #define ippsSHA384Init sgx_disp_ippsSHA384Init + #define ippsSHA384Duplicate sgx_disp_ippsSHA384Duplicate + #define ippsSHA384Pack sgx_disp_ippsSHA384Pack + #define ippsSHA384Unpack sgx_disp_ippsSHA384Unpack + #define ippsSHA384Update sgx_disp_ippsSHA384Update + #define ippsSHA384GetTag sgx_disp_ippsSHA384GetTag + #define ippsSHA384Final sgx_disp_ippsSHA384Final + #define ippsSHA384MessageDigest sgx_disp_ippsSHA384MessageDigest + #define ippsSHA512GetSize sgx_disp_ippsSHA512GetSize + #define ippsSHA512Init sgx_disp_ippsSHA512Init + #define ippsSHA512Duplicate sgx_disp_ippsSHA512Duplicate + #define ippsSHA512Pack sgx_disp_ippsSHA512Pack + #define ippsSHA512Unpack sgx_disp_ippsSHA512Unpack + #define ippsSHA512Update sgx_disp_ippsSHA512Update + #define ippsSHA512GetTag sgx_disp_ippsSHA512GetTag + #define ippsSHA512Final sgx_disp_ippsSHA512Final + #define ippsSHA512MessageDigest sgx_disp_ippsSHA512MessageDigest + #define ippsMD5GetSize sgx_disp_ippsMD5GetSize + #define ippsMD5Init sgx_disp_ippsMD5Init + #define ippsMD5Duplicate sgx_disp_ippsMD5Duplicate + #define ippsMD5Pack sgx_disp_ippsMD5Pack + #define ippsMD5Unpack sgx_disp_ippsMD5Unpack + #define ippsMD5Update sgx_disp_ippsMD5Update + #define ippsMD5GetTag sgx_disp_ippsMD5GetTag + #define ippsMD5Final sgx_disp_ippsMD5Final + #define ippsMD5MessageDigest sgx_disp_ippsMD5MessageDigest + #define ippsSM3GetSize sgx_disp_ippsSM3GetSize + #define ippsSM3Init sgx_disp_ippsSM3Init + #define ippsSM3Duplicate sgx_disp_ippsSM3Duplicate + #define ippsSM3Pack sgx_disp_ippsSM3Pack + #define ippsSM3Unpack sgx_disp_ippsSM3Unpack + #define ippsSM3Update sgx_disp_ippsSM3Update + #define ippsSM3GetTag sgx_disp_ippsSM3GetTag + #define ippsSM3Final sgx_disp_ippsSM3Final + #define ippsSM3MessageDigest sgx_disp_ippsSM3MessageDigest + #define ippsHashGetSize sgx_disp_ippsHashGetSize + #define ippsHashInit sgx_disp_ippsHashInit + #define ippsHashPack sgx_disp_ippsHashPack + #define ippsHashUnpack sgx_disp_ippsHashUnpack + #define ippsHashDuplicate sgx_disp_ippsHashDuplicate + #define ippsHashUpdate sgx_disp_ippsHashUpdate + #define ippsHashGetTag sgx_disp_ippsHashGetTag + #define ippsHashFinal sgx_disp_ippsHashFinal + #define ippsHashMessage sgx_disp_ippsHashMessage + #define ippsHashMethod_MD5 sgx_disp_ippsHashMethod_MD5 + #define ippsHashMethod_SM3 sgx_disp_ippsHashMethod_SM3 + #define ippsHashMethod_SHA1 sgx_disp_ippsHashMethod_SHA1 + #define ippsHashMethod_SHA1_NI sgx_disp_ippsHashMethod_SHA1_NI + #define ippsHashMethod_SHA1_TT sgx_disp_ippsHashMethod_SHA1_TT + #define ippsHashMethod_SHA256 sgx_disp_ippsHashMethod_SHA256 + #define ippsHashMethod_SHA256_NI sgx_disp_ippsHashMethod_SHA256_NI + #define ippsHashMethod_SHA256_TT sgx_disp_ippsHashMethod_SHA256_TT + #define ippsHashMethod_SHA224 sgx_disp_ippsHashMethod_SHA224 + #define ippsHashMethod_SHA224_NI sgx_disp_ippsHashMethod_SHA224_NI + #define ippsHashMethod_SHA224_TT sgx_disp_ippsHashMethod_SHA224_TT + #define ippsHashMethod_SHA512 sgx_disp_ippsHashMethod_SHA512 + #define ippsHashMethod_SHA384 sgx_disp_ippsHashMethod_SHA384 + #define ippsHashMethod_SHA512_256 sgx_disp_ippsHashMethod_SHA512_256 + #define ippsHashMethod_SHA512_224 sgx_disp_ippsHashMethod_SHA512_224 + #define ippsHashGetSize_rmf sgx_disp_ippsHashGetSize_rmf + #define ippsHashInit_rmf sgx_disp_ippsHashInit_rmf + #define ippsHashPack_rmf sgx_disp_ippsHashPack_rmf + #define ippsHashUnpack_rmf sgx_disp_ippsHashUnpack_rmf + #define ippsHashDuplicate_rmf sgx_disp_ippsHashDuplicate_rmf + #define ippsHashUpdate_rmf sgx_disp_ippsHashUpdate_rmf + #define ippsHashGetTag_rmf sgx_disp_ippsHashGetTag_rmf + #define ippsHashFinal_rmf sgx_disp_ippsHashFinal_rmf + #define ippsHashMessage_rmf sgx_disp_ippsHashMessage_rmf + #define ippsMGF sgx_disp_ippsMGF + #define ippsMGF1_rmf sgx_disp_ippsMGF1_rmf + #define ippsMGF2_rmf sgx_disp_ippsMGF2_rmf + #define ippsHMAC_GetSize sgx_disp_ippsHMAC_GetSize + #define ippsHMAC_Init sgx_disp_ippsHMAC_Init + #define ippsHMAC_Pack sgx_disp_ippsHMAC_Pack + #define ippsHMAC_Unpack sgx_disp_ippsHMAC_Unpack + #define ippsHMAC_Duplicate sgx_disp_ippsHMAC_Duplicate + #define ippsHMAC_Update sgx_disp_ippsHMAC_Update + #define ippsHMAC_Final sgx_disp_ippsHMAC_Final + #define ippsHMAC_GetTag sgx_disp_ippsHMAC_GetTag + #define ippsHMAC_Message sgx_disp_ippsHMAC_Message + #define ippsHMACGetSize_rmf sgx_disp_ippsHMACGetSize_rmf + #define ippsHMACInit_rmf sgx_disp_ippsHMACInit_rmf + #define ippsHMACPack_rmf sgx_disp_ippsHMACPack_rmf + #define ippsHMACUnpack_rmf sgx_disp_ippsHMACUnpack_rmf + #define ippsHMACDuplicate_rmf sgx_disp_ippsHMACDuplicate_rmf + #define ippsHMACUpdate_rmf sgx_disp_ippsHMACUpdate_rmf + #define ippsHMACFinal_rmf sgx_disp_ippsHMACFinal_rmf + #define ippsHMACGetTag_rmf sgx_disp_ippsHMACGetTag_rmf + #define ippsHMACMessage_rmf sgx_disp_ippsHMACMessage_rmf + #define ippsBigNumGetSize sgx_disp_ippsBigNumGetSize + #define ippsBigNumInit sgx_disp_ippsBigNumInit + #define ippsCmpZero_BN sgx_disp_ippsCmpZero_BN + #define ippsCmp_BN sgx_disp_ippsCmp_BN + #define ippsGetSize_BN sgx_disp_ippsGetSize_BN + #define ippsSet_BN sgx_disp_ippsSet_BN + #define ippsGet_BN sgx_disp_ippsGet_BN + #define ippsRef_BN sgx_disp_ippsRef_BN + #define ippsExtGet_BN sgx_disp_ippsExtGet_BN + #define ippsAdd_BN sgx_disp_ippsAdd_BN + #define ippsSub_BN sgx_disp_ippsSub_BN + #define ippsMul_BN sgx_disp_ippsMul_BN + #define ippsMAC_BN_I sgx_disp_ippsMAC_BN_I + #define ippsDiv_BN sgx_disp_ippsDiv_BN + #define ippsMod_BN sgx_disp_ippsMod_BN + #define ippsGcd_BN sgx_disp_ippsGcd_BN + #define ippsModInv_BN sgx_disp_ippsModInv_BN + #define ippsSetOctString_BN sgx_disp_ippsSetOctString_BN + #define ippsGetOctString_BN sgx_disp_ippsGetOctString_BN + #define ippsMontGetSize sgx_disp_ippsMontGetSize + #define ippsMontInit sgx_disp_ippsMontInit + #define ippsMontSet sgx_disp_ippsMontSet + #define ippsMontGet sgx_disp_ippsMontGet + #define ippsMontForm sgx_disp_ippsMontForm + #define ippsMontMul sgx_disp_ippsMontMul + #define ippsMontExp sgx_disp_ippsMontExp + #define ippsPRNGGetSize sgx_disp_ippsPRNGGetSize + #define ippsPRNGInit sgx_disp_ippsPRNGInit + #define ippsPRNGSetModulus sgx_disp_ippsPRNGSetModulus + #define ippsPRNGSetH0 sgx_disp_ippsPRNGSetH0 + #define ippsPRNGSetAugment sgx_disp_ippsPRNGSetAugment + #define ippsPRNGSetSeed sgx_disp_ippsPRNGSetSeed + #define ippsPRNGGetSeed sgx_disp_ippsPRNGGetSeed + #define ippsPRNGen sgx_disp_ippsPRNGen + #define ippsPRNGen_BN sgx_disp_ippsPRNGen_BN + #define ippsPRNGenRDRAND sgx_disp_ippsPRNGenRDRAND + #define ippsPRNGenRDRAND_BN sgx_disp_ippsPRNGenRDRAND_BN + #define ippsTRNGenRDSEED sgx_disp_ippsTRNGenRDSEED + #define ippsTRNGenRDSEED_BN sgx_disp_ippsTRNGenRDSEED_BN + #define ippsPrimeGetSize sgx_disp_ippsPrimeGetSize + #define ippsPrimeInit sgx_disp_ippsPrimeInit + #define ippsPrimeGen sgx_disp_ippsPrimeGen + #define ippsPrimeTest sgx_disp_ippsPrimeTest + #define ippsPrimeGen_BN sgx_disp_ippsPrimeGen_BN + #define ippsPrimeTest_BN sgx_disp_ippsPrimeTest_BN + #define ippsPrimeGet sgx_disp_ippsPrimeGet + #define ippsPrimeGet_BN sgx_disp_ippsPrimeGet_BN + #define ippsPrimeSet sgx_disp_ippsPrimeSet + #define ippsPrimeSet_BN sgx_disp_ippsPrimeSet_BN + #define ippsRSA_GetSizePublicKey sgx_disp_ippsRSA_GetSizePublicKey + #define ippsRSA_InitPublicKey sgx_disp_ippsRSA_InitPublicKey + #define ippsRSA_SetPublicKey sgx_disp_ippsRSA_SetPublicKey + #define ippsRSA_GetPublicKey sgx_disp_ippsRSA_GetPublicKey + #define ippsRSA_GetSizePrivateKeyType1 sgx_disp_ippsRSA_GetSizePrivateKeyType1 + #define ippsRSA_InitPrivateKeyType1 sgx_disp_ippsRSA_InitPrivateKeyType1 + #define ippsRSA_SetPrivateKeyType1 sgx_disp_ippsRSA_SetPrivateKeyType1 + #define ippsRSA_GetPrivateKeyType1 sgx_disp_ippsRSA_GetPrivateKeyType1 + #define ippsRSA_GetSizePrivateKeyType2 sgx_disp_ippsRSA_GetSizePrivateKeyType2 + #define ippsRSA_InitPrivateKeyType2 sgx_disp_ippsRSA_InitPrivateKeyType2 + #define ippsRSA_SetPrivateKeyType2 sgx_disp_ippsRSA_SetPrivateKeyType2 + #define ippsRSA_GetPrivateKeyType2 sgx_disp_ippsRSA_GetPrivateKeyType2 + #define ippsRSA_GetBufferSizePublicKey sgx_disp_ippsRSA_GetBufferSizePublicKey + #define ippsRSA_GetBufferSizePrivateKey sgx_disp_ippsRSA_GetBufferSizePrivateKey + #define ippsRSA_Encrypt sgx_disp_ippsRSA_Encrypt + #define ippsRSA_Decrypt sgx_disp_ippsRSA_Decrypt + #define ippsRSA_GenerateKeys sgx_disp_ippsRSA_GenerateKeys + #define ippsRSA_ValidateKeys sgx_disp_ippsRSA_ValidateKeys + #define ippsRSAEncrypt_OAEP sgx_disp_ippsRSAEncrypt_OAEP + #define ippsRSADecrypt_OAEP sgx_disp_ippsRSADecrypt_OAEP + #define ippsRSAEncrypt_OAEP_rmf sgx_disp_ippsRSAEncrypt_OAEP_rmf + #define ippsRSADecrypt_OAEP_rmf sgx_disp_ippsRSADecrypt_OAEP_rmf + #define ippsRSAEncrypt_PKCSv15 sgx_disp_ippsRSAEncrypt_PKCSv15 + #define ippsRSADecrypt_PKCSv15 sgx_disp_ippsRSADecrypt_PKCSv15 + #define ippsRSASign_PSS sgx_disp_ippsRSASign_PSS + #define ippsRSAVerify_PSS sgx_disp_ippsRSAVerify_PSS + #define ippsRSASign_PSS_rmf sgx_disp_ippsRSASign_PSS_rmf + #define ippsRSAVerify_PSS_rmf sgx_disp_ippsRSAVerify_PSS_rmf + #define ippsRSASign_PKCS1v15 sgx_disp_ippsRSASign_PKCS1v15 + #define ippsRSAVerify_PKCS1v15 sgx_disp_ippsRSAVerify_PKCS1v15 + #define ippsRSASign_PKCS1v15_rmf sgx_disp_ippsRSASign_PKCS1v15_rmf + #define ippsRSAVerify_PKCS1v15_rmf sgx_disp_ippsRSAVerify_PKCS1v15_rmf + #define ippsDLGetResultString sgx_disp_ippsDLGetResultString + #define ippsDLPGetSize sgx_disp_ippsDLPGetSize + #define ippsDLPInit sgx_disp_ippsDLPInit + #define ippsDLPPack sgx_disp_ippsDLPPack + #define ippsDLPUnpack sgx_disp_ippsDLPUnpack + #define ippsDLPSet sgx_disp_ippsDLPSet + #define ippsDLPGet sgx_disp_ippsDLPGet + #define ippsDLPSetDP sgx_disp_ippsDLPSetDP + #define ippsDLPGetDP sgx_disp_ippsDLPGetDP + #define ippsDLPGenKeyPair sgx_disp_ippsDLPGenKeyPair + #define ippsDLPPublicKey sgx_disp_ippsDLPPublicKey + #define ippsDLPValidateKeyPair sgx_disp_ippsDLPValidateKeyPair + #define ippsDLPSetKeyPair sgx_disp_ippsDLPSetKeyPair + #define ippsDLPSignDSA sgx_disp_ippsDLPSignDSA + #define ippsDLPVerifyDSA sgx_disp_ippsDLPVerifyDSA + #define ippsDLPSharedSecretDH sgx_disp_ippsDLPSharedSecretDH + #define ippsDLPGenerateDSA sgx_disp_ippsDLPGenerateDSA + #define ippsDLPValidateDSA sgx_disp_ippsDLPValidateDSA + #define ippsDLPGenerateDH sgx_disp_ippsDLPGenerateDH + #define ippsDLPValidateDH sgx_disp_ippsDLPValidateDH + #define ippsECCGetResultString sgx_disp_ippsECCGetResultString + #define ippsECCPGetSize sgx_disp_ippsECCPGetSize + #define ippsECCPGetSizeStd128r1 sgx_disp_ippsECCPGetSizeStd128r1 + #define ippsECCPGetSizeStd128r2 sgx_disp_ippsECCPGetSizeStd128r2 + #define ippsECCPGetSizeStd192r1 sgx_disp_ippsECCPGetSizeStd192r1 + #define ippsECCPGetSizeStd224r1 sgx_disp_ippsECCPGetSizeStd224r1 + #define ippsECCPGetSizeStd256r1 sgx_disp_ippsECCPGetSizeStd256r1 + #define ippsECCPGetSizeStd384r1 sgx_disp_ippsECCPGetSizeStd384r1 + #define ippsECCPGetSizeStd521r1 sgx_disp_ippsECCPGetSizeStd521r1 + #define ippsECCPGetSizeStdSM2 sgx_disp_ippsECCPGetSizeStdSM2 + #define ippsECCPInit sgx_disp_ippsECCPInit + #define ippsECCPInitStd128r1 sgx_disp_ippsECCPInitStd128r1 + #define ippsECCPInitStd128r2 sgx_disp_ippsECCPInitStd128r2 + #define ippsECCPInitStd192r1 sgx_disp_ippsECCPInitStd192r1 + #define ippsECCPInitStd224r1 sgx_disp_ippsECCPInitStd224r1 + #define ippsECCPInitStd256r1 sgx_disp_ippsECCPInitStd256r1 + #define ippsECCPInitStd384r1 sgx_disp_ippsECCPInitStd384r1 + #define ippsECCPInitStd521r1 sgx_disp_ippsECCPInitStd521r1 + #define ippsECCPInitStdSM2 sgx_disp_ippsECCPInitStdSM2 + #define ippsECCPSet sgx_disp_ippsECCPSet + #define ippsECCPSetStd sgx_disp_ippsECCPSetStd + #define ippsECCPSetStd128r1 sgx_disp_ippsECCPSetStd128r1 + #define ippsECCPSetStd128r2 sgx_disp_ippsECCPSetStd128r2 + #define ippsECCPSetStd192r1 sgx_disp_ippsECCPSetStd192r1 + #define ippsECCPSetStd224r1 sgx_disp_ippsECCPSetStd224r1 + #define ippsECCPSetStd256r1 sgx_disp_ippsECCPSetStd256r1 + #define ippsECCPSetStd384r1 sgx_disp_ippsECCPSetStd384r1 + #define ippsECCPSetStd521r1 sgx_disp_ippsECCPSetStd521r1 + #define ippsECCPSetStdSM2 sgx_disp_ippsECCPSetStdSM2 + #define ippsECCPBindGxyTblStd192r1 sgx_disp_ippsECCPBindGxyTblStd192r1 + #define ippsECCPBindGxyTblStd224r1 sgx_disp_ippsECCPBindGxyTblStd224r1 + #define ippsECCPBindGxyTblStd256r1 sgx_disp_ippsECCPBindGxyTblStd256r1 + #define ippsECCPBindGxyTblStd384r1 sgx_disp_ippsECCPBindGxyTblStd384r1 + #define ippsECCPBindGxyTblStd521r1 sgx_disp_ippsECCPBindGxyTblStd521r1 + #define ippsECCPBindGxyTblStdSM2 sgx_disp_ippsECCPBindGxyTblStdSM2 + #define ippsECCPGet sgx_disp_ippsECCPGet + #define ippsECCPGetOrderBitSize sgx_disp_ippsECCPGetOrderBitSize + #define ippsECCPValidate sgx_disp_ippsECCPValidate + #define ippsECCPPointGetSize sgx_disp_ippsECCPPointGetSize + #define ippsECCPPointInit sgx_disp_ippsECCPPointInit + #define ippsECCPSetPoint sgx_disp_ippsECCPSetPoint + #define ippsECCPSetPointAtInfinity sgx_disp_ippsECCPSetPointAtInfinity + #define ippsECCPGetPoint sgx_disp_ippsECCPGetPoint + #define ippsECCPCheckPoint sgx_disp_ippsECCPCheckPoint + #define ippsECCPComparePoint sgx_disp_ippsECCPComparePoint + #define ippsECCPNegativePoint sgx_disp_ippsECCPNegativePoint + #define ippsECCPAddPoint sgx_disp_ippsECCPAddPoint + #define ippsECCPMulPointScalar sgx_disp_ippsECCPMulPointScalar + #define ippsECCPGenKeyPair sgx_disp_ippsECCPGenKeyPair + #define ippsECCPPublicKey sgx_disp_ippsECCPPublicKey + #define ippsECCPValidateKeyPair sgx_disp_ippsECCPValidateKeyPair + #define ippsECCPSetKeyPair sgx_disp_ippsECCPSetKeyPair + #define ippsECCPSharedSecretDH sgx_disp_ippsECCPSharedSecretDH + #define ippsECCPSharedSecretDHC sgx_disp_ippsECCPSharedSecretDHC + #define ippsECCPSignDSA sgx_disp_ippsECCPSignDSA + #define ippsECCPVerifyDSA sgx_disp_ippsECCPVerifyDSA + #define ippsECCPSignNR sgx_disp_ippsECCPSignNR + #define ippsECCPVerifyNR sgx_disp_ippsECCPVerifyNR + #define ippsECCPSignSM2 sgx_disp_ippsECCPSignSM2 + #define ippsECCPVerifySM2 sgx_disp_ippsECCPVerifySM2 + #define ippsGFpGetSize sgx_disp_ippsGFpGetSize + #define ippsGFpInitArbitrary sgx_disp_ippsGFpInitArbitrary + #define ippsGFpInitFixed sgx_disp_ippsGFpInitFixed + #define ippsGFpInit sgx_disp_ippsGFpInit + #define ippsGFpMethod_p192r1 sgx_disp_ippsGFpMethod_p192r1 + #define ippsGFpMethod_p224r1 sgx_disp_ippsGFpMethod_p224r1 + #define ippsGFpMethod_p256r1 sgx_disp_ippsGFpMethod_p256r1 + #define ippsGFpMethod_p384r1 sgx_disp_ippsGFpMethod_p384r1 + #define ippsGFpMethod_p521r1 sgx_disp_ippsGFpMethod_p521r1 + #define ippsGFpMethod_p256sm2 sgx_disp_ippsGFpMethod_p256sm2 + #define ippsGFpMethod_p256bn sgx_disp_ippsGFpMethod_p256bn + #define ippsGFpMethod_p256 sgx_disp_ippsGFpMethod_p256 + #define ippsGFpMethod_pArb sgx_disp_ippsGFpMethod_pArb + #define ippsGFpxGetSize sgx_disp_ippsGFpxGetSize + #define ippsGFpxInit sgx_disp_ippsGFpxInit + #define ippsGFpxInitBinomial sgx_disp_ippsGFpxInitBinomial + #define ippsGFpxMethod_binom2_epid2 sgx_disp_ippsGFpxMethod_binom2_epid2 + #define ippsGFpxMethod_binom3_epid2 sgx_disp_ippsGFpxMethod_binom3_epid2 + #define ippsGFpxMethod_binom2 sgx_disp_ippsGFpxMethod_binom2 + #define ippsGFpxMethod_binom3 sgx_disp_ippsGFpxMethod_binom3 + #define ippsGFpxMethod_binom sgx_disp_ippsGFpxMethod_binom + #define ippsGFpxMethod_com sgx_disp_ippsGFpxMethod_com + #define ippsGFpScratchBufferSize sgx_disp_ippsGFpScratchBufferSize + #define ippsGFpElementGetSize sgx_disp_ippsGFpElementGetSize + #define ippsGFpElementInit sgx_disp_ippsGFpElementInit + #define ippsGFpSetElement sgx_disp_ippsGFpSetElement + #define ippsGFpSetElementRegular sgx_disp_ippsGFpSetElementRegular + #define ippsGFpSetElementOctString sgx_disp_ippsGFpSetElementOctString + #define ippsGFpSetElementRandom sgx_disp_ippsGFpSetElementRandom + #define ippsGFpSetElementHash sgx_disp_ippsGFpSetElementHash + #define ippsGFpSetElementHash_rmf sgx_disp_ippsGFpSetElementHash_rmf + #define ippsGFpCpyElement sgx_disp_ippsGFpCpyElement + #define ippsGFpGetElement sgx_disp_ippsGFpGetElement + #define ippsGFpGetElementOctString sgx_disp_ippsGFpGetElementOctString + #define ippsGFpCmpElement sgx_disp_ippsGFpCmpElement + #define ippsGFpIsZeroElement sgx_disp_ippsGFpIsZeroElement + #define ippsGFpIsUnityElement sgx_disp_ippsGFpIsUnityElement + #define ippsGFpConj sgx_disp_ippsGFpConj + #define ippsGFpNeg sgx_disp_ippsGFpNeg + #define ippsGFpInv sgx_disp_ippsGFpInv + #define ippsGFpSqrt sgx_disp_ippsGFpSqrt + #define ippsGFpSqr sgx_disp_ippsGFpSqr + #define ippsGFpAdd sgx_disp_ippsGFpAdd + #define ippsGFpSub sgx_disp_ippsGFpSub + #define ippsGFpMul sgx_disp_ippsGFpMul + #define ippsGFpExp sgx_disp_ippsGFpExp + #define ippsGFpMultiExp sgx_disp_ippsGFpMultiExp + #define ippsGFpAdd_PE sgx_disp_ippsGFpAdd_PE + #define ippsGFpSub_PE sgx_disp_ippsGFpSub_PE + #define ippsGFpMul_PE sgx_disp_ippsGFpMul_PE + #define ippsGFpECGetSize sgx_disp_ippsGFpECGetSize + #define ippsGFpECInit sgx_disp_ippsGFpECInit + #define ippsGFpECSet sgx_disp_ippsGFpECSet + #define ippsGFpECSetSubgroup sgx_disp_ippsGFpECSetSubgroup + #define ippsGFpECInitStd128r1 sgx_disp_ippsGFpECInitStd128r1 + #define ippsGFpECInitStd128r2 sgx_disp_ippsGFpECInitStd128r2 + #define ippsGFpECInitStd192r1 sgx_disp_ippsGFpECInitStd192r1 + #define ippsGFpECInitStd224r1 sgx_disp_ippsGFpECInitStd224r1 + #define ippsGFpECInitStd256r1 sgx_disp_ippsGFpECInitStd256r1 + #define ippsGFpECInitStd384r1 sgx_disp_ippsGFpECInitStd384r1 + #define ippsGFpECInitStd521r1 sgx_disp_ippsGFpECInitStd521r1 + #define ippsGFpECInitStdSM2 sgx_disp_ippsGFpECInitStdSM2 + #define ippsGFpECInitStdBN256 sgx_disp_ippsGFpECInitStdBN256 + #define ippsGFpECBindGxyTblStd192r1 sgx_disp_ippsGFpECBindGxyTblStd192r1 + #define ippsGFpECBindGxyTblStd224r1 sgx_disp_ippsGFpECBindGxyTblStd224r1 + #define ippsGFpECBindGxyTblStd256r1 sgx_disp_ippsGFpECBindGxyTblStd256r1 + #define ippsGFpECBindGxyTblStd384r1 sgx_disp_ippsGFpECBindGxyTblStd384r1 + #define ippsGFpECBindGxyTblStd521r1 sgx_disp_ippsGFpECBindGxyTblStd521r1 + #define ippsGFpECBindGxyTblStdSM2 sgx_disp_ippsGFpECBindGxyTblStdSM2 + #define ippsGFpECGet sgx_disp_ippsGFpECGet + #define ippsGFpECGetSubgroup sgx_disp_ippsGFpECGetSubgroup + #define ippsGFpECScratchBufferSize sgx_disp_ippsGFpECScratchBufferSize + #define ippsGFpECVerify sgx_disp_ippsGFpECVerify + #define ippsGFpECPointGetSize sgx_disp_ippsGFpECPointGetSize + #define ippsGFpECPointInit sgx_disp_ippsGFpECPointInit + #define ippsGFpECSetPointAtInfinity sgx_disp_ippsGFpECSetPointAtInfinity + #define ippsGFpECSetPoint sgx_disp_ippsGFpECSetPoint + #define ippsGFpECSetPointRegular sgx_disp_ippsGFpECSetPointRegular + #define ippsGFpECSetPointRandom sgx_disp_ippsGFpECSetPointRandom + #define ippsGFpECMakePoint sgx_disp_ippsGFpECMakePoint + #define ippsGFpECSetPointHash sgx_disp_ippsGFpECSetPointHash + #define ippsGFpECSetPointHash_rmf sgx_disp_ippsGFpECSetPointHash_rmf + #define ippsGFpECGetPoint sgx_disp_ippsGFpECGetPoint + #define ippsGFpECGetPointRegular sgx_disp_ippsGFpECGetPointRegular + #define ippsGFpECTstPoint sgx_disp_ippsGFpECTstPoint + #define ippsGFpECTstPointInSubgroup sgx_disp_ippsGFpECTstPointInSubgroup + #define ippsGFpECCpyPoint sgx_disp_ippsGFpECCpyPoint + #define ippsGFpECCmpPoint sgx_disp_ippsGFpECCmpPoint + #define ippsGFpECNegPoint sgx_disp_ippsGFpECNegPoint + #define ippsGFpECAddPoint sgx_disp_ippsGFpECAddPoint + #define ippsGFpECMulPoint sgx_disp_ippsGFpECMulPoint + #define ippsGFpECPrivateKey sgx_disp_ippsGFpECPrivateKey + #define ippsGFpECPublicKey sgx_disp_ippsGFpECPublicKey + #define ippsGFpECTstKeyPair sgx_disp_ippsGFpECTstKeyPair + #define ippsGFpECSharedSecretDH sgx_disp_ippsGFpECSharedSecretDH + #define ippsGFpECSharedSecretDHC sgx_disp_ippsGFpECSharedSecretDHC + #define ippsGFpECSignDSA sgx_disp_ippsGFpECSignDSA + #define ippsGFpECVerifyDSA sgx_disp_ippsGFpECVerifyDSA + #define ippsGFpECSignNR sgx_disp_ippsGFpECSignNR + #define ippsGFpECVerifyNR sgx_disp_ippsGFpECVerifyNR + #define ippsGFpECSignSM2 sgx_disp_ippsGFpECSignSM2 + #define ippsGFpECVerifySM2 sgx_disp_ippsGFpECVerifySM2 + +#ifdef __cplusplus +} +#endif +#endif diff --git a/external/sgxssl/prepare_sgxssl.sh b/external/sgxssl/prepare_sgxssl.sh index 230559a9..7d7c7d51 100755 --- a/external/sgxssl/prepare_sgxssl.sh +++ b/external/sgxssl/prepare_sgxssl.sh @@ -32,13 +32,14 @@ top_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" openssl_out_dir=$top_dir/openssl_source -openssl_ver_name=openssl-1.1.0f +openssl_ver_name=openssl-1.1.0h sgxssl_github_archive=https://github.com/01org/intel-sgx-ssl/archive -sgxssl_ver_name=sdk_2.0_integ -sgxssl_ver=sdk_2.0_integ +sgxssl_ver_name=sdk_2.1_integ +sgxssl_ver=sdk_2.1_integ build_script=$top_dir/Linux/build_sgxssl.sh -server_url_path=https://www.openssl.org/source/old/1.1.0 +server_url_path=https://www.openssl.org/source/ full_openssl_url=$server_url_path/$openssl_ver_name.tar.gz +full_openssl_url_old=$server_url_path/old/1.1.0/$openssl_ver_name.tar.gz if [ ! -f $build_script ]; then wget $sgxssl_github_archive/$sgxssl_ver_name.zip -P $top_dir --no-check-certificate || exit 1 @@ -49,7 +50,7 @@ if [ ! -f $build_script ]; then fi if [ ! -f $openssl_out_dir/$openssl_ver_name.tar.gz ]; then - wget $full_openssl_url -P $openssl_out_dir --no-check-certificate || exit 1 + wget $full_openssl_url_old -P $openssl_out_dir --no-check-certificate || wget $full_openssl_url -P $openssl_out_dir --no-check-certificate || exit 1 fi chmod +x $build_script $build_script no-clean linux-sgx || exit 1 diff --git a/external/sqlite/src/sqlite3.c b/external/sqlite/src/sqlite3.c index 320d6355..c49f89c9 100644 --- a/external/sqlite/src/sqlite3.c +++ b/external/sqlite/src/sqlite3.c @@ -1,6 +1,6 @@ /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite -** version 3.21.0. By combining all the individual C code files into this +** version 3.23.1. By combining all the individual C code files into this ** single large file, the entire code can be compiled as a single translation ** unit. This allows many compilers to do optimizations that would not be ** possible if the files were compiled separately. Performance improvements @@ -213,7 +213,7 @@ static const char * const sqlite3azCompileOpt[] = { "ENABLE_BATCH_ATOMIC_WRITE", #endif #if SQLITE_ENABLE_CEROD - "ENABLE_CEROD", + "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), #endif #if SQLITE_ENABLE_COLUMN_METADATA "ENABLE_COLUMN_METADATA", @@ -1147,9 +1147,9 @@ extern "C" { ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ -#define SQLITE_VERSION "3.21.0" -#define SQLITE_VERSION_NUMBER 3021000 -#define SQLITE_SOURCE_ID "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827" +#define SQLITE_VERSION "3.23.1" +#define SQLITE_VERSION_NUMBER 3023001 +#define SQLITE_SOURCE_ID "2018-04-10 17:39:29 4bb2294022060e61de7da5c227a69ccd846ba330e31626ebcd59a94efd148b3b" /* ** CAPI3REF: Run-Time Library Version Numbers @@ -1494,6 +1494,8 @@ SQLITE_API int sqlite3_exec( ** the most recent error can be obtained using ** [sqlite3_extended_errcode()]. */ +#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) +#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) @@ -1537,6 +1539,8 @@ SQLITE_API int sqlite3_exec( #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) +#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) +#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) @@ -2084,6 +2088,12 @@ struct sqlite3_io_methods { ** so that all subsequent write operations are independent. ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. +** +**
    • [[SQLITE_FCNTL_LOCK_TIMEOUT]] +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain +** a file lock using the xLock or xShmLock methods of the VFS to wait +** for up to M milliseconds before failing, where M is the single +** unsigned integer parameter. **